Skip to content

fix(mcp): tool error codes and access token revoke - #36498

Merged
Vishnuujain merged 5 commits into
mainfrom
mcp-tool-errors-and-revoke
Oct 29, 2026
Merged

Vishnuujain merged 5 commits into
mainfrom
mcp-tool-errors-and-revoke

Conversation

@Vishnuujain

@Vishnuujain Vishnuujain commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

Describe your changes:

Fixes https://github.com/open-metadata/openmetadata-collate/issues/7966

  • MCP tools reported caller mistakes as a 500 "backend fault": get_entity_details with no arguments, a malformed queryFilter, a search page past the result window. They now return the 400 (or 404) the error already carries, and argument errors from company_context, find_context and semantic_search are recorded as VALIDATION instead of INTERNAL. A wrong-case entityType now names the type that was meant, and search errors no longer include the search host.
  • /mcp/revoke had nothing to act on for an access token: access tokens were never stored. They are now stored when issued and checked on every request, and a client can revoke only its own tokens.

Type of change:

  • Bug fix

High-level design:

  • MCP access tokens carry client_id and a random jti (RFC 9068), and their SHA-256 hash goes into the existing oauth_access_tokens table. JwtFilter refuses a token signed with our key that carries client_id and is no longer stored; deleting an OAuth client deletes its tokens. An in-memory denylist was rejected: it is per server and lost on restart. ADR:2026-10-29-mcp-access-tokens-are-stored-so-revoke-reaches-every-server.
  • /mcp/revoke deletes a token only when its row names the authenticated client, and answers 200 either way (RFC 7009). token_type_hint only picks which type is looked up first. Revoking a refresh token also deletes the access tokens of its grant (the client and user pair rotation already treats as one), in the same transaction. The provider's revokeToken(Object) has no client to check and now refuses; /mcp/revoke is the path.
  • A refresh stores the new access token before rotating the refresh token, so a failed write does not cost the client its grant.
  • MCP error classification trusts a 4xx status the exception already carries (SearchException reports the engine's 400). JwtTokenCacheManager keys logout entries on the token's signed part.
  • Visible difference: the REST message for an unknown entity type is now Unknown entity type 'x'. Did you mean 'y'? (still 404). No migration: the table exists since 1.12.4. Tokens issued before the upgrade carry no client_id and expire within 10 minutes.

Tests:

Unit tests

  • GetEntityToolTest#missingEntityIsRejectedAsABadRequest, McpResponseTrimTest#searchFailureDoesNotNameTheSearchHost, DefaultToolContextTest#searchExceptionCarryingA400IsTheCallersMistake, CatalogExceptionMessageTest#unknownEntityTypeNamesTheTypeSpelledWithAnotherCase
  • JwtFilterTest#mcpAccessTokenNoLongerStoredIsRejected, #mcpAccessTokenStillStoredIsAccepted, #mcpAccessTokenFromAnEarlierIssuerIsStillLookedUp, #providerTokenWithAClientIdIsNotLookedUp; JWTTokenGeneratorTest#mcpAccessTokenNamesItsClient; OAuthTokenRepositoryTest#accessTokenIsRevokedOnlyForTheClientItWasIssuedTo, #refreshTokenIsRevokedOnlyForTheClientItWasIssuedTo; RevocationHandlerTest#accessTokenWithoutTypeHintIsRevokedWhenNoRefreshTokenMatches; JwtTokenCacheManagerTest
  • UserSSOOAuthProviderTest#exchangeRefreshToken_aFailedAccessTokenWriteLeavesTheRefreshTokenUnrotated
  • Updated: CompanyContextToolTest, SemanticSearchToolTest, UserSSOOAuthProviderTest, RevocationHandlerTest (a missed hint now extends the search)

Backend integration tests

  • McpOAuthIT#testRevokedAccessToken_isRefusedOnTheNextCall, #testRevokedRefreshToken_endsItsAccessTokens

Unit and integration tests not run locally yet, so this PR stays draft until make java_affected_run passes.

Manual testing performed

On a local server built from this branch (basic auth, Postgres, OpenSearch 3.4.0), through /mcp, /mcp/token, /mcp/revoke and REST:

  • get_entity_details, company_context, find_context and semantic_search with {}: 400, and their usage rows recorded as VALIDATION. A malformed queryFilter, a page past the result window and a bad script filter: 400. eventSubscription: "Did you mean 'eventsubscription'?".
  • OAuth: new access tokens carry client_id and jti and are stored. Another client's revoke leaves them working; the owning client's revoke, with or without token_type_hint, gives 401 on /mcp and REST. A refresh in the same second as sign-in succeeds; a refresh after revoking the refresh token fails.
  • Rebuilt on f3e7d4d8ed4: own token revoked with the wrong token_type_hint gives 401; revoking a refresh token gives 401 for its access token on /mcp and REST and fails the next refresh; another client's refresh-token revoke changes nothing; a new sign-in afterwards works. The issuer-change case is covered by JwtFilterTest only.

UI screen recording:

Not applicable: backend and MCP only.

Checklist:

  • I have read the CONTRIBUTING document.
  • My PR is linked to a GitHub issue via Fixes above.
  • 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.
    • REVIEW.md review of d61dc07a7b3: no 🔴; 🟡 fixed in 97831bdd420 (a missed token_type_hint extends the search, access token issued before refresh rotation, refresh revoke ends its access tokens, tests, dead code). Second pass on 97831bdd420: no 🔴; 🟡 fixed in f3e7d4d8ed4 (refresh revoke and access-token cleanup in one transaction, tests). Not changed: a rotation landing between a revoke's lookup and its write keeps the new refresh token (pre-existing).
  • Decision check: ADR:2026-10-29-mcp-access-tokens-are-stored-so-revoke-reaches-every-server
  • I have added a test that covers the exact scenario we are fixing.

@gitar-bot

gitar-bot Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Code Review ✅ Approved

🔴 High risk · MCP token issuance, storage, and revocation now gate authentication; incorrect record handling could block legitimate users or leave revoked credentials usable.

Fixes MCP error classification so caller mistakes return 400/404 instead of 500, and adds stored access tokens with client_id and jti so /mcp/revoke reaches every server. No issues found.

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

@Vishnuujain
Vishnuujain marked this pull request as ready for review October 29, 2026 00:47
@Vishnuujain
Vishnuujain requested a review from a team as a code owner October 29, 2026 00:47
@github-actions

Copy link
Copy Markdown
Contributor

❌ PR checklist incomplete

This PR cannot be merged until the following are addressed on its linked issue:

  • No GitHub issue is linked. Link an issue in the Development section of the PR (or add Fixes #12345 to the description). For a same-org cross-repo issue, add Fixes open-metadata/<repo>#123 to the description.

The fields live on the linked issue in the Shipping project (open the issue → right sidebar → Projects). After you set them, re-run this check (or push a commit) — issue/project changes do not re-trigger it automatically.

Maintainers can bypass this check by adding the skip-pr-checks label.

@Vishnuujain Vishnuujain self-assigned this Oct 29, 2026
@Vishnuujain Vishnuujain added the To release Will cherry-pick this PR into the release branch label Oct 29, 2026
@github-actions

github-actions Bot commented Oct 29, 2026 •

Copy link
Copy Markdown
Contributor

✅ SSO Login Nightly — PASSED

View workflow run · Commit a9da8b9

Provider Status Pass Fail Flaky Skip Duration
basic ✅ pass 28 0 0 0 6m 48s
ldap ✅ pass 7 0 0 0 0m 56s
keycloak-oidc-confidential ✅ pass 12 0 0 0 1m 40s
keycloak-oidc-public ✅ pass 11 0 0 0 1m 22s
msal-mock ✅ pass 7 0 0 0 0m 47s
auth0-mock ✅ pass 6 0 0 0 0m 52s
okta ⏩ skipped - - - - -
keycloak-azure-saml ✅ pass 23 0 0 0 5m 45s
keycloak-azure-saml-crosssite ⏩ skipped - - - - -

Totals: 94 passed · 0 failed · 0 flaky · 0 skipped · duration 18m 13s

@Vishnuujain
Vishnuujain added this pull request to the merge queue Oct 29, 2026
Merged via the queue into main with commit 57376d0 Oct 29, 2026
181 of 183 checks passed
@Vishnuujain
Vishnuujain deleted the mcp-tool-errors-and-revoke branch October 29, 2026 13:30
@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.0 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@github-actions

Copy link
Copy Markdown
Contributor

🤖 Backport to 2.1 is under way. It is built from openmetadata-collate, which holds the credentials needed to open a PR here, and it will comment again with the result — nothing is needed from you unless it reports otherwise.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.1 opened as #36554 (clean cherry-pick). It merges itself once the checks pass.

@gh-bot-collate

Copy link
Copy Markdown

🤖 Backport to 2.0 failed. The conflict could not be resolved, so this change is not on that branch. Resolver run.

Vishnuujain added a commit that referenced this pull request Oct 29, 2026
* fix(mcp): tool error codes and access token revoke

* jti and search status

* key id token lookup

* review fixes

* atomic grant revoke

(cherry picked from commit 57376d0)

Co-authored-by: Vishnu Jain <[email protected]>
Vishnuujain added a commit that referenced this pull request Nov 2, 2026
* fix(mcp): access token revoke (backport 2.0 #36498)

* fix(mcp): revoke oauth grants of deleted users (backport 2.0 #36699) (#36779)
sonika-shah added a commit that referenced this pull request Nov 19, 2026
…backport 2.0 #36498) (#38160)

A call with neither a batch nor an entityType reached the
OperationContext constructor with a null resource, so the caller got an
NPE (logged at ERROR) instead of a validation error. Backports the
GetEntityTool guard from #36498, which #36778 did not carry.

This branch was previously deployed

1 inactive deployment
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 To release Will cherry-pick this PR into the release branch

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants