[Feat] Make MCP timeouts configurable via environment variables#22287
Open
shivamrawat1 wants to merge 1 commit intomainfrom
Open
[Feat] Make MCP timeouts configurable via environment variables#22287shivamrawat1 wants to merge 1 commit intomainfrom
shivamrawat1 wants to merge 1 commit intomainfrom
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Contributor
Greptile SummaryThis PR makes all four MCP-related timeouts configurable via environment variables instead of being hardcoded. It introduces
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/constants.py | Adds 4 new float constants for MCP timeouts, each configurable via env var with sensible defaults. Follows existing patterns in the file. |
| litellm/experimental_mcp_client/client.py | Changes timeout parameter default from 60.0 to None, falling back to MCP_CLIENT_TIMEOUT constant. Maintains backward compatibility since explicit timeout values still take precedence. |
| litellm/proxy/_experimental/mcp_server/mcp_server_manager.py | Replaces all hardcoded timeout values (60.0, 30.0, 10.0) with corresponding constants from litellm.constants. Health check error message now uses the configurable timeout value. |
| tests/mcp_tests/test_mcp_client_unit.py | Adds a mock-only test verifying MCPClient uses the configurable MCP_CLIENT_TIMEOUT constant when no explicit timeout is passed. |
| tests/test_litellm/test_constants.py | Adds the 4 new MCP timeout constants to the env var name mapping so the existing generic override test covers them. |
| docs/my-website/docs/proxy/config_settings.md | Documents the 4 new environment variables for MCP timeouts with descriptions and defaults. |
Flowchart
%%{init: {'theme': 'neutral'}}%%
flowchart TD
ENV["Environment Variables\n(LITELLM_MCP_CLIENT_TIMEOUT,\nLITELLM_MCP_TOOL_LISTING_TIMEOUT,\nLITELLM_MCP_METADATA_TIMEOUT,\nLITELLM_MCP_HEALTH_CHECK_TIMEOUT)"]
CONST["litellm/constants.py\n(MCP_CLIENT_TIMEOUT,\nMCP_TOOL_LISTING_TIMEOUT,\nMCP_METADATA_TIMEOUT,\nMCP_HEALTH_CHECK_TIMEOUT)"]
CLIENT["MCPClient.__init__\ntimeout parameter"]
MGR_CLIENT["MCPServerManager._create_mcp_client\nclient timeout"]
MGR_TOOLS["MCPServerManager._fetch_tools_with_timeout\nanyio.fail_after"]
MGR_META["MCPServerManager._fetch_oauth_metadata\nhttpx timeout"]
MGR_HEALTH["MCPServerManager.health_check\nasyncio.wait_for timeout"]
ENV -->|os.getenv| CONST
CONST -->|MCP_CLIENT_TIMEOUT| CLIENT
CONST -->|MCP_CLIENT_TIMEOUT| MGR_CLIENT
CONST -->|MCP_TOOL_LISTING_TIMEOUT| MGR_TOOLS
CONST -->|MCP_METADATA_TIMEOUT| MGR_META
CONST -->|MCP_HEALTH_CHECK_TIMEOUT| MGR_HEALTH
Last reviewed commit: 420c12a
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.
Relevant issues
MCP timeouts were hardcoded and could not be adjusted for slower or custom MCP servers. This change adds four environment variables so all MCP-related timeouts can be configured:
LITELLM_MCP_CLIENT_TIMEOUT (default 60s) – connection timeout for stdio and HTTP/SSE transports
LITELLM_MCP_TOOL_LISTING_TIMEOUT (default 30s) – timeout when listing tools for an MCP server
LITELLM_MCP_METADATA_TIMEOUT (default 10s) – HTTP timeout for OAuth metadata fetching
LITELLM_MCP_HEALTH_CHECK_TIMEOUT (default 10s) – timeout for MCP server health checks
These are read from litellm.constants and used in MCPClient and mcp_server_manager.py.
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
tests/litellm/directory, Adding at least 1 test is a hard requirement - see detailsmake test-unit@greptileaiand received a Confidence Score of at least 4/5 before requesting a maintainer reviewCI (LiteLLM team)
Branch creation CI run
Link:
CI run for the last commit
Link:
Merge / cherry-pick CI run
Links:
Type
🆕 New Feature
📖 Documentation
✅ Test