(
spec: McpServerSpec,
opts: AddServerOptions = {},
)
| 104 | |
| 105 | /** Add (or overwrite) a server entry under mcp.servers.<id> in user config. */ |
| 106 | export async function addServerToConfig( |
| 107 | spec: McpServerSpec, |
| 108 | opts: AddServerOptions = {}, |
| 109 | ): Promise<{ id: string; entry: BuiltServerEntry }> { |
| 110 | const id = opts.asId ?? spec.id; |
| 111 | const cfg = await readRawUserConfig(); |
| 112 | cfg.mcp = cfg.mcp ?? {}; |
| 113 | cfg.mcp.servers = cfg.mcp.servers ?? {}; |
| 114 | const entry = buildServerEntry(spec, opts); |
| 115 | cfg.mcp.servers[id] = entry; |
| 116 | await writeRawUserConfig(cfg); |
| 117 | return { id, entry }; |
| 118 | } |
| 119 | |
| 120 | /** Remove a server entry. Returns true if it existed. */ |
| 121 | export async function removeServerFromConfig(id: string): Promise<boolean> { |
no test coverage detected