Commit f5823c6
authored
feat: add public get_mcp_status() method to ClaudeSDKClient (#516)
## Motivation
The Claude Investigator app, which uses the python claude agent SDK,
needs to query MCP server connection status (example
[here](https://github.com/anthropics/anthropic/blob/948dc8cc4a739b7d026d54e8da2e175cd1659340/ts-threat-intel/ts_threat_intel/claude_investigator/services/client_actor.py#L554-L557)).
Currently it does this by reaching into private SDK internals:
```python
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:
```python
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.1 parent 6a0140a commit f5823c6
2 files changed
Lines changed: 30 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
517 | 517 | | |
518 | 518 | | |
519 | 519 | | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
520 | 524 | | |
521 | 525 | | |
522 | 526 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
293 | 293 | | |
294 | 294 | | |
295 | 295 | | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
296 | 322 | | |
297 | 323 | | |
298 | 324 | | |
| |||
0 commit comments