fix(mcp-loader): read user-level MCP config from ~/.claude.json (#814)

This commit is contained in:
YeonGyu-Kim 2026-02-07 20:01:16 +09:00
parent 8e92704316
commit 1760367a25
2 changed files with 66 additions and 33 deletions

View File

@ -1,7 +1,7 @@
import { describe, it, expect, beforeEach, afterEach } from "bun:test" import { describe, it, expect, beforeEach, afterEach } from "bun:test"
import { mkdirSync, writeFileSync, rmSync } from "fs" import { mkdirSync, writeFileSync, rmSync } from "fs"
import { join } from "path" import { join } from "path"
import { tmpdir } from "os" import { tmpdir, homedir } from "os"
const TEST_DIR = join(tmpdir(), "mcp-loader-test-" + Date.now()) const TEST_DIR = join(tmpdir(), "mcp-loader-test-" + Date.now())
@ -159,4 +159,37 @@ describe("getSystemMcpServerNames", () => {
process.chdir(originalCwd) process.chdir(originalCwd)
} }
}) })
it("reads user-level MCP config from ~/.claude.json", async () => {
// given
const userConfigPath = join(homedir(), ".claude.json")
const userMcpConfig = {
mcpServers: {
"user-server": {
command: "npx",
args: ["user-mcp-server"],
},
},
}
// Create user config if it doesn't exist
const originalCwd = process.cwd()
process.chdir(TEST_DIR)
try {
// Write user config temporarily
writeFileSync(userConfigPath, JSON.stringify(userMcpConfig))
// when
const { getSystemMcpServerNames } = await import("./loader")
const names = getSystemMcpServerNames()
// then
expect(names.has("user-server")).toBe(true)
} finally {
process.chdir(originalCwd)
// Clean up user config
rmSync(userConfigPath, { force: true })
}
})
}) })

View File

@ -1,5 +1,6 @@
import { existsSync, readFileSync } from "fs" import { existsSync, readFileSync } from "fs"
import { join } from "path" import { join } from "path"
import { homedir } from "os"
import { getClaudeConfigDir } from "../../shared" import { getClaudeConfigDir } from "../../shared"
import type { import type {
ClaudeCodeMcpConfig, ClaudeCodeMcpConfig,
@ -16,11 +17,10 @@ interface McpConfigPath {
} }
function getMcpConfigPaths(): McpConfigPath[] { function getMcpConfigPaths(): McpConfigPath[] {
const claudeConfigDir = getClaudeConfigDir()
const cwd = process.cwd() const cwd = process.cwd()
return [ return [
{ path: join(claudeConfigDir, ".mcp.json"), scope: "user" }, { path: join(homedir(), ".claude.json"), scope: "user" },
{ path: join(cwd, ".mcp.json"), scope: "project" }, { path: join(cwd, ".mcp.json"), scope: "project" },
{ path: join(cwd, ".claude", ".mcp.json"), scope: "local" }, { path: join(cwd, ".claude", ".mcp.json"), scope: "local" },
] ]