Skip to content

Commit 5cec8d5

Browse files
Copilotpontemonti
andcommitted
Add server_name fallback logic in configuration service URL construction
Co-authored-by: pontemonti <[email protected]>
1 parent 0195f73 commit 5cec8d5

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,11 @@ def _parse_manifest_server_config(
401401
# Check if a URL is provided
402402
endpoint = self._extract_server_url(server_element)
403403

404+
# Use mcp_server_name if available, otherwise fall back to mcp_server_unique_name for URL construction
405+
server_name = mcp_server_name or mcp_server_unique_name
406+
404407
# Determine the final URL: use custom URL if provided, otherwise construct it
405-
final_url = endpoint if endpoint else build_mcp_server_url(mcp_server_unique_name)
408+
final_url = endpoint if endpoint else build_mcp_server_url(server_name)
406409

407410
return MCPServerConfig(
408411
mcp_server_name=mcp_server_name, mcp_server_unique_name=mcp_server_unique_name, url=final_url
@@ -433,8 +436,11 @@ def _parse_gateway_server_config(
433436
# Check if a URL is provided by the gateway
434437
endpoint = self._extract_server_url(server_element)
435438

439+
# Use mcp_server_name if available, otherwise fall back to mcp_server_unique_name for URL construction
440+
server_name = mcp_server_name or mcp_server_unique_name
441+
436442
# Determine the final URL: use custom URL if provided, otherwise construct it
437-
final_url = endpoint if endpoint else build_mcp_server_url(mcp_server_unique_name)
443+
final_url = endpoint if endpoint else build_mcp_server_url(server_name)
438444

439445
return MCPServerConfig(mcp_server_name=mcp_server_name, mcp_server_unique_name=mcp_server_unique_name, url=final_url)
440446

tests/tooling/test_mcp_server_configuration.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ def test_parse_manifest_server_config_with_custom_url(self, service):
107107
@patch("microsoft_agents_a365.tooling.services.mcp_tool_server_configuration_service.build_mcp_server_url")
108108
def test_parse_manifest_server_config_without_custom_url(self, mock_build_url, service):
109109
"""Test parsing manifest config without custom URL constructs URL."""
110-
mock_build_url.return_value = "https://default.server/agents/servers/test_server"
110+
mock_build_url.return_value = "https://default.server/agents/servers/DefaultServer"
111111

112112
server_element = {
113113
"mcpServerName": "DefaultServer",
@@ -120,8 +120,9 @@ def test_parse_manifest_server_config_without_custom_url(self, mock_build_url, s
120120
assert config.mcp_server_name == "DefaultServer"
121121
assert config.mcp_server_unique_name == "test_server"
122122
# Without a custom URL, build_mcp_server_url constructs the full URL and stores it in the url field
123-
assert config.url == "https://default.server/agents/servers/test_server"
124-
mock_build_url.assert_called_once_with("test_server")
123+
# Uses mcp_server_name if available, otherwise falls back to mcp_server_unique_name
124+
assert config.url == "https://default.server/agents/servers/DefaultServer"
125+
mock_build_url.assert_called_once_with("DefaultServer")
125126

126127
def test_parse_gateway_server_config_with_custom_url(self, service):
127128
"""Test parsing gateway config with custom URL."""
@@ -141,7 +142,7 @@ def test_parse_gateway_server_config_with_custom_url(self, service):
141142
@patch("microsoft_agents_a365.tooling.services.mcp_tool_server_configuration_service.build_mcp_server_url")
142143
def test_parse_gateway_server_config_without_custom_url(self, mock_build_url, service):
143144
"""Test parsing gateway config without custom URL."""
144-
mock_build_url.return_value = "https://default.server/agents/servers/gateway_server"
145+
mock_build_url.return_value = "https://default.server/agents/servers/GatewayServer"
145146

146147
server_element = {
147148
"mcpServerName": "GatewayServer",
@@ -154,8 +155,9 @@ def test_parse_gateway_server_config_without_custom_url(self, mock_build_url, se
154155
assert config.mcp_server_name == "GatewayServer"
155156
assert config.mcp_server_unique_name == "gateway_server"
156157
# Without a custom URL, build_mcp_server_url constructs the full URL and stores it in the url field
157-
assert config.url == "https://default.server/agents/servers/gateway_server"
158-
mock_build_url.assert_called_once_with("gateway_server")
158+
# Uses mcp_server_name if available, otherwise falls back to mcp_server_unique_name
159+
assert config.url == "https://default.server/agents/servers/GatewayServer"
160+
mock_build_url.assert_called_once_with("GatewayServer")
159161

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

0 commit comments

Comments
 (0)