Repository navigation
Fixes #35539: serve MCP under a non-root BASE_PATH - #35771
Conversation
Code Review ✅ Approved 1 closed / 1 findings🟡 Medium risk · Routing MCP and OAuth endpoints under BASE_PATH changes authentication-flow reachability; path mismatches could block client access or advertise incorrect discovery URLs. Fixes MCP and OAuth routing under a non-root ✅ 1 closed✅ Quality: New MCP discovery contract and base-URL rule have no decision record
VerificationRules No rules evaluated Functional validation Not enabledAuto-approval Not enabledFor more verification details, comment OptionsDisplay: compact → Showing compact verification results. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source |
|
When will it be released? Urgent need! |
@liaooo will get it in next minor release of 2.0.x, probaby 2.07. you have to wait some days since 2.0.6 recently released |
Describe your changes:
Fixes #35539
BASE_PATHset to a sub-path, every MCP request failed: the transport compared the full request URI, which includes the base path, with/mcp. This came in with Mcp oauth #25391, when the SDK transport'sendsWithcheck became an exact match..well-knownfilter. The basic-auth login form posts to a relativelogininstead of/mcp/login./mcp/.well-known/openid-configuration, the one discovery URL in the MCP spec that stays under a sub-path. The metadata now carriesjwks_uri,subject_types_supportedandid_token_signing_alg_values_supported, which the TypeScript MCP SDK requires on that URL. Logs a warning, at startup and whenever the MCP base URL changes, when that URL does not include the base path.https://host/om/, and every OAuth URL is built as base URL +/mcp, so the slash doubled andauthorizefailed.Type of change:
High-level design:
HttpServletStatelessServerTransport.pathInContext(request)is the request URI minus the context path. Both transports andOAuthWellKnownFilterroute on it. At the root context the path is empty, so nothing changes there.https://host/.well-known/...) are outside the app under a sub-path. Clients that only try those still need an ingress route.Tests:
Use cases covered
POST <BASE_PATH>mcpwith a PAT reaches the MCP handler instead of 404/405..well-knownendpoints resolve under<BASE_PATH>mcp/....BASE_PATHbehave as before.Unit tests
HttpServletStatelessServerTransportTest:doPost_underBasePath_reachesTheHandler(fails without the fix) andpathInContext_stripsOnlyTheContextPath.BasicAuthLoginServletTest: the re-rendered login form posts to a relativelogin.UriUtilsTest.testWithoutTrailingSlash_dropsOnlyTheTrailingSlash.HttpServletStatelessServerTransportTest,OAuthHttpStatelessServerTransportProviderTest,BasicAuthLoginServletTest,UriUtilsTest,McpServerRequestContextTestand the other auth tests: 122/122 pass. Coverage not measured.Backend integration tests
McpOAuthIT.testOpenIdConfigurationAppendedToIssuer_servesOpenIdDiscoveryMetadata: compiled locally, not run.Manual testing performed
BASE_PATH=/om/and MCP base URLhttp://localhost:8585/om/: PATinitializeandtools/liston/om/mcp, the 401 challenge, all.well-knownroutes, and the full OAuth flow (register, authorize, login, token,tools/list) pass. The same checks pass at the root path.Checklist:
Fixes <issue-number>: <short explanation>Fixes #35539above.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.9c50ffbc1c6and2df7c04e150. Fixed the 🔴 (theopenid-configurationdocument lacked fields the TypeScript MCP SDK requires) in2df7c04e150, and the 🟡 that the base URL warning ran only at startup inff8aa0e4c8c(only moves the warning, not re-reviewed).e66b11f27e1(trailing slash) was not re-reviewed.pathInContext, which is tested.ADR:2026-10-19-mcp-oauth-discovery-stays-inside-the-base-path.

Confidence Score: 5/5
The changes appear safe to merge; no new blocking issue was found.Summary
Fixes MCP routing under a non-root
BASE_PATH.BASE_PATH.No new actionable issues found. Tests were inspected, not run.
Diagram
%%{init: {'theme': 'neutral'}}%% flowchart LR A["Request: /om/mcp"] --> B["Strip context path: /om"] B --> C["Exact route match: /mcp"] C --> D["Existing MCP handler"]Reviews (3) · Last reviewed commit: "trailing slash fix" · Reviewed by Greptile