1354
1355
private async _handleMcpAuthRequest(request: McpAuthRequest): Promise<McpAuthResult | null | undefined> {
1356
>
const githubToken = request.reason === 'initial' && this._scopesFromChallenge(request.wwwAuthenticateParams?.scope).length === 0
copilotAgentSession.ts
1357
? await this._initialGitHubMcpToken(request)
1358
: undefined;
1360
this._logService.info(`[Copilot:${this.sessionId}] Reusing the existing GitHub token for initial GitHub MCP authentication`);
1361
return { kind: 'token', accessToken: githubToken };
1362
}
1363
const resource = this._protectedResourceFromMcpAuthRequest(request);
1364
>
const requiredScopes = this._scopesFromChallenge(request.wwwAuthenticateParams?.scope);
copilotAgentSession.ts
1365
>
const oauthClient: McpAuthRequirement['oauthClient'] = request.staticClientConfig?.publicClient
1366
? { clientId: request.staticClientConfig.clientId }
1367
: request.staticClientConfig?.clientSecret
1368
? { clientId: request.staticClientConfig.clientId, clientSecret: request.staticClientConfig.clientSecret }
1369
: undefined;
1371
>
reason: this._mcpAuthRequiredReason(request.reason),
1372
>
...(oauthClient ? { oauthClient } : {}),
1373
>
resource,
1374
>
requiredScopes: requiredScopes.length ? [...requiredScopes] : undefined,
1375
>
description: request.wwwAuthenticateParams?.error,
1376
>
};
1377
>
const toolCalls = this._activeMcpToolCalls(request.serverName);
1378
>
const deferred = new DeferredPromise<McpAuthResult | null | undefined>();
1379
>
this._pendingMcpAuthRequests.set(request.requestId, {
1380
>
serverName: request.serverName,
1381
>
resource,
1382
>
requiredScopes,
1383
>
toolCalls,
1384
>
deferred,
1385
>
});
1386
>
this._mcpCustomizations.applyOne({
1387
>
name: request.serverName,
1388
>
state: {
1389
>
kind: McpServerStatus.AuthRequired,
1390
>
...auth,
1391
>
},
1392
>
});
1393
>
for (const toolCall of toolCalls) {
1394
this._emitAction({
1395
type: ActionType.ChatToolCallAuthRequired,