Skip to content

Commit 294d69a

Browse files
committed
Revert "Remove environment id usage"
This reverts commit c6473e7.
1 parent 9c66800 commit 294d69a

10 files changed

Lines changed: 72 additions & 30 deletions

File tree

‎libraries/microsoft-agents-a365-tooling-extensions-azureaifoundry/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ registration_service = McpToolRegistrationService()
6464
await registration_service.add_tool_servers_to_agent(
6565
project_client=project_client,
6666
agent_id="your-agent-id",
67+
environment_id="prod",
6768
auth_token="your-auth-token"
6869
)
6970
```

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class McpToolRegistrationService:
4444
4545
Example:
4646
>>> service = McpToolRegistrationService()
47-
>>> service.add_tool_servers_to_agent(project_client, agent_id, token)
47+
>>> service.add_tool_servers_to_agent(project_client, agent_id, env_id, token)
4848
"""
4949

5050
def __init__(
@@ -73,6 +73,7 @@ async def add_tool_servers_to_agent(
7373
self,
7474
project_client: "AIProjectClient",
7575
agent_user_id: str,
76+
environment_id: str,
7677
auth: Authorization,
7778
context: TurnContext,
7879
auth_token: Optional[str] = None,
@@ -83,6 +84,7 @@ async def add_tool_servers_to_agent(
8384
Args:
8485
project_client: The Azure Foundry AIProjectClient instance.
8586
agent_user_id: Agent User ID for the agent.
87+
environment_id: Environment ID for the environment.
8688
auth_token: Authentication token to access the MCP servers.
8789
8890
Raises:
@@ -100,7 +102,7 @@ async def add_tool_servers_to_agent(
100102
try:
101103
# Get the tool definitions and resources using the async implementation
102104
tool_definitions, tool_resources = await self._get_mcp_tool_definitions_and_resources(
103-
agent_user_id, auth_token or ""
105+
agent_user_id, environment_id, auth_token or ""
104106
)
105107

106108
# Update the agent with the tools
@@ -119,7 +121,7 @@ async def add_tool_servers_to_agent(
119121
raise
120122

121123
async def _get_mcp_tool_definitions_and_resources(
122-
self, agent_user_id: str, auth_token: str
124+
self, agent_user_id: str, environment_id: str, auth_token: str
123125
) -> Tuple[List[McpTool], Optional[ToolResources]]:
124126
"""
125127
Internal method to get MCP tool definitions and resources.
@@ -128,6 +130,7 @@ async def _get_mcp_tool_definitions_and_resources(
128130
129131
Args:
130132
agent_user_id: Agent User ID for the agent.
133+
environment_id: Environment ID for the environment.
131134
auth_token: Authentication token to access the MCP servers.
132135
133136
Returns:
@@ -140,7 +143,7 @@ async def _get_mcp_tool_definitions_and_resources(
140143
# Get MCP server configurations
141144
try:
142145
servers = await self._mcp_server_configuration_service.list_tool_servers(
143-
agent_user_id, auth_token
146+
agent_user_id, environment_id, auth_token
144147
)
145148
except Exception as ex:
146149
self._logger.error(
@@ -150,7 +153,7 @@ async def _get_mcp_tool_definitions_and_resources(
150153

151154
if len(servers) == 0:
152155
self._logger.info(
153-
f"No MCP servers configured for AgentUserId={agent_user_id}"
156+
f"No MCP servers configured for AgentUserId={agent_user_id}, EnvironmentId={environment_id}"
154157
)
155158
return ([], None)
156159

@@ -190,6 +193,9 @@ async def _get_mcp_tool_definitions_and_resources(
190193
)
191194
mcp_tool.update_headers(Constants.Headers.AUTHORIZATION, header_value)
192195

196+
# Set environment ID header
197+
mcp_tool.update_headers(Constants.Headers.ENVIRONMENT_ID, environment_id)
198+
193199
# Add to collections
194200
tool_definitions.extend(mcp_tool.definitions)
195201
if mcp_tool.resources and mcp_tool.resources.mcp:

‎libraries/microsoft-agents-a365-tooling-extensions-openai/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ registration_service = McpToolRegistrationService()
5454
await registration_service.add_tool_servers_to_agent(
5555
agent=your_openai_agent,
5656
agent_user_id="user-123",
57+
environment_id="prod",
5758
auth=authorization_context,
5859
context=turn_context,
5960
auth_token="your-auth-token"

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ async def add_tool_servers_to_agent(
3939
self,
4040
agent: Agent,
4141
agent_user_id: str,
42+
environment_id: str,
4243
auth: Authorization,
4344
context: TurnContext,
4445
auth_token: Optional[str] = None,
@@ -53,6 +54,7 @@ async def add_tool_servers_to_agent(
5354
Args:
5455
agent: The existing agent to add servers to
5556
agent_user_id: Agent User ID for the agent
57+
environment_id: Environment ID for the environment
5658
auth_token: Authentication token to access the MCP servers
5759
5860
Returns:
@@ -68,7 +70,7 @@ async def add_tool_servers_to_agent(
6870
# mcp_server_configs = []
6971
# TODO: radevika: Update once the common project is merged.
7072
mcp_server_configs = await self.config_service.list_tool_servers(
71-
agent_user_id=agent_user_id, auth_token=auth_token
73+
agent_user_id=agent_user_id, environment_id=environment_id, auth_token=auth_token
7274
)
7375

7476
# Convert MCP server configs to MCPServerInfo objects
@@ -112,6 +114,8 @@ async def add_tool_servers_to_agent(
112114
headers = si.headers or {}
113115
if auth_token:
114116
headers["Authorization"] = f"Bearer {auth_token}"
117+
if environment_id:
118+
headers["x-ms-environment-id"] = environment_id
115119

116120
# Create MCPServerStreamableHttpParams with proper configuration
117121
params = MCPServerStreamableHttpParams(url=si.url, headers=headers)

‎libraries/microsoft-agents-a365-tooling-extensions-semantickernel/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ registration_service = McpToolRegistrationService()
5656
await registration_service.add_tool_servers_to_kernel(
5757
kernel=kernel,
5858
agent_user_id="user-123",
59+
environment_id="prod",
5960
auth_token="your-auth-token"
6061
)
6162
```

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ async def add_tool_servers_to_agent(
8484
self,
8585
kernel: sk.Kernel,
8686
agent_user_id: str,
87+
environment_id: str,
8788
auth: Authorization,
8889
context: TurnContext,
8990
auth_token: Optional[str] = None,
@@ -94,6 +95,7 @@ async def add_tool_servers_to_agent(
9495
Args:
9596
kernel: The Semantic Kernel instance to which the tools will be added.
9697
agent_user_id: Agent User ID for the agent.
98+
environment_id: Environment ID for the environment.
9799
auth_token: Authentication token to access the MCP servers.
98100
99101
Raises:
@@ -106,7 +108,7 @@ async def add_tool_servers_to_agent(
106108
authToken = await auth.exchange_token(context, scopes, "AGENTIC")
107109
auth_token = authToken.token
108110

109-
self._validate_inputs(kernel, agent_user_id, auth_token)
111+
self._validate_inputs(kernel, agent_user_id, environment_id, auth_token)
110112

111113
if self._mcp_server_configuration_service is None:
112114
raise ValueError(
@@ -115,7 +117,7 @@ async def add_tool_servers_to_agent(
115117

116118
# Get and process servers
117119
servers = await self._mcp_server_configuration_service.list_tool_servers(
118-
agent_user_id, auth_token
120+
agent_user_id, environment_id, auth_token
119121
)
120122
self._logger.info(f"🔧 Adding MCP tools from {len(servers)} servers")
121123

@@ -132,12 +134,16 @@ async def add_tool_servers_to_agent(
132134
headers = {}
133135

134136
if tools_mode == "MockMCPServer":
135-
# Use mock authorization header if provided
137+
# Mock server does not require bearer auth, but still forward environment id if available.
138+
if environment_id:
139+
headers[Constants.Headers.ENVIRONMENT_ID] = environment_id
140+
136141
if mock_auth_header := os.getenv("MOCK_MCP_AUTHORIZATION"):
137142
headers[Constants.Headers.AUTHORIZATION] = mock_auth_header
138143
else:
139144
headers = {
140145
Constants.Headers.AUTHORIZATION: f"{Constants.Headers.BEARER_PREFIX} {auth_token}",
146+
Constants.Headers.ENVIRONMENT_ID: environment_id,
141147
}
142148

143149
plugin = MCPStreamableHttpPlugin(
@@ -172,13 +178,15 @@ async def add_tool_servers_to_agent(
172178
# ============================================================================
173179

174180
def _validate_inputs(
175-
self, kernel: Any, agent_user_id: str, auth_token: str
181+
self, kernel: Any, agent_user_id: str, environment_id: str, auth_token: str
176182
) -> None:
177183
"""Validate all required inputs."""
178184
if kernel is None:
179185
raise ValueError("kernel cannot be None")
180186
if not agent_user_id or not agent_user_id.strip():
181187
raise ValueError("agent_user_id cannot be null or empty")
188+
if not environment_id or not environment_id.strip():
189+
raise ValueError("environment_id cannot be null or empty")
182190
if not auth_token or not auth_token.strip():
183191
raise ValueError("auth_token cannot be null or empty")
184192

‎libraries/microsoft-agents-a365-tooling/README.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ mcp_config = MCPServerConfig(
5959
config_service = McpToolServerConfigurationService()
6060
mcp_servers = await config_service.list_tool_servers(
6161
agent_user_id="agent-123",
62+
environment_id="prod",
6263
auth_token="your-auth-token"
6364
)
6465
```

0 commit comments

Comments
 (0)