Add support for custom MCP server URLs#96
Conversation
Co-authored-by: pontemonti <[email protected]>
Co-authored-by: pontemonti <[email protected]>
Co-authored-by: pontemonti <[email protected]>
Co-authored-by: pontemonti <[email protected]>
Co-authored-by: pontemonti <[email protected]>
Co-authored-by: pontemonti <[email protected]>
...a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py
Outdated
Show resolved
Hide resolved
Co-authored-by: pontemonti <[email protected]>
...a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py
Outdated
Show resolved
Hide resolved
… naming Co-authored-by: pontemonti <[email protected]>
Co-authored-by: pontemonti <[email protected]>
...a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py
Outdated
Show resolved
Hide resolved
...a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py
Outdated
Show resolved
Hide resolved
...soft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py
Outdated
Show resolved
Hide resolved
Co-authored-by: pontemonti <[email protected]>
...soft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py
Outdated
Show resolved
Hide resolved
Co-authored-by: pontemonti <[email protected]>
|
@copilot - this is failing build due to format issues. Please run |
Co-authored-by: pontemonti <[email protected]>
Fixed formatting issues by running |
There was a problem hiding this comment.
Pull request overview
This PR adds support for custom MCP server URLs in the Python SDK, aligning with the functionality provided in PR #147 of the .NET SDK. The implementation allows users to specify custom URLs for MCP servers instead of relying solely on constructed URLs from server names.
Key changes:
- Extended
MCPServerConfigmodel with an optionalurlfield for custom server endpoints - Updated configuration parsing logic to extract and use custom URLs from both manifest files and gateway responses
- Modified all tool registration services to utilize the custom URL when available
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 3 comments.
Show a summary per file
| File | Description |
|---|---|
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/models/mcp_server_config.py |
Added optional url field to MCPServerConfig dataclass with proper documentation |
libraries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/services/mcp_tool_server_configuration_service.py |
Implemented _extract_server_url method and updated manifest/gateway parsing to support custom URLs with fallback to constructed URLs |
libraries/microsoft-agents-a365-tooling-extensions-semantickernel/microsoft_agents_a365/tooling/extensions/semantickernel/services/mcp_tool_registration_service.py |
Updated to use config.url directly with consistent server name fallback logic |
libraries/microsoft-agents-a365-tooling-extensions-openai/microsoft_agents_a365/tooling/extensions/openai/mcp_tool_registration_service.py |
Updated to use config.url directly with consistent server name fallback logic |
libraries/microsoft-agents-a365-tooling-extensions-azureaifoundry/microsoft_agents_a365/tooling/extensions/azureaifoundry/services/mcp_tool_registration_service.py |
Updated to use config.url directly from server configuration |
libraries/microsoft-agents-a365-tooling-extensions-agentframework/microsoft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py |
Simplified URL handling by using config.url directly and moved server_name variable outside try block for better error handling |
tests/tooling/test_mcp_server_configuration.py |
Added comprehensive unit tests covering custom URL scenarios for both manifest and gateway configurations |
tests/tooling/__init__.py |
Added init file with proper copyright header for test module |
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
...soft_agents_a365/tooling/extensions/agentframework/services/mcp_tool_registration_service.py
Show resolved
Hide resolved
...ries/microsoft-agents-a365-tooling/microsoft_agents_a365/tooling/models/mcp_server_config.py
Show resolved
Hide resolved
* Initial plan * Add support for custom MCP server URLs * Add comprehensive tests for custom MCP server URL support * Remove unnecessary hasattr check in exception handler * Simplify custom URL checks by removing redundant strip calls * Improve exception handling and clarify test comments * Refactor to consistently store URLs in the url field * Use 'url' field consistently in both manifest and gateway responses * Refactor gateway parsing to match manifest logic and improve variable naming * Fix formatting: remove extra blank line in test * Rename custom_url to endpoint for better clarity * Remove fallback logic and use config.url directly in all tool registration services * Remove redundant null check for server_url in Agent Framework service * Use 'or' operator for cleaner fallback logic in server_name assignment * Add clarifying comment for server_name fallback logic * Fix undefined variable reference in log statement * Move server_name assignment outside try block to ensure it's always available in exception handler * Clarify comment for server_name fallback logic * Add server_name fallback logic in OpenAI MCP tool registration service * Improve variable naming consistency and add server_name fallback in Semantic Kernel service * Fix inconsistent server_name usage in Semantic Kernel service * Add server_name fallback logic in configuration service URL construction * Run ruff formatter to fix formatting issues * Update tests/tooling/test_mcp_server_configuration.py * Update tests/tooling/test_mcp_server_configuration.py * Update tests/tooling/test_mcp_server_configuration.py --------- Co-authored-by: Copilot <[email protected]> Co-authored-by: pontemonti <[email protected]> Co-authored-by: Copilot <[email protected]>
Implementation Plan for Custom MCP Server URL Support
This PR adds support for custom MCP server URLs in the Python SDK, matching the functionality provided in PR #147 of the .NET SDK.
Changes Required:
MCPServerConfigmodel to add optionalurlfieldmcp_tool_server_configuration_service.pyto support custom URLs in manifest parsingmcp_tool_server_configuration_service.pyto support custom URLs in gateway parsingChanges Made:
urlfield to support custom URLsurlfrom both ToolingManifest.json and gateway responses (standardized onurlfield only)urlis not provided, callbuild_mcp_server_url(server_name)to construct itserver_namevariable with fallback logic (usesmcp_server_nameif available, otherwisemcp_server_unique_name) for URL constructionurlfield, whilemcp_server_unique_nameremains as the identifierendpointfor extracted URL valuesmcp_server_nameandmcp_server_unique_nameconsistently throughout (instead ofnameandserver_name)config.urldirectly (no fallback or null checks needed since URL is always populated)oroperator for clean fallback tomcp_server_unique_nameifmcp_server_nameis None or empty (with clarifying comments)server_namevariable consistently throughout (not mixing direct field access with the variable)server_nameassignment outside try block in Agent Framework service to ensure it's always available in exception handlerQuality Assurance:
Implementation Details:
urlfield for custom URLsurlfield, it's stored in theurlfield of MCPServerConfigbuild_mcp_server_url(server_name)whereserver_nameusesmcp_server_nameif available, otherwisemcp_server_unique_namemcp_server_unique_nameremains as the server identifier/nameconfig.urldirectly (always populated by configuration service)mcp_server_nameif available, otherwisemcp_server_unique_namemcp_server_nameandmcp_server_unique_nameused throughoutserver_namevariable consistently (no mixing with direct field access)Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.