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

Function authenticate

packages/arctic/src/mcp/index.ts:489–512  ·  view source on GitHub ↗
(mcpName: string)

Source from the content-addressed store, hash-verified

487 * Opens the browser and waits for callback.
488 */
489 export async function authenticate(mcpName: string): Promise<Status> {
490 const { authorizationUrl } = await startAuth(mcpName)
491
492 if (!authorizationUrl) {
493 // Already authenticated
494 const s = await state()
495 return s.status[mcpName] ?? { status: "connected" }
496 }
497
498 // Extract state from authorization URL to use as callback key
499 // If no state parameter, use mcpName as fallback
500 const authUrl = new URL(authorizationUrl)
501 const oauthState = authUrl.searchParams.get("state") ?? mcpName
502
503 // Open browser
504 log.info("opening browser for oauth", { mcpName, url: authorizationUrl, state: oauthState })
505 await open(authorizationUrl)
506
507 // Wait for callback using the OAuth state parameter (or mcpName as fallback)
508 const code = await McpOAuthCallback.waitForCallback(oauthState)
509
510 // Finish auth
511 return finishAuth(mcpName, code)
512 }
513
514 /**
515 * Complete OAuth authentication with the authorization code.

Callers

nothing calls this directly

Calls 5

startAuthFunction · 0.85
stateFunction · 0.85
finishAuthFunction · 0.85
openFunction · 0.70
getMethod · 0.45

Tested by

no test coverage detected