How to set MCP server timeouts in Claude Code

Set MCP_TIMEOUT before you start Claude Code to change how long an MCP server may take to start. Set MCP_TOOL_TIMEOUT, or a timeout field in that server’s .mcp.json entry, to bound one tool call. All of these values are in milliseconds. The per-server field overrides the global variable for its server only.
Which timeout controls what
Claude Code has five timeout settings for MCP servers, and each one stops a different thing. Startup, a single tool call, and silence during a call are separate limits. Set the one that matches the problem you are trying to solve, because raising one does not move the others.
| Setting | What it bounds | Default | Where it is set |
|---|---|---|---|
MCP_TIMEOUT |
MCP server startup | 30000 ms (30 seconds) | Environment variable |
MCP_TOOL_TIMEOUT |
One tool execution, for every server | 100000000 ms (about 28 hours) | Environment variable |
timeout in .mcp.json |
One tool execution, for one server | Unset, so MCP_TOOL_TIMEOUT applies |
Server entry in .mcp.json |
CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT |
Silence: no response and no progress notification | 300000 ms for network servers, 1800000 ms for stdio servers | Environment variable; 0 turns it off |
CLAUDE_CODE_MCP_AUTO_BACKGROUND_MS |
When a running call moves to a background task | 120000 ms (2 minutes) | Environment variable; 0 turns it off |
The idle window ends a call that goes silent. The background threshold never ends a call; it only moves a long call into a background task. A call that keeps reporting progress is ended only by a wall-clock limit.
Set the startup timeout
Startup timeouts matter when a server needs time to launch, such as one that installs packages or starts a container. The default is 30 seconds. Set the value on the command that starts Claude Code, as the example below shows.
- Choose a value in milliseconds. For example, 60000 is one minute.
- Set the variable on the same line as the start command:
MCP_TIMEOUT=60000 claude
- To apply the value to every session, add it to the
envkey ofsettings.jsoninstead. The environment variables page describesenvas the place to set variables in settings.
Set a tool-call timeout for one server
A per-server timeout is the right tool when one server runs long jobs, such as a scanner or a test runner, and the rest should keep the global limit. The field goes in that server’s entry in .mcp.json, and its value is in milliseconds.
{
"mcpServers": {
"review-tools": {
"command": "node",
"args": ["./review-tools/server.js"],
"timeout": 600000
}
}
}
- Add the
timeoutfield to the server entry. The example allows ten minutes per call. - Keep the value at 1000 or higher. A smaller value is ignored, and the server falls back to
MCP_TOOL_TIMEOUT. - Treat the value as a hard wall-clock limit. Progress notifications from the server do not extend it, so set it above the longest normal call, not above the longest call you have seen once.
What a hung call does to a review
A stuck call blocks the step that waits on it. In a review pipeline, that means the check does not finish, and nobody sees a result until a timeout ends the call. With the defaults, a silent stdio server holds a call for 30 minutes before the idle check aborts it. A call that keeps sending progress is not aborted by idleness, so it runs to the wall-clock limit instead.
The docs describe these limits in time, not in tokens, so this post does not estimate spend during a wait. What the docs do make clear is which limit fires first. Shorter idle windows fail sooner on a silent server. Shorter wall-clock limits cap the work a single call can do, even when it keeps reporting progress. Pick the one that matches the failure you most need to catch.
Timeouts bound time, but they do not decide which servers may run at all. For that, see how to restrict which MCP servers Claude Code can use. If the slow part of a call is the size of its result, how to limit MCP tool output size in Claude Code covers that limit.
Fine print that changes the result
Several rules in the docs are easy to miss, and each one changes what a value does.
- A per-server
timeoutbelow 1000 is ignored and falls through toMCP_TOOL_TIMEOUT. CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUTvalues below 1000 are raised to one second, and the value is capped at the effectiveMCP_TOOL_TIMEOUT.- For HTTP, SSE and claude.ai connector servers, a second per-request timer covers each request until the first response byte. It uses the greatest of 60 seconds, that server’s tool timeout and
MCP_TIMEOUT. Stdio and WebSocket servers have no per-request timer. - The idle timeout needs Claude Code v2.1.187 or later.
Checklist for a review pipeline
- Measure how long a normal call to each server takes on a typical input.
- Set each server’s
timeoutin.mcp.jsonabove that normal time, in milliseconds. - Set
CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUTto the longest silence you accept for that server type. - Raise
MCP_TIMEOUTonly for servers that are slow to start, not for ones that are slow to answer. - Commit the
.mcp.jsonvalues to the repository, so a reviewer can see the limits next to the server definition.
Enforcing this with AIControls
This post does not claim that AIControls sets or enforces MCP timeouts. The timeouts above are Claude Code settings. AIControls provides per-user and per-session cost and budget limits, which cap spend for each developer or session. Use those limits to control cost, and use the timeout settings here to control how long one call may run. For the wider set of controls, read the MCP security guide, or see AIControls for the cost and budget limits.
Frequently asked questions
What happens when an MCP tool call hangs in Claude Code?
Two limits can end it. If the server sends no response and no progress notification for the idle window, the call aborts with an error. If the server keeps sending progress, the call runs until the wall-clock limit, which is MCP_TOOL_TIMEOUT or the server's own timeout field. The docs call the per-server timeout a hard limit that progress notifications do not extend.
Does a per-server timeout override the global tool timeout?
Yes, for that server only. A timeout field in the server's .mcp.json entry replaces MCP_TOOL_TIMEOUT for that server, and other servers keep the global value. Values below 1000 are ignored, so the call falls back to MCP_TOOL_TIMEOUT or its default. A per-server timeout of at least 1000 also sets a floor on the idle window, so Claude Code does not abort that server's calls for idleness sooner than that value.
Can I turn off the idle timeout for MCP tools?
Yes. Set CLAUDE_CODE_MCP_TOOL_IDLE_TIMEOUT to 0 and the idle check is off. Calls then run until the wall-clock limit, which is about 28 hours when MCP_TOOL_TIMEOUT is unset. That is a long wait for a reviewer or an agent to sit through. Keep the idle check on for review pipelines, and set the window to the longest silence you accept for each server type.
Why do stdio servers get a longer idle window than HTTP servers?
The docs set the idle default at 30 minutes for stdio servers, and 5 minutes for HTTP, SSE, WebSocket and claude.ai connector servers. Before Claude Code v2.1.203, stdio servers were exempt from the idle timeout, so on an older version a silent stdio call waits until the wall-clock limit. Check your version before you rely on idle aborts for local servers.