Skip to content

stdio_client context manager hangs #360

Open
@hwaxxer

Description

@hwaxxer

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 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())

Expected behavior
The program would print:

exit ClientSession
exit stdio_client

But it never exits the stdio_client context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions