MCPcopy Create free account
hub / github.com/arctic-cli/interface / finishAuth

Function finishAuth

packages/arctic/src/mcp/index.ts:517–552  ·  view source on GitHub ↗
(mcpName: string, authorizationCode: string)

Source from the content-addressed store, hash-verified

515 * Complete OAuth authentication with the authorization code.
516 */
517 export async function finishAuth(mcpName: string, authorizationCode: string): Promise<Status> {
518 const transport = pendingOAuthTransports.get(mcpName)
519
520 if (!transport) {
521 throw new Error(`No pending OAuth flow for MCP server: ${mcpName}`)
522 }
523
524 try {
525 // Call finishAuth on the transport
526 await transport.finishAuth(authorizationCode)
527
528 // Clear the code verifier after successful auth
529 await McpAuth.clearCodeVerifier(mcpName)
530
531 // Now try to reconnect
532 const cfg = await Config.get()
533 const mcpConfig = cfg.mcp?.[mcpName]
534
535 if (!mcpConfig) {
536 throw new Error(`MCP server not found: ${mcpName}`)
537 }
538
539 // Re-add the MCP server to establish connection
540 pendingOAuthTransports.delete(mcpName)
541 const result = await add(mcpName, mcpConfig)
542
543 const statusRecord = result.status as Record<string, Status>
544 return statusRecord[mcpName] ?? { status: "failed", error: "Unknown error after auth" }
545 } catch (error) {
546 log.error("failed to finish oauth", { mcpName, error })
547 return {
548 status: "failed",
549 error: error instanceof Error ? error.message : String(error),
550 }
551 }
552 }
553
554 /**
555 * Remove OAuth credentials for an MCP server.

Callers 1

authenticateFunction · 0.85

Calls 3

addFunction · 0.85
getMethod · 0.45
deleteMethod · 0.45

Tested by

no test coverage detected