Skip to content

fix: prevent process hanging in stdio_client context manager - #361

Closed
hwaxxer wants to merge 1 commit into
modelcontextprotocol:mainfrom
hwaxxer:stdio-client-cleanup
Closed

fix: prevent process hanging in stdio_client context manager#361
hwaxxer wants to merge 1 commit into
modelcontextprotocol:mainfrom
hwaxxer:stdio-client-cleanup

Conversation

@hwaxxer

@hwaxxerhwaxxer commented Mar 24, 2025

Copy link
Copy Markdown

Motivation and Context

Fixes#360

How Has This Been Tested?

Tested minimal example:

import asyncio
from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client
async def run():
server_params = StdioServerParameters(
command="claude",
args=["mcp", "serve"],
)
async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as _:
pass
print("exit ClientSession")
print("exit stdio_client")
if __name__ == "__main__":
asyncio.run(run())

Breaking Changes

No

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Documentation
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have added or updated documentation as needed

Additional context

@hwaxxer
hwaxxerforce-pushed the stdio-client-cleanup branch from 69b81ce to c40498fCompareMarch 24, 2025 14:19
@hwaxxer
hwaxxerforce-pushed the stdio-client-cleanup branch from c40498f to 2c89611CompareMarch 25, 2025 07:17
@hwaxxerhwaxxer changed the title fix: prevent process deadlock in stdio_client context managerfix: prevent process hanging in stdio_client context managerMar 25, 2025
@mroch

Copy link
Copy Markdown
Contributor

#372 made the same fix

@ihrprihrpr added this to the r-05-25 milestone Apr 29, 2025
@ihrpr

ihrpr commented May 8, 2025

Copy link
Copy Markdown
Contributor

duplicate #372

@ihrprihrpr closed this May 8, 2025
Sign up for freeto 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.

stdio_client context manager hangs

3 participants

@hwaxxer@mroch@ihrpr