Repository navigation
fix(mcp): stop proxy-started legacy listeners from consuming server rpm (rc/1.107.0) - #46982
Merged
Merged
Conversation
…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)
Contributor
|
Automatic reviews are disabled for this repository. |
yuneng-berri
had a problem deploying
to
e2e-changed
October 16, 2026 21:37 — with
GitHub Actions
Error
This branch was successfully deployed
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.
TLDR
Problem this solves:
test_shared_redis_enforces_paginated_tools_and_rest_listingsis red on the rc lineHow it solves it:
ac6300f380) with-x, applied cleanlyUser Flow
Before: a team using an MCP server with
rpm: 5on rc/1.107.0 loses requests to sessions they never usedrpm: 5tools/list8 times in one sessionRate limit exceeded for mcp_server ... Current limit: 5After: connecting is free again, so the client gets its full budget
rpm: 5tools/list8 times in one sessionAffected 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
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 moreDelays 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 oneaddtool. ThelistChangedcase uses a second upstream that declares tools, prompts and resourceslistChanged. Config:client.py URL KEY MODE Nopens sessions with the officialmcpPython SDK streamable HTTP client and counts successfultools/listcalls.singleis one session with N calls,per_callis N sessions with one call each,init_onlyconnects and exits. Each case starts in a fresh 60s windowBefore (c1d8cf1, rc/1.107.0)
One session, 8 tools/list
python client.py http://127.0.0.1:54481/mcp/ $KEY single 8MODE=single succeeded=4/8New session per call
python client.py http://127.0.0.1:54481/mcp/ $KEY per_call 6MODE=per_call succeeded=2/6Idle sessions starve the next caller
for i in {1..5}; do python client.py http://127.0.0.1:54481/mcp/ $KEY init_only 0; donepython client.py http://127.0.0.1:54481/mcp/ $KEY single 1call 1: MCPError Rate limit exceeded for mcp_server: 5914b6cf.... Limit type: requests. Current limit: 5,thenMODE=single succeeded=0/1listChanged upstream, two idle sessions then 6 tools/list
for i in 1 2; do python client.py http://127.0.0.1:54484/mcp/ $KEY init_only 0; donepython client.py http://127.0.0.1:54484/mcp/ $KEY single 6MODE=single succeeded=0/6After (2b7f184)
One session, 8 tools/list
python client.py http://127.0.0.1:54482/mcp/ $KEY single 8MODE=single succeeded=5/8New session per call
python client.py http://127.0.0.1:54482/mcp/ $KEY per_call 6MODE=per_call succeeded=5/6Idle sessions starve the next caller
for i in {1..5}; do python client.py http://127.0.0.1:54482/mcp/ $KEY init_only 0; donepython client.py http://127.0.0.1:54482/mcp/ $KEY single 1call 1: okthenMODE=single succeeded=1/1listChanged upstream, two idle sessions then 6 tools/list
for i in 1 2; do python client.py http://127.0.0.1:54485/mcp/ $KEY init_only 0; donepython client.py http://127.0.0.1:54485/mcp/ $KEY single 6MODE=single succeeded=5/6Regression gate on the rc line
tests/integration/mcp/test_mcp_rate_limits.py::test_shared_redis_enforces_paginated_tools_and_rest_listingsfails at rc/1.107.0 withMCPError(-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 skippedType
🐛 Bug Fix
Caveats (if any)
Low
rpm