Skip to content

Commit 5d811a1

Browse files
Add agentic auth for AF
1 parent 7d7ae9c commit 5d811a1

1 file changed

Lines changed: 15 additions & 4 deletions

File tree

  • libraries/microsoft-agents-a365-tooling-extensions-agentframework/microsoft_agents_a365/tooling/extensions/agentframework/services

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

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@
1414
)
1515
from microsoft_agents_a365.tooling.utils.constants import Constants
1616

17+
from microsoft_agents_a365.tooling.utils.utility import (
18+
get_ppapi_token_scope,
19+
get_use_environment_id,
20+
)
21+
1722

1823
class McpToolRegistrationService:
1924
"""
@@ -43,9 +48,9 @@ async def add_tool_servers_to_agent(
4348
initial_tools: List[Any],
4449
agent_user_id: str,
4550
environment_id: str,
46-
auth: Optional[Authorization] = None,
51+
auth: Authorization,
52+
turn_context: TurnContext,
4753
auth_token: Optional[str] = None,
48-
turn_context: Optional[TurnContext] = None,
4954
) -> Optional[ChatAgent]:
5055
"""
5156
Add MCP tool servers to a chat agent (mirrors .NET implementation).
@@ -56,14 +61,20 @@ async def add_tool_servers_to_agent(
5661
initial_tools: List of initial tools to add to the agent
5762
agent_user_id: Unique identifier for the agent user
5863
environment_id: Environment identifier for MCP server discovery
59-
auth: Optional authorization context
64+
auth: Authorization context for token exchange
65+
turn_context: Turn context for the operation
6066
auth_token: Optional bearer token for authentication
61-
turn_context: Optional turn context for the operation
6267
6368
Returns:
6469
ChatAgent instance with MCP tools registered, or None if creation failed
6570
"""
6671
try:
72+
# Exchange token if not provided
73+
if not auth_token:
74+
scopes = get_ppapi_token_scope()
75+
authToken = await auth.exchange_token(turn_context, scopes, "AGENTIC")
76+
auth_token = authToken.token
77+
6778
self._logger.info(
6879
f"Listing MCP tool servers for agent {agent_user_id} in environment {environment_id}"
6980
)

0 commit comments

Comments
 (0)