Repository navigation
Conversation
|
| if self._has_mapped_tools(server): | ||
| return | ||
|
|
||
| await self._get_tools_from_server(server) |
There was a problem hiding this comment.
Discovery drops caller credentials
On a direct first call to a cold server that requires a caller credential, this fetches tools/list without the BYOK or OAuth credentials and identity already available to call_tool(). Discovery also runs before the BYOK check. A valid call can fail with an upstream authentication error instead of resolving its tool, and a caller missing a BYOK credential can receive that error instead of the intended gateway challenge.
Knowledge Base Used: Proxy endpoints and request processing
| ) | ||
|
|
||
| async def _ensure_tool_mapping_for_server(self, server: MCPServer) -> None: | ||
| if self._has_mapped_tools(server): |
There was a problem hiding this comment.
This treats the server as warm when any of its tools is mapped, even if the requested tool is not. If one tool has been mapped but another exposed tool is still unmapped, discovery is skipped and the direct call can still return Tool <name> not found. Check whether the requested tool is mapped before skipping discovery.
Knowledge Base Used: Proxy endpoints and request processing
| async def _ensure_tool_mapping_for_server(self, server: MCPServer) -> None: | ||
| if self._has_mapped_tools(server): | ||
| return | ||
|
|
||
| await self._get_tools_from_server(server) |
There was a problem hiding this comment.
Concurrent calls duplicate discovery
Concurrent first calls can all see the shared mapping as cold before any fetch finishes. Each then makes its own upstream tools/list request, creating avoidable connection and catalog work during a cold start. Coalescing in-flight discovery per server would prevent that burst.
|
|
||
| assert resolved is server | ||
|
|
||
| @pytest.mark.asyncioc |
There was a problem hiding this comment.
asyncioc is not a declared pytest marker. Automatic asyncio mode still runs this test today, but the marker has no effect and collecting the file with strict marker validation would fail. Use asyncio, as the adjacent tests do.
| @pytest.mark.asyncioc | |
| @pytest.mark.asyncio |
Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time!
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
|
||
| def _get_server_for_tool_call(self, server_name: str, name: str) -> MCPServer | None: | ||
| prefixed_tool_name = add_server_prefix_to_name(name, server_name) | ||
| return self.server_owning_tool_name_prefix(prefixed_tool_name) |
There was a problem hiding this comment.
Medium: Cross-server authorization bypass
This lookup matches the longest prefix of the concatenated server/tool name, rather than the explicit server: if public (ID public-id) exposes admin-read, and a cold private server with configured ID public-admin exposes both read and admin-read, calling {"server_id":"public-id","name":"admin-read","arguments":{}} warms the private server and overwrites the public-admin-read mapping. The subsequent resolver dispatches admin-read to that private server after operations._execute_mcp_tool has already authorized public; the later tool-permission check does not repeat server authorization, so a key granted only public can execute the private tool.
Resolve the warmup target from the exact server identifier rather than the concatenated tool name, and keep discovery and dispatch bound to the authorized server.
PR overviewThis PR updates MCP tool resolution to handle cold server mappings, warming server tool catalogs when an explicitly requested tool is not yet mapped. Two security issues remain open, with none addressed so far. Ambiguous server/tool name matching can cause a request authorized for a public server to dispatch to a private server instead. The warmup path can also forward the caller’s LiteLLM admission key to a malicious upstream, exposing that credential even when tool resolution ultimately fails. Open issues (2)
Fixed/addressed: 0 · PR risk: 8/10 |
|
Anurag seems not to be a GitHub user. You need a GitHub account to be able to sign the CLA. If you have already a GitHub account, please add the email address used for this commit to your account. You have signed the CLA already but the status is still pending? Let us recheck it. |
| server=mcp_server, | ||
| tool_name=name, | ||
| mcp_auth_header=mcp_auth_header, | ||
| extra_headers=oauth2_headers, |
There was a problem hiding this comment.
High: LiteLLM admission key forwarded upstream
For oauth_delegate/true_passthrough REST calls, oauth2_headers contains the incoming Authorization, even when it was used as the LiteLLM admission credential. A malicious upstream can return an empty catalog for a request with an explicit server_id and an unmapped tool, then receive the caller's key on this warmup request before tool resolution fails; unlike normal discovery and execution, this path never applies _should_strip_caller_authorization.
Prepare warmup credentials through the existing per-server header preparation and admission-token filtering instead of passing oauth2_headers unchanged.
|
Main lists a cold server with the caller's credentials before its first tool call since #42072, so closing this. Reopen if something is missing |
TLDR
Problem
DB-backed MCP servers can start with a cold
tool_name_to_mcp_server_name_mapping. In this state, a directtools/callcan fail withTool <name> not foundeven though the MCP server exposes the requested tool.Fix
User Flow
Before
tools/calldirectly for a valid tool.Tool <name> not found.tools/listfirst warms the mapping, after whichtools/callsucceeds.After
tools/calldirectly for a valid tool.tools/list.Relevant issues
Fixes #44373
Tests
Added coverage for:
call_tool()Targeted test result:
12 passedProof of Fix
DB-backed MCP server
Verified registration through the management API with:
is_config: falsee2e_mathadd,multiplyE2E cold-mapping verification
[Add the actual result here after restarting the proxy and calling
tools/calldirectly withouttools/list.]Expected behavior:
add(10, 20)succeeds immediately after restart.tools/listrequest is made.Type
🐛 Bug Fix
Caveats
Low
A cold server mapping requires one upstream
tools/listrequest before the first tool call can be resolved.