Skip to content

Conversation

@pontemonti
Copy link
Contributor

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:

  • Logging and diagnostics
  • Usage analytics

Solution

Add the x-ms-agentid header to outbound requests with the following 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

Runtime Package

  • Add GetAgentIdFromToken() - extracts agent ID from JWT with priority fallback
  • Add GetApplicationName() - returns entry assembly name

Tooling Package

  • Add AgentIdHeader constant (x-ms-agentid)
  • Update HttpContextHeadersHandler to add the header when authToken is available
  • Pass authToken to HttpContextHeadersHandler constructor
  • Add InternalsVisibleTo for test access

Tests

  • Add 11 unit tests for GetAgentIdFromToken() covering all priority paths
  • Add test for GetApplicationName()

Documentation

  • Add PRD document adapted for .NET

Testing

  • All 548 existing tests pass
  • Build succeeds with no errors or warnings
  • 3 code review iterations completed

Breaking Changes

None - this is a backward-compatible addition.

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
Copy link
Contributor

Copilot AI left a 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

@pontemonti pontemonti merged commit e264964 into main Feb 5, 2026
11 checks passed
@pontemonti pontemonti deleted the users/johanb/AgentIdHeader branch February 5, 2026 18:20
pontemonti pushed a commit that referenced this pull request Feb 5, 2026
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).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants