Pull the per-project MCP servers Claude Code stores in `~/.claude.json`.
()
| 207 | |
| 208 | /** Pull the per-project MCP servers Claude Code stores in `~/.claude.json`. */ |
| 209 | function readClaudeCodeProjectServers(): Record<string, McpServerConfig> { |
| 210 | const json = readJson(path.join(os.homedir(), ".claude.json")); |
| 211 | if (!json) return {}; |
| 212 | const projects = json.projects; |
| 213 | if (!isPlainObject(projects)) return {}; |
| 214 | const cwd = process.cwd(); |
| 215 | // Prefer the cwd entry, fall back to the first project entry that has |
| 216 | // any servers (helps when the cwd path doesn't match exactly, e.g. a |
| 217 | // symlinked or differently-cased home directory). |
| 218 | const entries = Object.entries(projects).filter( |
| 219 | (entry): entry is [string, Record<string, unknown>] => |
| 220 | isPlainObject(entry[1]), |
| 221 | ); |
| 222 | const direct = entries.find(([projectPath]) => projectPath === cwd); |
| 223 | const fallback = entries.find(([, project]) => |
| 224 | isPlainObject(project.mcpServers), |
| 225 | ); |
| 226 | const target = direct ?? fallback; |
| 227 | if (!target) return {}; |
| 228 | return readMcpServersFromObject(target[1]); |
| 229 | } |
| 230 | |
| 231 | /** Same as `readMcpServers` but takes a pre-parsed object. */ |
| 232 | function readMcpServersFromObject( |
no test coverage detected