Repository navigation
fix(mcp): require ready connection after remote MCP OAuth callback - #966
Conversation
Bernardo's Recipe Keeper / Clerk MCP stayed "Authorization required" with no auth URL after a successful provider redirect because the Agents SDK authSuccess path cleared the stored auth URL without verifying the hub reached ready. Treat callback success as ready-only, recover the stuck authenticating-without-authUrl state on callback/reconnect, and surface a concrete error in the account UI. Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughWalkthroughOAuth callback success now requires an MCP connection to reach ChangesMCP OAuth outcome handling
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant User
participant AccountMcpServers
participant McpClientHubBase
participant MCPServer
participant AccountRoute
User->>AccountMcpServers: Complete OAuth authorization
AccountMcpServers->>McpClientHubBase: handleOAuthCallback
McpClientHubBase->>MCPServer: Establish connection
MCPServer-->>McpClientHubBase: Connection state
McpClientHubBase-->>AccountMcpServers: Success or error outcome
AccountMcpServers->>AccountRoute: Redirect with auth result and server id
AccountRoute-->>User: Show ready state or recovery guidance
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
🔎 Preview deployed: https://kody-pr-966.kody-a99.workers.dev Worker: Mocks:
|
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@docs/contributing/architecture/mcp-client-servers.md`:
- Around line 51-52: Update the callback flow description to document redirects
to the server-scoped `/account/mcp-servers/:serverId` route for both successful
and failed callbacks, replacing the list-route-only wording while preserving the
existing feedback query parameters.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro Plus
Run ID: 9031cfbf-6d31-42bb-a9aa-3a486af9da04
📒 Files selected for processing (7)
docs/contributing/architecture/mcp-client-servers.mdpackages/worker/client/routes/account-mcp-servers.tsxpackages/worker/src/app/handlers/account-mcp-servers.node.test.tspackages/worker/src/app/handlers/account-mcp-servers.tspackages/worker/src/mcp-client/hub.tspackages/worker/src/mcp-client/oauth-callback-outcome.node.test.tspackages/worker/src/mcp-client/oauth-callback-outcome.ts
CodeRabbit correctly flagged that callbacks with a resolved serverId now land on /account/mcp-servers/:serverId, including failure cases. Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Co-authored-by: Kent C. Dodds <me+github@kentcdodds.com>
Summary
Bernardo Munz (
moonbe77@gmail.com) emailed about connecting his Recipe Keeper MCP (https://polite-ladybug-723.convex.site/mcp, Clerk OAuth). After Clerk authorization succeeded, Kody left the server in Authorization required with no Authorize link, no error, and no authenticated request reaching Recipe Keeper. Reconnect did the same.Root cause: the Agents SDK
authSuccesspath clears the storedauth_urland can leave the live connection inauthenticatingwithout a usable auth URL. Kody treated SDKauthSuccessas final and redirected with?auth=success.Fix
readyauthenticating+ missingauthUrl, invalidate unusable tokens, and reconnect to mint a fresh auth URL (callback + reconnect)Test plan
auth=errorSystem recap — extends existing primitives (medium risk)
Classification
extends— changes MCP client OAuth callback success semantics and reconnect recovery for stuck auth state.Primitives touched
mcp-client-serversapp-uiWhat changed
handleOAuthCallbackno longer trusts Agents SDKauthSuccessalone; success requiresreadyauthenticatingwithoutauthUrlrecovers by invalidating tokens and reconnectingRisk / invariants
userId)Docs
docs/contributing/architecture/mcp-client-servers.md— ready-only callback success + reconnect recoveryflowchart LR A[Clerk OAuth redirect] --> B[Hub handleOAuthCallback] B --> C{SDK authSuccess?} C -->|no| F[auth=error] C -->|yes| D[establishConnection] D --> E{state ready?} E -->|yes| G[auth=success] E -->|authenticating no authUrl| H[invalidate tokens + reconnect] H --> E E -->|still not ready| FSummary by CodeRabbit