Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 30, 2025

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:

  • Analyze existing code and understand the requirement
  • Update MCPServerConfig model to add optional url field
  • Update mcp_tool_server_configuration_service.py to support custom URLs in manifest parsing
  • Update mcp_tool_server_configuration_service.py to support custom URLs in gateway parsing
  • Update all MCP tool registration services to use custom URL when available
    • Semantic Kernel extension
    • Agent Framework extension
    • OpenAI extension
    • Azure AI Foundry extension
  • Add tests for custom URL support
  • Run tests to validate changes
  • Address all code review feedback
  • Refactor for consistency
  • Final code review (✅ No issues found)
  • Run security scan with CodeQL (✅ No vulnerabilities found)
  • Standardize on 'url' field only
  • Make gateway parsing logic consistent with manifest parsing
  • Improve variable naming in gateway parsing
  • Rename custom_url to endpoint for clarity
  • Remove unnecessary fallback logic in tool registration services
  • Remove redundant null checks
  • Improve fallback logic clarity
  • Add clarifying comments
  • Fix undefined variable references
  • Move server_name outside try block for exception handler access
  • Clarify comment for fallback logic
  • Add server_name fallback in OpenAI service
  • Add server_name fallback in Semantic Kernel service
  • Improve variable naming consistency in configuration service
  • Fix inconsistent server_name usage
  • Add server_name fallback in configuration service URL construction
  • Fix formatting issues with ruff

Changes Made:

  1. MCPServerConfig Model: Added optional url field to support custom URLs
  2. Configuration Service:
    • Extracts url from both ToolingManifest.json and gateway responses (standardized on url field only)
    • Improved consistency: Both manifest and gateway parsing now use the same logic - if url is not provided, call build_mcp_server_url(server_name) to construct it
    • Consistent fallback logic: Introduced server_name variable with fallback logic (uses mcp_server_name if available, otherwise mcp_server_unique_name) for URL construction
    • Consistently stores the final URL (whether custom or constructed) in the url field, while mcp_server_unique_name remains as the identifier
    • Improved variable naming:
      • Renamed endpoint for extracted URL values
      • Use mcp_server_name and mcp_server_unique_name consistently throughout (instead of name and server_name)
      • Updated comments to remove "custom" where appropriate
  3. All MCP Tool Registration Services:
    • Updated to use config.url directly (no fallback or null checks needed since URL is always populated)
    • Consistent fallback logic: Agent Framework, OpenAI, and Semantic Kernel services all use or operator for clean fallback to mcp_server_unique_name if mcp_server_name is None or empty (with clarifying comments)
    • Consistent usage: All services use the server_name variable consistently throughout (not mixing direct field access with the variable)
    • Improved error handling: Moved server_name assignment outside try block in Agent Framework service to ensure it's always available in exception handler
    • Fixed undefined variable references in log statements
  4. Tests: Added comprehensive unit tests covering:
    • MCPServerConfig creation with and without custom URL
    • Validation of required fields
    • Parsing manifest configurations with custom URLs
    • Parsing gateway configurations with custom URLs
    • Development and production scenarios
    • All tests passing (12/12)
    • Updated tests to reflect new fallback behavior in URL construction
  5. Code Formatting: Applied ruff formatter to ensure consistent code style

Quality Assurance:

  • ✅ All tests passing (12/12)
  • ✅ Code review completed with no issues
  • ✅ CodeQL security scan completed with no vulnerabilities
  • ✅ Code formatting applied with ruff

Implementation Details:

  • Both ToolingManifest.json and gateway responses use the url field for custom URLs
  • When a custom URL is provided via the url field, it's stored in the url field of MCPServerConfig
  • When no custom URL is provided, both manifest and gateway parsing call build_mcp_server_url(server_name) where server_name uses mcp_server_name if available, otherwise mcp_server_unique_name
  • mcp_server_unique_name remains as the server identifier/name
  • Tool registration services use config.url directly (always populated by configuration service)
  • Consistent fallback logic across ALL services (configuration and tool registration): use mcp_server_name if available, otherwise mcp_server_unique_name
  • Consistent variable naming: mcp_server_name and mcp_server_unique_name used throughout
  • All services use computed server_name variable consistently (no mixing with direct field access)
  • Code formatted according to project style guidelines with ruff
Original prompt

This section details on the original issue you should resolve

<issue_title>Custom MCP server URLs are not supported in the SDK</issue_title>
<issue_description>Describe the bug
Custom MCP server URLs are not supported in the SDK.

Proposed solution:
This PR needs to be replicated for the Python SDK as well: microsoft/Agent365-dotnet#147
</issue_description>

Comments on the Issue (you are @copilot in this section)


💡 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.

Copilot AI changed the title [WIP] Add support for custom MCP server URLs in SDK Add support for custom MCP server URLs Dec 30, 2025
Copilot AI requested a review from pontemonti December 30, 2025 17:32
@pontemonti
Copy link
Contributor

@copilot - this is failing build due to format issues. Please run uv run --frozen ruff format .

Copy link
Contributor Author

Copilot AI commented Dec 30, 2025

@copilot - this is failing build due to format issues. Please run uv run --frozen ruff format .

Fixed formatting issues by running ruff format .. The formatter reformatted 3 files (configuration service, agent framework service, and tests) for consistent code style. All tests still pass (12/12). Commit: 76790f1

@pontemonti pontemonti marked this pull request as ready for review December 31, 2025 03:40
@pontemonti pontemonti requested a review from a team as a code owner December 31, 2025 03:40
Copilot AI review requested due to automatic review settings December 31, 2025 03:40
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 MCPServerConfig model with an optional url field 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

@pontemonti pontemonti enabled auto-merge (squash) December 31, 2025 03:57
@pontemonti pontemonti merged commit 310ffa8 into main Jan 26, 2026
8 checks passed
@pontemonti pontemonti deleted the copilot/add-custom-mcp-server-support branch January 26, 2026 16:58
pontemonti added a commit that referenced this pull request Jan 26, 2026
* 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]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Custom MCP server URLs are not supported in the SDK

4 participants