Skip to content

MCP Streamable HTTP Server Client times out in v0.1.0 #1029

Open
@aaguirre-rdit

Description

@aaguirre-rdit

Please read this first

  • Have you read the docs?Agents SDK docs
  • Have you searched for related issues? Others may have faced similar issues. ✅

Describe the bug

MCP Client fails to initialise, always times out.
I am testing this with an MCP server URL deployed on the cloud, but I have tested the connection with both MCP Inspector and AWS Strands Agents SDK and I had no issue initialising a client connection with them.

Debug information

  • Agents SDK version: v0.1.0
  • Python version: Python 3.12.7

Repro steps

I am having trouble to initialise a client with a script as simple as this:


from agents.mcp import  MCPServerStreamableHttp
from agents import Agent, Runner

async def main():
    async with MCPServerStreamableHttp(
        params = {
                "name": "dataplex_search",
                "description": "Dataplex Search Server",
                "transport": "http",
                "url": "http://<MCP_SERVER_URL>/mcp/"
            },
    ) as server:
        agent = Agent(
            name="dataplex_search_agent",
            description="Agent for searching Dataplex entries",
            mcp_servers=[server],
        )
        user_query = input("Enter your query: ")
        response = await Runner.run(agent, user_query)
        print(f"Response: {response}")

if __name__ == "__main__":
    import asyncio
    asyncio.run(main())

Expected behavior

I would expect the MCP Client to initialise and see an input prompt on the terminal. The execution fails before any input prompt appears, as the MCP client is timing out. This is the error traceback:

Error initializing MCP server: Timed out while waiting for response to ClientRequest. Waited 5.0 seconds.
Traceback (most recent call last):
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/anyio/streams/memory.py", line 111, in receive
    return self.receive_nowait()
           ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/anyio/streams/memory.py", line 106, in receive_nowait
    raise WouldBlock
anyio.WouldBlock

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/anyio/_core/_tasks.py", line 115, in fail_after
    yield cancel_scope
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/mcp/shared/session.py", line 272, in send_request
    response_or_error = await response_stream_reader.receive()
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/anyio/streams/memory.py", line 119, in receive
    await receive_event.wait()
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/anyio/_backends/_asyncio.py", line 1774, in wait
    await self._event.wait()
  File "/Users/some_user/opt/anaconda3/lib/python3.12/asyncio/locks.py", line 212, in wait
    await fut
asyncio.exceptions.CancelledError: Cancelled by cancel scope 1087eccb0

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/mcp/shared/session.py", line 271, in send_request
    with anyio.fail_after(timeout):
         ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/some_user/opt/anaconda3/lib/python3.12/contextlib.py", line 158, in __exit__
    self.gen.throw(value)
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/anyio/_core/_tasks.py", line 118, in fail_after
    raise TimeoutError
TimeoutError

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/some_user/Projects/internal/AgentSol/some-app/app/mcp/debug.py", line 28, in <module>
    asyncio.run(main())
  File "/Users/some_user/opt/anaconda3/lib/python3.12/asyncio/runners.py", line 194, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "/Users/some_user/opt/anaconda3/lib/python3.12/asyncio/runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/some_user/opt/anaconda3/lib/python3.12/asyncio/base_events.py", line 687, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "/Users/some_user/Projects/internal/AgentSol/some-app/app/mcp/debug.py", line 7, in main
    async with MCPServerStreamableHttp(
               ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/agents/mcp/server.py", line 196, in __aenter__
    await self.connect()
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/agents/mcp/server.py", line 224, in connect
    server_result = await session.initialize()
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/mcp/client/session.py", line 151, in initialize
    result = await self.send_request(
             ^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/some_user/Projects/internal/AgentSol/some-app/.venv/lib/python3.12/site-packages/mcp/shared/session.py", line 274, in send_request
    raise McpError(
mcp.shared.exceptions.McpError: Timed out while waiting for response to ClientRequest. Waited 5.0 seconds.

I have tried increasing the client timeout to 60s, which did not work anyways.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions