Skip to content

feat: Add x-ms-agentid header for MCP platform calls#162

Merged
pontemonti merged 2 commits intomainfrom
users/johanb/x-ms-agentid-header
Feb 5, 2026
Merged

feat: Add x-ms-agentid header for MCP platform calls#162
pontemonti merged 2 commits intomainfrom
users/johanb/x-ms-agentid-header

Conversation

@pontemonti
Copy link
Contributor

Summary

Port of Node.js SDK PR #183 - Add an \x-ms-agentid\ header to all outbound HTTP requests from the tooling package to the MCP platform for agent identification.

Problem

The MCP platform needs to identify which agent is making tooling requests for:

  • Logging and diagnostics
  • Usage analytics

Solution

Add \x-ms-agentid\ header with value determined by priority:

  1. TurnContext agenticAppBlueprintId (highest priority)
  2. Token claims (\xms_par_app_azp\ > \�ppid\ > \�zp)
  3. Application name from env var or pyproject.toml (lowest priority)

If no identifier is available, the header is omitted.

Changes

Runtime package (\microsoft-agents-a365-runtime)

  • Add \get_agent_id_from_token()\ method for extracting agent ID from JWT token
  • Add \get_application_name()\ method with thread-safe caching

Tooling package (\microsoft-agents-a365-tooling)

  • Add header constants: \AGENT_ID, \CHANNEL_ID, \SUBCHANNEL_ID\
  • Add _resolve_agent_id_for_header()\ method to resolve best agent identifier
  • Update _prepare_gateway_headers()\ to include \x-ms-agentid\

Documentation

  • Add PRD document: \docs/prd-x-ms-agentid-header.md\

Testing

  • Added 64 new unit tests covering all edge cases
  • All 514 existing tests continue to pass
  • 3 code review iterations completed

Breaking Changes

None - fully backward compatible

Add an x-ms-agentid header to all outbound HTTP requests from the tooling
package to the MCP platform. This header identifies the calling agent
using the best available identifier.

Priority for header value:
1. TurnContext agenticAppBlueprintId (highest priority)
2. Token claims (xms_par_app_azp > appid > azp)
3. Application name from env var or pyproject.toml (lowest priority)

Runtime package changes:
- Add get_agent_id_from_token() method for extracting agent ID
- Add get_application_name() method with thread-safe caching

Tooling package changes:
- Add AGENT_ID, CHANNEL_ID, SUBCHANNEL_ID header constants
- Add _resolve_agent_id_for_header() method
- Update _prepare_gateway_headers() to include x-ms-agentid

Port of Node.js SDK PR #183
Copilot AI review requested due to automatic review settings February 5, 2026 18:41
@pontemonti pontemonti requested review from a team as code owners February 5, 2026 18:41
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 an x-ms-agentid header to all outbound HTTP requests from the tooling package to the MCP platform for agent identification. The header value is determined through a priority-based fallback mechanism: TurnContext agenticAppBlueprintId (highest) → token claims (xms_par_app_azp > appid > azp) → application name from environment/pyproject.toml (lowest). If no identifier is available, the header is omitted.

Changes:

  • Added new utility methods for extracting agent ID from JWT tokens and reading application name from environment/pyproject.toml with thread-safe caching
  • Updated MCP tooling service to include x-ms-agentid header in gateway requests with priority-based fallback logic
  • Added comprehensive test coverage (64 new tests) for all edge cases and priority levels

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py Added get_agent_id_from_token() for JWT claim extraction and get_application_name() with thread-safe caching
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/utils/constants.py Added header name constants for AGENT_ID, CHANNEL_ID, and SUBCHANNEL_ID
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py Updated _prepare_gateway_headers() to include x-ms-agentid and added _resolve_agent_id_for_header() method
tests/runtime/test_utility.py Added 42 unit tests for new utility methods covering all priority levels and edge cases
tests/tooling/test_mcp_server_configuration.py Added 22 unit tests for header preparation and agent ID resolution
docs/prd-x-ms-agentid-header.md Added comprehensive PRD documentation explaining design decisions and implementation details
Comments suppressed due to low confidence (1)

libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py:1

  • The assumption that Path.cwd() returns the application root directory may not hold in all deployment scenarios (e.g., when the application is launched from a different directory, or in containerized environments). The documentation should mention this limitation and emphasize that users should rely on the AGENT365_APPLICATION_NAME environment variable for reliable behavior in production.
# Copyright (c) Microsoft Corporation.

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Copilot AI review requested due to automatic review settings February 5, 2026 18:46
@pontemonti pontemonti enabled auto-merge (squash) February 5, 2026 18:46
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

Copilot reviewed 6 out of 6 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (5)

libraries/microsoft-agents-a365-runtime/microsoft_agents_a365/runtime/utility.py:2

  • Missing Microsoft copyright header. All Python files should include the standard copyright header at the top of the file.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/utils/constants.py:2

  • Missing Microsoft copyright header. All Python files should include the standard copyright header at the top of the file.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py:2

  • Missing Microsoft copyright header. All Python files should include the standard copyright header at the top of the file.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

tests/tooling/test_mcp_server_configuration.py:2

  • Missing Microsoft copyright header. All Python files should include the standard copyright header at the top of the file.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

tests/runtime/test_utility.py:2

  • Missing Microsoft copyright header. All Python files should include the standard copyright header at the top of the file.
# Copyright (c) Microsoft Corporation.
# Licensed under the MIT License.

@pontemonti pontemonti merged commit 367525d into main Feb 5, 2026
8 checks passed
@pontemonti pontemonti deleted the users/johanb/x-ms-agentid-header branch February 5, 2026 19:05
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

Comments