Skip to content

[BUG] MCP Timeout needs to be configurable #424

Closed

Description

@workingdoge

Environment

  • Platform (select one):
    • Anthropic API
    • AWS Bedrock
    • Google Vertex AI
    • Other:
  • Claude CLI version:0.2.36
  • Operating System: MacOS
  • Terminal: Ghostty

Bug Description

MCP timeout error when using browser use

Steps to Reproduce

  1. install browser_use mcp
  2. tell claude code to search
  3. search takes too long and claude code times out with a -32000: Connection closed

Expected Behavior

Complete Search

Actual Behavior

Timeout

Activity

  1. self-assigned this
    on Mar 11, 2025
  2. ashwin-ant commented on Mar 11, 2025

    @ashwin-ant
    Collaborator

    Are you saying the tool call is timing out or the server startup?

  3. am0y commented on Mar 11, 2025

    @am0y

    also getting this issue frequently when server startup, sometimes i dont get it sometimes i do. its frustrating

  4. wskish commented on Mar 13, 2025

    @wskish

    I am seeing a timeout issue frequently as well (MCP error -32001: Request timed out) for long-running mcp tool calls.

    The issue is the underlying mcp library has a default 60 second timeout which is reasonable for most cases but there is a long tail of operations that will take longer than this.

    I tried adding progress_reporting to my mcp server but then discovered that claude code is not supporting it since the MCP typescript sdk defaults to ignoring progress reporting for timeout purposes. added #470 which would probably be better than trying to manage timeouts of unknown duration.

  5. pnispel commented on Mar 17, 2025

    @pnispel

    Getting connection timeouts on server startup as well:

    MCP server "postgres" Connection failed: Connection to MCP server "postgres" timed out after 5000ms
    MCP server "typescript-definition-finder" Connection failed: Connection to MCP server "typescript-definition-finder" timed out after 5000ms
    

    These both work in claude desktop fine

  6. ashwin-ant commented on Mar 17, 2025

    @ashwin-ant
    Collaborator

    @pnispel you can configure a longer timeout with the MCP_TIMEOUT environment variable: MCP_TIMEOUT=30000 claude for example

  7. pnispel commented on Mar 17, 2025

    @pnispel

    Oh awesome thank you. I figured I was missing something like that

  8. ashwin-ant commented on Mar 17, 2025

    @ashwin-ant
    Collaborator

    No worries, we just rolled it out last week!

  9. inheinsight commented on Mar 19, 2025

    @inheinsight

    @ashwin-ant it would be awesome if we could set this with claude config set. Do you plan to include that instead of having to add this as a variable when we start Claude?

  10. ashwin-ant commented on Mar 19, 2025

    @ashwin-ant
    Collaborator

    We can look into this! We're also going to be increasing the default timeout to 30 seconds, which should hopefully make it so you don't need to override it.

  11. inheinsight commented on Mar 19, 2025

    @inheinsight
  12. luketchang commented on Mar 19, 2025

    @luketchang

    you can configure a longer timeout with the MCP_TIMEOUT environment variable: MCP_TIMEOUT=30000 claude for example

    @ashwin-ant This isn't working on my end still. We set MCP_TIMEOUT in the transport and also specify the timeout option when we call client.callTool and I still get the below error, is this correct? Error still indicates even callTool timeout is not being applied either

    Code

    transport = new StdioClientTransport({
      command: "claude",
      args: ["mcp", "serve"],
      env: {
        ...Object.fromEntries(
          Object.entries(process.env)
            .filter(([, value]) => value !== undefined)
            .map(([key, value]) => [key, value as string])
        ),
        MCP_TIMEOUT: String(1200000), // 20 min
      },
      cwd: workingDirectory,
    });
    
    // Initialize client with explicit timeout settings
    mcpClient = new Client({
      name: "client",
      version: "1.0.0",
      options: {},
    });
    
    await mcpClient.connect(transport);
    
    const mcpResponse = await mcpClient.callTool({
        name: "dispatch_agent",
        arguments: {
          prompt: mcpPrompt,
        },
        options: {
          timeout: 1200000, // 20 min
        },
      });
    

    Error

    Error in main: McpError: MCP error -32001: Request timed out
        at Timeout.timeoutHandler (/Users/luketchang/code/<dir>/node_modules/.pnpm/@[email protected]/node_modules/@modelcontextprotocol/sdk/src/shared/protocol.ts:528:43)
        at listOnTimeout (node:internal/timers:581:17)
        at process.processTimers (node:internal/timers:519:7) {
      code: -32001,
      data: { timeout: 60000 }
    }
    
  13. ashwin-ant commented on Mar 19, 2025

    @ashwin-ant
    Collaborator

    @luketchang the timeout is not for launching Claude Code as an MCP server, it's for using Claude Code as an MCP client that launches other servers. Can you share more about what you're trying to do?

  14. luketchang commented on Mar 19, 2025

    @luketchang

    Can you share more about what you're trying to do?

    Yep! We have an agent that fetches code context and is currently doing so by dispatching a task (via client.callTool(...)) to Claude Code, which runs as an MCP server via claude mcp serve.

  15. Liu-Eroteme commented on Mar 21, 2025

    @Liu-Eroteme

    I'm running into this issue as well - wanted to test if giving claude access to other LLMs (e.g. large models like 4.5, expert finetunes, deep research like setups) could help in certain situations, but have not found a way to make longer running queries work without resorting to a firecrawl-like async setup (return job ID, let claude query job ID status, etc)

    Would greatly appreciate a config option / env var for MCP tool call timeout as well

  16. luketchang commented on Mar 25, 2025

    @luketchang

    Hey @ashwin-ant any updates here? Would there be a way to increase the timeout for dispatch_agent calls over MCP?

  17. bcherny commented on Apr 1, 2025

    @bcherny
    Collaborator

    Splitting this out and tracking in #680

  18. gaurav219 commented on Apr 30, 2025

    @gaurav219

    you can configure a longer timeout with the MCP_TIMEOUT environment variable: MCP_TIMEOUT=30000 claude for example

    @ashwin-ant This isn't working on my end still. We set MCP_TIMEOUT in the transport and also specify the timeout option when we call client.callTool and I still get the below error, is this correct? Error still indicates even callTool timeout is not being applied either

    Code

    transport = new StdioClientTransport({
      command: "claude",
      args: ["mcp", "serve"],
      env: {
        ...Object.fromEntries(
          Object.entries(process.env)
            .filter(([, value]) => value !== undefined)
            .map(([key, value]) => [key, value as string])
        ),
        MCP_TIMEOUT: String(1200000), // 20 min
      },
      cwd: workingDirectory,
    });
    
    // Initialize client with explicit timeout settings
    mcpClient = new Client({
      name: "client",
      version: "1.0.0",
      options: {},
    });
    
    await mcpClient.connect(transport);
    
    const mcpResponse = await mcpClient.callTool({
        name: "dispatch_agent",
        arguments: {
          prompt: mcpPrompt,
        },
        options: {
          timeout: 1200000, // 20 min
        },
      });
    

    Error

    Error in main: McpError: MCP error -32001: Request timed out
        at Timeout.timeoutHandler (/Users/luketchang/code/<dir>/node_modules/.pnpm/@[email protected]/node_modules/@modelcontextprotocol/sdk/src/shared/protocol.ts:528:43)
        at listOnTimeout (node:internal/timers:581:17)
        at process.processTimers (node:internal/timers:519:7) {
      code: -32001,
      data: { timeout: 60000 }
    }
    

    Hi, did you resolve this issue?
    I'm also facing similar issue where it seems the tool is not getting called and it times out.

  19. theodormarcu commented on May 12, 2025

    @theodormarcu

    Wanted to bump this! It still seems to cause issues.

    Ok I figured it out finally 🎊 🥳

    The issue is actually solved by the MCP typescript-sdk. I think there must've been an interface change sometime in the past few months. The correct way to set up the timeout on the client is:

    // Notice how we're calling callTool(arg1, arg2, arg3);
        const mcpResponse = await mcpClient.callTool(
          {
            name: "Task",
            arguments: {
              prompt: mcpPrompt,
              description: "Code Search",
            },
          },
          CallToolResultSchema,
    // options is here, after schema, not as part of arg1
          {
            timeout: DEFAULT_TOOL_CALL_TIMEOUT,
            resetTimeoutOnProgress: true,
          }
        );
    

    Notice how callTool does not accept an object, but 3 params, including two objects.

    The options should not be nested.

    Example of a wrong implementation:

        const mcpResponse = await mcpClient.callTool({
          name: "Task",
          arguments: {
            prompt: mcpPrompt,
          },
         // BAD -> options is part of the tool
          options: {
            timeout: DEFAULT_TOOL_CALL_TIMEOUT,
          },
        });```
    
  20. mzhadigerov commented on May 13, 2025

    @mzhadigerov

    is it possible to set the timeout argument for Claude Desktop? All my mcp servers were accessible yesterday. Without any changes in code, they throw timeout errors today

  21. github-actions commented on Aug 10, 2025

    @github-actions

    This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.

  22. locked as resolved and limited conversation to collaborators on Aug 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

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