Skip to content

feat: add MCP control methods and typed McpServerStatus#620

Merged
qing-ant merged 3 commits intomainfrom
qing/mcp-reconnect-toggle
Mar 3, 2026
Merged

feat: add MCP control methods and typed McpServerStatus#620
qing-ant merged 3 commits intomainfrom
qing/mcp-reconnect-toggle

Conversation

@qing-ant
Copy link
Copy Markdown
Contributor

@qing-ant qing-ant commented Mar 2, 2026

Adds MCP server control methods and a typed get_mcp_status() return, matching the TypeScript SDK.

New client methods

  • reconnect_mcp_server(server_name: str) -> None — reconnect a running MCP server
  • toggle_mcp_server(server_name: str, enabled: bool) -> None — enable/disable an MCP server
  • stop_task(task_id: str) -> None — stop a running task (a task_notification with status 'stopped' follows)

Typed get_mcp_status() return

Changed return type from dict[str, Any]McpStatusResponse (TypedDict). Runtime-safe — it's still a dict — but callers now get typed access to status["mcpServers"] with McpServerStatus entries (name, status, config, scope, tools, serverInfo, error).

Status enum: 'connected' | 'failed' | 'needs-auth' | 'pending' | 'disabled'

Wire format note: the mcp_reconnect/mcp_toggle control requests use camelCase serverName (verified against the CLI's Zod schemas).

  • Add reconnect_mcp_server(), toggle_mcp_server(), stop_task() methods to ClaudeSDKClient
  • Add typed McpServerStatus / McpStatusResponse for get_mcp_status() return

Test plan

  • Unit: control-request JSON shape verified via mock transport (camelCase serverName, enabled: bool, task_id: str)
  • E2E: full state machine verified against real CLI with a live stdio MCP server — connected → disabled → connected via toggle, reconnect succeeds, McpServerStatus shape validated against 41 real server entries including claudeai-proxy config

@qing-ant qing-ant enabled auto-merge (squash) March 3, 2026 01:19
@qing-ant qing-ant requested a review from dltn March 3, 2026 03:57
@qing-ant qing-ant merged commit 28f9b4b into main Mar 3, 2026
9 checks passed
@qing-ant qing-ant deleted the qing/mcp-reconnect-toggle branch March 3, 2026 18:20
sarahdeaton pushed a commit that referenced this pull request Mar 24, 2026
The changelog entry for #620 listed add_mcp_server()/remove_mcp_server(),
but the commit actually added reconnect_mcp_server()/toggle_mcp_server()/
stop_task() and the McpStatusResponse type. The commit's own CHANGELOG
block had the correct names; this was a transcription error.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants