Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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 @@ -83,7 +83,6 @@ async def main():
agent_instructions="You are a helpful assistant that can provide weather and restaurant information.",
initial_tools=[], # Your existing tools
agentic_app_id="user-123",
environment_id="prod",
auth_token="your-auth-token"
)

Expand Down Expand Up @@ -140,7 +139,6 @@ async def main():
""",
initial_tools=existing_tools,
agentic_app_id="user-123",
environment_id="production",
auth_token="your-auth-token"
)

Expand Down Expand Up @@ -191,7 +189,6 @@ agent = await service.add_tool_servers_to_agent(
agent_instructions="You are a helpful assistant with access to various tools.",
initial_tools=[], # Your existing tools
agentic_app_id="user-123",
environment_id="prod",
auth_token="your-token"
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

from microsoft_agents_a365.tooling.utils.utility import (
get_mcp_platform_authentication_scope,
get_use_environment_id,
)


Expand Down Expand Up @@ -47,7 +46,6 @@ async def add_tool_servers_to_agent(
agent_instructions: str,
initial_tools: List[Any],
agentic_app_id: str,
environment_id: str,
auth: Authorization,
turn_context: TurnContext,
auth_token: Optional[str] = None,
Expand All @@ -60,7 +58,6 @@ async def add_tool_servers_to_agent(
agent_instructions: Instructions for the agent behavior
initial_tools: List of initial tools to add to the agent
agentic_app_id: Agentic app identifier for the agent
environment_id: Environment identifier for MCP server discovery
auth: Authorization context for token exchange
turn_context: Turn context for the operation
auth_token: Optional bearer token for authentication
Expand All @@ -75,17 +72,11 @@ async def add_tool_servers_to_agent(
authToken = await auth.exchange_token(turn_context, scopes, "AGENTIC")
auth_token = authToken.token

if get_use_environment_id():
self._logger.info(
f"Listing MCP tool servers for agent {agentic_app_id} in environment {environment_id}"
)
else:
self._logger.info(f"Listing MCP tool servers for agent {agentic_app_id}")
self._logger.info(f"Listing MCP tool servers for agent {agentic_app_id}")

# Get MCP server configurations
server_configs = await self._mcp_server_configuration_service.list_tool_servers(
agentic_app_id=agentic_app_id,
environment_id=environment_id,
auth_token=auth_token,
)

Expand All @@ -110,8 +101,6 @@ async def add_tool_servers_to_agent(
headers[Constants.Headers.AUTHORIZATION] = (
f"{Constants.Headers.BEARER_PREFIX} {auth_token}"
)
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
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ registration_service = McpToolRegistrationService()
await registration_service.add_tool_servers_to_agent(
project_client=project_client,
agent_id="your-agent-id",
environment_id="prod",
auth_token="your-auth-token"
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from azure.ai.agents.models import McpTool, ToolResources
from microsoft_agents.hosting.core import Authorization, TurnContext

from ...common.utils.utility import get_mcp_platform_authentication_scope, get_use_environment_id
from ...common.utils.utility import get_mcp_platform_authentication_scope

# Local imports
from microsoft_kairo.tooling.common.services.mcp_tool_server_configuration_service import (
Expand All @@ -44,7 +44,7 @@ class McpToolRegistrationService:

Example:
>>> service = McpToolRegistrationService()
>>> service.add_tool_servers_to_agent(project_client, agent_id, env_id, token)
>>> service.add_tool_servers_to_agent(project_client, agent_id, token)
"""

def __init__(
Expand Down Expand Up @@ -73,7 +73,6 @@ async def add_tool_servers_to_agent(
self,
project_client: "AIProjectClient",
agentic_app_id: str,
environment_id: str,
auth: Authorization,
context: TurnContext,
auth_token: Optional[str] = None,
Expand All @@ -84,7 +83,6 @@ async def add_tool_servers_to_agent(
Args:
project_client: The Azure Foundry AIProjectClient instance.
agentic_app_id: Agentic App ID for the agent.
environment_id: Environment ID for the environment.
auth_token: Authentication token to access the MCP servers.

Raises:
Expand All @@ -102,7 +100,7 @@ async def add_tool_servers_to_agent(
try:
# Get the tool definitions and resources using the async implementation
tool_definitions, tool_resources = await self._get_mcp_tool_definitions_and_resources(
agentic_app_id, environment_id, auth_token or ""
agentic_app_id, auth_token or ""
)

# Update the agent with the tools
Expand All @@ -121,7 +119,7 @@ async def add_tool_servers_to_agent(
raise

async def _get_mcp_tool_definitions_and_resources(
self, agentic_app_id: str, environment_id: str, auth_token: str
self, agentic_app_id: str, auth_token: str
) -> Tuple[List[McpTool], Optional[ToolResources]]:
"""
Internal method to get MCP tool definitions and resources.
Expand All @@ -130,7 +128,6 @@ async def _get_mcp_tool_definitions_and_resources(

Args:
agentic_app_id: Agentic App ID for the agent.
environment_id: Environment ID for the environment.
auth_token: Authentication token to access the MCP servers.

Returns:
Expand All @@ -143,7 +140,7 @@ async def _get_mcp_tool_definitions_and_resources(
# Get MCP server configurations
try:
servers = await self._mcp_server_configuration_service.list_tool_servers(
agentic_app_id, environment_id, auth_token
agentic_app_id, auth_token
)
except Exception as ex:
self._logger.error(
Expand All @@ -152,12 +149,7 @@ async def _get_mcp_tool_definitions_and_resources(
return ([], None)

if len(servers) == 0:
if get_use_environment_id():
self._logger.info(
f"No MCP servers configured for AgenticAppId={agentic_app_id}, EnvironmentId={environment_id}"
)
else:
self._logger.info(f"No MCP servers configured for AgenticAppId={agentic_app_id}")
self._logger.info(f"No MCP servers configured for AgenticAppId={agentic_app_id}")
return ([], None)

# Collections to build for the return value
Expand Down Expand Up @@ -196,10 +188,6 @@ async def _get_mcp_tool_definitions_and_resources(
)
mcp_tool.update_headers(Constants.Headers.AUTHORIZATION, header_value)

# Set environment ID header
if get_use_environment_id() and environment_id:
mcp_tool.update_headers(Constants.Headers.ENVIRONMENT_ID, environment_id)

# Add to collections
tool_definitions.extend(mcp_tool.definitions)
if mcp_tool.resources and mcp_tool.resources.mcp:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ registration_service = McpToolRegistrationService()
await registration_service.add_tool_servers_to_agent(
agent=your_openai_agent,
agentic_app_id="user-123",
environment_id="prod",
auth=authorization_context,
context=turn_context,
auth_token="your-auth-token"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

from microsoft_agents_a365.tooling.utils.utility import (
get_mcp_platform_authentication_scope,
get_use_environment_id,
)


Expand Down Expand Up @@ -52,7 +51,6 @@ async def add_tool_servers_to_agent(
self,
agent: Agent,
agentic_app_id: str,
environment_id: str,
auth: Authorization,
context: TurnContext,
auth_token: Optional[str] = None,
Expand All @@ -67,7 +65,6 @@ async def add_tool_servers_to_agent(
Args:
agent: The existing agent to add servers to
agentic_app_id: Agentic App ID for the agent
environment_id: Environment ID for the environment
auth_token: Authentication token to access the MCP servers

Returns:
Expand All @@ -83,15 +80,9 @@ async def add_tool_servers_to_agent(
# mcp_server_configs = []
# TODO: radevika: Update once the common project is merged.

if get_use_environment_id():
self._logger.info(
f"Listing MCP tool servers for agent {agentic_app_id} in environment {environment_id}"
)
else:
self._logger.info(f"Listing MCP tool servers for agent {agentic_app_id}")
self._logger.info(f"Listing MCP tool servers for agent {agentic_app_id}")
mcp_server_configs = await self.config_service.list_tool_servers(
agentic_app_id=agentic_app_id,
environment_id=environment_id,
auth_token=auth_token,
)

Expand Down Expand Up @@ -138,8 +129,6 @@ async def add_tool_servers_to_agent(
headers = si.headers or {}
if auth_token:
headers["Authorization"] = f"Bearer {auth_token}"
if get_use_environment_id() and environment_id:
headers["x-ms-environment-id"] = environment_id

# Create MCPServerStreamableHttpParams with proper configuration
params = MCPServerStreamableHttpParams(url=si.url, headers=headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ registration_service = McpToolRegistrationService()
await registration_service.add_tool_servers_to_kernel(
kernel=kernel,
agentic_app_id="user-123",
environment_id="prod",
auth_token="your-auth-token"
)
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
from ...common.utils.utility import (
get_tools_mode,
get_mcp_platform_authentication_scope,
get_use_environment_id,
)


Expand Down Expand Up @@ -85,7 +84,6 @@ async def add_tool_servers_to_agent(
self,
kernel: sk.Kernel,
agentic_app_id: str,
environment_id: str,
auth: Authorization,
context: TurnContext,
auth_token: Optional[str] = None,
Expand All @@ -96,7 +94,6 @@ async def add_tool_servers_to_agent(
Args:
kernel: The Semantic Kernel instance to which the tools will be added.
agentic_app_id: Agentic App ID for the agent.
environment_id: Environment ID for the environment.
auth_token: Authentication token to access the MCP servers.

Raises:
Expand All @@ -109,11 +106,11 @@ async def add_tool_servers_to_agent(
authToken = await auth.exchange_token(context, scopes, "AGENTIC")
auth_token = authToken.token

self._validate_inputs(kernel, agentic_app_id, environment_id, auth_token)
self._validate_inputs(kernel, agentic_app_id, auth_token)

# Get and process servers
servers = await self._mcp_server_configuration_service.list_tool_servers(
agentic_app_id, environment_id, auth_token
agentic_app_id, auth_token
)
self._logger.info(f"🔧 Adding MCP tools from {len(servers)} servers")

Expand All @@ -130,17 +127,8 @@ async def add_tool_servers_to_agent(
headers = {}

if tools_mode == "MockMCPServer":
# Mock server does not require bearer auth, but still forward environment id if available.
if get_use_environment_id() and environment_id:
headers[Constants.Headers.ENVIRONMENT_ID] = environment_id

if mock_auth_header := os.getenv("MOCK_MCP_AUTHORIZATION"):
headers[Constants.Headers.AUTHORIZATION] = mock_auth_header
elif get_use_environment_id():
headers = {
Constants.Headers.AUTHORIZATION: f"{Constants.Headers.BEARER_PREFIX} {auth_token}",
Constants.Headers.ENVIRONMENT_ID: environment_id,
}
else:
headers = {
Constants.Headers.AUTHORIZATION: f"{Constants.Headers.BEARER_PREFIX} {auth_token}",
Expand Down Expand Up @@ -177,16 +165,12 @@ async def add_tool_servers_to_agent(
# Private Methods - Input Validation & Processing
# ============================================================================

def _validate_inputs(
self, kernel: Any, agentic_app_id: str, environment_id: str, auth_token: str
) -> None:
def _validate_inputs(self, kernel: Any, agentic_app_id: str, auth_token: str) -> None:
"""Validate all required inputs."""
if kernel is None:
raise ValueError("kernel cannot be None")
if not agentic_app_id or not agentic_app_id.strip():
raise ValueError("agentic_app_id cannot be null or empty")
if get_use_environment_id() and (not environment_id or not environment_id.strip()):
raise ValueError("environment_id cannot be null or empty")
if not auth_token or not auth_token.strip():
raise ValueError("auth_token cannot be null or empty")

Expand Down
1 change: 0 additions & 1 deletion libraries/microsoft-agents-a365-tooling/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ mcp_config = MCPServerConfig(
config_service = McpToolServerConfigurationService()
mcp_servers = await config_service.list_tool_servers(
agentic_app_id="agent-123",
environment_id="prod",
auth_token="your-auth-token"
)
```
Expand Down
Loading
Loading