Skip to content

Commit 86eae7b

Browse files
committed
fix: revoke OAuth tokens independently so one failure does not skip the other
When disconnecting an MCP account, revoke each token in its own try/catch so a failed access-token revocation (e.g. unsupported_token_type per RFC 7009 §2.2.1, or a 503) does not skip the refresh-token revocation. Refresh token is revoked first per RFC 7009 §2.1. Fixes #41
1 parent 0eaec6c commit 86eae7b

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

packages/mcp-shared/src/account.ts

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -831,15 +831,22 @@ export abstract class McpAccountBase<E extends AccountEnv, P = unknown>
831831
const discovery = this.ctx.storage.kv.get<OAuthDiscoveryState>("oauthDiscovery");
832832
const client = this.ctx.storage.kv.get<StoredOAuthClientInformation>("oauthClient");
833833
if (tokens && discovery && client) {
834-
// Best effort: a server that does not implement RFC 7009 must not block the disconnect.
835-
try {
836-
const fetchFn = sdkFetch(this.fetchOptions());
837-
await revokeToken(discovery, client, tokens.access_token, "access_token", fetchFn);
838-
if (tokens.refresh_token) {
834+
// Best effort per token: a server that refuses one token type (RFC 7009 §2.2.1) must not
835+
// cost the revocation of the other. Refresh token first: RFC 7009 §2.1 says revoking it
836+
// SHOULD also invalidate access tokens issued under the same grant.
837+
const fetchFn = sdkFetch(this.fetchOptions());
838+
if (tokens.refresh_token) {
839+
try {
839840
await revokeToken(discovery, client, tokens.refresh_token, "refresh_token", fetchFn);
841+
} catch (err) {
842+
this.log().warn("failed to revoke MCP refresh token",
843+
{ event: "oauth.token.revoke.failed", error: err });
840844
}
845+
}
846+
try {
847+
await revokeToken(discovery, client, tokens.access_token, "access_token", fetchFn);
841848
} catch (err) {
842-
this.log().warn("failed to revoke MCP tokens",
849+
this.log().warn("failed to revoke MCP access token",
843850
{ event: "oauth.token.revoke.failed", error: err });
844851
}
845852
}

0 commit comments

Comments
 (0)