Skip to content

fix(fetch): make request timeout configurable via CLI, env var, and per-call override - #4636

Open
magai2002 wants to merge 1 commit into
modelcontextprotocol:mainfrom
magai2002:fix-4448-fetch-timeout-override
Open

fix(fetch): make request timeout configurable via CLI, env var, and per-call override#4636
magai2002 wants to merge 1 commit into
modelcontextprotocol:mainfrom
magai2002:fix-4448-fetch-timeout-override

Conversation

@magai2002

Copy link
Copy Markdown

Description

The fetch MCP server hardcodes a 30s httpx timeout with no way to override it. This makes legitimate large downloads (big files, slow APIs) fail outright, and gives no way to fail fast on quick health-check-style calls.

Server Details

  • Server: fetch
  • Changes to: tools (new timeout_ms argument), CLI args, environment variables

Motivation and Context

Closes #4448. Different use cases need different timeouts — a 5-10s timeout for doc lookups vs. 60-300s for large file downloads. One hardcoded value forces a bad tradeoff either way.

Adds three ways to configure it, most specific wins:

  1. Per-call timeout_ms argument on the fetch tool
  2. FETCH_TIMEOUT_MS environment variable (server-wide default)
  3. --timeout CLI flag in milliseconds (takes precedence over the env var if both are set)

Default stays 30000ms if none of the above are set, so this is non-breaking.

How Has This Been Tested?

  • Added unit tests asserting fetch_url passes both the default and a custom timeout through to the underlying httpx call (uv run pytest: 22 passed).
  • uv run ruff check .: clean. uv run pyright: 0 errors.
  • Manually smoke-tested that both --timeout and FETCH_TIMEOUT_MS reach serve() with correct precedence.
  • Have not tested this against a live LLM client (e.g. Claude Desktop) — happy to if that's wanted before merge.

Breaking Changes

None. Default behavior (30s timeout) is unchanged if no new option is used.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Documentation update

Checklist

  • I have read the MCP Protocol Documentation
  • My changes follows MCP security best practices
  • I have updated the server's README accordingly
  • I have tested this with an LLM client
  • My code follows the repository's style guidelines
  • New and existing tests pass locally
  • I have added appropriate error handling
  • I have documented all environment variables and configuration options

Additional context

timeout_ms uses gt=0 validation like the other numeric fields on the Fetch model. Precedence order (per-call > CLI flag > env var > 30s default) matches the issue's request, with CLI winning over env var when a server operator sets both.

…er-call override

The fetch server hardcoded a 30s httpx timeout with no way to change it,
which makes large downloads fail and slow health checks wait too long.

Add three ways to set it, most specific wins:
- per-call `timeout_ms` argument on the `fetch` tool
- `FETCH_TIMEOUT_MS` environment variable
- `--timeout` CLI flag (takes precedence over the env var)

Default stays 30s if none of the above are set.

Closes modelcontextprotocol#4448
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fetch: hardcoded 30s timeout with no CLI/env/per-request override

1 participant