diff --git a/packages/agents-a365-tooling-extensions-claude/src/McpToolRegistrationService.ts b/packages/agents-a365-tooling-extensions-claude/src/McpToolRegistrationService.ts index 4a22bf2d..21213e62 100644 --- a/packages/agents-a365-tooling-extensions-claude/src/McpToolRegistrationService.ts +++ b/packages/agents-a365-tooling-extensions-claude/src/McpToolRegistrationService.ts @@ -50,12 +50,8 @@ export class McpToolRegistrationService { const mcpServers: Record = {}; const tools: McpClientTool[] = []; - for (const server of servers) { - // Compose headers if values are available - const headers: Record = {}; - if (authToken) { - headers['Authorization'] = `Bearer ${authToken}`; - } + for (const server of servers) { + const headers: Record = Utility.GetToolRequestHeaders(authToken, turnContext); // Add each server to the config object mcpServers[server.mcpServerName] = { @@ -87,4 +83,4 @@ export class McpToolRegistrationService { agentOptions.mcpServers = Object.assign(agentOptions.mcpServers ?? {}, mcpServers); } -} \ No newline at end of file +} diff --git a/packages/agents-a365-tooling-extensions-langchain/src/McpToolRegistrationService.ts b/packages/agents-a365-tooling-extensions-langchain/src/McpToolRegistrationService.ts index 8ef519cc..75005c11 100644 --- a/packages/agents-a365-tooling-extensions-langchain/src/McpToolRegistrationService.ts +++ b/packages/agents-a365-tooling-extensions-langchain/src/McpToolRegistrationService.ts @@ -54,10 +54,7 @@ export class McpToolRegistrationService { for (const server of servers) { // Compose headers if values are available - const headers: Record = {}; - if (authToken) { - headers['Authorization'] = `Bearer ${authToken}`; - } + const headers: Record = Utility.GetToolRequestHeaders(authToken, turnContext); // Create Connection instance for LangChain agents mcpServers[server.mcpServerName] = { diff --git a/packages/agents-a365-tooling-extensions-openai/src/McpToolRegistrationService.ts b/packages/agents-a365-tooling-extensions-openai/src/McpToolRegistrationService.ts index 610f5517..4ae30146 100644 --- a/packages/agents-a365-tooling-extensions-openai/src/McpToolRegistrationService.ts +++ b/packages/agents-a365-tooling-extensions-openai/src/McpToolRegistrationService.ts @@ -53,10 +53,7 @@ export class McpToolRegistrationService { for (const server of servers) { // Compose headers if values are available - const headers: Record = {}; - if (authToken) { - headers['Authorization'] = `Bearer ${authToken}`; - } + const headers: Record = Utility.GetToolRequestHeaders(authToken, turnContext); // Create MCPServerStreamableHttp instance for OpenAI agents const mcpServer = new MCPServerStreamableHttp({ @@ -75,4 +72,4 @@ export class McpToolRegistrationService { return agent; } -} \ No newline at end of file +} diff --git a/packages/agents-a365-tooling/src/Utility.ts b/packages/agents-a365-tooling/src/Utility.ts index ab9d631b..ed225f87 100644 --- a/packages/agents-a365-tooling/src/Utility.ts +++ b/packages/agents-a365-tooling/src/Utility.ts @@ -1,10 +1,47 @@ // Copyright (c) Microsoft Corporation. // Licensed under the MIT License. +import { TurnContext } from '@microsoft/agents-hosting'; + // Constant for MCP Platform base URL in production const MCP_PLATFORM_PROD_BASE_URL = 'https://agent365.svc.cloud.microsoft'; export class Utility { + public static readonly HEADER_CHANNEL_ID = 'x-ms-channel-id'; + public static readonly HEADER_SUBCHANNEL_ID = 'x-ms-subchannel-id'; + + /** + * Compose standard headers for MCP tooling requests. + * Includes Authorization bearer token when provided, and optionally includes channel and subchannel identifiers for routing. + * + * @param authToken Bearer token for Authorization header. + * @param turnContext Optional TurnContext object from which channel and subchannel IDs are extracted. + * @returns A headers record suitable for HTTP requests. + */ + public static GetToolRequestHeaders( + authToken?: string, + turnContext?: TurnContext + ): Record { + const headers: Record = {}; + + if (authToken) { + headers['Authorization'] = `Bearer ${authToken}`; + } + + const channelId = turnContext?.activity?.channelId as string | undefined; + const subChannelId = turnContext?.activity?.channelIdSubChannel as string | undefined; + + if (channelId) { + headers[Utility.HEADER_CHANNEL_ID] = channelId; + } + + if (subChannelId) { + headers[Utility.HEADER_SUBCHANNEL_ID] = subChannelId; + } + + return headers; + } + /** * Validates a JWT authentication token. * Checks that the token is a valid JWT and is not expired. @@ -132,4 +169,4 @@ export class Utility { return MCP_PLATFORM_PROD_BASE_URL; } -} \ No newline at end of file +}