Skip to content

Fix tool filtering to work off mcp tool attribute name, not method name#12566

Merged
benbp merged 2 commits into
Azure:mainfrom
benbp:benbp/tool-filtering
Oct 21, 2025
Merged

Fix tool filtering to work off mcp tool attribute name, not method name#12566
benbp merged 2 commits into
Azure:mainfrom
benbp:benbp/tool-filtering

Conversation

@benbp

@benbp benbp commented Oct 20, 2025

Copy link
Copy Markdown
Member

Fix tool filtering to work off the mcp tool attribute name, not the C# method name.

The GetCommand method is going to change slightly after #12564 goes in, but the core logic change to tool filtering is the same so I figured I'd get this up for review.

⇉ ⇉ ⇉ dotnet run --no-restore -- mcp  --tools '*hello*'
...
info: Microsoft.Hosting.Lifetime[14]
      Now listening on: http://127.0.0.1:36615
...

{"jsonrpc":"2.0","id":3,"method":"tools/list","params":{}}

info: ModelContextProtocol.Server.McpServer[570385771]
      Server (azsdk 0.5.3.0) method 'tools/list' request handler called.
info: ModelContextProtocol.Server.McpServer[1867955179]
      Server (azsdk 0.5.3.0) method 'tools/list' request handler completed.

{"result":{"tools":[{"name":"azsdk_hello_world","description":"Echoes the message back to the client","inputSchema":{"type":"object","properties":{"message":{"type":"string"}},"required":[
"message"]}},{"name":"azsdk_hello_world_fail","description":"Echoes the message back to the client with a failure","inputSchema":{"type":"object","properties":{"message":{"type":"string"}}
,"required":["message"]}}]},"id":3,"jsonrpc":"2.0"}

@benbp
benbp requested a review from a team as a code owner October 20, 2025 18:18
Copilot AI review requested due to automatic review settings October 20, 2025 18:18
@benbp benbp added the Central-EngSys This issue is owned by the Engineering System team. label Oct 20, 2025
@benbp benbp self-assigned this Oct 20, 2025
@benbp
benbp requested a review from scbedd October 20, 2025 18:19

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 fixes the tool filtering mechanism in the MCP (Model Context Protocol) server to filter based on the McpServerToolAttribute.Name property rather than the method name. This ensures that tools are correctly matched against user-specified patterns regardless of the underlying method naming.

Key Changes:

  • Moved tool filtering logic from type-level to method-level within RegisterInstrumentedMcpTools
  • Removed the GetFilteredToolTypes method that was filtering by type name
  • Added ToolOption to the host server command to support tool filtering at runtime

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
ServiceRegistrations.cs Implements method-level filtering using McpServerToolAttribute.Name instead of type-based filtering
SharedOptions.cs Removes the now-obsolete GetFilteredToolTypes method that filtered by type name
HostServerCommand.cs Adds ToolOption to enable tool filtering for the MCP server command
CommandRunner.cs Simplifies tool type retrieval by removing the call to GetFilteredToolTypes

Comment thread tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/ServiceRegistrations.cs Outdated
Comment thread tools/azsdk-cli/Azure.Sdk.Tools.Cli/Services/ServiceRegistrations.cs Outdated
@benbp benbp moved this from 🤔 Triage to 🔬 Dev in PR in Azure SDK EngSys 🚀🌒🧑‍🚀 Oct 20, 2025
@benbp benbp added the azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli label Oct 20, 2025
@benbp
benbp merged commit db3d368 into Azure:main Oct 21, 2025
11 checks passed
@benbp
benbp deleted the benbp/tool-filtering branch October 21, 2025 01:30
@kurtzeborn kurtzeborn moved this from 🔬 Dev in PR to 🎊 Closed in Azure SDK EngSys 🚀🌒🧑‍🚀 Oct 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

azsdk-cli Issues related to Azure/azure-sdk-tools::tools/azsdk-cli Central-EngSys This issue is owned by the Engineering System team.

Projects

Development

Successfully merging this pull request may close these issues.

4 participants