diff --git a/src/mcp/index.test.ts b/src/mcp/index.test.ts index cf6499e3..178caf19 100644 --- a/src/mcp/index.test.ts +++ b/src/mcp/index.test.ts @@ -83,4 +83,22 @@ describe("createBuiltinMcps", () => { expect(result).toHaveProperty("grep_app") expect(Object.keys(result)).toHaveLength(3) }) + + test("should not throw when websearch disabled even if tavily configured without API key", () => { + // given + const originalTavilyKey = process.env.TAVILY_API_KEY + delete process.env.TAVILY_API_KEY + const disabledMcps = ["websearch"] + const config = { websearch: { provider: "tavily" as const } } + + // when + const createMcps = () => createBuiltinMcps(disabledMcps, config) + + // then + expect(createMcps).not.toThrow() + const result = createMcps() + expect(result).not.toHaveProperty("websearch") + + if (originalTavilyKey) process.env.TAVILY_API_KEY = originalTavilyKey + }) }) diff --git a/src/mcp/index.ts b/src/mcp/index.ts index 1adeff00..b8cf31df 100644 --- a/src/mcp/index.ts +++ b/src/mcp/index.ts @@ -15,18 +15,18 @@ type RemoteMcpConfig = { } export function createBuiltinMcps(disabledMcps: string[] = [], config?: OhMyOpenCodeConfig) { - const allBuiltinMcps: Record = { - websearch: createWebsearchConfig(config?.websearch), - context7, - grep_app, - } - const mcps: Record = {} - for (const [name, mcp] of Object.entries(allBuiltinMcps)) { - if (!disabledMcps.includes(name)) { - mcps[name] = mcp - } + if (!disabledMcps.includes("websearch")) { + mcps.websearch = createWebsearchConfig(config?.websearch) + } + + if (!disabledMcps.includes("context7")) { + mcps.context7 = context7 + } + + if (!disabledMcps.includes("grep_app")) { + mcps.grep_app = grep_app } return mcps