Repository navigation
fix(mcp): resolve team-granted toolsets for non-admin keys and dashboard sessions - #43908
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
|
bugbot run |
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
|
bugbot run |
Bugbot is paused — on-demand spend limit reachedBugbot 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. |
|
bugbot run |
Bugbot is paused — on-demand spend limit reachedBugbot 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. |
|
bugbot run |
Bugbot is paused — on-demand spend limit reachedBugbot 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. |
|
bugbot run |
…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
4e1e98b to
04159e6
Compare
ryan-crabbe-berri
left a comment
There was a problem hiding this comment.
Approving the fix. Follow-up: fold toolset grants into the main MCP resolver, and flag the gateway toolset URL narrowing as a behavior change
|
Thanks. The TLDR now flags the gateway toolset URL narrowing as a behavior change, and the resolver fold is tracked in LIT-9113 |
|
@greptileai re review |
|
bugbot run |
…an unknown-argument type error
There was a problem hiding this comment.
✅ 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.
…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
* 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
…) (#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)
) * 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>
TLDR
Problem this solves:
/toolset/<name>/mcpand on toolset detailHow it solves it:
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
/mcppath. Every management, REST and MCP request that worked before still works and returns the same bodyBehavior 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/mcppath and every other route are unchangedFollow-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
object_permission.mcp_toolsets[]with 200tools/listand gets 403 "API key does not have access to toolset"After: the same member sees the toolset and can call its tools
object_permission.mcp_toolsetstools/listand gets the toolset's tools;tools/call add(4,5)returns9[]and 403 on that toolsetLinear ticket
Resolves LIT-6029
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 more@greptileaito 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(servesadd), a second one asab2_c7baab, and a third one is operator-open to every key. Setup, identical on both sides: POST/v1/mcp/serverfor the three servers, POST/v1/mcp/toolset(granted_c7baabholding onlyab_c7baab add), POST/team/newwith"object_permission": {"mcp_toolsets": ["<toolset_id>"]}, POST/user/new(internal_userin that team), POST/key/generatewithteam_idanduser_idand no object permission of its own ($KEY), a second team grantingab_c7baab,ab2_c7baaband 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 offeredBefore (e662772)
Team key lists toolsets
curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $KEY"[]thenHTTP 200Team key calls the namespaced toolset route
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":{}}'{"detail":"API key does not have access to toolset '6b40ef9f-993c-4fde-8d4d-261ebd5216f2'."}thenHTTP 403{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"ab_c7baab-add","arguments":{"a":4,"b":5}}}returns the same 403curl -s -o /dev/null -w 'HTTP %{http_code}\n' "$P/v1/mcp/toolset/$TS_ID" -H "Authorization: Bearer $KEY"printsHTTP 403Dashboard session of the member lists toolsets and servers
curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $UI_SESSION_TOKEN"[]thenHTTP 200curl -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
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"}]}'"content":"48"thenHTTP 200['ab_c7baab-add', 'ab2_c7baab-add', 'ab2_c7baab-multiply', 'ab2_c7baab-fail'], the whole aggregate grant instead of the named toolsetAfter (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
curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $KEY"[{"toolset_id":"6b40ef9f-993c-4fde-8d4d-261ebd5216f2","toolset_name":"granted_c7baab","description":null,"tools":[{"server_id":"9f1e1344-b8e3-42b2-a3b3-378c2ac55e5e","tool_name":"add"}], ...}]thenHTTP 200Team key calls the namespaced toolset route
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":{}}'data: {"jsonrpc":"2.0","id":1,"result":{"_meta":{"litellm.ai/server_outcomes":{"ab_c7baab":{"status":"ok","tool_count":1}}},"tools":[{"description":"Add two integers", ...}]}}thenHTTP 200curl ... -d '{"jsonrpc":"2.0","id":2,"method":"tools/call","params":{"name":"ab_c7baab-add","arguments":{"a":4,"b":5}}}'data: {"jsonrpc":"2.0","id":2,"result":{"content":[{"text":"9","type":"text"}],"isError":false,"structuredContent":{"result":9}}}thenHTTP 200curl -s -o /dev/null -w 'HTTP %{http_code}\n' "$P/v1/mcp/toolset/$TS_ID" -H "Authorization: Bearer $KEY"printsHTTP 200Dashboard session of the member lists toolsets and servers
curl -s -w '\nHTTP %{http_code}\n' "$P/v1/mcp/toolset" -H "Authorization: Bearer $UI_SESSION_TOKEN"[{"toolset_id":"6b40ef9f-993c-4fde-8d4d-261ebd5216f2","toolset_name":"granted_c7baab", ...}]thenHTTP 200curl -s "$P/v1/mcp/server" -H "Authorization: Bearer $UI_SESSION_TOKEN"still returns['ab_c7baab']Wide team key chats through the toolset gateway URL
curl -s -w '\nHTTP %{http_code}\n' -X POST "$P/v1/chat/completions" ... "server_url":"litellm_proxy/mcp/granted_c7baab" ..."content":"48"thenHTTP 200['ab_c7baab-add'], only the named toolsetType
🐛 Bug Fix
Caveats (if any)
Medium
require_key_mcp_access_definedstops a virtual key inheriting team toolsets, matching the aggregate/mcpruleLow
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
/mcppath 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 treesThe 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 tipMutation check on
granted_toolset_ids: ignoring the own-grant ceiling, dropping access groups from the ceiling, ignoringrequire_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.pyruns 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 bothMain 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.pyis now themcp_toolset_idnarrowing of every admitted source plus two public lookup wrappers. The merge fixups on top are in d3410f3: the duplicateadmitted_subject_sourceswrapper that shadowed main's keyword signature is gone, the tests follow main's renamedresolve_admitted_subject_serversandresolve_admitted_subject_tools, and the gateway grant lookup no longer binds aFinalinside the server loopThe 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 thatTerminal audit at the tip 4b6fc5d: 27 deterministic
tests/integration/mcpcells (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 cachingLater trim: five cells in
test_mcp_toolsets.pywere 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 bytest_mcp_resilience.pyandtest_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 rigran /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
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_idshelper (per grant source: own MCP permission caps the key; otherwise inherit the team’smcp_toolsets), wired into toolset list/detail APIs, REST tools, LLM gateway toolset URLs, and/toolset/{name}/mcpaccess checks.Namespaced toolset routes for dashboard/gateway-admitted users no longer rewrite
object_permission(which broke on team sources); they setmcp_toolset_idand intersect every admitted source’s servers/tools via_toolset_scope/_narrow_tools_to_toolset. Virtual keys still getobject_permissionnarrowed 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 setsmcp_explicit_grants_onlyso 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.