Skip to content

feat: add public get_mcp_status() method to ClaudeSDKClient#516

Merged
ashwin-ant merged 1 commit intomainfrom
michaeldworsky/add-get-mcp-status-public-api
Jan 26, 2026
Merged

feat: add public get_mcp_status() method to ClaudeSDKClient#516
ashwin-ant merged 1 commit intomainfrom
michaeldworsky/add-get-mcp-status-public-api

Conversation

@mdworsky
Copy link
Collaborator

@mdworsky mdworsky commented Jan 24, 2026

Motivation

The Claude Investigator app, which uses the python claude agent SDK, needs to query MCP server connection status (example here). Currently it does this by reaching into private SDK internals:

if client._query and hasattr(client._query, "_send_control_request"):
    mcp_status_response = await client._query._send_control_request(
        {"subtype": "mcp_status"}
    )

This is fragile — any SDK refactor silently breaks the caller, and the hasattr guard means failures degrade silently to no MCP status reporting.

Changes

Add a public get_mcp_status() method following the exact same pattern as interrupt(), set_permission_mode(), set_model(), and rewind_files():

  • Query.get_mcp_status() — sends {"subtype": "mcp_status"} control request via _send_control_request
  • ClaudeSDKClient.get_mcp_status() — public wrapper with connection check, docstring with Returns and Example sections

Callers can now simply do:

mcp_status_response = await client.get_mcp_status()

Testing

The method delegates entirely to the existing _send_control_request infrastructure which is already tested. The new code is a 3-line wrapper with no branching logic.

Add a public API for querying live MCP server connection status,
following the same pattern as interrupt(), set_permission_mode(),
set_model(), and rewind_files().

This allows callers to check MCP server health without reaching into
private SDK internals (client._query._send_control_request), which
is fragile and breaks on SDK updates.

- Query.get_mcp_status(): sends {"subtype": "mcp_status"} control request
- ClaudeSDKClient.get_mcp_status(): public wrapper with connection check

:house: Remote-Dev: homespace
@mdworsky mdworsky force-pushed the michaeldworsky/add-get-mcp-status-public-api branch from 4fa9e1b to beaf88d Compare January 24, 2026 19:15
@mdworsky mdworsky requested a review from ashwin-ant January 24, 2026 19:23
@ashwin-ant ashwin-ant merged commit f5823c6 into main Jan 26, 2026
28 checks passed
@ashwin-ant ashwin-ant deleted the michaeldworsky/add-get-mcp-status-public-api branch January 26, 2026 17:31
phil65 added a commit to phil65/claude-agent-sdk-python that referenced this pull request Jan 29, 2026
Backport of anthropics#516

Adds get_mcp_status() to query MCP server connection status including:
- Server name
- Connection status (connected, pending, failed, needs-auth, disabled)
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