Skip to content

Fix HTTP transport timeout defaulting to 5 seconds#2849

Merged
jlowin merged 4 commits intomainfrom
fix-http-transport-timeout-3x
Jan 12, 2026
Merged

Fix HTTP transport timeout defaulting to 5 seconds#2849
jlowin merged 4 commits intomainfrom
fix-http-transport-timeout-3x

Conversation

@jlowin
Copy link
Copy Markdown
Member

@jlowin jlowin commented Jan 12, 2026

Forward-port of #2848 for FastMCP 3.x.

When StreamableHttpTransport was updated to use the new streamable_http_client API, the code path for creating an httpx client when no factory is provided used httpx.AsyncClient() directly. Without an explicit timeout, httpx defaults to 5 seconds for all operations.

This caused tools taking longer than 5 seconds to fail with a 409 Conflict error as the client's SSE stream would timeout and trigger reconnection logic that conflicts with the existing GET stream.

The fix uses create_mcp_http_client() from the MCP SDK which sets appropriate defaults (30s connect, 5min read timeout) and enables follow_redirects.

Use create_mcp_http_client() instead of bare httpx.AsyncClient()
when no httpx_client_factory is provided. This ensures proper MCP
timeouts (30s connect, 5min read) instead of httpx's 5-second default.

Forward-port of fix from release/2.x for issues #2842 and #2845.
@marvin-context-protocol marvin-context-protocol Bot added bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. client Related to the FastMCP client SDK or client-side functionality. http Related to HTTP transport, networking, or web server functionality. labels Jan 12, 2026
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4f671d903e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

transport=StreamableHttpTransport(streamable_http_server)
) as client:
# This should NOT timeout since we fixed the default timeout
result = await client.call_tool("slow_tool", {"duration": 6})
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Prevent test timeout from 6s tool duration

This test exercises a 6‑second tool call, but the repo’s pytest configuration sets a default timeout of 5 seconds (pyproject.tomltimeout = 5), so the test will time out under the normal test run even when the fix works. That makes CI fail for the new test in any environment where pytest-timeout is enabled (as it is here). Consider adding @pytest.mark.timeout(10) or shortening the duration so the test completes within the global timeout.

Useful? React with 👍 / 👎.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 12, 2026

Warning

Rate limit exceeded

@jlowin has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 8 minutes and 28 seconds before requesting another review.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

📥 Commits

Reviewing files that changed from the base of the PR and between 4f671d9 and 9b33a05.

⛔ Files ignored due to path filters (2)
  • loq.toml is excluded by none and included by none
  • tests/integration_tests/test_timeout_fix.py is excluded by none and included by none
📒 Files selected for processing (1)
  • src/fastmcp/client/transports.py

Walkthrough

This pull request refactors timeout handling in the StreamableHttpTransport.connect_session method. It introduces explicit timeout variable management derived from read_timeout_seconds and updates the HTTP client construction logic. When an httpx_client_factory is provided, the timeout is now passed along with headers, auth, and follow_redirects parameters. When no factory is provided, the code now uses create_mcp_http_client from the MCP utilities instead of direct httpx client configuration. The change maintains backward compatibility while centralizing timeout encapsulation as httpx.Timeout objects.

Possibly related PRs

🚥 Pre-merge checks | ✅ 1 | ❌ 2
❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides clear context about the issue and fix, but is missing the required contributors checklist with issue reference, testing confirmation, and self-review confirmation. Add the contributors checklist items including the issue number reference (#2848 forward-port context), test confirmation, and review readiness markers.
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (1 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main change: fixing HTTP transport timeout defaults from 5 seconds to appropriate values.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 18c71f9 and 4f671d9.

⛔ Files ignored due to path filters (2)
  • loq.toml is excluded by none and included by none
  • tests/integration_tests/test_timeout_fix.py is excluded by none and included by none
📒 Files selected for processing (1)
  • src/fastmcp/client/transports.py
🧰 Additional context used
📓 Path-based instructions (1)
src/**/*.py

📄 CodeRabbit inference engine (AGENTS.md)

src/**/*.py: Python source code must use Python ≥3.10 with full type annotations
Never use bare except - be specific with exception types
Prioritize readable, understandable code - clarity over cleverness; avoid obfuscated or confusing patterns
Follow existing patterns and maintain consistency across the codebase

Files:

  • src/fastmcp/client/transports.py
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (4)
  • GitHub Check: Run tests: Python 3.10 on windows-latest
  • GitHub Check: Run tests: Python 3.13 on ubuntu-latest
  • GitHub Check: Run tests: Python 3.10 on ubuntu-latest
  • GitHub Check: Run tests with lowest-direct dependencies
🔇 Additional comments (2)
src/fastmcp/client/transports.py (2)

256-262: LGTM - timeout handling is straightforward.

The conversion from timedelta to httpx.Timeout is correct. Note that httpx.Timeout(seconds) sets all timeout types (connect, read, write, pool) to the same value, which is a reasonable default when users specify a single timeout duration.


28-28: Verify stability and support status of private module import.

The import from mcp.shared._httpx_utils uses a private-designated module (underscore prefix), but web search indicates both McpHttpClientFactory and create_mcp_http_client are documented in the MCP SDK source and referenced in official docs. However, confirm whether this is an officially supported public API or internal implementation detail, and whether version pinning or an alternative approach is recommended.

Comment thread src/fastmcp/client/transports.py
@jlowin jlowin merged commit 9b18db2 into main Jan 12, 2026
11 checks passed
@jlowin jlowin deleted the fix-http-transport-timeout-3x branch January 12, 2026 19:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working. Reports of errors, unexpected behavior, or broken functionality. client Related to the FastMCP client SDK or client-side functionality. http Related to HTTP transport, networking, or web server functionality.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant