From 97a1b5be06730b8343f9f8b361fef6bbcd2ebd58 Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Wed, 4 Feb 2026 13:39:09 -0800 Subject: [PATCH 1/2] update required scope for copilot studio --- .github/workflows/e2e-nodejs-copilot-studio.yml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/.github/workflows/e2e-nodejs-copilot-studio.yml b/.github/workflows/e2e-nodejs-copilot-studio.yml index 5c2fce2f..b851a5f3 100644 --- a/.github/workflows/e2e-nodejs-copilot-studio.yml +++ b/.github/workflows/e2e-nodejs-copilot-studio.yml @@ -31,7 +31,7 @@ jobs: nodejs-copilot-studio: name: Node.js Copilot Studio Agent runs-on: windows-latest - + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -74,7 +74,8 @@ jobs: -ClientId "${{ secrets.MCP_CLIENT_ID }}" ` -TenantId "${{ secrets.MCP_TENANT_ID }}" ` -Username "${{ secrets.MCP_TEST_USERNAME }}" ` - -Password "${{ secrets.MCP_TEST_PASSWORD }}" + -Password "${{ secrets.MCP_TEST_PASSWORD }}" ` + -Scope "https://api.powerplatform.com/CopilotStudio.Copilots.Invoke" echo "BEARER_TOKEN=$token" >> $env:GITHUB_OUTPUT echo "::add-mask::$token" From 33e68fbb41ab034b6627cf52be572c4a8a6ffe49 Mon Sep 17 00:00:00 2001 From: Jesus Terrazas Date: Wed, 4 Feb 2026 14:00:09 -0800 Subject: [PATCH 2/2] Add bearer token support for copilot studio connection --- .../copilot-studio/sample-agent/src/client.ts | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/nodejs/copilot-studio/sample-agent/src/client.ts b/nodejs/copilot-studio/sample-agent/src/client.ts index 3b1942a7..b22d53e3 100644 --- a/nodejs/copilot-studio/sample-agent/src/client.ts +++ b/nodejs/copilot-studio/sample-agent/src/client.ts @@ -186,17 +186,22 @@ export async function getClient( // Load Copilot Studio connection settings from environment const settings = loadCopilotStudioConnectionSettingsFromEnv(); - // Acquire token for Copilot Studio API - const tokenResult = await authorization.exchangeToken(turnContext, authHandlerName, { - scopes: ['https://api.powerplatform.com/.default'] - }); + let authtoken = process.env.BEARER_TOKEN; + if (!authtoken) { + // Acquire token for Copilot Studio API + const tokenResult = await authorization.exchangeToken(turnContext, authHandlerName, { + scopes: ['https://api.powerplatform.com/.default'] + }); + + if (!tokenResult?.token) { + throw new Error('Failed to acquire token for Copilot Studio. User may need to sign in.'); + } - if (!tokenResult?.token) { - throw new Error('Failed to acquire token for Copilot Studio. User may need to sign in.'); + authtoken = tokenResult.token; } // Create the Copilot Studio client with the token - const copilotClient = new CopilotStudioClient(settings, tokenResult.token); + const copilotClient = new CopilotStudioClient(settings, authtoken); return new McsClient(copilotClient); }