feat(cc-config): add and remove MCP servers through the claude CLI
Mutation goes through `claude mcp add|remove`, never a direct edit of ~/.claude.json — the running CLI rewrites that file concurrently, so a dashboard write would race it. Reads stay on readMcpServers. The plan specified a --url flag; the real CLI (v2.1.266) has none — commandOrUrl is positional, and --header must trail it or the variadic flag swallows the url. Built against the verified shape.
This commit is contained in:
@@ -97,6 +97,8 @@
|
||||
* - `CcPluginsResponse` — exported API; see TSDoc on the symbol for behavior.
|
||||
* - `CcMcpServer` — exported API; see TSDoc on the symbol for behavior.
|
||||
* - `CcMcpResponse` — exported API; see TSDoc on the symbol for behavior.
|
||||
* - `CcMcpScope` — exported API; see TSDoc on the symbol for behavior.
|
||||
* - `CcMcpAddArgs` — exported API; see TSDoc on the symbol for behavior.
|
||||
* - `CcHookEntry` — exported API; see TSDoc on the symbol for behavior.
|
||||
* - `CcHookSource` — exported API; see TSDoc on the symbol for behavior.
|
||||
* - `CcSettingsSource` — exported API; see TSDoc on the symbol for behavior.
|
||||
@@ -1404,6 +1406,28 @@ export const api = {
|
||||
* @returns {@link CcMcpResponse} — servers split into `user`/`projectScoped`.
|
||||
*/
|
||||
mcp: () => request<CcMcpResponse>("/cc-config/mcp"),
|
||||
/**
|
||||
* POST /api/cc-config/mcp/add - add an MCP server via `claude mcp add`.
|
||||
* Either `url` (http/sse) or `command`+`args` (stdio) must be given, not
|
||||
* both. `scope` is required — `user` or `project` only, never the
|
||||
* settings union's third `project-local` value.
|
||||
* @returns {@link CcCliResult} — the CLI's stdout/stderr on success.
|
||||
*/
|
||||
mcpAdd: (args: CcMcpAddArgs) =>
|
||||
request<CcCliResult>("/cc-config/mcp/add", {
|
||||
method: "POST",
|
||||
body: JSON.stringify(args),
|
||||
}),
|
||||
/**
|
||||
* POST /api/cc-config/mcp/remove - remove an MCP server via
|
||||
* `claude mcp remove`. `scope` narrows which config layer to remove
|
||||
* from; omit it to let the CLI find the server wherever it exists.
|
||||
*/
|
||||
mcpRemove: (name: string, scope?: CcMcpScope) =>
|
||||
request<CcCliResult>("/cc-config/mcp/remove", {
|
||||
method: "POST",
|
||||
body: JSON.stringify({ name, scope }),
|
||||
}),
|
||||
/**
|
||||
* GET /api/cc-config/hooks - hook entries from every settings.json layer.
|
||||
* @returns `{ items }` — one {@link CcHookSource} per settings layer.
|
||||
@@ -2647,6 +2671,25 @@ export interface CcMcpResponse {
|
||||
projectScoped: CcMcpServer[];
|
||||
}
|
||||
|
||||
/** Scope the `claude mcp` CLI accepts from this form. Deliberately not the
|
||||
* three-value settings union — the CLI's own third scope (`local`) is a
|
||||
* different axis and is not offered here. */
|
||||
export type CcMcpScope = "user" | "project";
|
||||
|
||||
/** Body of POST /api/cc-config/mcp/add. Either `url` (http/sse) or
|
||||
* `command`+`args` (stdio) is required, never both. `env` is stdio-only;
|
||||
* `headers` is http/sse-only. */
|
||||
export interface CcMcpAddArgs {
|
||||
name: string;
|
||||
scope: CcMcpScope;
|
||||
transport?: "http" | "sse";
|
||||
url?: string;
|
||||
headers?: Record<string, string>;
|
||||
command?: string;
|
||||
args?: string[];
|
||||
env?: Record<string, string>;
|
||||
}
|
||||
|
||||
/** One hook binding within a settings.json `hooks` block. */
|
||||
export interface CcHookEntry {
|
||||
/** Tool-name matcher pattern (e.g. "Bash", "Edit|Write", or "*"). */
|
||||
|
||||
Reference in New Issue
Block a user