Skip to content

MCPServerSse not able to connect to mcp server running within docker container #946

Closed as not planned
@yogeshnikam671

Description

@yogeshnikam671

Describe the bug

I am using MCPServerSee to establish a SSE connect with the MCP server. Following is the code snippet -

 mcp_server = MCPServerSse( name="SSE Python Server", params={ "url": f"{mcp_base_url}/mcp/specs/{chat_id}.yaml/sse", }, ) await mcp_server.connect()

This works seamlessly on local but when I run the mcp_server within a docker container along with this app where both the mcp server and this app share the same network, I get an error.

This error doesn't seem like a connection error. Following are the error logs -

File "/usr/src/app/app/core/chat_state.py", line 43, in create | await mcp_server.connect() | File "/venv/lib/python3.12/site-packages/agents/mcp/server.py", line 111, in connect | transport = await self.exit_stack.enter_async_context(self.create_streams()) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/usr/lib/python3.12/contextlib.py", line 659, in enter_async_context | result = await _enter(cm) | ^^^^^^^^^^^^^^^^ | File "/usr/lib/python3.12/contextlib.py", line 210, in __aenter__ | return await anext(self.gen) | ^^^^^^^^^^^^^^^^^^^^^ | File "/venv/lib/python3.12/site-packages/mcp/client/sse.py", line 54, in sse_client | async with anyio.create_task_group() as tg: | ^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 772, in __aexit__ | raise BaseExceptionGroup( | ExceptionGroup: unhandled errors in a TaskGroup (1 sub-exception) +-+---------------- 1 ---------------- | Traceback (most recent call last): | File "/venv/lib/python3.12/site-packages/mcp/client/sse.py", line 133, in sse_client | endpoint_url = await tg.start(sse_reader) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | File "/venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 898, in start | return await future | ^^^^^^^^^^^^ | RuntimeError: Child exited without calling task_status.started() 

Not sure how to resolve this error.
P.S. There are no docker setup related issues. Everything is setup correctly.

Debug information

  • Agents SDK version: (e.g. v0.0.16)
  • Python version (e.g. Python 3.10)

Expected behavior

MCPServerSse should be able to establish the SSE connection even in a docker setup.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions