Heuristic:1mcp app Agent Tool Call Timeout Budget
| Knowledge Sources | |
|---|---|
| Domains | Optimization, Reliability |
| Last Updated | 2026-10-29 00:00 GMT |
Overview
Bound MCP tool call execution to 30 seconds by default (configurable 1ms–600s) to prevent runaway tool invocations from blocking the gateway.
Description
The 1MCP gateway enforces a timeout on MCP tool calls invoked through the CLI (`run` command) and the HTTP transport. The default timeout is 30,000ms (30 seconds), matching the MCP execution budget on both CLI transports. The maximum allowed value is 600,000ms (10 minutes). The timeout is configurable via the `--timeout` CLI flag or the `ONE_MCP_TIMEOUT_MS` environment variable. When a tool call exceeds the timeout, it is aborted and the caller receives an error.
Usage
Use this heuristic when:
- Configuring tool call deadlines for long-running MCP tools (e.g., code execution, file operations)
- Experiencing timeout errors for tools that legitimately need more than 30 seconds
- Hardening the gateway against runaway or hung MCP server tools
The Insight (Rule of Thumb)
- Action: Set `--timeout <ms>` on the `run` command, or set `ONE_MCP_TIMEOUT_MS` environment variable.
- Default value: 30,000ms (30 seconds)
- Maximum value: 600,000ms (10 minutes)
- Minimum value: 1ms
- Trade-off: A longer timeout allows slow tools to complete but holds gateway resources longer. A shorter timeout fails legitimate long-running tools.
- Rule: Keep the default 30s for interactive agent workflows. Increase to 60-120s for tools that perform file I/O or network requests. Use the maximum (600s) only for exceptional long-running operations.
Reasoning
MCP tool calls are synchronous from the agent's perspective: the agent sends a `tools/call` request and waits for the result. Without a timeout, a hung MCP server (e.g., waiting on a deadlocked database connection) would block the agent indefinitely. The 30-second default matches the common expectation for interactive AI agent workflows, where tools are expected to return within a conversational turn.
The 600-second maximum (10 minutes) provides an upper bound for exceptional cases while preventing truly unbounded execution. This protects the gateway from resource exhaustion: each in-flight tool call holds a transport connection, a worker slot, and potentially a subprocess.
Code Evidence
Default and max timeout from `src/constants/cliTimeouts.ts:1-3`:
/** Match the existing MCP execution budget on both CLI transports. */
export const DEFAULT_TOOL_CALL_TIMEOUT_MS = 30_000;
export const MAX_TOOL_CALL_TIMEOUT_MS = 600_000;
CLI flag and env var from `src/commands/run/index.ts:47`:
describe: 'Tool execution deadline in milliseconds (1–600000; env: ONE_MCP_TIMEOUT_MS)',
Environment variable usage in tests from `src/commands/run/index.test.ts:29`:
vi.stubEnv('ONE_MCP_TIMEOUT_MS', '45000');