(cwd: string, name: string, config: McpServerConfig, scope: McpScope)
| 234 | |
| 235 | /** Add (or overwrite) a server in the given scope's config file. */ |
| 236 | export function addMcpServer(cwd: string, name: string, config: McpServerConfig, scope: McpScope): void { |
| 237 | if (!/^[A-Za-z0-9_-]+$/.test(name)) { |
| 238 | throw new Error(`Invalid server name "${name}". Use only letters, numbers, hyphens, and underscores.`) |
| 239 | } |
| 240 | if (scope === "project") { |
| 241 | const existing = readProjectMcpJson(cwd) |
| 242 | existing[name] = config |
| 243 | writeProjectMcpJson(cwd, existing) |
| 244 | } else { |
| 245 | const filePath = settingsPathForScope(cwd, scope) |
| 246 | const settings = readFullSettings(filePath) |
| 247 | const servers = normalizeServers(settings.mcpServers) |
| 248 | servers[name] = config |
| 249 | settings.mcpServers = servers |
| 250 | writeFullSettings(filePath, settings) |
| 251 | } |
| 252 | } |
| 253 | |
| 254 | /** Remove a server from the given scope's config file. Returns true if it |
| 255 | * existed and was removed, false if it wasn't found. */ |
no test coverage detected