Repository navigation
fix(gateway): apply the tool rules to child MCP calls through /svc - #669
Merged
Merged
Conversation
A POST to a backing server's own MCP endpoint through /svc reached the server without the gateway's per-role tool rules, so a tool disabled (or hidden by default) for a role on /mcp stayed callable there. The proxy now checks each tools/call against the same rules before forwarding: a single call gets the tool error /mcp gives, a batch with such a call is refused whole, and neither reaches the server. Other /svc routes are unchanged. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A body the gateway can't parse as JSON (a gzip-encoded one, say) was forwarded unchecked, and a server that inflates or otherwise parses it more leniently would run the call. Such a POST is now refused with an invalid request error and never forwarded. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Some servers route paths case-insensitively (Express does by default), so /svc/<child>/MCP could reach the MCP endpoint without the tool check or the role stamp. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… too /svc/<child>/public%2Fx/../mcp routes here as public/x/../mcp, but forward() keeps the encoded slash and httpx then removes 'public%2Fx/..', so the child received /mcp without the tool check or the role stamp. Both now check the path as routed and the path sent, as reserved_site_request does for sites. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
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.
What and why
The gateway applies its per-role tool rules on its own
/mcpendpoint. A POST to a backing server's own MCP endpoint through/svc/{service}/...was forwarded without them. So a tool disabled for a role on/mcp, or one hidden by default, could still be called there.Now, before forwarding, the proxy reads each
tools/callin such a POST and checks it against the same rules/mcpuses (_is_disabled)./mcpgives (isError: true, "Tool 'X' is disabled for role 'r'"). It never reaches the server./MCPto/mcp./stepreturns. That check is now one helper,_discovery_unavailable, shared by both.These are unchanged:
/svcroutes (REST,export-state, cards);tools/call.tools/listthrough/svcisn't filtered, because listing a tool's name grants nothing. A client that calls a hidden tool through/svcnow needs a rule naming that tool, as it already did on/mcp.How it was tested
Unit (
tst/unit/env/gateway/rest_proxy_stream_test.py, gateway ASGI harness). The new tests fail with the check removed. All 1,047 gateway unit tests pass. They cover:/mcp's exact text, at/mcpor/MCP/, and nothing reaches the server;"*"rule and forwarded once a rule names it;Integration (
tst/integration/env/gateway/gateway_test.py, local Docker). In the newtest_a_tool_disabled_for_a_role_is_refused_through_svc_as_on_the_gateway_s_mcp, a real MCP client calls through/mcpand/svc/mcp-email/mcp. The disabled role gets the same refusal on both paths and writes nothing; another role's calls succeed on both. It passed, together with the existing/svcwrite test (2 passed).Manual, at 6c0cb51. Two local gateways, one built from
mainand one from this branch, each in front of a file-storage server and a mail server on Postgres, loaded with their QC fixtures. A file read is disabled for one user./svc/<server>/mcpmain/mcp's errorhttp.clientpublic%2Fx/../mcp,%2E%2E,x%2F..%2Fmcp,%6dcp,MCP,//mcp,?x=1, an escapedname, a duplicatenamekey, UTF-8 BOM, UTF-16, gzip, batch,text/plain, and the plain call./svc, with every tool enabled, onmainand on this branch: 1,264 tests. They had the same outcome test by test (0 differ)./svctool calls get 503 here, wheremainforwarded them.mainit passes (16 passed). On this branch it is refused under a"*"rule, and passes once a rule names the tool (16 passed).gateway_test.pygave 9 passed and 10 skipped (the remote-sandbox variants).🤖 Generated with Claude Code


Confidence Score: 5/5
The PR appears safe to merge; no outstanding blocking issue was found.Summary
The PR applies role-based tool rules to child MCP calls through
/svc.Diagram
%%{init: {'theme': 'neutral'}}%% flowchart TD A[Child MCP POST through /svc] --> B[Check routed and forwarded paths] B --> C[Read tool names] C --> D[Discover tools and check role rules] D -->|Disabled or unavailable| E[Return refusal] D -->|Allowed| F[Stamp role and forward to child]Reviews (6) · Last reviewed commit: "fix(gateway): judge the child MCP path b..." · Reviewed by Greptile