-
Couldn't load subscription status.
- Fork 257
Add a command listing all the tool names #741
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
fanyang-mono
wants to merge
12
commits into
microsoft:main
Choose a base branch
from
fanyang-mono:list_tool_names
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
e47f467
Add a command listing all tool names
fanyang-mono f311a5c
Add --namespace option to scope it down to a specific namespace
fanyang-mono 939c2b4
Fix format
fanyang-mono 117e3a1
Add --name switch to tool list command to only return tool names
fanyang-mono d9f5332
Merge remote-tracking branch 'origin/main' into list_tool_names
fanyang-mono 7459e1f
Update CHANGELOG
fanyang-mono 325dc3f
Create a helper function to reuse the namespace filtering logic
fanyang-mono ca614ac
Merge remote-tracking branch 'origin/main' into list_tool_names
fanyang-mono 785390b
Fix format
fanyang-mono 1a9f02d
Merge branch 'main' into list_tool_names
fanyang-mono f54b5d8
Fix test failure
fanyang-mono 2c2c325
Merge remote-tracking branch 'origin/main' into list_tool_names
fanyang-mono File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
71 changes: 71 additions & 0 deletions
71
core/Azure.Mcp.Core/src/Areas/Tools/Commands/ToolsListNamesCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using Azure.Mcp.Core.Areas.Tools.Options; | ||
| using Azure.Mcp.Core.Commands; | ||
| using Azure.Mcp.Core.Models; | ||
| using Azure.Mcp.Core.Models.Command; | ||
| using Microsoft.Extensions.Logging; | ||
| using System.CommandLine.Parsing; | ||
|
|
||
| namespace Azure.Mcp.Core.Areas.Tools.Commands; | ||
|
|
||
| [HiddenCommand] | ||
| public sealed class ToolsListNamesCommand(ILogger<ToolsListNamesCommand> logger) : BaseCommand<ToolsListNamesOptions> | ||
| { | ||
| private const string CommandTitle = "List Tool Names"; | ||
|
|
||
| public override string Name => "list-names"; | ||
|
|
||
| public override string Description => | ||
| """ | ||
| List all available tool names in the Azure MCP server. This command returns a simple list of tool names | ||
| without descriptions or metadata, useful for quick discovery or automated tool enumeration. | ||
| """; | ||
|
|
||
| public override string Title => CommandTitle; | ||
|
|
||
| public override ToolMetadata Metadata => new() | ||
| { | ||
| Destructive = false, | ||
| Idempotent = true, | ||
| OpenWorld = false, | ||
| ReadOnly = true, | ||
| LocalRequired = false, | ||
| Secret = false | ||
| }; | ||
|
|
||
| protected override ToolsListNamesOptions BindOptions(ParseResult parseResult) | ||
| { | ||
| return new ToolsListNamesOptions(); | ||
| } | ||
|
|
||
| public override async Task<CommandResponse> ExecuteAsync(CommandContext context, ParseResult parseResult) | ||
| { | ||
| try | ||
| { | ||
| var factory = context.GetService<CommandFactory>(); | ||
| var options = BindOptions(parseResult); | ||
|
|
||
| // Get all visible commands and extract their tokenized names (full command paths) | ||
| var toolNames = await Task.Run(() => CommandFactory.GetVisibleCommands(factory.AllCommands) | ||
| .Select(kvp => kvp.Key) // Use the tokenized key instead of just the command name | ||
| .Where(name => !string.IsNullOrEmpty(name)) | ||
| .OrderBy(name => name, StringComparer.OrdinalIgnoreCase) | ||
| .ToList()); | ||
fanyang-mono marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| var result = new ToolNamesResult(toolNames); | ||
| context.Response.Results = ResponseResult.Create(result, ModelsJsonContext.Default.ToolNamesResult); | ||
| return context.Response; | ||
| } | ||
| catch (Exception ex) | ||
| { | ||
| logger.LogError(ex, "An exception occurred while processing tool names listing."); | ||
| HandleException(context, ex); | ||
|
|
||
| return context.Response; | ||
| } | ||
| } | ||
|
|
||
| public record ToolNamesResult(List<string> Names); | ||
| } | ||
9 changes: 9 additions & 0 deletions
9
core/Azure.Mcp.Core/src/Areas/Tools/Options/ToolsListNamesOptions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| namespace Azure.Mcp.Core.Areas.Tools.Options; | ||
|
|
||
| public sealed class ToolsListNamesOptions | ||
| { | ||
| // This command requires no additional options - it simply lists all tool names | ||
| } | ||
fanyang-mono marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.