Skip to content

Fixes #35539: serve MCP under a non-root BASE_PATH - #35771

Merged
pmbrull merged 5 commits into
mainfrom
fix/mcp-base-path
Oct 20, 2026
Merged

pmbrull merged 5 commits into
mainfrom
fix/mcp-base-path

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes #35539

  • With BASE_PATH set 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's endsWith check became an exact match.
  • Route matching now strips the servlet context path first and stays exact. Same for the OAuth routes and the .well-known filter. The basic-auth login form posts to a relative login instead of /mcp/login.
  • Also serves /mcp/.well-known/openid-configuration, the one discovery URL in the MCP spec that stays under a sub-path. The metadata now carries jwks_uri, subject_types_supported and id_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.
  • Also trims a trailing slash from the MCP base URL. Under a sub-path it's natural to enter https://host/om/, and every OAuth URL is built as base URL + /mcp, so the slash doubled and authorize failed.

Type of change:

  • Bug fix

High-level design:

  • HttpServletStatelessServerTransport.pathInContext(request) is the request URI minus the context path. Both transports and OAuthWellKnownFilter route on it. At the root context the path is empty, so nothing changes there.
  • The MCP base URL is not rewritten. Behind a proxy that rewrites the path, a base URL without the base path is correct, so the server only warns.
  • Discovery URLs at the host root (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>mcp with a PAT reaches the MCP handler instead of 404/405.
  • The OAuth routes and .well-known endpoints resolve under <BASE_PATH>mcp/....
  • Deployments without a BASE_PATH behave as before.

Unit tests

  • HttpServletStatelessServerTransportTest: doPost_underBasePath_reachesTheHandler (fails without the fix) and pathInContext_stripsOnlyTheContextPath.
  • BasicAuthLoginServletTest: the re-rendered login form posts to a relative login.
  • UriUtilsTest.testWithoutTrailingSlash_dropsOnlyTheTrailingSlash.
  • HttpServletStatelessServerTransportTest, OAuthHttpStatelessServerTransportProviderTest, BasicAuthLoginServletTest, UriUtilsTest, McpServerRequestContextTest and the other auth tests: 122/122 pass. Coverage not measured.

Backend integration tests

  • McpOAuthIT.testOpenIdConfigurationAppendedToIssuer_servesOpenIdDiscoveryMetadata: compiled locally, not run.

Manual testing performed

  • Local server with BASE_PATH=/om/ and MCP base URL http://localhost:8585/om/: PAT initialize and tools/list on /om/mcp, the 401 challenge, all .well-known routes, and the full OAuth flow (register, authorize, login, token, tools/list) pass. The same checks pass at the root path.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR title is Fixes <issue-number>: <short explanation>
  • My PR is linked to a GitHub issue via Fixes #35539 above.
  • I have commented on my code, particularly in hard-to-understand areas.
  • I have added tests (unit / integration / Playwright as applicable) and listed them above.
  • Self-review: I reviewed the final diff against REVIEW.md (the pr-checklist skill runs it) and fixed every 🔴 finding, or answered it on the line below.
    • Reviewed 9c50ffbc1c6 and 2df7c04e150. Fixed the 🔴 (the openid-configuration document lacked fields the TypeScript MCP SDK requires) in 2df7c04e150, and the 🟡 that the base URL warning ran only at startup in ff8aa0e4c8c (only moves the warning, not re-reviewed). e66b11f27e1 (trailing slash) was not re-reviewed.
    • Answered: 🟡 no test for the OAuth routes under a base path. The provider needs the full auth stack to construct; its route checks are one-line swaps to pathInContext, which is tested.
  • Decision check: ADR:2026-10-19-mcp-oauth-discovery-stays-inside-the-base-path.
  • I have added a test that covers the exact scenario we are fixing.

RetriggerView in GreptileConfidence 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.

  • MCP and OAuth routes match beneath BASE_PATH.
  • OpenID discovery works at the issuer’s sub-path URL.
  • Basic-auth login stays under the configured app 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"]
Loading

Reviews (3) · Last reviewed commit: "trailing slash fix" · Reviewed by Greptile

@github-actions github-actions Bot added the safe to test Add this label to run secure Github workflows on PRs label Oct 19, 2026
@Vishnuujain Vishnuujain self-assigned this Oct 19, 2026
@gitar-bot

gitar-bot Bot commented Oct 19, 2026

Copy link
Copy Markdown
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 BASE_PATH by matching routes against the context-relative path, adds /mcp/.well-known/openid-configuration discovery metadata, and trims trailing slashes from the MCP base URL. The previously missing decision record for the discovery contract and base-URL rule was resolved. No open issues found.

✅ 1 closed
✅ Quality: New MCP discovery contract and base-URL rule have no decision record

📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/server/transport/OAuthHttpStatelessServerTransportProvider.java:213-227 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/server/transport/OAuthHttpStatelessServerTransportProvider.java:401-404 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/server/transport/OAuthHttpStatelessServerTransportProvider.java:487-501 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/auth/OAuthMetadata.java:79-86 📄 openmetadata-mcp/src/main/java/org/openmetadata/mcp/McpServer.java:150-151
This PR adds a contract that MCP clients must agree with: a new REST route /mcp/.well-known/openid-configuration that returns the same document as oauth-authorization-server, plus three new metadata fields (jwks_uri → <baseUrl>/api/v1/system/config/jwks, subject_types_supported: ["public"], id_token_signing_alg_values_supported taken from tokenValidationAlgorithm). The description also states a rule in prose: "the MCP base URL must carry the base path; the server warns instead of rewriting it". The checklist answers that these are "recorded as comments next to the code". Under ADR:2026-10-08-a-decision-is-recorded-in-the-tree-not-in-the-pr-body, though, a durable decision goes in docs/decisions/, and no record there covers MCP discovery or BASE_PATH handling. Code comments are not what the review triggers ask for, and they disappear when the code is refactored. The record would state roughly: "Under a non-root BASE_PATH, MCP serves authorization-server metadata at <issuer>/.well-known/openid-configuration as well as oauth-authorization-server, and that document carries the OIDC Discovery fields the TypeScript MCP SDK requires. The MCP base URL must be the external URL including BASE_PATH. The server only warns when it doesn't, because a path-rewriting proxy makes a base URL without it valid. Host-root discovery URLs need an ingress route."

Verification

Rules No rules evaluated

Functional validation Not enabled

Set up

Auto-approval Not enabled

Set up

For more verification details, comment gitar display:verbose.

Options

Display: compact → Showing compact verification results.

Comment with these commands to change the behavior for this request:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Powered by Gitar — free for open source

@pmbrull
pmbrull added this pull request to the merge queue Oct 20, 2026
Merged via the queue into main with commit 7cb1814 Oct 20, 2026
79 checks passed
@pmbrull
pmbrull deleted the fix/mcp-base-path branch October 20, 2026 08:18
@liaooo

liaooo commented Oct 21, 2026

Copy link
Copy Markdown

When will it be released? Urgent need!

@Vishnuujain

Copy link
Copy Markdown
Contributor Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

safe to test Add this label to run secure Github workflows on PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

MCP endpoint unreachable when the server runs under a non-root BASE_PATH

3 participants