Skip to content

fix(mcp): resolve team-granted toolsets for non-admin keys and dashboard sessions - #43908

Merged
ryan-crabbe-berri merged 15 commits into
mainfrom
litellm_mcp_toolset_team_grants
Oct 1, 2026
Merged

ryan-crabbe-berri merged 15 commits into
mainfrom
litellm_mcp_toolset_team_grants

Conversation

@devin-ai-integration

@devin-ai-integration devin-ai-integration Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

TLDR

Problem this solves:

  • Team-granted MCP toolsets are invisible to non-admin users
  • The dashboard Toolsets tab is empty for a team member
  • A team key gets 403 on /toolset/<name>/mcp and on toolset detail
  • The LLM gateway toolset URL silently skips a team-granted toolset

How it solves it:

  • Resolve toolset grants per effective context: own grant, else the team's
  • Reuse that one resolver in listing, detail, namespaced MCP, REST and the gateway URL
  • Keep the aggregate key/team rule: a key's own MCP grant is a ceiling the team cannot widen

Intentional product change: a non-admin whose team grants a toolset now sees and can use it on every toolset route, the same way they already could through the aggregate /mcp path. Every management, REST and MCP request that worked before still works and returns the same body

Behavior change to flag: the LLM gateway toolset URL (litellm_proxy/mcp/<toolset> on chat, responses and messages) used to skip the toolset scope for a team-granted toolset and fall back to the key's aggregate MCP access, and it let an operator-open server (allow_all_keys) join the list. It now offers the model the named toolset's tools only. A deployment whose model relied on seeing extra tools through that URL sees fewer tools after this PR; the aggregate /mcp path and every other route are unchanged

Follow-up tracked in LIT-9113: fold toolset grants into the main MCP permission resolver so the toolset routes narrow from one answer instead of a sibling resolver

User Flow

Before: a team member cannot see or use the toolset their team was granted

  1. The admin creates a toolset with POST https://litellm-domain/v1/mcp/toolset and puts its id in the team's object_permission.mcp_toolsets
  2. A member of that team opens https://litellm-domain/ui/?page=mcp-servers and the Toolsets tab is empty, while All Servers shows the server
  3. Their team key sends GET https://litellm-domain/v1/mcp/toolset and gets [] with 200
  4. The same key sends POST https://litellm-domain/toolset/google_suite/mcp tools/list and gets 403 "API key does not have access to toolset"

After: the same member sees the toolset and can call its tools

  1. The admin creates a toolset with POST https://litellm-domain/v1/mcp/toolset and puts its id in the team's object_permission.mcp_toolsets
  2. A member of that team opens https://litellm-domain/ui/?page=mcp-servers and the Toolsets tab lists it, All Servers unchanged
  3. Their team key sends GET https://litellm-domain/v1/mcp/toolset and gets the toolset back with 200
  4. The same key sends POST https://litellm-domain/toolset/google_suite/mcp tools/list and gets the toolset's tools; tools/call add(4,5) returns 9
  5. A key of another team, or a key with no grant at all, still gets [] and 403 on that toolset

Linear ticket

Resolves LIT-6029

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's scope is as isolated as possible; it only solves 1 specific problem
  • I have received a Greptile Confidence Score of at least 4/5 before requesting a maintainer review (Greptile reviews automatically once the PR is opened; only comment @greptileai to re-request a review after pushing changes)

Screenshots / Proof of Fix

Live two-worker proxies against real Postgres and Redis, one at the merge base and one at the PR tip, sharing one database. A local MCP server is registered as ab_c7baab (serves add), a second one as ab2_c7baab, and a third one is operator-open to every key. Setup, identical on both sides: POST /v1/mcp/server for the three servers, POST /v1/mcp/toolset (granted_c7baab holding only ab_c7baab add), POST /team/new with "object_permission": {"mcp_toolsets": ["<toolset_id>"]}, POST /user/new (internal_user in that team), POST /key/generate with team_id and user_id and no object permission of its own ($KEY), a second team granting ab_c7baab, ab2_c7baab and the toolset with its own key ($WIDE), and a dashboard session token of the member ($UI_SESSION_TOKEN). The chat model is a scripted upstream that records which tools it was offered

Before (e662772)

Team key lists toolsets

  1. curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $KEY"
  2. [] then HTTP 200

Team key calls the namespaced toolset route

  1. curl -s -w '\nHTTP %{http_code}\n' -X POST "$P/toolset/granted_c7baab/mcp" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
  2. {"detail":"API key does not have access to toolset '6b40ef9f-993c-4fde-8d4d-261ebd5216f2'."} then HTTP 403
  3. The same with {"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"ab_c7baab-add","arguments":{"a":4,"b":5}}} returns the same 403
  4. curl -s -o /dev/null -w 'HTTP %{http_code}\n' "$P/v1/mcp/toolset/$TS_ID" -H "Authorization: Bearer $KEY" prints HTTP 403

Dashboard session of the member lists toolsets and servers

  1. curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $UI_SESSION_TOKEN"
  2. [] then HTTP 200
  3. curl -s "$P/v1/mcp/server" -H "Authorization: Bearer $UI_SESSION_TOKEN" returns the server: ['ab_c7baab']

Wide team key chats through the toolset gateway URL

  1. curl -s -w '\nHTTP %{http_code}\n' -X POST "$P/v1/chat/completions" -H "Authorization: Bearer $WIDE" -H 'Content-Type: application/json' -d '{"model":"ab-openai-chat-c7baab","messages":[{"role":"user","content":"Use the add tool to add 41 and 7 and reply with just the number"}],"tools":[{"type":"mcp","server_label":"gw","server_url":"litellm_proxy/mcp/granted_c7baab","require_approval":"never"}]}'
  2. "content":"48" then HTTP 200
  3. Tools the upstream model was offered on the wire: ['ab_c7baab-add', 'ab2_c7baab-add', 'ab2_c7baab-multiply', 'ab2_c7baab-fail'], the whole aggregate grant instead of the named toolset

After (4b6fc5d)

Captured at 7df9c48 and replayed byte for byte against the proxy restarted at the tip 4b6fc5d (one merge of main on top, no MCP file changed): same list, same route answers, same wire tool list

Team key lists toolsets

  1. curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $KEY"
  2. [{"toolset_id":"6b40ef9f-993c-4fde-8d4d-261ebd5216f2","toolset_name":"granted_c7baab","description":null,"tools":[{"server_id":"9f1e1344-b8e3-42b2-a3b3-378c2ac55e5e","tool_name":"add"}], ...}] then HTTP 200

Team key calls the namespaced toolset route

  1. curl -s -w '\nHTTP %{http_code}\n' -X POST "$P/toolset/granted_c7baab/mcp" -H "Authorization: Bearer $KEY" -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' -d '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}'
  2. data: {"jsonrpc":"2.0","id":1,"result":{"_meta":{"litellm.ai/server_outcomes":{"ab_c7baab":{"status":"ok","tool_count":1}}},"tools":[{"description":"Add two integers", ...}]}} then HTTP 200
  3. curl ... -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"ab_c7baab-add","arguments":{"a":4,"b":5}}}'
  4. data: {"jsonrpc":"2.0","id":2,"result":{"content":[{"text":"9","type":"text"}],"isError":false,"structuredContent":{"result":9}}} then HTTP 200
  5. curl -s -o /dev/null -w 'HTTP %{http_code}\n' "$P/v1/mcp/toolset/$TS_ID" -H "Authorization: Bearer $KEY" prints HTTP 200

Dashboard session of the member lists toolsets and servers

  1. curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $UI_SESSION_TOKEN"
  2. [{"toolset_id":"6b40ef9f-993c-4fde-8d4d-261ebd5216f2","toolset_name":"granted_c7baab", ...}] then HTTP 200
  3. curl -s "$P/v1/mcp/server" -H "Authorization: Bearer $UI_SESSION_TOKEN" still returns ['ab_c7baab']

Wide team key chats through the toolset gateway URL

  1. The same curl -s -w '\nHTTP %{http_code}\n' -X POST "$P/v1/chat/completions" ... "server_url":"litellm_proxy/mcp/granted_c7baab" ...
  2. "content":"48" then HTTP 200
  3. Tools the upstream model was offered on the wire: ['ab_c7baab-add'], only the named toolset

Type

🐛 Bug Fix

Caveats (if any)

Medium

  • Toolset routes now read the team's object permission for non-admins, one cached lookup per effective context
  • require_key_mcp_access_defined stops a virtual key inheriting team toolsets, matching the aggregate /mcp rule
  • The LLM gateway toolset URL narrows to the named toolset's tools, including for operator-open servers, where it used to fall back to the key's aggregate access for a team grant (see TLDR)

Low

  • Admin toolset listing is unchanged: unrestricted, or narrowed only by the admin key's own grant
  • Dashboard screenshots of the Toolsets tab follow in a comment once the UI run is captured
  • A toolset edit reaches every worker within two management cache TTLs (120s by default): the edit evicts the handling worker's memory, Redis keeps the entry for one TTL and a Redis hit back-fills the other worker for another. Pre-existing and unchanged by this PR

REVIEWER MUST KNOW BEFORE APPROVING

Every toolset route now shares one grant resolver. For each effective context (the key itself, or for a dashboard session each of the user's teams plus the user row) it takes the context's own toolsets when the context declares any MCP grant of its own, otherwise the team's. That is the same key-over-team rule the aggregate /mcp path already applies, so nothing a key could reach before becomes unreachable, and the team grant is only inherited by a key that declares no MCP scope of its own. Key creation already refuses key toolsets outside the team's list, so the ceiling case that can exist is "team grants A and B, key grants A", and that key sees A only, checked live on both trees

The gateway toolset URL (litellm_proxy/mcp/<toolset> on chat, responses and messages) used to skip the scope for a team-granted toolset and fall back to the key's aggregate access, which can expose more tools than the named toolset. It now narrows to the toolset. The integration test proves this by granting the team two toolsets and asserting the model only ever sees the named one, red on the merge base and green on the tip

Mutation check on granted_toolset_ids: ignoring the own-grant ceiling, dropping access groups from the ceiling, ignoring require_key_mcp_access_defined, zeroing dashboard sessions under that flag, dropping team toolsets, using only the first context, and inverting membership each fail at least one of the added unit or integration tests. Unchanged tests: tests/integration/mcp/test_mcp_toolsets.py runs 2 red on the merge-base proxy and 5 green on the tip, with the direct-grant, no-grant, admin and key-ceiling cases green on both

Main merged in after review: the live roster check and the keyless admitted source model landed there independently, so this PR's delta on user_api_key_auth_mcp.py is now the mcp_toolset_id narrowing of every admitted source plus two public lookup wrappers. The merge fixups on top are in d3410f3: the duplicate admitted_subject_sources wrapper that shadowed main's keyword signature is gone, the tests follow main's renamed resolve_admitted_subject_servers and resolve_admitted_subject_tools, and the gateway grant lookup no longer binds a Final inside the server loop

The LLM gateway toolset URL also used to let an operator-open server (allow_all_keys) join the named toolset's tool list; the scoped auth is now pinned to explicit grants, so the model sees the toolset's tools only. The proof's last case and the gateway integration cells cover that

Terminal audit at the tip 4b6fc5d: 27 deterministic tests/integration/mcp cells (happy, sad, edge and chaos rows, two-worker proxies, scripted MCP peers and a scripted provider upstream, no mocks inside litellm) run with one seed and one order, 22 red on the merge-base proxy and 58 of 58 selected tests green twice on the tip (reran after the merge of main, lint and the ruff, type-discipline and type-check gates green at the tip against its merge base a3a7650). Covered rows: team key and dashboard member on list, detail, namespaced route, REST and the three gateway surfaces plus streaming, gateway-admitted and resource-scoped session bearers, revoked and deleted teams, own-grant precedence, require_key_mcp_access_defined, unknown and malformed names, garbage, expired and tampered credentials, two-team union and membership added after caching

Later trim: five cells in test_mcp_toolsets.py were dropped because they test behavior this PR does not change. Byte-identical repeat reads, 20 concurrent calls, a stopped peer and a killed worker are covered generically by test_mcp_resilience.py and test_mcp_user_env_vars.py. The toolset edit cell asserts pre-existing cache propagation and flaked locally (connection reset while polling, 1 pass and 2 fails in 3 runs). The remaining 16 cells in that file pass twice on a local Postgres, Redis and two-proxy rig

ran /live-pr-risk at the merge base and at the tip 4b6fc5d on live two-worker proxies: 20 rows identical, 15 rows differ as intended, Postgres freeze leg identical to the previous run on the head side, no regressions or backward incompatible risks

Link to Devin session: https://app.devin.ai/sessions/06ea1439eb914889af3720296322dd87
Open in Devin Desktop: https://app.devin.ai/desktop/session/06ea1439eb914889af3720296322dd87?variant=devin


Devin Review


Note

Medium Risk
Changes authorization across MCP toolset listing, routes, and LLM gateway URLs; the gateway toolset URL intentionally exposes fewer tools than before for team-granted keys.

Overview
Team-granted MCP toolsets now resolve through a shared granted_toolset_ids helper (per grant source: own MCP permission caps the key; otherwise inherit the team’s mcp_toolsets), wired into toolset list/detail APIs, REST tools, LLM gateway toolset URLs, and /toolset/{name}/mcp access checks.

Namespaced toolset routes for dashboard/gateway-admitted users no longer rewrite object_permission (which broke on team sources); they set mcp_toolset_id and intersect every admitted source’s servers/tools via _toolset_scope / _narrow_tools_to_toolset. Virtual keys still get object_permission narrowed to the toolset; resource-scoped OAuth sessions are denied when the toolset’s servers fall outside the pinned resource.

Behavioral tightening: the litellm_proxy/mcp/<toolset> path uses the same grant resolver and sets mcp_explicit_grants_only so the model sees only the named toolset (not aggregate team MCP or operator-open servers). Team member add evicts cached team roster so new members pick up team toolsets promptly.

Reviewed by Cursor Bugbot for commit 0eccc4c. Bugbot is set up for automated code reviews on this repo. Configure here.

@devin-ai-integration
devin-ai-integration Bot requested a review from a team September 30, 2026 19:27
@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

devin-ai-integration[bot]

This comment was marked as resolved.

@greptile-apps

greptile-apps Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

RetriggerConfidence Score: 5/5

[High risk] Rewrites how team-granted toolsets resolve for non-admin keys.

The PR appears safe to merge based on the reviewed changes.

Summary

The PR makes team-granted MCP toolsets available to eligible keys and dashboard sessions across listing, detail, REST, namespaced MCP, and gateway URLs. It also narrows gateway tool lists to the named toolset and adds grant, roster, and session-scope coverage.

Reviews (7) · Last reviewed commit: "chore(mcp): drop mutable-ok suppressions..."

greptile-apps[bot]

This comment was marked as resolved.

cursor[bot]

This comment was marked as resolved.

@codspeed

codspeed Bot commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 31 untouched benchmarks


Comparing litellm_mcp_toolset_team_grants (830ee03) with main (a38fff6)1

Open in CodSpeed

Footnotes

  1. No successful run was found on main (a14af73) during the generation of this report, so a38fff6 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@codecov

codecov Bot commented Sep 30, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 97.39130% with 3 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
litellm/proxy/_experimental/mcp_server/server.py 80.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

github-advanced-security[bot]

This comment was marked as resolved.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor

cursor Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@cursor

cursor Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

devin-ai-integration[bot]

This comment was marked as resolved.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor

cursor Bot commented Sep 30, 2026

Copy link
Copy Markdown
Contributor

Bugbot is paused — on-demand spend limit reached

Bugbot uses usage-based billing for this team and has hit its on-demand spend limit.

A team admin can raise the spend limit in the Cursor dashboard, or wait for the next billing cycle to continue.

@mateo-berri

Copy link
Copy Markdown
Contributor

@greptileai

@mateo-berri

Copy link
Copy Markdown
Contributor

bugbot run

ryan-crabbe-berri and others added 11 commits October 1, 2026 13:29
…pshot stays unchanged

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
A key that declares any MCP grant of its own keeps only its own toolsets, one
that declares none inherits its team's, and require_key_mcp_access_defined
stops a virtual key inheriting while dashboard sessions and admitted users
still do. Adds the direct, no-grant, admin and key-ceiling integration cases
and makes the LLM gateway toolset case discriminate a scoped toolset from the
aggregate grant

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…live team roster

Dashboard sessions and gateway-admitted users now expand into the admitted
subject's per-team sources when resolving toolset grants, so a team-granted
toolset is not capped by the user's own MCP row and is reachable on the
namespaced route. A cached team id no longer grants a toolset unless the live
roster still lists the user, a team lookup fault only drops that team's
inherited grant, and /team/member_add evicts the cached team object so the new
member is authoritative immediately

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…rit team toolsets

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…o tests stop patching MCPRequestHandler

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…erging main and follow its renamed resolvers

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…d toolsets

A pinned toolset scope now reads the toolset through the writer when the admitted session
requires fresh policy, so a tool revoked from the toolset is gone on the next request. A
gateway bearer scoped to one server can only open a toolset that names that server

Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
…does not change

Repeat-read byte identity, 20 concurrent calls, a stopped peer and a killed worker are covered
generically by test_mcp_resilience.py and test_mcp_user_env_vars.py. The toolset edit cell asserts
pre-existing cache propagation and flaked locally with connection resets while polling

@ryan-crabbe-berri ryan-crabbe-berri left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Approving the fix. Follow-up: fold toolset grants into the main MCP resolver, and flag the gateway toolset URL narrowing as a behavior change

@devin-ai-integration

Copy link
Copy Markdown
Contributor Author

Thanks. The TLDR now flags the gateway toolset URL narrowing as a behavior change, and the resolver fold is tracked in LIT-9113

@ryan-crabbe-berri

Copy link
Copy Markdown
Contributor

@greptileai re review

@ryan-crabbe-berri

Copy link
Copy Markdown
Contributor

bugbot run

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

✅ Bugbot reviewed your changes and found no new issues!

Comment @cursor review or bugbot run to trigger another review on this PR

Reviewed by Cursor Bugbot for commit 0eccc4c. Configure here.

@ryan-crabbe-berri
ryan-crabbe-berri merged commit d7e6154 into main Oct 1, 2026
96 of 97 checks passed
@ryan-crabbe-berri
ryan-crabbe-berri deleted the litellm_mcp_toolset_team_grants branch October 1, 2026 21:15
yuneng-berri added a commit that referenced this pull request Oct 2, 2026
…ccess matrix tool list

test_toolset_gateway_url_serves_a_team_granted_toolset_to_a_key_without_its_own_grant (#43908) registers an allow_all_keys server on the shared gateway, and allow_all_keys servers are listed to every key by design, so a matrix case running on another xdist worker at the same time saw its tools. The matrix now drops tools of allow_all_keys servers it did not create, read from LiteLLM_MCPServerTable before and after listing, and still compares everything else exactly
yuneng-berri added a commit that referenced this pull request Oct 2, 2026
* test(proxy): stop the proxy_server app fixture leaking LITELLM_LOG

The session app fixture set LITELLM_LOG=ERROR with os.environ.setdefault and never removed it, so later tests on the same xdist worker inherited it. test_drop_params_env_var spawns a subprocess with os.environ and lost the warning it asserts on. Scope the variable to the import with a MonkeyPatch context

* test(secret-detection): give the hand-built redaction request an ASGI path

Since #43975 _read_request_body checks the route path via request.scope, and a scope without path raised KeyError that was swallowed into an empty body, so chat_completion failed with a missing messages parameter. Real ASGI scopes always carry path

* test(integration): isolate litellm callback lists per sdk test

usage-based-routing-v2 Routers register their selector in litellm.callbacks and nothing removes it, not even Router.reset(). The counter TTL and Redis service metrics tests left their selectors behind, and the next usage routing test ran their pre-call checks against its own rpm=1 deployments, raising "Deployment over defined rpm limit". An autouse fixture now gives each sdk test copies of the callback lists and restores the originals afterwards

* test(integration): keep the owner-lookup fault proxy off the shared read replica

The owned proxy points DATABASE_URL at a scratch database but inherited
DATABASE_URL_READ_REPLICA from the replica job, so auth read the shared
database and rejected the freshly created key with token_not_found_in_db.
Drop the replica variable like the other scratch-database owned proxies

* test(integration): request every seeded key in the team owner breakdown

The aggregated team activity endpoint now caps breakdown.api_keys at the top
100 keys by default (#43398), so the 300 seeded keys came back as 100 rows.
The test guarantees each key is reported with its own owner, so ask for an
api_key_limit that covers all seeded keys

* test(integration): give every owned Redis its own port in the redis-cache container

On CircleCI every owned Redis ran on the fixed port 16379 inside the shared
redis-cache container. When an earlier server still held that port, the new
one failed to bind, readiness pinged the old server, the pidfile read failed
and cleanup then reported "Owned Redis still serves after shutdown"

Reserve an ephemeral port for the docker-exec path the same way the local
binary path already does, and refuse to start when something already serves
the chosen port so the failure names the real cause

* test(e2e): skip the Vertex Mistral partner case the e2e project cannot reach

The e2e Vertex project gets a 404 publisher model not found for vertex_ai/mistral-small-2503, so the case can only fail

* test(e2e): skip the Vertex gpt-oss partner case the e2e project never serves

vertex_ai/openai/gpt-oss-120b-maas has hit a 60s read timeout with no response headers on every run in the e2e Vertex project since the case was ported, and no other Vertex partner chat model passes there to switch to

* test(e2e): check only stored message content for a leaked card number

The Presidio spend-log check ran the card-number pattern over the whole serialized response, so a Luhn-valid usage.cost float (0.0003466000000000001) failed the streaming /v1/messages case although the stored content was <CREDIT_CARD>. The check now reads the content and text strings of the stored response, which is where a raw card would land, and still requires the placeholder there

* test(e2e): assert the proxy decodes token-array embeddings for titan

The port in #44120 carried over a legacy SDK-direct test that expected Bedrock to reject token ids with a 400. Through the proxy, /embeddings decodes token arrays to text for providers that cannot embed tokens, so titan answers 200. The test now sends a token array and its decoded sentence and requires the two vectors to match, which fails if the proxy stops decoding or decodes with the wrong tokenizer

* test(e2e): run the Bedrock extended-thinking round trip on a model that honors enabled thinking

us.anthropic.claude-sonnet-5-5 is adaptive-only, so litellm sends thinking.type=enabled with a 1024 budget as adaptive with low effort, and Bedrock returned no reasoning blocks on 5 of 5 identical Converse calls (boto3 direct agreed). us.anthropic.claude-sonnet-4-6 accepts the legacy shape verbatim and returned reasoning on 5 of 5. The non-thinking Bedrock case stays on sonnet-5-5

* test(proxy): stop unit modules forcing DEBUG logging into the event-loop lag tests

Five tests/unit modules set verbose_proxy_logger to DEBUG at import, so every xdist worker that collected them logged the 2.4MB pass-through response from a worker thread, and secret redaction of that line held the GIL for ~0.8s+ inside the timed window. The lag tests now pin the LiteLLM loggers to WARNING and freeze gc while timing, and the module-level DEBUG overrides are removed

* test(e2e): cite the tokenizer and date behind the titan token-array fixture

* test(e2e): let migration seed replicas finish their request-log indexes before cloning

Since #43948 a serving proxy builds the two LiteLLM_SpendLogs indexes on a background thread after it reports ready. The seed fixtures stopped the replica at readiness, so every cloned legacy database lacked an index no real deployment would be missing, and the v2 baseline diff refused it. Seeds now wait until both indexes exist and are valid in the database's schema

* test(passthrough): give the pass-through MockRequest an httpx URL and ASGI scope

#43626 made get_request_route read request.scope during pass-through kwarg setup; the MockRequest in tests/unit/passthrough had neither a scope nor a URL object, so both stream-param tests raised before reaching the code they check. Mirrors the repair #43626 made to the tests/pass_through_unit_tests fake

* test(integration): ignore foreign allow_all_keys MCP servers in the access matrix tool list

test_toolset_gateway_url_serves_a_team_granted_toolset_to_a_key_without_its_own_grant (#43908) registers an allow_all_keys server on the shared gateway, and allow_all_keys servers are listed to every key by design, so a matrix case running on another xdist worker at the same time saw its tools. The matrix now drops tools of allow_all_keys servers it did not create, read from LiteLLM_MCPServerTable before and after listing, and still compares everything else exactly
yuneng-berri added a commit that referenced this pull request Oct 2, 2026
…) (#44254)

* test(proxy): stop the proxy_server app fixture leaking LITELLM_LOG

The session app fixture set LITELLM_LOG=ERROR with os.environ.setdefault and never removed it, so later tests on the same xdist worker inherited it. test_drop_params_env_var spawns a subprocess with os.environ and lost the warning it asserts on. Scope the variable to the import with a MonkeyPatch context

* test(secret-detection): give the hand-built redaction request an ASGI path

Since #43975 _read_request_body checks the route path via request.scope, and a scope without path raised KeyError that was swallowed into an empty body, so chat_completion failed with a missing messages parameter. Real ASGI scopes always carry path

* test(integration): isolate litellm callback lists per sdk test

usage-based-routing-v2 Routers register their selector in litellm.callbacks and nothing removes it, not even Router.reset(). The counter TTL and Redis service metrics tests left their selectors behind, and the next usage routing test ran their pre-call checks against its own rpm=1 deployments, raising "Deployment over defined rpm limit". An autouse fixture now gives each sdk test copies of the callback lists and restores the originals afterwards

* test(integration): keep the owner-lookup fault proxy off the shared read replica

The owned proxy points DATABASE_URL at a scratch database but inherited
DATABASE_URL_READ_REPLICA from the replica job, so auth read the shared
database and rejected the freshly created key with token_not_found_in_db.
Drop the replica variable like the other scratch-database owned proxies

* test(integration): request every seeded key in the team owner breakdown

The aggregated team activity endpoint now caps breakdown.api_keys at the top
100 keys by default (#43398), so the 300 seeded keys came back as 100 rows.
The test guarantees each key is reported with its own owner, so ask for an
api_key_limit that covers all seeded keys

* test(integration): give every owned Redis its own port in the redis-cache container

On CircleCI every owned Redis ran on the fixed port 16379 inside the shared
redis-cache container. When an earlier server still held that port, the new
one failed to bind, readiness pinged the old server, the pidfile read failed
and cleanup then reported "Owned Redis still serves after shutdown"

Reserve an ephemeral port for the docker-exec path the same way the local
binary path already does, and refuse to start when something already serves
the chosen port so the failure names the real cause

* test(e2e): skip the Vertex Mistral partner case the e2e project cannot reach

The e2e Vertex project gets a 404 publisher model not found for vertex_ai/mistral-small-2503, so the case can only fail

* test(e2e): skip the Vertex gpt-oss partner case the e2e project never serves

vertex_ai/openai/gpt-oss-120b-maas has hit a 60s read timeout with no response headers on every run in the e2e Vertex project since the case was ported, and no other Vertex partner chat model passes there to switch to

* test(e2e): check only stored message content for a leaked card number

The Presidio spend-log check ran the card-number pattern over the whole serialized response, so a Luhn-valid usage.cost float (0.0003466000000000001) failed the streaming /v1/messages case although the stored content was <CREDIT_CARD>. The check now reads the content and text strings of the stored response, which is where a raw card would land, and still requires the placeholder there

* test(e2e): assert the proxy decodes token-array embeddings for titan

The port in #44120 carried over a legacy SDK-direct test that expected Bedrock to reject token ids with a 400. Through the proxy, /embeddings decodes token arrays to text for providers that cannot embed tokens, so titan answers 200. The test now sends a token array and its decoded sentence and requires the two vectors to match, which fails if the proxy stops decoding or decodes with the wrong tokenizer

* test(e2e): run the Bedrock extended-thinking round trip on a model that honors enabled thinking

us.anthropic.claude-sonnet-5-5 is adaptive-only, so litellm sends thinking.type=enabled with a 1024 budget as adaptive with low effort, and Bedrock returned no reasoning blocks on 5 of 5 identical Converse calls (boto3 direct agreed). us.anthropic.claude-sonnet-4-6 accepts the legacy shape verbatim and returned reasoning on 5 of 5. The non-thinking Bedrock case stays on sonnet-5-5

* test(proxy): stop unit modules forcing DEBUG logging into the event-loop lag tests

Five tests/unit modules set verbose_proxy_logger to DEBUG at import, so every xdist worker that collected them logged the 2.4MB pass-through response from a worker thread, and secret redaction of that line held the GIL for ~0.8s+ inside the timed window. The lag tests now pin the LiteLLM loggers to WARNING and freeze gc while timing, and the module-level DEBUG overrides are removed

* test(e2e): cite the tokenizer and date behind the titan token-array fixture

* test(e2e): let migration seed replicas finish their request-log indexes before cloning

Since #43948 a serving proxy builds the two LiteLLM_SpendLogs indexes on a background thread after it reports ready. The seed fixtures stopped the replica at readiness, so every cloned legacy database lacked an index no real deployment would be missing, and the v2 baseline diff refused it. Seeds now wait until both indexes exist and are valid in the database's schema

* test(passthrough): give the pass-through MockRequest an httpx URL and ASGI scope

#43626 made get_request_route read request.scope during pass-through kwarg setup; the MockRequest in tests/unit/passthrough had neither a scope nor a URL object, so both stream-param tests raised before reaching the code they check. Mirrors the repair #43626 made to the tests/pass_through_unit_tests fake

* test(integration): ignore foreign allow_all_keys MCP servers in the access matrix tool list

test_toolset_gateway_url_serves_a_team_granted_toolset_to_a_key_without_its_own_grant (#43908) registers an allow_all_keys server on the shared gateway, and allow_all_keys servers are listed to every key by design, so a matrix case running on another xdist worker at the same time saw its tools. The matrix now drops tools of allow_all_keys servers it did not create, read from LiteLLM_MCPServerTable before and after listing, and still compares everything else exactly

(cherry picked from commit 9b5562f)
yuneng-berri added a commit that referenced this pull request Oct 3, 2026
)

* test: repair stale and polluting tests red on scheduled main CI (#44229)

Partial backport to rc/1.104.0: only the owned Redis port, Presidio stored-content check and event-loop lag logging fixes apply here. The other repairs target tests or behavior this line does not have

* test(proxy): stop the proxy_server app fixture leaking LITELLM_LOG

The session app fixture set LITELLM_LOG=ERROR with os.environ.setdefault and never removed it, so later tests on the same xdist worker inherited it. test_drop_params_env_var spawns a subprocess with os.environ and lost the warning it asserts on. Scope the variable to the import with a MonkeyPatch context

* test(secret-detection): give the hand-built redaction request an ASGI path

Since #43975 _read_request_body checks the route path via request.scope, and a scope without path raised KeyError that was swallowed into an empty body, so chat_completion failed with a missing messages parameter. Real ASGI scopes always carry path

* test(integration): isolate litellm callback lists per sdk test

usage-based-routing-v2 Routers register their selector in litellm.callbacks and nothing removes it, not even Router.reset(). The counter TTL and Redis service metrics tests left their selectors behind, and the next usage routing test ran their pre-call checks against its own rpm=1 deployments, raising "Deployment over defined rpm limit". An autouse fixture now gives each sdk test copies of the callback lists and restores the originals afterwards

* test(integration): keep the owner-lookup fault proxy off the shared read replica

The owned proxy points DATABASE_URL at a scratch database but inherited
DATABASE_URL_READ_REPLICA from the replica job, so auth read the shared
database and rejected the freshly created key with token_not_found_in_db.
Drop the replica variable like the other scratch-database owned proxies

* test(integration): request every seeded key in the team owner breakdown

The aggregated team activity endpoint now caps breakdown.api_keys at the top
100 keys by default (#43398), so the 300 seeded keys came back as 100 rows.
The test guarantees each key is reported with its own owner, so ask for an
api_key_limit that covers all seeded keys

* test(integration): give every owned Redis its own port in the redis-cache container

On CircleCI every owned Redis ran on the fixed port 16379 inside the shared
redis-cache container. When an earlier server still held that port, the new
one failed to bind, readiness pinged the old server, the pidfile read failed
and cleanup then reported "Owned Redis still serves after shutdown"

Reserve an ephemeral port for the docker-exec path the same way the local
binary path already does, and refuse to start when something already serves
the chosen port so the failure names the real cause

* test(e2e): skip the Vertex Mistral partner case the e2e project cannot reach

The e2e Vertex project gets a 404 publisher model not found for vertex_ai/mistral-small-2503, so the case can only fail

* test(e2e): skip the Vertex gpt-oss partner case the e2e project never serves

vertex_ai/openai/gpt-oss-120b-maas has hit a 60s read timeout with no response headers on every run in the e2e Vertex project since the case was ported, and no other Vertex partner chat model passes there to switch to

* test(e2e): check only stored message content for a leaked card number

The Presidio spend-log check ran the card-number pattern over the whole serialized response, so a Luhn-valid usage.cost float (0.0003466000000000001) failed the streaming /v1/messages case although the stored content was <CREDIT_CARD>. The check now reads the content and text strings of the stored response, which is where a raw card would land, and still requires the placeholder there

* test(e2e): assert the proxy decodes token-array embeddings for titan

The port in #44120 carried over a legacy SDK-direct test that expected Bedrock to reject token ids with a 400. Through the proxy, /embeddings decodes token arrays to text for providers that cannot embed tokens, so titan answers 200. The test now sends a token array and its decoded sentence and requires the two vectors to match, which fails if the proxy stops decoding or decodes with the wrong tokenizer

* test(e2e): run the Bedrock extended-thinking round trip on a model that honors enabled thinking

us.anthropic.claude-sonnet-5-5 is adaptive-only, so litellm sends thinking.type=enabled with a 1024 budget as adaptive with low effort, and Bedrock returned no reasoning blocks on 5 of 5 identical Converse calls (boto3 direct agreed). us.anthropic.claude-sonnet-4-6 accepts the legacy shape verbatim and returned reasoning on 5 of 5. The non-thinking Bedrock case stays on sonnet-5-5

* test(proxy): stop unit modules forcing DEBUG logging into the event-loop lag tests

Five tests/unit modules set verbose_proxy_logger to DEBUG at import, so every xdist worker that collected them logged the 2.4MB pass-through response from a worker thread, and secret redaction of that line held the GIL for ~0.8s+ inside the timed window. The lag tests now pin the LiteLLM loggers to WARNING and freeze gc while timing, and the module-level DEBUG overrides are removed

* test(e2e): cite the tokenizer and date behind the titan token-array fixture

* test(e2e): let migration seed replicas finish their request-log indexes before cloning

Since #43948 a serving proxy builds the two LiteLLM_SpendLogs indexes on a background thread after it reports ready. The seed fixtures stopped the replica at readiness, so every cloned legacy database lacked an index no real deployment would be missing, and the v2 baseline diff refused it. Seeds now wait until both indexes exist and are valid in the database's schema

* test(passthrough): give the pass-through MockRequest an httpx URL and ASGI scope

* test(integration): ignore foreign allow_all_keys MCP servers in the access matrix tool list

test_toolset_gateway_url_serves_a_team_granted_toolset_to_a_key_without_its_own_grant (#43908) registers an allow_all_keys server on the shared gateway, and allow_all_keys servers are listed to every key by design, so a matrix case running on another xdist worker at the same time saw its tools. The matrix now drops tools of allow_all_keys servers it did not create, read from LiteLLM_MCPServerTable before and after listing, and still compares everything else exactly

(cherry picked from commit 9b5562f)

* fix(proxy-extras): retry P3009 when a peer already recovered the named migration row (#44283)

* fix(proxy-extras): retry P3009 when a peer already recovered the named migration row

* fix(proxy-extras): pin P3009 recovery locals as Final and cover a recovered sibling row

* test(proxy-extras): stop the P3009 ledger fakes shadowing the partition detector cursor

* fix(proxy-extras): annotate the migration ledger reader locals as Final

---------

Co-authored-by: yuneng <yuneng@berri.ai>
(cherry picked from commit 8b11b68)

---------

Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>

This branch had an error being deployed

1 failed deployment
e2e-changed — 830ee039 Deployed Oct 1, 2026 by ryan-crabbe-berri via oauth #2425
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