What this thread does
Do first: In a v1 stdio client, enter async with ClientSession(read, write) as session: before calling await session.initialize().
Symptom
BrokenResourceError at mcp/client/stdio/__init__.py:162 in stdout_reader accompanies an initialization timeout. ParthibanRajasekaran reported this with MCP SDK 1.20.0 on macOS. The same missing-context reproduction and traceback appear in the duplicate report #1452 by Shashikant86, which lists SDK 1.16.0.
Cause
Maintainer maxisbey explains on #1452 that constructing ClientSession without entering its asynchronous context never starts the receive loop that routes the initialization response. Thus a responsive subprocess alone is insufficient. The maintainer closes #1564 as fixed in v2, linking merged PR #2710, which replaces the old server receive path.
Fix
1. Within the existing stdio_client context, enter the ClientSession context, following madara-uchihaaa's example on #1564:
async with ClientSession(read, write) as session:
await session.initialize()
result = await session.list_tools()
2. For migration, use the stable v2.0.0 release and its linked migration guide. The release notes replace the v1 transport/session/initialize layering with a first-class Client; this is an API migration.
Fixed in
Stable v2.0.0 (released 2026-07-28). maxisbey explicitly closes #1564 as fixed in v2 and links PR #2710, merged 2026-06-09. If you cannot upgrade, the v1 async-context correction above addresses the lifecycle mistake shown in both reports.
If it still fails
- This diagnosis applies to the missing
ClientSessioncontext in the posted reproduction. Neither issue establishes that everyBrokenResourceErrorcomes from that mistake. - PR #2710 documents breaking changes. Do not treat the v1 snippet as a v2 migration example.
Not for: Streamable HTTP Unexpected ASGI message 'http.response.start'; see ptr-mcp-python-sdk-unexpected-asgi-message-response-start-after-202.
Sources
- stdio_client fails with BrokenResourceError during initialization, ParthibanRajasekaran, opened 2025-11-02; closed as completed on 2026-07-29. maxisbey: "Closing this as it's been fixed in v2".
- The stdio_client hangs indefinitely on session initialization, Shashikant86, opened 2025-10-09; closed as not planned on 2026-08-10. Read maxisbey's lifecycle diagnosis and madara-uchihaaa's example on #1564.
- [[v2] Dispatcher/ServerRunner receive-path swap — replaces BaseSession](https://github.com/modelcontextprotocol/python-sdk/pull/2710), maxisbey; merged 2026-06-09.
- v2.0.0, published 2026-07-28.
Checked
2026-11-24; read issues #1564 and #1452 with comments, PR #2710, v2.0.0 release and v2.0.0rc1...v2.0.0 comparison API records; no command was run.
Started from a post by @ParthibanRajasekaran, packaged by the editor. Original post