fix(mcp): harden OAuth request isolation - #7481
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
Greptile SummaryThis PR hardens MCP OAuth request isolation and cancellation behavior.
Confidence Score: 5/5The PR appears safe to merge; no actionable new failure remains, and the previously reported refresh-serialization issue is fully fixed. The current implementation preserves a potentially acquired owner token while an uncoordinated refresh runs, releases it only when cancellation prevents the refresh callback, and scopes configured MCP headers away from OAuth endpoints. Abort checks prevent cancelled queued work from executing without abandoning an already-running token rotation.
|
| Filename | Overview |
|---|---|
| apps/sim/lib/mcp/client.ts | Routes OAuth transports through endpoint-scoped fetch handling while retaining configured headers for non-OAuth transports. |
| apps/sim/lib/mcp/oauth/coordinated-fetch.ts | Restricts configured headers to the MCP endpoint and propagates request cancellation into refresh-lock coordination. |
| apps/sim/lib/mcp/oauth/storage.ts | Adds abort-aware queue and Redis-lock waiting while preserving ambiguous lock ownership for fail-open refreshes. |
| apps/sim/lib/mcp/client.test.ts | Verifies OAuth transports use scoped fetch injection rather than globally applied request initialization. |
| apps/sim/lib/mcp/oauth/coordinated-fetch.test.ts | Covers endpoint-only header application and prompt cancellation while waiting for refresh serialization. |
| apps/sim/lib/mcp/oauth/storage.test.ts | Covers queued cancellation and both fail-open and cancelled ambiguous-acquire ownership behavior. |
Sequence Diagram
sequenceDiagram
participant Client as MCP client
participant Scope as Endpoint-scoped fetch
participant MCP as MCP endpoint
participant Lock as OAuth refresh lock
participant OAuth as OAuth discovery/token endpoint
Client->>Scope: MCP request with configured headers
Scope->>MCP: Forward request with configured headers
MCP-->>Client: 401 OAuth challenge
Client->>Lock: Wait for serialized refresh
alt Request is cancelled while queued
Lock-->>Client: Reject without running refresh
else Lock acquired or safely falls open
Lock->>OAuth: Discovery/token request without configured MCP headers
OAuth-->>Lock: Updated credentials
Client->>Scope: Retry MCP request
Scope->>MCP: Forward with configured headers
end
Reviews (3): Last reviewed commit: "fix(mcp): preserve ambiguous refresh loc..." | Re-trigger Greptile
There was a problem hiding this comment.
All reported issues were addressed across 6 files
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
|
@cubic-dev-ai review this PR |
@waleedlatif1 I have started the AI code review. It will take a few minutes to complete. |
Summary
Type of Change
Testing
bun run lintbun run check:auditsbun run docs-manifest:checkbunx tsc --noEmit --incremental falseChecklist