MCPcopy Create free account
hub / github.com/MatterAIOrg/OrbCode / readClaudeCodeProjectServers

Function readClaudeCodeProjectServers

src/commands/migrate.ts:209–229  ·  view source on GitHub ↗

Pull the per-project MCP servers Claude Code stores in `~/.claude.json`.

()

Source from the content-addressed store, hash-verified

207
208/** Pull the per-project MCP servers Claude Code stores in `~/.claude.json`. */
209function 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. */
232function readMcpServersFromObject(

Callers 1

discoverSourcesFunction · 0.85

Calls 3

readMcpServersFromObjectFunction · 0.85
readJsonFunction · 0.70
isPlainObjectFunction · 0.70

Tested by

no test coverage detected