fix(mcp): clear OAuth token when deleting MCP server#14065
fix(mcp): clear OAuth token when deleting MCP server#14065404-Page-Found wants to merge 4 commits intoCherryHQ:v2from
Conversation
…tions Signed-off-by: fullex <[email protected]>
kangfenmao
left a comment
There was a problem hiding this comment.
Clean and focused fix. Reuses existing JsonFileStorage.clear() nicely. One minor consistency suggestion — see inline comment.
src/main/services/MCPService.ts
Outdated
|
|
||
| // Clear OAuth token for this server | ||
| if (server.baseUrl) { | ||
| const serverUrlHash = crypto.createHash('md5').update(server.baseUrl).digest('hex') |
There was a problem hiding this comment.
[B3] Minor inconsistency in MD5 hash computation
In the original OAuth creation flow (lines 323–326), when server.baseUrl is undefined, the code falls back to an empty string:
serverUrlHash: crypto.createHash('md5').update(server.baseUrl || '').digest('hex')Here, the if (server.baseUrl) guard means cleanup is skipped when baseUrl is undefined or an empty string — but the creation flow would still generate a hash (from '') and create an OAuth file in that case.
In practice, a server without a baseUrl is unlikely to reach the OAuth flow, so this won't cause real issues. Still, for consistency, consider extracting the hash computation into a shared helper to avoid duplicated logic:
private getServerUrlHash(server: MCPServer): string {
return crypto.createHash('md5').update(server.baseUrl || '').digest('hex')
}Extract getServerUrlHash() to avoid duplicating MD5 hash logic between OAuth creation and deletion flows, as requested in PR review.
What this PR does
Before this PR: When an MCP server was deleted, the OAuth token stored in
~/.cherrystudio/config/mcp/oauth/was not cleared. This caused the server to bypass the OAuth authorization flow when re-installed.After this PR: When an MCP server is deleted, the
removeServer()method now clears the OAuth token file by computing the MD5 hash of the server'sbaseUrland callingJsonFileStorage.clear().Fixes #14047
Why we need it and why it was done in this way
The bug prevents users from re-authenticating with an MCP server that uses OAuth. When the token expires or needs to be refreshed, users had to manually delete the OAuth file from
~/.cherrystudio/config/mcp/oauth/.The following tradeoffs were made:
JsonFileStorage.clear()method which already handles file deletion gracefullyThe following alternatives were considered:
JsonFileStorage.clear()already existsBreaking changes
None - this is a bug fix that only affects the deletion flow.
Special notes for your reviewer
The fix adds OAuth token cleanup in the
removeServer()method. The implementation:server.baseUrlexists (not all MCP servers have a baseUrl)JsonFileStorage.clear()which handles non-existent files gracefully (catches ENOENT)Checklist
This checklist is not enforcing, but it's a reminder of items that could be relevant to every PR.
Approvers are expected to review this list.
/gh-pr-review,gh pr diff, or GitHub UI) before requesting review from othersRelease note