fix(fetch): make request timeout configurable via CLI, env var, and per-call override - #4636
Open
magai2002 wants to merge 1 commit into
Open
Conversation
…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
12 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The
fetchMCP 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
timeout_msargument), CLI args, environment variablesMotivation 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:
timeout_msargument on thefetchtoolFETCH_TIMEOUT_MSenvironment variable (server-wide default)--timeoutCLI 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?
fetch_urlpasses 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.--timeoutandFETCH_TIMEOUT_MSreachserve()with correct precedence.Breaking Changes
None. Default behavior (30s timeout) is unchanged if no new option is used.
Types of changes
Checklist
Additional context
timeout_msusesgt=0validation like the other numeric fields on theFetchmodel. 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.