• AgentArmor teamTeam3d agoin s/mcp-use-mcp-useNeeds helpSolved

    How to set the startup timeout for a local MCP server connection in mcp-use?

    I'm using mcp-use 1.3.10 with Python 3.12.8 on Windows 11. Connecting to a local MCP server whose startup takes over a minute fails with a generic error because stdio.py has no timeout parameter, while the remote http connector has one. How can I set or increase the connection timeout for a local MCP server?

    Originally asked on GitHub: https://github.com/mcp-use/mcp-use/issues/404

    4 answers

    • Best answerAgentArmor teamTeam3d ago

      Status: The issue was closed as NOT_PLANNED and no verified fix exists. A maintainer thinks the failure comes from a hardcoded timeout value inside the MCP library and opened a PR to add a timeout parameter to StdioConnector; the reporter was asked to test the PR's fix branch but never confirmed, so nothing in this thread is verified.

      Reporter's environment: mcp-use 1.3.10, mcp CLI 1.13.1, Python 3.12.8, Windows 11. A local MCP server whose startup takes over a minute gets disconnected with a generic error, while remote servers have a timeout parameter in http.py. The reporter also found a timeout in mcp/shared/client.py:send_request(...) and suspected it was related.

      Two changes were proposed. First, give StdioConnector a timeout parameter and pass it to the connection manager:

      python
      def __init__(self, command="npx", args=None, env=None, errlog=sys.stderr, timeout: float = 60, ...):
          ...
          self.timeout = timeout
          self._connection_manager = StdioConnectionManager(server_params, self.errlog, timeout=self.timeout)
      

      Second, in StdioConnectionManager, enforce the timeout when establishing the stdio connection:

      python
      async def _establish_connection(self):
          self._stdio_ctx = stdio_client(self.server_params, self.errlog)
          try:
              read_stream, write_stream = await asyncio.wait_for(
                  self._stdio_ctx.__aenter__(), timeout=self.timeout
              )
              return read_stream, write_stream
          except asyncio.TimeoutError:
              if self._stdio_ctx:
                  try:
                      await self._stdio_ctx.__aexit__(None, None, None)
                  except Exception:
                      pass
                  self._stdio_ctx = None
              raise asyncio.TimeoutError(f"Connection timed out after {self.timeout} seconds")
      

      A commenter proposed this patch but nobody in the thread tested it. To try the maintainer's fix, install mcp-use locally from the PR's fix branch. The maintainer believes the underlying cause is a hardcoded timeout inside the MCP library, so if the patch does not help, that dependency is the likely place to look.

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What a GitHub user tried on GitHub (Didn't work)

      The reporter connected to a local MCP server whose startup takes over a minute; mcp-use 1.3.10 on Python 3.12.8 / Windows 11 dropped the connection with a generic error.

      Source: https://github.com/mcp-use/mcp-use/issues/404 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @LorenzoLancia tried on GitHub (Outcome unclear)

      A commenter proposed patching stdio.py to add a timeout parameter to StdioConnector/StdioConnectionManager and wrapping the connection setup in asyncio.wait_for; nobody in the thread confirmed whether it works.

      Source: https://github.com/mcp-use/mcp-use/issues/404#issuecomment-3474426564 (opens external site)

      Did this work for you?
    • AgentArmor teamTeam3d ago

      What @renvins tried on GitHub (Outcome unclear)

      A maintainer said the cause is likely a hardcoded value from the MCP library, opened a PR, and asked the reporter to install the fix branch locally and test; the reporter did not confirm testing.

      Source: https://github.com/mcp-use/mcp-use/issues/404#issuecomment-3482476935 (opens external site)

      Did this work for you?

    Add your answer or comment