From f1253a74e1e3da5ba29ef48bb94dab016dea2d27 Mon Sep 17 00:00:00 2001 From: Dallin Romney Date: Wed, 24 Sep 2025 19:50:11 -0700 Subject: [PATCH] feat: claude code mcp json format support --- core/context/mcp/json/loadJsonMcpConfigs.ts | 71 ++++++++++++------- .../claude_desktop_config.json | 9 +++ packages/config-yaml/src/schemas/mcp/json.ts | 12 ++++ 3 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 manual-testing-sandbox/claude_desktop_config.json diff --git a/core/context/mcp/json/loadJsonMcpConfigs.ts b/core/context/mcp/json/loadJsonMcpConfigs.ts index b31321023..e5150be66 100644 --- a/core/context/mcp/json/loadJsonMcpConfigs.ts +++ b/core/context/mcp/json/loadJsonMcpConfigs.ts @@ -1,4 +1,5 @@ import { + claudeLikeConfigFileSchema, ConfigValidationError, convertJsonMcpConfigToYamlMcpConfig, McpJsonConfig, @@ -15,6 +16,7 @@ import { DEFAULT_IGNORE_FILETYPES, } from "../../../indexing/ignore"; import { walkDir } from "../../../indexing/walkDir"; +import { deduplicateArray } from "../../../util"; import { getGlobalFolderWithName } from "../../../util/paths"; import { localPathToUri } from "../../../util/pathToUri"; import { getUriPathBasename, joinPathsToUri } from "../../../util/uri"; @@ -94,34 +96,49 @@ export async function loadJsonMcpConfigs( for (const { content, uri } of jsonFiles) { try { const json = JSONC.parse(content); - const claudeFileParsed = mcpServerConfigFileSchema.safeParse(json); - - // Try parsing as a file with mcpServers and multiple servers (claude-esque format) - if (claudeFileParsed.success) { - validJsonConfigs.push( - ...Object.entries(claudeFileParsed.data.mcpServers).map( - ([name, mcpJson]) => ({ + // Try parsing as a file with mcpServers and multiple servers (claude code/desktop-esque format) + const claudeCodeFileParsed = claudeLikeConfigFileSchema.safeParse(json); + if (claudeCodeFileParsed.success) { + const projectServers = Object.values( + claudeCodeFileParsed.data.projects, + ).map((v) => v.mcpServers); + for (const mcpServers of projectServers) { + validJsonConfigs.push( + ...Object.entries(mcpServers).map(([name, mcpJson]) => ({ name, mcpJson, uri, - }), - ), - ); - claudeFileParsed.data; + })), + ); + } } else { - // Try parsing as single JSON file - const singleConfigParsed = mcpServersJsonSchema.safeParse(json); - if (singleConfigParsed.success) { - validJsonConfigs.push({ - mcpJson: singleConfigParsed.data, - name: getUriPathBasename(uri).replace(".json", ""), - uri, - }); + const claudeDesktopFileParsed = + mcpServerConfigFileSchema.safeParse(json); + if (claudeDesktopFileParsed.success) { + validJsonConfigs.push( + ...Object.entries(claudeDesktopFileParsed.data.mcpServers).map( + ([name, mcpJson]) => ({ + name, + mcpJson, + uri, + }), + ), + ); } else { - errors.push({ - fatal: false, - message: `MCP JSON file at ${uri} doesn't match a supported MCP JSON configuration format`, - }); + // Try parsing as single JSON file + const singleConfigParsed = mcpServersJsonSchema.safeParse(json); + if (singleConfigParsed.success) { + validJsonConfigs.push({ + mcpJson: singleConfigParsed.data, + name: getUriPathBasename(uri).replace(".json", ""), + uri, + }); + } else { + errors.push({ + fatal: false, + message: `MCP JSON file at ${uri} doesn't match a supported MCP JSON configuration format`, + }); + } } } } catch (e) { @@ -132,8 +149,14 @@ export async function loadJsonMcpConfigs( } } + // De-duplicate + const deduplicatedJsonConfigs = deduplicateArray( + validJsonConfigs, + (a, b) => a.name === b.name, + ); + // Two levels of conversion for now. - const yamlConfigs = validJsonConfigs.map((c) => { + const yamlConfigs = deduplicatedJsonConfigs.map((c) => { const { warnings, yamlConfig } = convertJsonMcpConfigToYamlMcpConfig( c.name, c.mcpJson, diff --git a/manual-testing-sandbox/claude_desktop_config.json b/manual-testing-sandbox/claude_desktop_config.json new file mode 100644 index 000000000..b397e36fd --- /dev/null +++ b/manual-testing-sandbox/claude_desktop_config.json @@ -0,0 +1,9 @@ +{ + "mcpServers": { + "linear": { + "command": "npx", + "args": ["-y", "mcp-remote", "https://mcp.linear.app/sse"], + "envFile": "hey" + } + } +} diff --git a/packages/config-yaml/src/schemas/mcp/json.ts b/packages/config-yaml/src/schemas/mcp/json.ts index 20a283350..578ef5d77 100644 --- a/packages/config-yaml/src/schemas/mcp/json.ts +++ b/packages/config-yaml/src/schemas/mcp/json.ts @@ -36,3 +36,15 @@ export const mcpServerConfigFileSchema = z.object({ export type McpServersJsonConfigFile = z.infer< typeof mcpServerConfigFileSchema >; + +export const claudeLikeConfigFileSchema = z.object({ + projects: z.record( + z.string(), + z.object({ + mcpServers: mcpServersRecordSchema, + }), + ), +}); +export type ClaudeLikeConfigFileSchema = z.infer< + typeof claudeLikeConfigFileSchema +>;