Hi everyone! Why can the connection to an MCP serv...
# questions
p
Hi everyone! Why can the connection to an MCP server over SSE be lost? Both OpenHands and the MCP server are on the same host. Through MCP Inspector the server responds correctly, but when starting a new conversation (not always, but often — I still haven’t identified the pattern) the Docker log shows an error (into the thread)
Copy code
File "/app/.venv/lib/python3.13/site-packages/mcp/shared/session.py", line 285, in send_request
    raise McpError(
    ...<8 lines>...
    )
mcp.shared.exceptions.McpError: Timed out while waiting for response to ClientRequest. Waited 30.0 seconds.
10:39:36 - openhands:INFO: utils.py:127 - Initializing MCP agent for url='<http://fct01-slt-msk1.yclients.cloud:8100/sse>' api_key='******' with SSE connection...
10:39:37 - openhands:INFO: client.py:57 - Connected to server with tools: ['gitlab_mr_diff']
The last log line shows a successful connection to the second server on port 8100, and it connects immediately. Both MCP servers have the same configuration. I don’t understand where to look next — if anyone has faced something similar, I’d appreciate any advice.
Copy code
[Agent Controller 2ab04e5654b34965ba3dacf6666a750b] **MCPAction**
NAME: ai_review
ARGUMENTS: {'repo_slug': 'yclients/biz.erp', 'project_id': '12', 'mr_iid': '26954', 'conversation_id': 'conv1'}
10:39:06 - openhands:INFO: utils.py:127 - Initializing MCP agent for url='<http://fct01-slt-msk1.yclients.cloud:8000/sse>' api_key='******' with SSE connection...
10:39:36 - openhands:ERROR: client.py:103 - McpError connecting to <http://fct01-slt-msk1.yclients.cloud:8000/sse>: Timed out while waiting for response to ClientRequest. Waited 30.0 seconds.
10:39:36 - openhands:ERROR: utils.py:152 - Failed to connect to url='<http://fct01-slt-msk1.yclients.cloud:8000/sse>' api_key='******': Timed out while waiting for response to ClientRequest. Waited 30.0 seconds.
Traceback (most recent call last):
  File "/app/openhands/mcp/utils.py", line 138, in create_mcp_clients
    await client.connect_http(server, conversation_id=conversation_id)
  File "/app/openhands/mcp/client.py", line 100, in connect_http
    await self._initialize_and_list_tools()
  File "/app/openhands/mcp/client.py", line 40, in _initialize_and_list_tools
    async with self.client:
               ^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/fastmcp/client/client.py", line 260, in __aexit__
    await self._disconnect()
  File "/app/.venv/lib/python3.13/site-packages/fastmcp/client/client.py", line 298, in _disconnect
    await runner_task
  File "/app/.venv/lib/python3.13/site-packages/fastmcp/client/client.py", line 309, in _session_runner
    await stack.enter_async_context(self._context_manager())
  File "/usr/local/lib/python3.13/contextlib.py", line 668, in enter_async_context
    result = await _enter(cm)
             ^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.13/contextlib.py", line 214, in __aenter__
    return await anext(self.gen)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/fastmcp/client/client.py", line 237, in _context_manager
    with catch(get_catch_handlers()):
         ~~~~~^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/exceptiongroup/_catch.py", line 39, in __exit__
    raise unhandled from exc.__cause__
  File "/app/.venv/lib/python3.13/site-packages/exceptiongroup/_catch.py", line 65, in handle_exception
    result = handler(matched)
  File "/app/.venv/lib/python3.13/site-packages/fastmcp/utilities/exceptions.py", line 29, in _exception_handler
    raise leaf
  File "/app/.venv/lib/python3.13/site-packages/fastmcp/client/transports.py", line 216, in connect_session
    yield session
  File "/app/.venv/lib/python3.13/site-packages/fastmcp/client/client.py", line 245, in _context_manager
    self._initialize_result = await self._session.initialize()
                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/app/.venv/lib/python3.13/site-packages/mcp/client/session.py", line 133, in initialize
    result = await self.send_request(
             ^^^^^^^^^^^^^^^^^^^^^^^^
    ...<15 lines>...
    )
    ^
  File "/app/.venv/lib/python3.13/site-packages/mcp/shared/session.py", line 285, in send_request
    raise McpError(
    ...<8 lines>...
    )
mcp.shared.exceptions.McpError: Timed out while waiting for response to ClientRequest. Waited 30.0 seconds.
10:39:36 - openhands:INFO: utils.py:127 - Initializing MCP agent for url='<http://fct01-slt-msk1.yclients.cloud:8100/sse>' api_key='******' with SSE connection...
10:39:37 - openhands:INFO: client.py:57 - Connected to server with tools: ['gitlab_mr_diff']
l
Hey @plain-orange-3218, unfortunately I don’t know the answer for this, but if you can open a github issue about it we can track it and see if anyone else notices too
🙌 1
p
Thanks for the response! I’m still keeping an eye on this issue and noticed that it doesn’t occur when running locally on a different port. I’ll continue monitoring it further.
👍 1