Repository navigation
fix(mcp): tool error codes and access token revoke - #36498
Conversation
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 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 |
❌ PR checklist incompleteThis PR cannot be merged until the following are addressed on its linked issue:
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 |
|
✅ SSO Login Nightly — PASSED View workflow run · Commit
Totals: 94 passed · 0 failed · 0 flaky · 0 skipped · duration 18m 13s |
|
🤖 Backport to |
|
🤖 Backport to |
|
🤖 Backport to |
|
🤖 Backport to |
* 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]>
Describe your changes:
Fixes https://github.com/open-metadata/openmetadata-collate/issues/7966
get_entity_detailswith no arguments, a malformedqueryFilter, a search page past the result window. They now return the 400 (or 404) the error already carries, and argument errors fromcompany_context,find_contextandsemantic_searchare recorded as VALIDATION instead of INTERNAL. A wrong-caseentityTypenow names the type that was meant, and search errors no longer include the search host./mcp/revokehad 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:
High-level design:
client_idand a randomjti(RFC 9068), and their SHA-256 hash goes into the existingoauth_access_tokenstable.JwtFilterrefuses a token signed with our key that carriesclient_idand 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/revokedeletes a token only when its row names the authenticated client, and answers 200 either way (RFC 7009).token_type_hintonly 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'srevokeToken(Object)has no client to check and now refuses;/mcp/revokeis the path.SearchExceptionreports the engine's 400).JwtTokenCacheManagerkeys logout entries on the token's signed part.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 noclient_idand expire within 10 minutes.Tests:
Unit tests
GetEntityToolTest#missingEntityIsRejectedAsABadRequest,McpResponseTrimTest#searchFailureDoesNotNameTheSearchHost,DefaultToolContextTest#searchExceptionCarryingA400IsTheCallersMistake,CatalogExceptionMessageTest#unknownEntityTypeNamesTheTypeSpelledWithAnotherCaseJwtFilterTest#mcpAccessTokenNoLongerStoredIsRejected,#mcpAccessTokenStillStoredIsAccepted,#mcpAccessTokenFromAnEarlierIssuerIsStillLookedUp,#providerTokenWithAClientIdIsNotLookedUp;JWTTokenGeneratorTest#mcpAccessTokenNamesItsClient;OAuthTokenRepositoryTest#accessTokenIsRevokedOnlyForTheClientItWasIssuedTo,#refreshTokenIsRevokedOnlyForTheClientItWasIssuedTo;RevocationHandlerTest#accessTokenWithoutTypeHintIsRevokedWhenNoRefreshTokenMatches;JwtTokenCacheManagerTestUserSSOOAuthProviderTest#exchangeRefreshToken_aFailedAccessTokenWriteLeavesTheRefreshTokenUnrotatedCompanyContextToolTest,SemanticSearchToolTest,UserSSOOAuthProviderTest,RevocationHandlerTest(a missed hint now extends the search)Backend integration tests
McpOAuthIT#testRevokedAccessToken_isRefusedOnTheNextCall,#testRevokedRefreshToken_endsItsAccessTokensUnit and integration tests not run locally yet, so this PR stays draft until
make java_affected_runpasses.Manual testing performed
On a local server built from this branch (basic auth, Postgres, OpenSearch 3.4.0), through
/mcp,/mcp/token,/mcp/revokeand REST:get_entity_details,company_context,find_contextandsemantic_searchwith{}: 400, and their usage rows recorded as VALIDATION. A malformedqueryFilter, a page past the result window and a bad script filter: 400.eventSubscription: "Did you mean 'eventsubscription'?".client_idandjtiand are stored. Another client's revoke leaves them working; the owning client's revoke, with or withouttoken_type_hint, gives 401 on/mcpand REST. A refresh in the same second as sign-in succeeds; a refresh after revoking the refresh token fails.f3e7d4d8ed4: own token revoked with the wrongtoken_type_hintgives 401; revoking a refresh token gives 401 for its access token on/mcpand 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 byJwtFilterTestonly.UI screen recording:
Not applicable: backend and MCP only.
Checklist:
Fixesabove.REVIEW.md(thepr-checklistskill runs it) and fixed every 🔴 finding, or answered it on the line below.REVIEW.mdreview ofd61dc07a7b3: no 🔴; 🟡 fixed in97831bdd420(a missedtoken_type_hintextends the search, access token issued before refresh rotation, refresh revoke ends its access tokens, tests, dead code). Second pass on97831bdd420: no 🔴; 🟡 fixed inf3e7d4d8ed4(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).ADR:2026-10-29-mcp-access-tokens-are-stored-so-revoke-reaches-every-server