[BUG] MCP Timeout needs to be configurable

Resolved 💬 20 comments Opened Mar 11, 2025 by workingdoge Closed Apr 1, 2025
💡 Likely answer: A maintainer (ashwin-ant, collaborator) responded on this thread — see the highlighted reply below.

Environment

  • Platform (select one):
  • [x] Anthropic API
  • [ ] AWS Bedrock
  • [ ] Google Vertex AI
  • [ ] Other: <!-- specify -->
  • 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

View original on GitHub ↗

20 Comments

ashwin-ant collaborator · 1 year ago

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

am0y · 1 year ago

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

wskish · 1 year ago

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 https://github.com/anthropics/claude-code/issues/470 which would probably be better than trying to manage timeouts of unknown duration.

pnispel · 1 year ago

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

ashwin-ant collaborator · 1 year ago

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

pnispel · 1 year ago

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

ashwin-ant collaborator · 1 year ago

No worries, we just rolled it out last week!

inheinsight · 1 year ago

@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?

ashwin-ant collaborator · 1 year ago

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.

inheinsight · 1 year ago

Oh yeah, that'd definitely help!

On Tue, Mar 18, 2025, 8:07 PM Ashwin Bhat @.***> wrote:

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. — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/424#issuecomment-2735140921>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AHFKXUREFYHW3K7NFCP444T2VDGPXAVCNFSM6AAAAABYXX3IBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZVGE2DAOJSGE> . You are receiving this because you commented.Message ID: @.***> [image: ashwin-ant]ashwin-ant left a comment (anthropics/claude-code#424) <https://github.com/anthropics/claude-code/issues/424#issuecomment-2735140921> 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. — Reply to this email directly, view it on GitHub <https://github.com/anthropics/claude-code/issues/424#issuecomment-2735140921>, or unsubscribe <https://github.com/notifications/unsubscribe-auth/AHFKXUREFYHW3K7NFCP444T2VDGPXAVCNFSM6AAAAABYXX3IBGVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDOMZVGE2DAOJSGE> . You are receiving this because you commented.Message ID: @.***>
luketchang · 1 year ago
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/@modelcontextprotocol+sdk@1.7.0/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 }
}
ashwin-ant collaborator · 1 year ago

@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?

luketchang · 1 year ago
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.

Liu-Eroteme · 1 year ago

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

luketchang · 1 year ago

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

bcherny collaborator · 1 year ago

Splitting this out and tracking in https://github.com/anthropics/claude-code/issues/680

gaurav219 · 1 year ago
> 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/@modelcontextprotocol+sdk@1.7.0/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.

theodormarcu · 1 year ago

~~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,
      },
    });```
mzhadigerov · 1 year ago

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

github-actions[bot] · 11 months ago

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.