* Authenticate MCP source via OAuth
(
source: LoadedSource,
callbacks: OAuthCallbacks
)
| 349 | * Authenticate MCP source via OAuth |
| 350 | */ |
| 351 | private async authenticateMcp( |
| 352 | source: LoadedSource, |
| 353 | callbacks: OAuthCallbacks |
| 354 | ): Promise<AuthResult> { |
| 355 | if (!source.config.mcp?.url) { |
| 356 | return { success: false, error: 'MCP URL not configured' }; |
| 357 | } |
| 358 | |
| 359 | try { |
| 360 | const oauth = new CraftOAuth( |
| 361 | { mcpBaseUrl: getMcpBaseUrl(source.config.mcp.url) }, |
| 362 | callbacks |
| 363 | ); |
| 364 | |
| 365 | const { tokens, clientId } = await oauth.authenticate(); |
| 366 | |
| 367 | // Save the credentials |
| 368 | await this.save(source, { |
| 369 | value: tokens.accessToken, |
| 370 | refreshToken: tokens.refreshToken, |
| 371 | expiresAt: tokens.expiresAt, |
| 372 | clientId, |
| 373 | tokenType: tokens.tokenType, |
| 374 | }); |
| 375 | |
| 376 | // Mark source as authenticated in config.json |
| 377 | markSourceAuthenticated(source.workspaceRootPath, source.config.slug); |
| 378 | |
| 379 | return { success: true }; |
| 380 | } catch (error) { |
| 381 | const message = error instanceof Error ? error.message : String(error); |
| 382 | callbacks.onError(message); |
| 383 | return { success: false, error: message }; |
| 384 | } |
| 385 | } |
| 386 | |
| 387 | /** |
| 388 | * Authenticate Google API source via Google OAuth |
no test coverage detected