fix(lint): extract helper function to reduce statement count in MCP rest_endpoints#20629
Merged
ishaan-jaff merged 1 commit intomainfrom Feb 7, 2026
Merged
fix(lint): extract helper function to reduce statement count in MCP rest_endpoints#20629ishaan-jaff merged 1 commit intomainfrom
ishaan-jaff merged 1 commit intomainfrom
Conversation
…tool_rest_api Extract the allowed MCP servers resolution logic with IP filtering into a dedicated helper function _resolve_allowed_mcp_servers_with_ip_filter. This reduces the statement count in call_tool_rest_api from 51 to under 50, fixing the ruff PLR0915 (too many statements) lint error.
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Shin seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
Contributor
Greptile OverviewGreptile Summary
Confidence Score: 5/5
|
| Filename | Overview |
|---|---|
| litellm/proxy/_experimental/mcp_server/rest_endpoints.py | Extracts allowed MCP server resolution + IP filtering into _resolve_allowed_mcp_servers_with_ip_filter to reduce call_tool_rest_api statement count; refactor appears behavior-preserving with the same 403 behavior when server is not allowed. |
Sequence Diagram
sequenceDiagram
autonumber
participant C as Client
participant RE as rest_endpoints.py
participant AC as build_effective_auth_contexts
participant MM as global_mcp_server_manager
C->>RE: POST /mcp/tool/call (call_tool_rest_api)
RE->>RE: _resolve_allowed_mcp_servers_with_ip_filter(request, user_api_key_dict, server_id)
RE->>AC: build_effective_auth_contexts(user_api_key_dict)
AC-->>RE: auth_contexts[]
RE->>RE: collect allowed_mcp_server_ids
RE->>MM: filter_server_ids_by_ip(allowed_ids, request.client.host)
MM-->>RE: filtered_server_ids
alt server_id not in filtered_server_ids
RE-->>C: 403 HTTPException (MCP server not allowed)
else server allowed
RE->>MM: get_server(server_id)
MM-->>RE: MCPServer
RE-->>C: continue tool call using server config
end
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.
Summary
Fixes the ruff
PLR0915lint error (too many statements) incall_tool_rest_apifunction.Changes
Extracted the allowed MCP servers resolution logic with IP filtering into a dedicated helper function
_resolve_allowed_mcp_servers_with_ip_filter.This reduces the statement count in
call_tool_rest_apifrom 51 to under 50.Root Cause
PR #20607 (MCP Gateway - Allow setting MCP Servers as Private/Public available on Internet) replaced the previous
_resolve_allowed_mcp_servers_for_tool_callhelper with inline code, which pushed the function over 50 statements.Testing
ruff check --select PLR0915passes