-
Notifications
You must be signed in to change notification settings - Fork 8
feat: Add x-ms-agentid header for MCP platform calls #196
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Port from Node.js SDK PR #183 - adds x-ms-agentid header to all outbound HTTP requests to the MCP platform for agent identification. Header priority: 1. Agent Blueprint ID from TurnContext (agenticAppBlueprintId) 2. Agent Blueprint ID from token (xms_par_app_azp claim) 3. Entra Application ID from token (appid or azp claim) 4. Application name from entry assembly Changes: - Add GetAgentIdFromToken() and GetApplicationName() to Runtime Utility - Add AgentIdHeader constant to Tooling Constants - Update HttpContextHeadersHandler to add x-ms-agentid header - Pass authToken to HttpContextHeadersHandler for header resolution - Add InternalsVisibleTo for test access - Add comprehensive unit tests for new methods - Add PRD documentation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
This PR adds the x-ms-agentid header to all outbound HTTP requests to the MCP platform for agent identification, porting functionality from the Node.js SDK (PR #183). The header enables the MCP platform to identify calling agents for logging, diagnostics, and usage analytics.
Changes:
- Added utility methods in Runtime package to extract agent identifiers from JWT tokens and application assembly
- Updated HttpContextHeadersHandler to inject the x-ms-agentid header with priority-based fallback logic
- Added comprehensive unit tests for token parsing with 11 test cases covering all priority paths
- Created PRD documentation describing the technical design and implementation strategy
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 4 comments.
Show a summary per file
| File | Description |
|---|---|
| src/Tooling/Core/docs/prd-x-ms-agentid-header.md | PRD documentation detailing the technical design, priority logic, and implementation approach for the x-ms-agentid header feature |
| src/Tooling/Core/Utils/Constants.cs | Added AgentIdHeader constant for the x-ms-agentid header name |
| src/Tooling/Core/Services/McpToolServerConfigurationService.cs | Updated to pass authToken to HttpContextHeadersHandler constructor |
| src/Tooling/Core/Microsoft.Agents.A365.Tooling.csproj | Added InternalsVisibleTo attribute for test project access |
| src/Tooling/Core/Handlers/HttpContextHeadersHandler.cs | Implemented header injection logic with priority fallback: TurnContext blueprint ID > token claims > application name |
| src/Tests/Runtime.Tests/UtilityTests.cs | Added 11 unit tests for GetAgentIdFromToken() covering all claim priority paths and edge cases, plus test for GetApplicationName() |
| src/Runtime/Core/Utility.cs | Added GetAgentIdFromToken() method to extract agent ID from JWT with claim priority, and GetApplicationName() to get entry assembly name |
Add comprehensive guide for porting features from Node.js SDK to .NET SDK, including workflow steps, language translation patterns, and checklist template. Based on the experience porting x-ms-agentid header (PR #196).
Overview
Port of Node.js SDK PR #183 - adds x-ms-agentid header to all outbound HTTP requests to the MCP platform for agent identification.
Related PR: microsoft/Agent365-nodejs#183
Problem Statement
The MCP platform needs to identify which agent is making tooling requests for:
Solution
Add the x-ms-agentid header to outbound requests with the following priority:
agenticAppBlueprintId)xms_par_app_azpclaim)appidorazpclaim)Changes
Runtime Package
GetAgentIdFromToken()- extracts agent ID from JWT with priority fallbackGetApplicationName()- returns entry assembly nameTooling Package
AgentIdHeaderconstant (x-ms-agentid)HttpContextHeadersHandlerto add the header when authToken is availableHttpContextHeadersHandlerconstructorInternalsVisibleTofor test accessTests
GetAgentIdFromToken()covering all priority pathsGetApplicationName()Documentation
Testing
Breaking Changes
None - this is a backward-compatible addition.