Repository navigation
refactor(api): simplify MCP OAuth authorization and consent - #1034
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Advanced Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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 |
There was a problem hiding this comment.
All reported issues were addressed across 20 files
Architecture diagram
sequenceDiagram
participant Client as Dashboard Client
participant API as API Route (Elysia)
participant Auth as Auth Service (Better Auth)
participant MCP as MCP Handler
participant Ctx as Tool Context
participant RPC as RPC Layer
participant DB as Database
Note over Client,DB: MCP OAuth Authorization Flow
Client->>Auth: Request /oauth2/authorize
Auth->>Auth: mcpConsentAccess - encode consent reference
Auth->>Auth: mcpPostLogin - store encoded reference
Client->>Auth: POST /oauth2/consent (accept/deny)
Auth->>Auth: Native OAuth client - validate consent
alt Accept
Auth-->>Client: Redirect URL
Client->>API: MCP request with OAuth token
API->>API: Validate token scopes (no API scope filter)
API->>DB: Find user by subject ID
alt User exists
API->>MCP: handleDatabuddyMcpRequest (oauth principal + user)
MCP->>Ctx: ensureWebsiteAccess / buildRpcContext
Ctx->>DB: Check fresh membership
alt Valid membership
Ctx->>RPC: Execute tool with OAuth context
RPC->>DB: Access websites with organization boundary
RPC-->>Ctx: Result
Ctx-->>MCP: Response
MCP-->>API: Success
else No membership
Ctx-->>MCP: Access denied
MCP-->>API: Unauthorized
end
else User not found
API-->>Client: Unauthorized
end
else Deny
Auth-->>Client: Redirect URL
end
Note over Client,DB: Connected Apps Display
Client->>Auth: oauth2.getConsents (native client)
Auth-->>Client: Consent list with clientIds
Client->>Auth: oauth2.publicClient (per consent)
Auth-->>Client: client metadata (client_name)
Client->>Client: Display provider client_name
Note over Client,DB: Disconnect/Revocation
Client->>Auth: oauth2.deleteConsent (native client)
Auth->>DB: Revoke OAuth grant
DB-->>Auth: Confirmation
Auth-->>Client: Success
Client->>Client: Invalidate connected apps query
Shadow auto-approve: would not auto-approve because issues were found.
Re-trigger cubic
|
e646953 to
0c868f5
Compare
|
The latest updates on your projects. Learn more about Unkey Deploy
|
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Refactors MCP OAuth authorization/consent to use Better Auth's native OAuth client and one required OAuth principal. Human review needed: the route now passes unfiltered token scopes into grant validation, and consent redirect handling is only partially visible.
Re-trigger cubic
0c868f5 to
16cd1a2
Compare
There was a problem hiding this comment.
0 issues found across 3 files (changes from recent commits).
Confidence score: 5/5
- Automated review surfaced no issues in the provided summaries.
- No files require special attention.
Shadow auto-approve: would require human review. Refactors MCP OAuth authorization/consent to use Better Auth's native OAuth client with a single OAuth principal. Human review is still needed because scope enforcement in getMcpAccessGrant and consent redirect handling are not fully verifiable from the diff.
Re-trigger cubic
16cd1a2 to
d02c43c
Compare
The scoped MCP connection flow carried the same authorization through several optional fields and used handwritten OAuth requests and response types. This cleanup uses Better Auth's native OAuth client and one required OAuth principal from the API through MCP and RPC. Consent and Connected apps now show the provider's actual
client_name.Validation: repository lint and all 37 typecheck/build tasks; 93 focused MCP tool and selected-site regressions; native TanStack mutation check confirming disconnect stays pending until revoked rows disappear; normal pre-push monorepo tests. The separately landed staging test-budget fix passed all 23 revenue integration cases and the full 31-task CI test workload with ClickHouse and website-reader integration enabled.
Slice: MCP OAuth authorization and consent cleanup. Based on current staging; #1032 is already merged. No unmerged dependencies. Checked open PRs; #692 touches auth initialization/storage, with no overlapping files or contracts in this slice.
Maintainer-requested change; implemented and reviewed with Codex assistance.