fix(oauth): clean up orphaned tokens on server removal and startup#288
Merged
fix(oauth): clean up orphaned tokens on server removal and startup#288
Conversation
This fixes the issue where OAuth tokens accumulate in the database for servers that have been removed, causing unnecessary refresh attempts and confusing error messages like "OAuth token refresh failed - token expired too long ago". Changes: 1. RemoveServer() now calls ClearOAuthState() to remove OAuth tokens when a server is deleted 2. RemoveServer() notifies RefreshManager to stop tracking the removed server's token refresh schedule 3. Added CleanupOrphanedOAuthTokens() to storage manager that removes tokens for servers no longer in configuration 4. Startup now cleans up orphaned tokens before starting RefreshManager Key storage design notes: - Tokens use serverName_hash(serverName|serverURL) as storage key - This ensures multiple servers can share the same URL (different names) - URL changes for a server name are properly handled via ClearOAuthState which deletes all tokens with the serverName_ prefix Tested: Verified 7 orphaned tokens were cleaned up on startup Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Deploying mcpproxy-docs with
|
| Latest commit: |
7af5775
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://8de25c32.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-oauth-token-cleanup.mcpproxy-docs.pages.dev |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 21545962892 --repo smart-mcp-proxy/mcpproxy-go
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Problem
OAuth tokens were accumulating in the database for servers that had been removed, causing:
Evidence from investigation:
Root Cause
RemoveServer()was not callingClearOAuthState()to remove OAuth tokens when a server was deleted, and there was no startup cleanup for tokens of servers removed while mcpproxy was not running.Changes
1.
internal/server/server.goClearOAuthState()call inRemoveServer()to clean up OAuth tokensRefreshManager.OnTokenCleared()notification to stop refresh scheduling2.
internal/storage/manager.goCleanupOrphanedOAuthTokens(validServerNames []string)method3.
internal/runtime/lifecycle.goCleanupOrphanedOAuthTokens()before starting RefreshManager4.
internal/storage/manager_oauth_test.goTestManager_CleanupOrphanedOAuthTokenstestStorage Key Design (already correct)
Tokens use
serverName_hash(serverName|serverURL)as storage key, ensuring:ClearOAuthState(serverName)removes all tokens withserverName_prefixTest plan
CleanupOrphanedOAuthTokenspasses🤖 Generated with Claude Code