Skip to content

Conversation

@dltn
Copy link
Collaborator

@dltn dltn commented Dec 1, 2025

Port SDK MCP fix from TypeScript to Python.

Now, when SDK MCP servers or hooks are present, stream_input() waits for the first result message before closing stdin, allowing bidirectional control protocol communication to complete.

Fixes repro in #266.

The query() design requires input streams to be held open by the user for SDK MCP bidirectional communication to work. This has confused a lot of folks, so we're moving towards a more explicit lifecycle design. In the meantime, this is the way we've addressed it with V1 APIs in https://github.com/anthropics/claude-agent-sdk-typescript.

🤖 Generated with Claude Code

…are present

When using SDK MCP servers with the query() function, stdin was being
closed immediately after all user messages were sent. This prevented
the CLI from sending MCP control requests back to the SDK, causing
tools to never execute.

Now, when SDK MCP servers or hooks are present, stream_input() waits
for the first result message before closing stdin, allowing
bidirectional control protocol communication to complete.

Fixes #266

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
@dltn dltn requested a review from ashwin-ant December 1, 2025 18:13
@dltn dltn merged commit a2f24a3 into main Dec 1, 2025
25 of 26 checks passed
@dltn dltn deleted the dalton/investigate-266 branch December 1, 2025 18:19
@murtaza64
Copy link

murtaza64 commented Dec 3, 2025

Is this fix actually in 0.1.11? I'm seeing the same error when trying to use an SDK MCP server

edit:

Traceback (most recent call last):
  File "/Users/murtaza/infra-baymax/.venv/lib/python3.13/site-packages/claude_agent_sdk/_internal/query.py", line 320, in _handle_control_request
    await self.transport.write(json.dumps(success_response) + "\n")
  File "/Users/murtaza/infra-baymax/.venv/lib/python3.13/site-packages/claude_agent_sdk/_internal/transport/subprocess_cli.py", line 511, in write
    raise CLIConnectionError("ProcessTransport is not ready for writing")
claude_agent_sdk._errors.CLIConnectionError: ProcessTransport is not ready for writing

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/murtaza/infra-baymax/.venv/lib/python3.13/site-packages/claude_agent_sdk/_internal/query.py", line 332, in _handle_control_request
    await self.transport.write(json.dumps(error_response) + "\n")
  File "/Users/murtaza/infra-baymax/.venv/lib/python3.13/site-packages/claude_agent_sdk/_internal/transport/subprocess_cli.py", line 511, in write
    raise CLIConnectionError("ProcessTransport is not ready for writing")
claude_agent_sdk._errors.CLIConnectionError: ProcessTransport is not ready for writing

disabling the SDK MCP server gets rid of this 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.

4 participants