Skip to content

fix(lint): extract helper function to reduce statement count in MCP rest_endpoints#20629

Merged
ishaan-jaff merged 1 commit intomainfrom
litellm_fix_ruff_plr0915_mcp
Feb 7, 2026
Merged

fix(lint): extract helper function to reduce statement count in MCP rest_endpoints#20629
ishaan-jaff merged 1 commit intomainfrom
litellm_fix_ruff_plr0915_mcp

Conversation

@shin-bot-litellm
Copy link
Collaborator

Summary

Fixes the ruff PLR0915 lint error (too many statements) in call_tool_rest_api function.

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_api from 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_call helper with inline code, which pushed the function over 50 statements.

Testing

  • ruff check --select PLR0915 passes
  • Full ruff check passes
  • No functional changes - only refactoring

…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.
@vercel
Copy link

vercel bot commented Feb 7, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
litellm Ready Ready Preview, Comment Feb 7, 2026 3:35am

Request Review

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.


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.

@greptile-apps
Copy link
Contributor

greptile-apps bot commented Feb 7, 2026

Greptile Overview

Greptile Summary

  • Refactors MCP call_tool_rest_api by extracting allowed-server resolution + IP filtering into a helper to satisfy Ruff PLR0915.
  • Keeps request-time behavior in litellm/proxy/_experimental/mcp_server/rest_endpoints.py, aiming for no functional changes.
  • Moves the “which MCP servers are callable from this client IP?” logic into _resolve_allowed_mcp_servers_with_ip_filter, reducing statement count and improving readability.

Confidence Score: 5/5

  • This PR is safe to merge with minimal risk.
  • Changes are a behavior-preserving refactor to satisfy Ruff PLR0915 by extracting existing allowed-server/IP-filter logic into a helper; review found no altered conditions, return types, or exception behavior on the request path.
  • No files require special attention

Important Files Changed

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
Loading

Copy link
Contributor

@greptile-apps greptile-apps bot left a comment

Choose a reason for hiding this comment

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

1 file reviewed, no comments

Edit Code Review Agent Settings | Greptile

@ishaan-jaff ishaan-jaff merged commit 02a33ab into main Feb 7, 2026
57 of 67 checks passed
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.

3 participants