Skip to content

fix(mcp): stop proxy-started legacy listeners from consuming server rpm (rc/1.107.0) - #46982

Merged
yuneng-berri merged 1 commit into
rc/1.107.0from
litellm_mcp-admission-1016-rc
Oct 16, 2026
Merged

yuneng-berri merged 1 commit into
rc/1.107.0from
litellm_mcp-admission-1016-rc

Conversation

@yuneng-berri

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

How it solves it:

User Flow

Before: a team using an MCP server with rpm: 5 on rc/1.107.0 loses requests to sessions they never used

  1. The admin configures an MCP server with rpm: 5
  2. A client connects to POST http://localhost:4000/mcp/ and calls tools/list 8 times in one session
  3. Only 4 calls succeed, the 5th fails with Rate limit exceeded for mcp_server ... Current limit: 5
  4. If the MCP server announces tool list changes, two clients that only connect use up the whole budget

After: connecting is free again, so the client gets its full budget

  1. The admin configures an MCP server with rpm: 5
  2. A client connects to POST http://localhost:4000/mcp/ and calls tools/list 8 times in one session
  3. 5 calls succeed, matching the configured limit
  4. With an MCP server that announces tool list changes, two idle clients still leave 5 of 5 calls for the next one

Affected release

Regression in rc/1.107.0, from #46153. Fixed on main by #46968

Pre-Submission checklist

Please complete all items before asking a LiteLLM maintainer to review your PR

  • I have added meaningful tests
  • The handful of test files covering my change pass locally, e.g. uv run pytest tests/unit/<your_test_file>.py -v. Leave the suites (make test-unit-*, make test-unit) to CI: it finishes in ~15 minutes where a laptop takes an hour or more
  • My PR passes all required CI/CD checks (e.g., lint, schema.d.ts sync check, etc.)
  • My PR's scope is as isolated as possible; it only solves 1 specific problem
  • Every automated review on my PR's latest commit has finished, and I have addressed or replied to each of its findings before requesting a maintainer review

Delays in PR merge?

If you're seeing a delay in your PR being merged, ping the LiteLLM Team on Slack (#pr-review).

Screenshots / Proof of Fix

Same rig as #46968, run against the rc line. A local proxy with no DB or Redis, LITELLM_RATE_LIMIT_WINDOW_SIZE=60, and a local MCP upstream with one add tool. The listChanged case uses a second upstream that declares tools, prompts and resources listChanged. Config:

model_list: []
general_settings:
  master_key: os.environ/LITELLM_MASTER_KEY
mcp_servers:
  echo:
    url: http://127.0.0.1:54480/mcp
    transport: http
    rpm: 5

client.py URL KEY MODE N opens sessions with the official mcp Python SDK streamable HTTP client and counts successful tools/list calls. single is one session with N calls, per_call is N sessions with one call each, init_only connects and exits. Each case starts in a fresh 60s window

Before (c1d8cf1, rc/1.107.0)

One session, 8 tools/list

  1. python client.py http://127.0.0.1:54481/mcp/ $KEY single 8
  2. MODE=single succeeded=4/8

New session per call

  1. python client.py http://127.0.0.1:54481/mcp/ $KEY per_call 6
  2. MODE=per_call succeeded=2/6

Idle sessions starve the next caller

  1. for i in {1..5}; do python client.py http://127.0.0.1:54481/mcp/ $KEY init_only 0; done
  2. python client.py http://127.0.0.1:54481/mcp/ $KEY single 1
  3. call 1: MCPError Rate limit exceeded for mcp_server: 5914b6cf.... Limit type: requests. Current limit: 5, then MODE=single succeeded=0/1

listChanged upstream, two idle sessions then 6 tools/list

  1. for i in 1 2; do python client.py http://127.0.0.1:54484/mcp/ $KEY init_only 0; done
  2. python client.py http://127.0.0.1:54484/mcp/ $KEY single 6
  3. MODE=single succeeded=0/6

After (2b7f184)

One session, 8 tools/list

  1. python client.py http://127.0.0.1:54482/mcp/ $KEY single 8
  2. MODE=single succeeded=5/8

New session per call

  1. python client.py http://127.0.0.1:54482/mcp/ $KEY per_call 6
  2. MODE=per_call succeeded=5/6

Idle sessions starve the next caller

  1. for i in {1..5}; do python client.py http://127.0.0.1:54482/mcp/ $KEY init_only 0; done
  2. python client.py http://127.0.0.1:54482/mcp/ $KEY single 1
  3. call 1: ok then MODE=single succeeded=1/1

listChanged upstream, two idle sessions then 6 tools/list

  1. for i in 1 2; do python client.py http://127.0.0.1:54485/mcp/ $KEY init_only 0; done
  2. python client.py http://127.0.0.1:54485/mcp/ $KEY single 6
  3. MODE=single succeeded=5/6
Regression gate on the rc line

tests/integration/mcp/test_mcp_rate_limits.py::test_shared_redis_enforces_paginated_tools_and_rest_listings fails at rc/1.107.0 with MCPError(-32600, 'Rate limit exceeded ... Current limit: 2, Remaining: 0') and passes at 2b7f184. Both ran from clean trees outside the checkout. tests/unit/proxy/_experimental/mcp_server/ passes on the pick, 6817 passed and 22 skipped

Type

🐛 Bug Fix

Caveats (if any)

Low

  • The skipped admission covers per-key and per-team MCP limits too, not only server rpm
  • Rate-limited callers can now hold a legacy listener, capped by the existing 8 per caller and 128 total
  • Upstream list-change refreshes no longer count against the caller once a listener is running

…pm (#46968)

* fix(mcp): stop proxy-started legacy listeners from consuming server rpm

The listener the proxy opens on notifications/initialized for legacy MCP
sessions ran the server rate-limit admission once per target, so every
session spent an rpm slot before the client sent anything. Admission is
now injected into the listener and applied only to client-initiated
subscriptions (subscriptions/listen and resources/subscribe). Authorization
and its periodic recheck still run on every path.

* test(mcp): key the fake admission window by caller and server

* fix(mcp): stop subscription catalog refreshes from consuming server rpm

A subscription listener lists the caller's catalog to diff list_changed
events, at setup and on every upstream event. Those listings went through
the normal per-server admission, so against an upstream that declares
listChanged each legacy session spent several rpm slots before the client
asked for anything. The listener now marks its targets as already admitted
for its own lifetime, so its refreshes reuse the subscription's admission.
Client requests on the session are still metered.

* test(mcp): exercise subscription admission through the proxy rate limiter

(cherry picked from commit ac6300f)
@greptile-apps

greptile-apps Bot commented Oct 16, 2026

Copy link
Copy Markdown
Contributor

Automatic reviews are disabled for this repository.

@yuneng-berri
yuneng-berri merged commit c61bb56 into rc/1.107.0 Oct 16, 2026
3 of 4 checks passed
@yuneng-berri
yuneng-berri deleted the litellm_mcp-admission-1016-rc branch October 16, 2026 22:22

This branch was successfully deployed

No deployments
e2e-changed — 2b7f1844 Deployed Oct 16, 2026 by yuneng-berri via oauth #5715
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.

1 participant