Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。
TypeScript agentai-agentai-assistantandroidclaude-codecodexelectroniosllmmacosreact-nativetypescriptwindows
fix(bots): match custom MCP availability to SSH Codex transport
zqchrise9a6baa1f8bd
diff --git a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.tsindex 75ed41e306..6feb8f96f6 100644--- a/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts+++ b/apps/desktop/src/main/localDb/ipc/__tests__/botCanonicalSession.test.ts@@ -424,8 +424,8 @@ async function invoke(channel: string, body: unknown): Promise<any> {const capabilityDeps = {getMaker, getPluginRegistry, isBotToolsetAvailable,resolveBotAgentKind: async (): Promise<AgentKind | null> => 'pi',- listMcpServers: async ({ agentKind }: { agentKind: AgentKind }) => buildBotMcpCatalog({- agentKind, providers: h.mcpProviders, builtinNames: getBuiltinMcpServerNames(),+ listMcpServers: async ({ agentKind, remoteHostId }: { agentKind: AgentKind; remoteHostId?: string }) => buildBotMcpCatalog({+ agentKind, remoteHostId, providers: h.mcpProviders, builtinNames: getBuiltinMcpServerNames(),customServers: h.customMcpConfigs.map((config) => ({ ...config, updatedAt: 1 })),}),};@@ -1997,6 +1997,41 @@ describe('Bot canonical Session lifecycle', () => {}});+ it('rejects unforwarded custom MCPs on SSH Codex while preserving saved references and supported routes', async () => {+ await invoke('local-db:bots:update', {+ id: 'bot-1', capabilities: { mcpServers: ['shared-docs'], mcpMode: 'allowlist' },+ });+ const created = await invoke('local-db:bots:create-canonical-session', {+ botId: 'bot-1', expectedCanonicalSessionId: null, expectedProfileVersion: 2,+ });+ h.sqlite!.prepare('UPDATE sessions SET remote_host_id = ? WHERE id = ?').run('ssh-host', created.session.id);+ const input = { callerSessionId: created.session.id, kind: 'mcp' as const, id: 'shared-docs' };+ for (const agentKind of ['codex', 'claude-code', 'pi'] as const) {+ const service = createBotCapabilityService({ ...capabilityDeps, resolveBotAgentKind: async () => agentKind });+ await expect(service.list(input)).resolves.toMatchObject({+ capabilities: [expect.objectContaining({ id: 'shared-docs', joined: true, available: agentKind !== 'codex' })],+ });+ const opts: MakerSessionCreateOpts = {+ id: created.session.id, agentKind, workingDir: '/srv/bot', remoteHostId: 'ssh-host',+ workspaceKind: 'project', model: 'test-model', permissionMode: 'auto',+ };+ const snapshot = await hydrateBotProfileRuntime(opts, { listMcpServers: capabilityDeps.listMcpServers });+ expect(snapshot).toMatchObject({+ configuredMcpServers: ['shared-docs'],+ resolvedMcpServers: agentKind === 'codex' ? [] : ['shared-docs'],+ unavailableMcpServers: agentKind === 'codex' ? ['shared-docs'] : [],+ });+ }+ const service = createBotCapabilityService({ ...capabilityDeps, resolveBotAgentKind: async () => 'codex' });+ h.validateCapabilityAdditions.mockImplementation(service.validateAdditions);+ await expect(service.select({ ...input, joined: false })).resolves.toMatchObject({ ok: true, joined: false });+ await expect(service.select({ ...input, joined: true })).resolves.toMatchObject({ ok: false, errorCode: 'CAPABILITY_UNAVAILABLE' });+ await expect(invoke('local-db:bots:update', { id: 'bot-1', capabilities: { mcpServers: ['shared-docs'] } }))+ .rejects.toMatchObject({ code: 'PRECONDITION_FAILED' });+ h.sqlite!.prepare('UPDATE sessions SET remote_host_id = NULL WHERE id = ?').run(created.session.id);+ await expect(service.select({ ...input, joined: true })).resolves.toMatchObject({ ok: true, joined: true });+ });+it.each(['contacts', 'lsp'])('rejects gated %s despite registry enablement and keeps joined references removable', async (id) => {const created = await invoke('local-db:bots:create-canonical-session', { botId: 'bot-1', expectedCanonicalSessionId: null, expectedProfileVersion: 1 });const input = { callerSessionId: created.session.id, kind: 'toolset' as const, id };diff --git a/apps/desktop/src/main/maker-host/botMcpCatalog.ts b/apps/desktop/src/main/maker-host/botMcpCatalog.tsindex c51476b1e0..055a092161 100644--- a/apps/desktop/src/main/maker-host/botMcpCatalog.ts+++ b/apps/desktop/src/main/maker-host/botMcpCatalog.ts@@ -5,6 +5,7 @@ import { isPiCustomMcpProviderAvailable } from '../mcp-integrations/piMcpTranspo/** Freeze only metadata; compatibility is recomputed for each actual start route. */export function buildBotMcpCatalog(input: {agentKind: McpProviderContext['agentKind'];+ remoteHostId?: string;providers: readonly McpProvider[];builtinNames: readonly string[];customServers: readonly { id: string; transport: McpTransport; updatedAt: number }[];@@ -16,9 +17,11 @@ export function buildBotMcpCatalog(input: {const custom = customServers.get(provider.name);// Evaluate registered user configs using Pi's actual serialization and URL gate.// Builtins retain their SDK bridge path and are not instantiated by catalog queries.- const available = builtin || (input.agentKind === 'pi' && custom- ? isPiCustomMcpProviderAvailable(provider)- : input.agentKind !== 'codex' || custom?.transport !== 'sse');+ // SSH Codex receives only the remote builtin allowlist; local custom configs+ // are not serialized into its daemon. Claude forwards them and Pi tunnels them.+ const available = builtin || (input.agentKind === 'codex'+ ? !input.remoteHostId && custom?.transport !== 'sse'+ : input.agentKind === 'pi' && custom ? isPiCustomMcpProviderAvailable(provider) : true);return [provider.name, {name: provider.name,source: builtin ? 'builtin' as const : 'custom' as const,diff --git a/apps/desktop/src/main/maker-host/index.ts b/apps/desktop/src/main/maker-host/index.tsindex 796ccb3412..0f3e20bc44 100644--- a/apps/desktop/src/main/maker-host/index.ts+++ b/apps/desktop/src/main/maker-host/index.ts@@ -742,9 +742,10 @@ export function isBotToolsetAvailable(input: BotToolsetContext & { toolsetId: st}/** Shared by Bot tools, settings and hydration; never infer registration from raw DB rows. */-export async function listBotRuntimeMcpServers({ agentKind }: { agentKind: AgentKind }) {+export async function listBotRuntimeMcpServers({ agentKind, remoteHostId }: { agentKind: AgentKind; remoteHostId?: string }) {return buildBotMcpCatalog({agentKind,+ remoteHostId,providers: _mcpProviders[agentKind] ?? [],builtinNames: getBuiltinMcpServerNames(),customServers: await listCustomMcpRuntimeGenerations(),diff --git a/apps/desktop/src/main/maker-ipc/__tests__/mcpHandlers.test.ts b/apps/desktop/src/main/maker-ipc/__tests__/mcpHandlers.test.tsindex 592c40d68b..4d4ce2f9bd 100644--- a/apps/desktop/src/main/maker-ipc/__tests__/mcpHandlers.test.ts+++ b/apps/desktop/src/main/maker-ipc/__tests__/mcpHandlers.test.ts@@ -10,7 +10,7 @@ import type { McpProvider } from '@cindy/maker-core';import type { DbClient } from '../../localDb/client/DbClient.js';import { clearCurrentDbClient, setCurrentDbClient } from '../../localDb/client/current.js';import * as schema from '../../localDb/schema.js';-import { listCustomMcpServers, listCustomMcpRuntimeGenerations } from '../../maker-host/custom-mcp-store.js';+import { createCustomMcpServer, listCustomMcpServers, listCustomMcpRuntimeGenerations } from '../../maker-host/custom-mcp-store.js';import { buildBotMcpCatalog } from '../../maker-host/botMcpCatalog.js';import {getBuiltinMcpServerNames,@@ -66,7 +66,7 @@ function mountDb(): void {function makeDeps(over: Partial<McpHandlerDeps> = {}): McpHandlerDeps {return {listMcpServers: vi.fn(async () => []),- resolveBotAgentKind: vi.fn(async () => 'claude-code' as const),+ resolveBotContext: vi.fn(async () => ({ agentKind: 'claude-code' as const })),refreshProviders: vi.fn(async () => {}),broadcastChanged: vi.fn(() => {}),invalidateCodex: vi.fn(async () => {}),@@ -131,12 +131,12 @@ describe('mcp:custom:* CRUD handlers', () => {mountDb();const harness = new IpcHarness();const chain = [{ harness: 'claude' as const, model: 'claude-x', providerId: null, effort: '', fastMode: false }];- const deps = makeDeps({ resolveBotAgentKind: vi.fn(async () => 'codex' as const) });+ const deps = makeDeps({ resolveBotContext: vi.fn(async () => ({ agentKind: 'codex' as const })) });registerMcpHandlers(harness, deps);expect(await harness.invoke(MAKER_INVOKE.MCP_CUSTOM_LIST, {agentKind: 'claude-code', botSessionId: 'canonical', modelChain: chain,})).toEqual({ agentKind: 'codex', servers: [] });- expect(deps.resolveBotAgentKind).toHaveBeenCalledWith('canonical', chain);+ expect(deps.resolveBotContext).toHaveBeenCalledWith('canonical', chain);expect(deps.listMcpServers).toHaveBeenCalledWith({ agentKind: 'codex' });expect(deps.refreshProviders).not.toHaveBeenCalled();});@@ -144,7 +144,7 @@ describe('mcp:custom:* CRUD handlers', () => {it('does not fall back to a renderer hint for a missing canonical task', async () => {mountDb();const harness = new IpcHarness();- const deps = makeDeps({ resolveBotAgentKind: vi.fn(async () => null) });+ const deps = makeDeps({ resolveBotContext: vi.fn(async () => null) });registerMcpHandlers(harness, deps);await expect(harness.invoke(MAKER_INVOKE.MCP_CUSTOM_LIST, {agentKind: 'claude-code', botSessionId: 'other-task',@@ -152,6 +152,28 @@ describe('mcp:custom:* CRUD handlers', () => {expect(deps.listMcpServers).not.toHaveBeenCalled();});+ it.each(['claude-code', 'codex', 'pi'] as const)('evaluates the trusted SSH target for %s capability settings', async (agentKind) => {+ mountDb();+ await createCustomMcpServer(validConfig);+ const providers: McpProvider[] = [];+ registerCustomMcpArrays(providers);+ await refreshCustomMcpProviders();+ const deps = makeDeps({+ resolveBotContext: vi.fn(async () => ({ agentKind, remoteHostId: 'ssh-host' })),+ listMcpServers: vi.fn(async (context) => buildBotMcpCatalog({+ ...context, providers, builtinNames: getBuiltinMcpServerNames(),+ customServers: await listCustomMcpRuntimeGenerations(),+ })),+ });+ const harness = new IpcHarness();+ registerMcpHandlers(harness, deps);+ const result = await harness.invoke(MAKER_INVOKE.MCP_CUSTOM_LIST, {+ agentKind: 'claude-code', botSessionId: 'canonical',+ });+ expect(deps.listMcpServers).toHaveBeenCalledWith({ agentKind, remoteHostId: 'ssh-host' });+ expect(result).toEqual({ agentKind, servers: [expect.objectContaining({ id: 'mytools', available: agentKind !== 'codex' })] });+ });+it.each([null, {}, { agentKind: 'unknown' },{ agentKind: 'codex', modelChain: [] },{ agentKind: 'codex', botSessionId: 'canonical', modelChain: [{ harness: 'unknown', model: 'x' }] },diff --git a/apps/desktop/src/main/maker-ipc/mcpHandlers.ts b/apps/desktop/src/main/maker-ipc/mcpHandlers.tsindex 8e57060e5f..d356397085 100644--- a/apps/desktop/src/main/maker-ipc/mcpHandlers.ts+++ b/apps/desktop/src/main/maker-ipc/mcpHandlers.ts@@ -30,8 +30,10 @@ import type { IpcHandlerRegistry } from './ipcHandlerRegistry.js';export interface McpHandlerDeps {/** Same registered runtime catalog used by Bot capability tools and hydration. */- listMcpServers(context: CustomMcpListContext): ReturnType<NonNullable<BotProfileRuntimeDeps['listMcpServers']>>;- resolveBotAgentKind(sessionId: string, chain?: BotModelRoute[]): Promise<CustomMcpListContext['agentKind'] | null>;+ listMcpServers(context: { agentKind: CustomMcpListContext['agentKind']; remoteHostId?: string }): ReturnType<NonNullable<BotProfileRuntimeDeps['listMcpServers']>>;+ resolveBotContext(sessionId: string, chain?: BotModelRoute[]): Promise<{+ agentKind: CustomMcpListContext['agentKind']; remoteHostId?: string;+ } | null>;/** CRUD 成功后刷新 agent mcpProviders 数组(生产 = refreshCustomMcpProviders)。 */refreshProviders(): Promise<void>;/** CRUD 成功后广播变更(生产 = 向所有窗口 send MCP_CHANGED)。 */@@ -71,12 +73,14 @@ export function registerMcpHandlers(registry: IpcHandlerRegistry, deps: McpHandlconst parsed = context === undefined ? undefined : listContextSchema.safeParse(context);if (parsed && !parsed.success) throwIpcError('INVALID_PARAMS', 'Invalid MCP catalog context');const input = parsed?.data;- const agentKind = input?.botSessionId- ? await deps.resolveBotAgentKind(input.botSessionId, input.modelChain) : input?.agentKind;- if (input?.botSessionId && !agentKind) throwIpcError('NOT_FOUND', 'Canonical Bot task not found');+ const runtime = input?.botSessionId+ ? await deps.resolveBotContext(input.botSessionId, input.modelChain)+ : input ? { agentKind: input.agentKind } : undefined;+ if (input?.botSessionId && !runtime) throwIpcError('NOT_FOUND', 'Canonical Bot task not found');const servers = await listCustomMcpServers();- if (!agentKind) return { servers };- const catalog = await deps.listMcpServers({ agentKind });+ if (!runtime) return { servers };+ const { agentKind } = runtime;+ const catalog = await deps.listMcpServers(runtime);const available = new Set(catalog.filter((entry) => entry.source === 'custom' && entry.available !== false).map((entry) => entry.name));diff --git a/apps/desktop/src/main/maker-ipc/register.ts b/apps/desktop/src/main/maker-ipc/register.tsindex 37ce6c5526..791bbaf183 100644--- a/apps/desktop/src/main/maker-ipc/register.ts+++ b/apps/desktop/src/main/maker-ipc/register.ts@@ -5505,8 +5505,12 @@ export function registerMakerIpc(maker: Maker, options: RegisterMakerIpcOptions)// (下次新建会话生效)并广播 MCP_CHANGED 让设置页列表 live 刷新。registerMcpHandlers(createElectronIpcHandlerRegistry(), {listMcpServers: listBotRuntimeMcpServers,- resolveBotAgentKind: async (sessionId, chain) =>- (await reconcileBotModelRoute.preview(sessionId, chain))?.agentKind ?? null,+ resolveBotContext: async (sessionId, chain) => {+ const route = await reconcileBotModelRoute.preview(sessionId, chain);+ if (!route) return null;+ const meta = await maker.getSessionMeta(sessionId);+ return meta ? { agentKind: route.agentKind, remoteHostId: meta.remoteHostId } : null;+ },refreshProviders: () => refreshCustomMcpProviders(),broadcastChanged: () => broadcastToAllWindows(MAKER_PUSH.MCP_CHANGED, {}),// 内置 server 名对自定义 MCP 是保留名:撞名会在装配层顶替内置 server 并继承