Skip to content

Commit 7ce0f25

Browse files
Copilotpontemonti
andcommitted
Refactor to consistently store URLs in the url field
Co-authored-by: pontemonti <[email protected]>
1 parent 967d25a commit 7ce0f25

File tree

4 files changed

+17
-25
lines changed

4 files changed

+17
-25
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -133,12 +133,8 @@ async def add_tool_servers_to_agent(
133133
self._logger.info(f"Added MCP plugin '{server_name}' to agent tools")
134134

135135
except Exception as tool_ex:
136-
try:
137-
server_name = config.mcp_server_name
138-
except AttributeError:
139-
server_name = "Unknown"
140136
self._logger.warning(
141-
f"Failed to create MCP plugin for {server_name}: {tool_ex}"
137+
f"Failed to create MCP plugin for {config.mcp_server_name}: {tool_ex}"
142138
)
143139
continue
144140

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ async def add_tool_servers_to_agent(
125125
self._orchestrator_name
126126
)
127127

128-
# Use custom URL if provided, otherwise use the unique name
128+
# Use custom URL if provided, otherwise use the unique name
129129
server_url = server.url if server.url else server.mcp_server_unique_name
130130

131131
plugin = MCPStreamableHttpPlugin(

libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -401,15 +401,12 @@ def _parse_manifest_server_config(
401401
# Check if a custom URL is provided
402402
custom_url = self._extract_server_url(server_element)
403403

404-
# If custom URL is provided, use it directly; otherwise construct from base URL
405-
if custom_url:
406-
return MCPServerConfig(
407-
mcp_server_name=name, mcp_server_unique_name=server_name, url=custom_url
408-
)
409-
else:
410-
# Construct full URL using environment utilities
411-
full_url = build_mcp_server_url(server_name)
412-
return MCPServerConfig(mcp_server_name=name, mcp_server_unique_name=full_url)
404+
# Determine the final URL: use custom URL if provided, otherwise construct it
405+
final_url = custom_url if custom_url else build_mcp_server_url(server_name)
406+
407+
return MCPServerConfig(
408+
mcp_server_name=name, mcp_server_unique_name=server_name, url=final_url
409+
)
413410

414411
except Exception:
415412
return None
@@ -436,13 +433,10 @@ def _parse_gateway_server_config(
436433
# Check if a custom URL is provided by the gateway
437434
custom_url = self._extract_server_url(server_element)
438435

439-
# If custom URL is provided, use it; otherwise use the endpoint as-is
440-
if custom_url:
441-
return MCPServerConfig(
442-
mcp_server_name=name, mcp_server_unique_name=endpoint, url=custom_url
443-
)
444-
else:
445-
return MCPServerConfig(mcp_server_name=name, mcp_server_unique_name=endpoint)
436+
# Determine the final URL: use custom URL if provided, otherwise use endpoint
437+
final_url = custom_url if custom_url else endpoint
438+
439+
return MCPServerConfig(mcp_server_name=name, mcp_server_unique_name=endpoint, url=final_url)
446440

447441
except Exception:
448442
return None

tests/tooling/test_mcp_server_configuration.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,9 @@ def test_parse_manifest_server_config_without_custom_url(self, mock_build_url, s
123123

124124
assert config is not None
125125
assert config.mcp_server_name == "DefaultServer"
126-
# Without a custom URL, build_mcp_server_url constructs the full URL and stores it in mcp_server_unique_name
127-
assert config.mcp_server_unique_name == "https://default.server/agents/servers/test_server"
126+
assert config.mcp_server_unique_name == "test_server"
127+
# Without a custom URL, build_mcp_server_url constructs the full URL and stores it in the url field
128+
assert config.url == "https://default.server/agents/servers/test_server"
128129
mock_build_url.assert_called_once_with("test_server")
129130

130131
def test_parse_gateway_server_config_with_custom_url(self, service):
@@ -154,7 +155,8 @@ def test_parse_gateway_server_config_without_custom_url(self, service):
154155
assert config is not None
155156
assert config.mcp_server_name == "GatewayServer"
156157
assert config.mcp_server_unique_name == "https://gateway.default/endpoint"
157-
assert config.url is None
158+
# Without a custom URL, the endpoint is used as the url
159+
assert config.url == "https://gateway.default/endpoint"
158160

159161
@patch.dict(os.environ, {"ENVIRONMENT": "Development"})
160162
def test_is_development_scenario(self, service):

0 commit comments

Comments
 (0)