Skip to content

Commit d5a2c42

Browse files
committed
Warn when V2 server falls back to shared BEARER_TOKEN in dev mode
In dev, createDevTokenAcquirer previously ignored the resolved scope and silently fell back to BEARER_TOKEN for all servers. V2 servers (distinct audience) would receive a token scoped to the shared ATG audience and get a 401 from the MCP server with no indication of why. Now emits a console.warn identifying the server, the required scope, and the exact env var to set (BEARER_TOKEN_<SERVERNAME_UPPER>) so the misconfiguration is visible before hitting the 401.
1 parent 91ce104 commit d5a2c42

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

packages/agents-a365-tooling/src/McpToolServerConfigurationService.ts

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,23 @@ export class McpToolServerConfigurationService {
188188
* 1. BEARER_TOKEN_<MCPSERVERNAME_UPPER> — per-server token (effective for V2 unique audiences)
189189
* 2. BEARER_TOKEN — shared fallback (V1 servers share one token)
190190
* Returns null when neither variable is set; no Authorization header is attached.
191+
* Emits a warning when a V2 server (distinct audience) falls back to the shared BEARER_TOKEN,
192+
* because that token is scoped to the shared ATG audience and will cause a 401 at the server.
191193
*/
192194
private createDevTokenAcquirer(): TokenAcquirer {
193-
return (server, _scope) => {
194-
const token = this.configProvider.getConfiguration().getBearerTokenForServer(server.mcpServerName ?? '');
195+
const sharedScope = this.configProvider.getConfiguration().mcpPlatformAuthenticationScope;
196+
return (server, scope) => {
197+
const serverName = server.mcpServerName ?? '';
198+
const perServerEnvKey = `BEARER_TOKEN_${serverName.toUpperCase()}`;
199+
const hasPerServerToken = !!process.env[perServerEnvKey];
200+
const token = this.configProvider.getConfiguration().getBearerTokenForServer(serverName);
201+
if (token && !hasPerServerToken && scope !== sharedScope) {
202+
this.logger.warn(
203+
`Dev: MCP server '${serverName}' requires scope '${scope}' but only BEARER_TOKEN is set. ` +
204+
`The shared token is scoped to a different audience and will likely cause a 401. ` +
205+
`Set ${perServerEnvKey} to a token acquired for the correct audience.`
206+
);
207+
}
195208
return Promise.resolve(token ?? null);
196209
};
197210
}

0 commit comments

Comments
 (0)