Title: stdio_client context manager hangs · Issue #360 · modelcontextprotocol/python-sdk · GitHub
Open Graph Title: stdio_client context manager hangs · Issue #360 · modelcontextprotocol/python-sdk
X Title: stdio_client context manager hangs · Issue #360 · modelcontextprotocol/python-sdk
Description: Describe the bug When using the stdio_client context manager, the process is never cleaned up. To Reproduce Steps to reproduce the behavior: import asyncio from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import...
Open Graph Description: Describe the bug When using the stdio_client context manager, the process is never cleaned up. To Reproduce Steps to reproduce the behavior: import asyncio from mcp import ClientSession, StdioServe...
X Description: Describe the bug When using the stdio_client context manager, the process is never cleaned up. To Reproduce Steps to reproduce the behavior: import asyncio from mcp import ClientSession, StdioServe...
Opengraph URL: https://github.com/modelcontextprotocol/python-sdk/issues/360
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"stdio_client context manager hangs","articleBody":"**Describe the bug**\nWhen using the stdio_client context manager, the process is never cleaned up.\n\n**To Reproduce**\nSteps to reproduce the behavior:\n\n```\nimport asyncio\n\nfrom mcp import ClientSession, StdioServerParameters\nfrom mcp.client.stdio import stdio_client\n\n\nasync def run():\n server_params = StdioServerParameters(\n command=\"claude\",\n args=[\"mcp\", \"serve\"],\n )\n async with stdio_client(server_params) as (read, write): \n async with ClientSession(read, write) as _:\n pass\n print(\"exit ClientSession\")\n print(\"exit stdio_client\")\n\nif __name__ == \"__main__\":\n asyncio.run(run())\n```\n\n**Expected behavior**\nThe program would print:\n```\nexit ClientSession\nexit stdio_client\n```\n\nBut it never exits the stdio_client context.\n","author":{"url":"https://github.com/hwaxxer","@type":"Person","name":"hwaxxer"},"datePublished":"2025-03-24T14:16:14.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":8},"url":"https://github.com/360/python-sdk/issues/360"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:5f56b3f5-a400-9ba6-553e-1d24ba3e1aae |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A3BE:1F761C:CDED3B:1135910:6A5A8DC0 |
| html-safe-nonce | 8fc097bab68a92658ac8c6d2b4fa551f5781c44f12b8da9ab53f398995248b73 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBM0JFOjFGNzYxQzpDREVEM0I6MTEzNTkxMDo2QTVBOERDMCIsInZpc2l0b3JfaWQiOiIyNzUxMjExNDc0NDEyODAxNDcyIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | a3c99e3562974f8d45a148153e12ae953c1f5f0fde53edac3df7f068c148dc60 |
| hovercard-subject-tag | issue:2943413820 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/python-sdk/360/issue_layout |
| twitter:image | https://opengraph.githubassets.com/addee498d219eb3a8ea93e21e5ccae0709a024e9943d8c3c8cdee3b5b172612f/modelcontextprotocol/python-sdk/issues/360 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/addee498d219eb3a8ea93e21e5ccae0709a024e9943d8c3c8cdee3b5b172612f/modelcontextprotocol/python-sdk/issues/360 |
| og:image:alt | Describe the bug When using the stdio_client context manager, the process is never cleaned up. To Reproduce Steps to reproduce the behavior: import asyncio from mcp import ClientSession, StdioServe... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | hwaxxer |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9989a1a1d89aa5a38a19e5d0c7ee88a8ffde84acde90048990492aae52f235db |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/python-sdk git https://github.com/modelcontextprotocol/python-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 862584018 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/python-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 862584018 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/python-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | ba6769fbf719c56dbf7bed650ce454dafc5b1528 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width