Skip to content

Commit 8f8c779

Browse files
waleedlatif1claude
andcommitted
fix(mcp): pass serverId to early OAuth callback error closes
Look up the OAuth row by state once at the top of the callback so the serverId can be threaded into provider_error, missing_params, and unauthenticated closes. Without it, the popup's postMessage omits serverId and the parent UI can't clear the connecting state until the 500ms popup-closed poll fires. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
1 parent 755ea3b commit 8f8c779

1 file changed

Lines changed: 22 additions & 3 deletions

File tree

  • apps/sim/app/api/mcp/oauth/callback

apps/sim/app/api/mcp/oauth/callback/route.ts

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,19 +60,38 @@ export const GET = withRouteHandler(async (request: NextRequest) => {
6060
const code = url.searchParams.get('code')
6161
const errorParam = url.searchParams.get('error')
6262

63+
const stateRowServerId = state
64+
? (await loadOauthRowByState(state).catch(() => null))?.mcpServerId
65+
: undefined
66+
6367
if (errorParam) {
6468
logger.warn(`MCP OAuth callback received error: ${errorParam}`)
65-
return htmlClose(`Authorization failed: ${errorParam}`, false, 'provider_error')
69+
return htmlClose(
70+
`Authorization failed: ${errorParam}`,
71+
false,
72+
'provider_error',
73+
stateRowServerId
74+
)
6675
}
6776
if (!state || !code) {
68-
return htmlClose('Missing state or code in callback URL.', false, 'missing_params')
77+
return htmlClose(
78+
'Missing state or code in callback URL.',
79+
false,
80+
'missing_params',
81+
stateRowServerId
82+
)
6983
}
7084

7185
let serverId: string | undefined
7286
try {
7387
const session = await getSession()
7488
if (!session?.user?.id) {
75-
return htmlClose('You must be signed in to complete authorization.', false, 'unauthenticated')
89+
return htmlClose(
90+
'You must be signed in to complete authorization.',
91+
false,
92+
'unauthenticated',
93+
stateRowServerId
94+
)
7695
}
7796

7897
const row = await loadOauthRowByState(state)

0 commit comments

Comments
 (0)