Skip to content

Commit c82e08b

Browse files
fix
1 parent 1289d10 commit c82e08b

File tree

4 files changed

+40
-23
lines changed

4 files changed

+40
-23
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,4 @@
1212

1313
__all__ = [
1414
"McpToolRegistrationService",
15-
]
15+
]

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

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
from microsoft_agents_a365.tooling.services.mcp_tool_server_configuration_service import (
1212
McpToolServerConfigurationService,
1313
)
14-
from microsoft_agents_a365.tooling.utils.utility import get_ppapi_token_scope
1514
from microsoft_agents_a365.tooling.utils.constants import Constants
1615

1716

@@ -64,7 +63,9 @@ async def add_tool_servers_to_agent(
6463
ChatAgent instance with MCP tools registered, or None if creation failed
6564
"""
6665
try:
67-
self._logger.info(f"Listing MCP tool servers for agent {agent_user_id} in environment {environment_id}")
66+
self._logger.info(
67+
f"Listing MCP tool servers for agent {agent_user_id} in environment {environment_id}"
68+
)
6869

6970
# Get MCP server configurations
7071
server_configs = await self._mcp_server_configuration_service.list_tool_servers(
@@ -81,39 +82,45 @@ async def add_tool_servers_to_agent(
8182
# Add MCP plugins for each server config
8283
for config in server_configs:
8384
try:
84-
server_url = getattr(config, 'server_url', None) or getattr(config, 'mcp_server_unique_name', None)
85+
server_url = getattr(config, "server_url", None) or getattr(
86+
config, "mcp_server_unique_name", None
87+
)
8588
if not server_url:
8689
self._logger.warning(f"MCP server config missing server_url: {config}")
8790
continue
88-
91+
8992
# Prepare auth headers
9093
headers = {}
9194
if auth_token:
92-
headers[Constants.Headers.AUTHORIZATION] = f"{Constants.Headers.BEARER_PREFIX} {auth_token}"
95+
headers[Constants.Headers.AUTHORIZATION] = (
96+
f"{Constants.Headers.BEARER_PREFIX} {auth_token}"
97+
)
9398
if environment_id:
9499
headers[Constants.Headers.ENVIRONMENT_ID] = environment_id
95-
96-
server_name = getattr(config, 'mcp_server_name', 'Unknown')
97-
100+
101+
server_name = getattr(config, "mcp_server_name", "Unknown")
102+
98103
# Create and configure MCP plugin
99104
mcp_tools = MCPStreamableHTTPTool(
100105
name=server_name,
101106
url=server_url,
102107
headers=headers,
103-
description=f"MCP tools from {server_name}"
108+
description=f"MCP tools from {server_name}",
104109
)
105-
110+
106111
# Let Agent Framework handle the connection automatically
107112
self._logger.info(f"Created MCP plugin for '{server_name}' at {server_url}")
108-
113+
109114
all_tools.append(mcp_tools)
110115
self._connected_servers.append(mcp_tools)
111-
116+
112117
self._logger.info(f"Added MCP plugin '{server_name}' to agent tools")
113-
118+
114119
except Exception as tool_ex:
115-
server_name = getattr(config, 'mcp_server_name', 'Unknown')
116-
self._logger.warning(f"Failed to create MCP plugin for {server_name}: {tool_ex}")
120+
server_name = getattr(config, "mcp_server_name", "Unknown")
121+
self._logger.warning(
122+
f"Failed to create MCP plugin for {server_name}: {tool_ex}"
123+
)
117124
continue
118125

119126
# Create the ChatAgent
@@ -135,10 +142,10 @@ async def cleanup(self):
135142
try:
136143
for plugin in self._connected_servers:
137144
try:
138-
if hasattr(plugin, 'close'):
145+
if hasattr(plugin, "close"):
139146
await plugin.close()
140147
except Exception as cleanup_ex:
141148
self._logger.debug(f"Error during cleanup: {cleanup_ex}")
142149
self._connected_servers.clear()
143150
except Exception as ex:
144-
self._logger.debug(f"Error during service cleanup: {ex}")
151+
self._logger.debug(f"Error during service cleanup: {ex}")

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

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,9 @@ async def add_tool_servers_to_agent(
8080
# Get MCP server configurations from the configuration service
8181
# mcp_server_configs = []
8282
# TODO: radevika: Update once the common project is merged.
83-
self._logger.info(f"Listing MCP tool servers for agent {agent_user_id} in environment {environment_id}")
83+
self._logger.info(
84+
f"Listing MCP tool servers for agent {agent_user_id} in environment {environment_id}"
85+
)
8486
mcp_server_configs = await self.config_service.list_tool_servers(
8587
agent_user_id=agent_user_id, environment_id=environment_id, auth_token=auth_token
8688
)
@@ -146,11 +148,15 @@ async def add_tool_servers_to_agent(
146148
connected_servers.append(mcp_server)
147149

148150
existing_server_urls.append(si.url)
149-
self._logger.info(f"Successfully connected to MCP server '{si.name}' at {si.url}")
151+
self._logger.info(
152+
f"Successfully connected to MCP server '{si.name}' at {si.url}"
153+
)
150154

151155
except Exception as e:
152156
# Log the error but continue with other servers
153-
self._logger.warning(f"Failed to connect to MCP server {si.name} at {si.url}: {e}")
157+
self._logger.warning(
158+
f"Failed to connect to MCP server {si.name} at {si.url}: {e}"
159+
)
154160
continue
155161

156162
# If we have new servers, we need to recreate the agent
@@ -184,7 +190,9 @@ async def add_tool_servers_to_agent(
184190
self._connected_servers = []
185191
self._connected_servers.extend(connected_servers)
186192

187-
self._logger.info(f"Agent recreated successfully with {len(all_mcp_servers)} total MCP servers")
193+
self._logger.info(
194+
f"Agent recreated successfully with {len(all_mcp_servers)} total MCP servers"
195+
)
188196
# Return the new agent (caller needs to replace the old one)
189197
return new_agent
190198

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ def __init__(
4949
logger: Logger instance for logging operations.
5050
"""
5151
self._logger = logger or logging.getLogger(self.__class__.__name__)
52-
self._mcp_server_configuration_service = McpToolServerConfigurationService(logger=self._logger)
52+
self._mcp_server_configuration_service = McpToolServerConfigurationService(
53+
logger=self._logger
54+
)
5355

5456
# Store connected plugins to keep them alive
5557
self._connected_plugins = []

0 commit comments

Comments
 (0)