fix(mcp): recover cleanly from OAuth failures#5595
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
PR SummaryMedium Risk Overview Discovery and refresh no longer overwrite connection status in the refresh API; status comes from the service layer with race handling when a newer success lands during a failed refresh. OAuth-pending servers stay disconnected without negative caching; header-auth 401 maps to a generic authentication failure; repeated failures can promote to error. Test connection tries a configured static Client honors configured initialize timeouts and logs structured diagnostics (header names only, not values). React Query skips auto-discovery for disconnected OAuth servers and refreshes the server list when connected OAuth discovery fails. Settings UI shows persisted errors and disconnected vs error states, a retryable red Failed refresh action, and shared helpers for tool labels and refresh button state. Reviewed by Cursor Bugbot for commit 7b2378c. Bugbot is set up for automated code reviews on this repo. Configure here. |
Greptile SummaryThis PR improves MCP OAuth recovery and refresh feedback. The main changes are:
Confidence Score: 4/5The changed MCP failure paths need fixes before merging.
apps/sim/lib/mcp/service.ts and apps/sim/lib/mcp/client.ts
|
| Filename | Overview |
|---|---|
| apps/sim/lib/mcp/service.ts | Adds MCP status persistence and OAuth-pending handling, but the shared auth-error helper can hide non-OAuth 401 credential failures. |
| apps/sim/lib/mcp/client.ts | Adds connect timeout handling and structured diagnostics, but the new error logging can expose truncated secret fragments. |
| apps/sim/hooks/queries/mcp.ts | Stops auto-discovery for disconnected OAuth servers while keeping non-OAuth discovery behavior. |
| apps/sim/app/workspace/[workspaceId]/settings/components/mcp/mcp.tsx | Uses helper functions for MCP refresh action state and server tool labels. |
| apps/sim/app/workspace/[workspaceId]/settings/components/settings-header/settings-header.tsx | Adds optional error-tone rendering for settings header actions. |
Reviews (1): Last reviewed commit: "fix(mcp): improve OAuth failure recovery" | Re-trigger Greptile
Treat static-header 401s as credential failures, keep OAuth failures pending, and prevent failed refreshes or reflected upstream errors from masquerading as connected state.
# Conflicts: # apps/sim/app/workspace/[workspaceId]/settings/components/mcp/mcp.tsx # apps/sim/app/workspace/[workspaceId]/settings/components/settings-header/settings-header.tsx
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes using default effort and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 7b2378c. Configure here.

Summary
This PR makes MCP authentication and refresh failures recover cleanly instead of leaving Workspace Settings in repeated discovery loops or generic error states. Abandoned OAuth servers now wait for an explicit reconnect, failed refreshes expose a retryable Failed state, and persisted connection errors reach the list and detail views.
Fixes #5665.
Dual-auth servers can now be added with a configured static
Authorization: Bearer ...header: the connection test tries that credential before optional OAuth discovery. Supplemental non-auth headers still follow OAuth discovery, preserving OAuth servers that need routing or metadata headers.Connection attempts honor the configured timeout, and diagnostics record timing, phase, outcome, auth type, and header names without header values. Connection-test and refresh failures now use safe categorized messages so an upstream server cannot reflect a configured credential into API responses, persisted status, or logs. OAuth-pending servers remain disconnected without negative caching; rejected static credentials increment the normal failure state and negative cache instead of being mislabeled as OAuth-pending. Failed refreshes cannot report a stale connected row unless a newer successful discovery actually won the race.
Merge order
Merge this PR before #5596. Once it lands in
staging, rebase #5596 onto the updated base and resolve its verification path against these authentication, status-persistence, and negative-cache semantics.Related: #5596
Type of Change
Testing
Review focus: static Bearer precedence, preservation of OAuth-plus-supplemental-header behavior, safe failure-state persistence, and the credential-reflection boundary.
Checklist
Post-Deploy Monitoring & Validation
McpClient,McpService,authorization_required,timeout, andOAuth authorization pendingduring the first 24 hours.Screenshots/Videos
Not applicable; this changes connection behavior and failure handling without altering layout.