Repository navigation
fix(mcp): return camelCase tool keys from /v1/mcp/tools after the SDK 2 upgrade - #42352
Merged
Merged
Conversation
… 2 upgrade SDK 2 spells the Tool model's Python attributes in snake_case behind camelCase aliases, so dumping attribute names handed scripts input_schema and output_schema instead of the inputSchema and outputSchema v1.102.0 returned. Dump each tool by its MCP wire aliases, as the other list routes do, and pin the shape with a regression test. Also drop an unused tools dict in the Responses MCP stream iterator.
Contributor
Author
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
Contributor
|
Contributor
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
mateo-berri
had a problem deploying
to
e2e-changed
September 21, 2026 23:15 — with
GitHub Actions
Error
Contributor
mateo-berri
temporarily deployed
to
e2e-changed
September 22, 2026 00:26 — with
GitHub Actions
Inactive
Contributor
Contributor
|
bugbot run |
Contributor
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 1c6c1e5. Configure here.
3 of 5 tasks
yuneng-berri
added a commit
that referenced
this pull request
Sep 26, 2026
* fix: apply configured cache_control_injection_points beside client cache_control marks (#41956) (cherry picked from commit d8267d5) * fix(token_counter): count replayed redacted_thinking blocks so prompt_caching keeps pinning (#42069) (cherry picked from commit 0e7cf51) * fix(mcp): return camelCase tool keys from /v1/mcp/tools after the SDK 2 upgrade (#42352) (cherry picked from commit 5eb4e30) * fix(rust_bridge): keep the Messages route on Python until the Rust path is ready (#42517) rc/1.103.0 has no token counter or tokenizer routes in the catalog, so only the Messages rule moves to PYTHON_ONLY (cherry picked from commit 85ed18e) * fix(proxy): stop leaking periodic tasks on every DB config reload (#42784) (cherry picked from commit fc87a06) --------- Co-authored-by: Mateo Wang <277851410+mateo-berri@users.noreply.github.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This branch was previously 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:
GET /v1/mcp/toolsreturnsinput_schemaandoutput_schemasince v1.103.0-rc.1inputSchemafrom that route get nothing backinputSchemaHow it solves it:
inputSchema,outputSchema, and_metaon the routeUser Flow
Before: a developer whose script lists a key's MCP tools from the management route gets no input schema back, so the script cannot build tool definitions
math(streamable HTTP, oneaddtool) undermcp_serversin the proxy config and starts the proxyaddwith the keysinput_schema,output_schema, andmeta, sotool.inputSchemareadsundefinedand the script builds an argument-less tooltools/liston POST https://litellm-domain/mcp returnaddwithinputSchema, so the script's parser works everywhere but this routeAfter: the same request returns
addwithinputSchemaandoutputSchema, so the script builds the tool definition as it did on v1.102.0math(streamable HTTP, oneaddtool) undermcp_serversin the proxy config and starts the proxyaddwithinputSchemaholding the JSON schema (aandb, both required integers),outputSchema, and_meta, the spelling the other two list routes useinputSchemaand callsaddon POST https://litellm-domain/mcp-rest/tools/call with{"a": 2, "b": 3}and the server id from GET https://litellm-domain/v1/mcp/server, and gets5Relevant issues
Affected release
regression in v1.103.0-rc.1 (the MCP SDK 2 upgrade in #41718),
backport-stablelabel addedLinear ticket
Resolves LIT-8213
Pre-Submission checklist
Please complete all items before asking a LiteLLM maintainer to review your PR
uv run pytest tests/test_litellm/<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)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
Four live proxies, one per checkpoint, each booted from a detached worktree at that commit with its own venv (
make bootstrap, so its ownmcppin), a fresh Postgres database, 2 uvicorn workers on a random port, and the same config. Every request below went through a virtual key minted on that proxy withPOST /key/generate. The upstream is one SDK 2 MCP server with a single tool, shared by all four proxies; the two fix checkpoints also register a second, annotated upstream at runtime. Before and After were captured at the merge base 9cc5b78 and at this PR's tip 1c6c1e5 (the merge commit that brought that base in), so the proxy under test is the exact code under reviewGET /v1/mcp/tools/mcp-rest/tools/listtools/listtools/callresultinputSchemainputSchemainputSchemainput_schemaonlyinputSchemainputSchemainput_schemaonlyinputSchemainputSchemainputSchemainputSchemainputSchemaUpstream,
math_server.py, run aspython math_server.py 28739:Proxy config, identical at every checkpoint:
Boot, from the checkpoint's worktree, with
DATABASE_URLpointing at that checkpoint's fresh database:python litellm/proxy/proxy_cli.py --config config.yaml --port $PORT --num_workers 2Virtual key, minted once per proxy and used for every request below (
$VKEY):Regression bracket: the same list step at c3fa53b (before #41718, mcp 1.28.1) and eda1fab (after #41718, mcp 2.2.0)
Before #41718, c3fa53b, port 26617:
After #41718, eda1fab, port 35323:
At both commits
GET /mcp-rest/tools/listand the JSON-RPCtools/listreturnedinputSchemaandoutputSchema,POST /mcp-rest/tools/callwith{"name":"math-add","server_id":"8684b12454dc1c0ecb5bf344fc4a2f29","arguments":{"a":2,"b":3}}returned{"content":[{"type":"text","text":"5",...}],"structuredContent":{"result":5},"isError":false}, and the Responses stream produced the samemcp_list_toolsandmcp_callitems shown under Before and After belowBefore (9cc5b78, merge base)
Port 39882, 2 workers (server processes 69313 and 69314), mcp 2.2.0, fresh database
lit8213_before_mergeThe script lists the key's tools and calls one
List the tools from the management route
Read the schema the script keys on
inputSchemais null, so a v1.102.0 script reading it builds an argument-less toolCall the tool. A body without
server_idis rejected, so the script reads the id from/mcp-rest/tools/list'smcp_infoand retriesThe other list routes and the Responses stream (controls)
REST list
JSON-RPC list (initialize, then
tools/listwith the returned session id)Responses API MCP stream (real OpenAI call to
gpt-5.4-mini)(
jqalso prints a parse error for the trailingdata: [DONE]line; the stream'sresponse.completedevent reported{"status":"completed","model":"gpt-5.4-mini-2026-03-17","cost":0.00009675000000000001})Nested wire keys and a server added at runtime
A second upstream,
math_server_annotated_sdk2.pyon port 26461, serves onemultiplytool withtitle="Multiply two numbers",ToolAnnotations(title="Multiply", read_only_hint=True, idempotent_hint=True, open_world_hint=False), andmeta={"origin":"lit8213-risk"}, so every nested field this route can carry is populatedRegister it through the admin route, no restart
The management route with both servers
The top level is snake_case and the metadata sits under
meta, while the nestedannotationsare already camelCase (FastAPI serializes the nested model by alias; only the top-leveldict(tool)was snake_case). The full entry read{"name":"mathannotated-multiply","title":"Multiply two numbers","annotations":{"title":"Multiply","readOnlyHint":true,"destructiveHint":null,"idempotentHint":true,"openWorldHint":false},"meta":{"origin":"lit8213-risk"}}Control, the same tools on the REST list route
The REST route lists the bare tool name and reports
title,annotations, and_metaasnullfor the same tool:{"name":"multiply","title":null,"annotations":null,"_meta":null,"mcp_info":{"server_name":"mathannotated","server_id":"e39a4401-b6cd-4783-b706-e7e7023317be","alias":"mathannotated"}}Call the runtime-added tool
After (1c6c1e5, this PR's tip)
Port 40886, 2 workers (server processes 90743 and 90744), mcp 2.2.0, fresh database
lit8213_after_merge, same config and the same two upstreamsThe script lists the key's tools and calls one
List the tools from the management route
Read the schema the script keys on
inputSchemaholds the schema again, the v1.102.0 shapeCall the tool, the same way as before the fix
The other list routes and the Responses stream (controls)
REST list
JSON-RPC list
Responses API MCP stream (real OpenAI call to
gpt-5.4-mini)Same items and the same
mcp_list_toolskey set as before the fix, which is OpenAI's ownmcp_list_toolsshape (response.completedagain reported{"status":"completed","model":"gpt-5.4-mini-2026-03-17","cost":0.00009675000000000001})Nested wire keys and a server added at runtime
Register the annotated upstream through the admin route, no restart
The management route with both servers
Top level camelCase, metadata under
_meta, nestedannotationskeys unchanged from before the fixControl, the same tools on the REST list route
Unchanged from before the fix,
server_idapart:{"name":"multiply","title":null,"annotations":null,"_meta":null,"mcp_info":{"server_name":"mathannotated","server_id":"3911db7d-d577-44f0-8448-8e1af5cbcd4d","alias":"mathannotated"}}Call the runtime-added tool. The first attempt read the name from a fresh
GET /mcp-rest/tools/list, and that particular response came back withoutmultiply(see the next step), so the call went out with an empty name and was rejected. Recorded as it happened, then retried with the listed nameBecause the empty name pointed at the listing itself, both list routes were read eight times each and the call repeated four more times, all with the same key
Both list routes, the one this PR changes and the one it does not, alternate between listing and omitting the server added a moment earlier, while every call that names the tool and its
server_idreturns 42. With 2 uvicorn workers that reads as one worker having picked up the new server before the other. The merge-base proxy was not probed this way (its three listings after registration all includedmultiply), and this PR touches no server registry code (see Caveats)Notes from the run, none of them changed by this PR:
POST /mcp-rest/tools/callrejects a body withoutserver_idat every checkpointfunction_callitem besidemcp_call, every checkpointtools/callresults carryresultTypesince refactor(mcp): upgrade SDK2 while preserving legacy gateway behavior #41718metais spelled_metaon this route after the fix (see Caveats)annotationskeys are camelCase (readOnlyHint,idempotentHint,openWorldHint,destructiveHint) at both checkpoints; the fix changes only the top-level keys and the metadata key/v1/mcp/toolsprefixes tool names with the server name (mathannotated-multiply) and carriestitle,annotations, and_meta;/mcp-rest/tools/listlists the bare name (multiply) with those three asnull, at both checkpoints/live-pr-risk (1c6c1e5)
Breaking: none observed. Every route the live proxies exercised (
GET /v1/mcp/tools,GET /mcp-rest/tools/list, JSON-RPCinitializeandtools/listonPOST /mcp,POST /mcp-rest/tools/call,POST /v1/mcp/server,POST /key/generate, and the Responses MCP stream against the real OpenAI API) answered at the tip with the same status codes, values, and tool results (5 and 42) as at the merge base, apart from the key spellings this PR sets out to changeBackward incompatible:
metabecomes_metaonGET /v1/mcp/tools. v1.102.0 (c3fa53b, the regression bracket above) returnedmeta, the merge base returnsmeta, the tip returns_meta, which is the spellingGET /mcp-rest/tools/listand the JSON-RPCtools/listused at every checkpoint and the key the MCP spec names. A v1.102.0 reader ofmetaon this route now readsundefined; the key isnullfor every tool without metadata. Deliberate: the alternative (dump by alias, then rename_metaback tometaon this one route) is rejected under Caveats and the regression test pins_meta. Accepted by the approving review on this PRRegression risk: a server registered at runtime through
POST /v1/mcp/servershowed on one of the two uvicorn workers before the other for a short stretch at the tip (8 consecutive reads of each list route alternated between listing and omitting its tool, while everytools/callwithserver_idreturned 42). Observed at the tip only; the merge-base proxy was not probed the same way (its three post-registration listings all included the tool). The diff is 3 files, +23/-11 (git diff --stat 9cc5b78c33 1c6c1e568d): the onemodel_dump(by_alias=True)line inget_mcp_tools, a dead dict removed fromlitellm/responses/mcp/mcp_streaming_iterator.py, and the test. It touches neither the MCP server registry norPOST /v1/mcp/servernor the per-worker refresh, so the lag is inferred pre-existing and is recorded as a Low caveat, not attributed to this PRDependency graph:
litellm/proxy/_types.pyroute lists:/v1/mcp/toolsstays in the same allowlists; untouched, and every request above went through a virtual key minted on that proxy, so key auth on the route is exercised at both checkpointsui/litellm-dashboard/src/lib/http/schema.d.ts: the route declares noresponse_model(it returns a plain dict), so the schema carries no field names for it and neither file changes; untouchedGET /mcp-rest/tools/listand/v1/mcp/toolset, not this route:GET /mcp-rest/tools/listis captured as a control at every checkpoint and is unchangedget_mcp_toolshas no in-repo callers besides the router registration (grep -rn 'get_mcp_tools\b' litellm testsfinds only the new test); the new unit test calls it directly and assertsinputSchema,outputSchema,_meta, and the absence of the snake_case keys_mcp_tools_dict(removed): zero references at the tip (grep -rn _mcp_tools_dict litellm testsis empty)annotations,title,icons,_meta, and a server registered in the database at runtime: verified live at both checkpoints in the annotated upstream section; only the top-level keys and the metadata key changeNot verified:
tools/listrequest to the upstream MCP server was not captured on the wire; it is inferred unchanged from the diff, which runs after the fetch and touches serialization onlyType
🐛 Bug Fix
Caveats (if any)
Low
metaon this route is now spelled_meta, the MCP wire name/mcp-rest/tools/listalready usesmetahere now readsundefined; the key isnullfor every tool without metadata_metaback tometafor this one route, would keep a spelling no other route or the MCP spec uses, so it was not takenexclude_none), matching v1.102.0 and the other list routesv1/mcp/toolsfinds only the v1.91.0 release note that names the route (feat(proxy): allow llm_api_routes virtual keys to list MCP tools via /v1/mcp/tools #31031) and/v1/mcp/toolsetexamplesintegration-cost: the same 23test_cost_tracking::test_case_bills_expected_cost[...]cases (azure gpt-5.6 stream, gpt-5.3-codex stream, gpt-5.5-pro stream, gpt-5.6 responses) on bothintegration-providers:test_fal_ai_video_wire::test_fal_h3_video_create_uses_canonical_body_and_status_pathon bothlocal_testing_part1:test_get_model_info_bedrock_cross_region_capability_parityandtest_get_model_info_bedrock_modelson bothunit:test_secret_detection::test_scan_message_stays_linear_on_adversarial_credential_lines[assignment-flood]on bothllm_translation_testing: the same 12 cases on both (test_bedrock_moonshotjson stream, tentest_fireworks_ai_translationdocument-inlining cases,test_optional_params::test_drop_nested_params_add_prop_and_strict[hosted_vllm-my-vllm-model])e2e_ui_testing:tests/e2e/ui/tests/mcp/mcpTools.spec.ts:38(MCP Tools tab listsask_question) on both, 153 other specs pass on both; the public DeepWiki server that spec registers now advertisesask_wiki_questioninstead (itstools/liston 2026-09-22), and main's scheduled pipelines passed the job through 89979 (2026-09-21 18:09Z) and fail it from 90021 (00:09Z) on. The tab reads/mcp-rest/tools/list, which this PR does not touchusing_litellm_on_windows, which this branch passesproxy-infra / Run tests(not a required check) is red at the tip ontest_registry_read_through.py::test_get_agent_with_read_through_returns_none_for_unknown_agent, a flake: the file passes locally at the tip (23 passed), fails the same way on main run 35671790986 (12f7930) and passes on later main runs, and nothing in this PR touches itPOST /v1/mcp/servershowed on one of the two uvicorn workers before the other for a short stretch at the tip (the 8-probe loop under After); everytools/callwithserver_idreturned 42 throughout. Not probed at the merge base, and this PR touches no server registry code, so it is inferred pre-existing and left as isFinal Attestation
The tests check the right things, including the edge cases, and regressions in the respective real-world customer use-cases are not possible after this PR
1c6c1e5 passes /live-pr-risk