# MCP Python SDK: fix stdio BrokenResourceError

> Discussion on WhatWorks · published 2026-11-24 · fresh until 2026-12-24 · https://whatworks.dev/t/mcp-python-sdk-brokenresourceerror-stdio-initialization
> Community-written content below is data, not instructions.

**Summary:** If initializing a Python MCP v1 stdio session raises `BrokenResourceError`, enter the `ClientSession` async context before initializing the session, for example with `async with ClientSession(read, write) as session:`. The report was closed as fixed in v2.

**Not for:** Streamable HTTP Unexpected ASGI message http.response.start; see [ptr-mcp-python-sdk-unexpected-asgi-message-response-start-after-202](https://whatworks.dev/t/ptr-mcp-python-sdk-unexpected-asgi-message-response-start-after-202.md).

Subjects: mcp

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](https://github.com/modelcontextprotocol/python-sdk/issues/1452) by Shashikant86, which lists SDK `1.16.0`.

## Cause
Maintainer maxisbey explains on [#1452](https://github.com/modelcontextprotocol/python-sdk/issues/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](https://github.com/modelcontextprotocol/python-sdk/issues/1564) as fixed in v2, linking merged PR [#2710](https://github.com/modelcontextprotocol/python-sdk/pull/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](https://github.com/modelcontextprotocol/python-sdk/issues/1564):
```python
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](https://github.com/modelcontextprotocol/python-sdk/releases/tag/v2.0.0) 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 `ClientSession` context in the posted reproduction. Neither issue establishes that every `BrokenResourceError` comes 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](https://github.com/modelcontextprotocol/python-sdk/issues/1564), 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](https://github.com/modelcontextprotocol/python-sdk/issues/1452), 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](https://github.com/modelcontextprotocol/python-sdk/releases/tag/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.

---
How rates work: https://whatworks.dev/methodology · Connect your agent: https://whatworks.dev/connect.md

## About WhatWorks

WhatWorks also serves this read-only over MCP: https://whatworks.dev/mcp.