Skip to content

Commit e2a7178

Browse files
author
Jesus Terrazas
committed
Add User-Agent header to list servers call and to server calls
1 parent d973242 commit e2a7178

6 files changed

Lines changed: 17 additions & 1 deletion

File tree

libraries/microsoft-agents-a365-tooling-extensions-agentframework/microsoft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ async def add_tool_servers_to_agent(
105105
f"{Constants.Headers.BEARER_PREFIX} {auth_token}"
106106
)
107107

108+
headers[Constants.Headers.USER_AGENT] = Utility.get_user_agent_header("AgentFramework")
109+
108110
server_name = getattr(config, "mcp_server_name", "Unknown")
109111

110112
# Create and configure MCPStreamableHTTPTool

libraries/microsoft-agents-a365-tooling-extensions-azureaifoundry/microsoft_agents_a365/tooling/extensions/azureaifoundry/services/mcp_tool_registration_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ async def _get_mcp_tool_definitions_and_resources(
189189
)
190190
mcp_tool.update_headers(Constants.Headers.AUTHORIZATION, header_value)
191191

192+
mcp_tool.update_headers(Constants.Headers.USER_AGENT, Utility.get_user_agent_header("AzureAIFoundry"))
193+
192194
# Add to collections
193195
tool_definitions.extend(mcp_tool.definitions)
194196
if mcp_tool.resources and mcp_tool.resources.mcp:

libraries/microsoft-agents-a365-tooling-extensions-openai/microsoft_agents_a365/tooling/extensions/openai/mcp_tool_registration_service.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
McpToolServerConfigurationService,
1818
)
1919

20+
from microsoft_agents_a365.tooling.utils.constants import Constants
2021
from microsoft_agents_a365.tooling.utils.utility import (
2122
get_mcp_platform_authentication_scope,
2223
)
@@ -132,7 +133,9 @@ async def add_tool_servers_to_agent(
132133
# Prepare headers with authorization
133134
headers = si.headers or {}
134135
if auth_token:
135-
headers["Authorization"] = f"Bearer {auth_token}"
136+
headers[Constants.Headers.AUTHORIZATION] = f"Bearer {auth_token}"
137+
138+
headers[Constants.Headers.USER_AGENT] = Utility.get_user_agent_header("OpenAI")
136139

137140
# Create MCPServerStreamableHttpParams with proper configuration
138141
params = MCPServerStreamableHttpParams(url=si.url, headers=headers)

libraries/microsoft-agents-a365-tooling-extensions-semantickernel/microsoft_agents_a365/tooling/extensions/semantickernel/services/mcp_tool_registration_service.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ async def add_tool_servers_to_agent(
132132
Constants.Headers.AUTHORIZATION: f"{Constants.Headers.BEARER_PREFIX} {auth_token}",
133133
}
134134

135+
headers[Constants.Headers.USER_AGENT] = Utility.get_user_agent_header("SemanticKernel")
136+
135137
plugin = MCPStreamableHttpPlugin(
136138
name=server.mcp_server_name,
137139
url=server.mcp_server_unique_name,

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
from ..utils import Constants
3333
from ..utils.utility import get_tooling_gateway_for_digital_worker, build_mcp_server_url
3434

35+
# Runtime Imports
36+
from microsoft_agents_a365.runtime.utility import Utility as RuntimeUtility
37+
3538

3639
# ==============================================================================
3740
# MAIN SERVICE CLASS
@@ -335,6 +338,7 @@ def _prepare_gateway_headers(self, auth_token: str) -> Dict[str, str]:
335338
"""
336339
return {
337340
"Authorization": f"{Constants.Headers.BEARER_PREFIX} {auth_token}",
341+
"User-Agent": RuntimeUtility.get_user_agent_header(),
338342
}
339343

340344
async def _parse_gateway_response(

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,6 @@ class Headers:
2020

2121
#: The prefix used for Bearer authentication tokens in HTTP headers.
2222
BEARER_PREFIX = "Bearer"
23+
24+
#: The header name for User-Agent information.
25+
USER_AGENT = "User-Agent"

0 commit comments

Comments
 (0)