Skip to content
Merged
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
)
from microsoft_agents_a365.tooling.utils.constants import Constants

from microsoft_agents_a365.tooling.utils.utility import (
get_ppapi_token_scope,
Comment thread
mrunalhirve128 marked this conversation as resolved.
Outdated
get_use_environment_id,
Comment thread
mrunalhirve128 marked this conversation as resolved.
)


class McpToolRegistrationService:
"""
Expand Down Expand Up @@ -43,9 +48,9 @@ async def add_tool_servers_to_agent(
initial_tools: List[Any],
agent_user_id: str,
environment_id: str,
auth: Optional[Authorization] = None,
auth: Authorization,
turn_context: TurnContext,
Comment thread
mrunalhirve128 marked this conversation as resolved.
auth_token: Optional[str] = None,
turn_context: Optional[TurnContext] = None,
) -> Optional[ChatAgent]:
"""
Add MCP tool servers to a chat agent (mirrors .NET implementation).
Expand All @@ -56,14 +61,20 @@ async def add_tool_servers_to_agent(
initial_tools: List of initial tools to add to the agent
agent_user_id: Unique identifier for the agent user
environment_id: Environment identifier for MCP server discovery
auth: Optional authorization context
auth: Authorization context for token exchange
turn_context: Turn context for the operation
auth_token: Optional bearer token for authentication
turn_context: Optional turn context for the operation

Returns:
ChatAgent instance with MCP tools registered, or None if creation failed
"""
try:
# Exchange token if not provided
if not auth_token:
scopes = get_ppapi_token_scope()
authToken = await auth.exchange_token(turn_context, scopes, "AGENTIC")
auth_token = authToken.token

self._logger.info(
f"Listing MCP tool servers for agent {agent_user_id} in environment {environment_id}"
)
Expand Down Expand Up @@ -96,7 +107,7 @@ async def add_tool_servers_to_agent(
headers[Constants.Headers.AUTHORIZATION] = (
f"{Constants.Headers.BEARER_PREFIX} {auth_token}"
)
if environment_id:
if get_use_environment_id() and environment_id:
headers[Constants.Headers.ENVIRONMENT_ID] = environment_id

server_name = getattr(config, "mcp_server_name", "Unknown")
Expand Down
Loading