fix(mcp): cache result of discoverServerTools to prevent post-OAuth refetch storm#4701
Conversation
…post-OAuth refetch storm
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryMedium Risk Overview Removes the OAuth callback’s workspace-wide cache clear, avoiding unintended invalidation of other servers’ cached tools, and caps Reviewed by Cursor Bugbot for commit 4e6210c. Configure here. |
Greptile SummaryThis PR fixes a post-OAuth "Loading…" loop on MCP servers:
Confidence Score: 4/5Safe to merge; the core OAuth cache-miss fix is correct and well-tested, with one minor gap in error observability. The fix is well-scoped and the new test validates end-to-end cache priming. The one remaining gap — no warning logged when apps/sim/lib/mcp/service.ts — the Important Files Changed
Sequence DiagramsequenceDiagram
participant UI
participant OAuthCallback as OAuth Callback
participant Service as McpService
participant Cache as Per-Server Cache
participant DB
UI->>OAuthCallback: "GET /api/mcp/oauth/callback?code=..."
OAuthCallback->>DB: Exchange code to store token
OAuthCallback->>Service: discoverServerTools(userId, serverId, workspaceId)
Service->>DB: getServerConfig(serverId)
Service->>Service: resolveConfigEnvVars + createClient
Service->>Service: client.listTools() timeout 30s
Service->>Cache: set(serverCacheKey, tools, 5min)
Service->>DB: updateServerStatus(connected, toolCount)
Service-->>OAuthCallback: tools[]
OAuthCallback-->>UI: htmlClose Connected
UI->>Service: discoverTools(userId, workspaceId)
Service->>Cache: get(serverCacheKey)
Cache-->>Service: tools[] cache HIT
Service-->>UI: tools[] no live re-fetch
Reviews (2): Last reviewed commit: "improvement(mcp): update server status f..." | Re-trigger Greptile |
… list-tools timeout at 30s
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit 4e6210c. Configure here.
Summary
discoverServerToolsto populate tools immediately after auth, but the result was never written to the cache — so the UI's immediate refetch missed cache and tried to live-fetch againtools/listfrom prod ECS), this left the UI in permanent "Loading…" forever, refetching every few seconds and timing out each timediscoverServerToolswrite its successful result to the per-server cache key, matching whatdiscoverToolsalready does in its fetched branchclearCache(workspaceId)from the OAuth callback — it was wiping cached tools for OTHER servers in the workspace unnecessarily; the new cache write replaces just the one server we care aboutType of Change
Testing
Tested manually by reproducing prod symptom on staging — confirmed OAuth flow leaves UI in "Loading…" indefinitely before the fix, and renders the tools list instantly after.
Added unit test:
discoverServerToolsprimes per-server cache so follow-updiscoverToolshits cache (no live re-fetch).All 286 MCP tests pass.
Checklist