Skip to content

Conversation

@drillan
Copy link

@drillan drillan commented Jan 19, 2026

Summary

  • SDK MCP servers require bidirectional communication through stdin/stdout
  • When using a string prompt, stdin was being closed immediately, causing "ProcessTransport is not ready for writing" errors
  • This fix detects SDK MCP servers and converts string prompts to async iterables, enabling the streaming protocol required for MCP communication

Changes

  • Added _string_to_async_iterable() helper function to convert string prompts to stream-json format
  • Added _has_sdk_mcp_servers() method to detect SDK MCP server presence
  • Modified __init__ to force streaming mode when SDK MCP servers are configured with string prompts

Test plan

  • Added tests for _string_to_async_iterable output format validation
  • Added tests for SDK MCP server detection (no servers, external only, SDK present, mixed)
  • Added tests for streaming mode enforcement with SDK MCP servers
  • Added tests for edge cases (file path config, invalid config values)
  • All 140 tests pass

Fixes #386

🤖 Generated with Claude Code

SDK MCP servers require bidirectional communication through stdin/stdout.
When using a string prompt, stdin was being closed immediately, causing
"ProcessTransport is not ready for writing" errors.

This fix detects SDK MCP servers and converts string prompts to async
iterables, enabling the streaming protocol required for MCP communication.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
drillan added a commit to drillan/claudecode-model that referenced this pull request Jan 19, 2026
Use forked branch to resolve ProcessTransport error when using SDK MCP
servers with string prompts.

- Add [tool.uv.sources] to use forked branch
- Bump version from 0.0.3 to 0.0.4

Upstream PR: anthropics/claude-agent-sdk-python#492

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
drillan and others added 2 commits January 19, 2026 12:12
When SDK MCP servers are present, the transport converts string prompts
to AsyncIterable for bidirectional communication. The client now:

1. Forces streaming mode when SDK MCP servers are configured, even for
   string prompts (they require bidirectional communication)
2. Uses the transport's potentially converted prompt (`_prompt` attribute)
   instead of the original prompt when starting the input stream

This ensures proper streaming behavior when using string prompts with
SDK MCP servers.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
When the CLI process exits immediately after processing the final
message, the transport may close before we can send the control
response. This caused unhandled CLIConnectionError exceptions.

Wrap transport.write calls in _handle_control_request with try/except
to gracefully handle the race condition when the transport is already
closed. Other exceptions still propagate normally.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
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.

bug: #380 fix only works with async generator prompts, not string prompts

1 participant