-
Notifications
You must be signed in to change notification settings - Fork 3.8k
feat(credential-groups): add personal MCP OAuth connections #7353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3508ab0
feat(credential-groups): add personal MCP OAuth connections
TheodoreSpeaks 1798bc5
fix(credential-groups): update managed MCP test fixtures
TheodoreSpeaks d1ac994
fix(credential-groups): harden managed MCP lifecycle
TheodoreSpeaks 6ae71ae
chore(db): squash managed MCP migration
TheodoreSpeaks 66c191f
feat(mcp): add credential-scoped agent tools
TheodoreSpeaks 2158fa2
feat(credential-groups): add managed MCP connector presets
TheodoreSpeaks 0caccb4
Merge remote-tracking branch 'origin/staging' into feat/api-key-cred-…
TheodoreSpeaks 5c10e8c
chore: refresh PR merge state
TheodoreSpeaks 13b9d07
Merge remote-tracking branch 'origin/staging' into feat/api-key-cred-…
TheodoreSpeaks 6953d4d
test(openapi): include advanced MCP agent tool
TheodoreSpeaks f1c9d34
test(mcp): align mocks with scoped execution
TheodoreSpeaks 9bd8d15
test(mcp): update managed connector fixtures
TheodoreSpeaks File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
apps/sim/app/api/credential-groups/enroll/[token]/mcp/[mcpServerId]/route.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| import { createLogger } from '@sim/logger' | ||
| import { getErrorMessage } from '@sim/utils/errors' | ||
| import type { NextRequest } from 'next/server' | ||
| import { NextResponse } from 'next/server' | ||
| import { startCredentialGroupMcpOAuthContract } from '@/lib/api/contracts/credential-groups' | ||
| import { parseRequest } from '@/lib/api/server' | ||
| import { withRouteHandler } from '@/lib/core/utils/with-route-handler' | ||
| import { authenticateCredentialGroupEnrollment } from '@/lib/credential-groups/application/enrollment-auth' | ||
| import { startPublicCredentialGroupMcpOAuth } from '@/lib/credential-groups/application/public-enrollment' | ||
| import { | ||
| enforceCredentialGroupEnrollmentOAuthRateLimit, | ||
| enforcePublicCredentialGroupOAuthStartIpRateLimit, | ||
| } from '@/lib/credential-groups/rate-limit' | ||
| import { makeTimedStep } from '@/lib/mcp/oauth' | ||
| import { createCredentialGroupEnrollmentRedirect } from '@/app/api/credential-groups/enrollment-redirect' | ||
|
|
||
| export const dynamic = 'force-dynamic' | ||
| export const runtime = 'nodejs' | ||
|
|
||
| const logger = createLogger('CredentialGroupMcpOAuthStartAPI') | ||
| const timedStep = makeTimedStep(logger) | ||
| const MANAGED_MCP_OAUTH_START_TIMEOUT_MS = 26_000 | ||
|
|
||
| export const GET = withRouteHandler( | ||
| async ( | ||
| request: NextRequest, | ||
| context: { params: Promise<{ token: string; mcpServerId: string }> } | ||
| ) => { | ||
| const limited = await enforcePublicCredentialGroupOAuthStartIpRateLimit(request) | ||
| const parsed = await parseRequest(startCredentialGroupMcpOAuthContract, request, context) | ||
| if (!parsed.success) return limited ?? parsed.response | ||
| const { token, mcpServerId } = parsed.data.params | ||
| if (limited) return createCredentialGroupEnrollmentRedirect(token, { oauth: 'rate_limited' }) | ||
|
|
||
| const principal = await authenticateCredentialGroupEnrollment(token) | ||
| if (!principal) { | ||
| return createCredentialGroupEnrollmentRedirect(token, { oauth: 'unavailable' }) | ||
| } | ||
| const enrollmentLimited = await enforceCredentialGroupEnrollmentOAuthRateLimit( | ||
| principal.enrollmentId | ||
| ) | ||
| if (enrollmentLimited) { | ||
| return createCredentialGroupEnrollmentRedirect(token, { oauth: 'rate_limited' }) | ||
| } | ||
|
|
||
| try { | ||
| const { authorizationUrl } = await timedStep( | ||
| 'startPublicCredentialGroupMcpOAuth', | ||
| MANAGED_MCP_OAUTH_START_TIMEOUT_MS, | ||
| () => | ||
| startPublicCredentialGroupMcpOAuth.execute({ | ||
| principal, | ||
| input: { invitationToken: token, mcpServerId }, | ||
| request, | ||
| }) | ||
| ) | ||
| const response = NextResponse.redirect(authorizationUrl) | ||
| response.headers.set('Cache-Control', 'no-store') | ||
| response.headers.set('Referrer-Policy', 'no-referrer') | ||
| return response | ||
| } catch (error) { | ||
| logger.error('Failed to start managed MCP OAuth authorization', { | ||
| error: getErrorMessage(error), | ||
| }) | ||
| return createCredentialGroupEnrollmentRedirect(token, { oauth: 'unavailable' }) | ||
| } | ||
| } | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import { listManagedMcpCatalogContract } from '@/lib/api/contracts/mcp' | ||
| import { | ||
| defineInternalJsonRoute, | ||
| internalOrchestrationErrorPolicy, | ||
| internalRateLimits, | ||
| internalSessionAuth, | ||
| } from '@/lib/api/server/routes' | ||
| import { listManagedMcpConnectionsUseCase } from '@/lib/mcp/application/managed-connections' | ||
| import { mcpServerOperations } from '@/lib/mcp/application/operations' | ||
|
|
||
| export const GET = defineInternalJsonRoute({ | ||
| contract: listManagedMcpCatalogContract, | ||
| auth: internalSessionAuth, | ||
| operation: mcpServerOperations.listManagedConnections, | ||
| rateLimit: internalRateLimits.none({ reason: 'Managed MCP metadata is workspace-scoped' }), | ||
| errorPolicy: internalOrchestrationErrorPolicy, | ||
| mapInput: ({ query }) => ({ workspaceId: query.workspaceId }), | ||
| useCase: listManagedMcpConnectionsUseCase, | ||
| present: (result) => result, | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.