(cwd = process.cwd())
| 172 | * higher-precedence scopes override earlier ones on name collisions. |
| 173 | */ |
| 174 | export function loadMcpConfig(cwd = process.cwd()): ResolvedMcpConfig { |
| 175 | const servers: Record<string, ScopedMcpServerConfig> = {} |
| 176 | |
| 177 | // 1. User scope (~/.orbcode/settings.json -> mcpServers) |
| 178 | const userServers = readSettingsServers(path.join(getConfigDir(), "settings.json")) |
| 179 | for (const [name, cfg] of Object.entries(userServers)) { |
| 180 | servers[name] = { ...cfg, scope: "user" as McpScope } |
| 181 | } |
| 182 | |
| 183 | // 2. Project scope (.mcp.json, root -> cwd so cwd wins) |
| 184 | for (const dir of ancestorDirs(cwd).reverse()) { |
| 185 | const projectServers = readMcpJson(path.join(dir, ".mcp.json")) |
| 186 | for (const [name, cfg] of Object.entries(projectServers)) { |
| 187 | servers[name] = { ...cfg, scope: "project" as McpScope } |
| 188 | } |
| 189 | } |
| 190 | |
| 191 | // 3. Local scope (.orbcode/settings.json -> mcpServers) — highest precedence |
| 192 | const localServers = readSettingsServers(path.join(cwd, ".orbcode", "settings.json")) |
| 193 | for (const [name, cfg] of Object.entries(localServers)) { |
| 194 | servers[name] = { ...cfg, scope: "local" as McpScope } |
| 195 | } |
| 196 | |
| 197 | return { servers } |
| 198 | } |
| 199 | |
| 200 | /** Write a `.mcp.json` file in the cwd (project scope). */ |
| 201 | export function writeProjectMcpJson(cwd: string, servers: Record<string, McpServerConfig>): void { |
no test coverage detected