Repository navigation
Add list_dsc_function() tool to MCP server
#1126
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
Merged
Steve Lee (SteveL-MSFT)
merged 13 commits into
PowerShell:main
from
Gijsreyn:mcp-list-extension
Sep 23, 2025
Merged
Changes from 4 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
0ef6bab
Add list_dsc_function()
Gijsreyn 3276183
Fix clippy
Gijsreyn 27314f6
Resolve remark
Gijsreyn 2d8a4fb
Resolve alpha
Gijsreyn 6f87599
Add list_dsc_function()
Gijsreyn c79943f
Fix clippy
Gijsreyn 7baa158
Resolve remark
Gijsreyn 83abeac
Resolve alpha
Gijsreyn 468824f
Merge branch 'mcp-list-extension' of https://github.com/Gijsreyn/oper…
Gijsreyn 1bcdd24
Rename function filter
Gijsreyn cb1e7b2
Fix up tests
Gijsreyn 5559394
Incorrect name in test
Gijsreyn a844e10
Forgot to uncomment tests
Gijsreyn 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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| use crate::mcp::mcp_server::McpServer; | ||
| use dsc_lib::functions::{FunctionDispatcher, FunctionDefinition}; | ||
| use dsc_lib::util::convert_wildcard_to_regex; | ||
| use rmcp::{ErrorData as McpError, Json, tool, tool_router, handler::server::wrapper::Parameters}; | ||
| use rust_i18n::t; | ||
| use schemars::JsonSchema; | ||
| use serde::{Deserialize, Serialize}; | ||
| use regex::RegexBuilder; | ||
| use tokio::task; | ||
|
|
||
| #[derive(Serialize, JsonSchema)] | ||
| pub struct FunctionListResult { | ||
| pub functions: Vec<FunctionDefinition>, | ||
| } | ||
|
|
||
| #[derive(Deserialize, JsonSchema)] | ||
| pub struct ListFunctionsRequest { | ||
| #[schemars(description = "Optional function name to filter the list. Supports wildcard patterns (*, ?)")] | ||
| pub function_name: Option<String>, | ||
| } | ||
|
|
||
| #[tool_router(router = list_dsc_functions_router, vis = "pub")] | ||
| impl McpServer { | ||
| #[tool( | ||
| description = "List available DSC functions to be used in expressions with optional filtering by name pattern", | ||
| annotations( | ||
| title = "Enumerate all available DSC functions on the local machine returning name, category, description, and metadata.", | ||
| read_only_hint = true, | ||
| destructive_hint = false, | ||
| idempotent_hint = true, | ||
| open_world_hint = true, | ||
| ) | ||
| )] | ||
| pub async fn list_dsc_functions(&self, Parameters(ListFunctionsRequest { function_name }): Parameters<ListFunctionsRequest>) -> Result<Json<FunctionListResult>, McpError> { | ||
| let result = task::spawn_blocking(move || { | ||
| let function_dispatcher = FunctionDispatcher::new(); | ||
| let mut functions = function_dispatcher.list(); | ||
|
|
||
| // apply filtering if function_name is provided | ||
| if let Some(name_pattern) = function_name { | ||
| let regex_str = convert_wildcard_to_regex(&name_pattern); | ||
| let mut regex_builder = RegexBuilder::new(®ex_str); | ||
| regex_builder.case_insensitive(true); | ||
|
|
||
| let regex = regex_builder.build() | ||
| .map_err(|_| McpError::invalid_params( | ||
| t!("mcp.list_dsc_functions.invalidNamePattern", pattern = name_pattern), | ||
| None | ||
| ))?; | ||
|
|
||
| functions.retain(|func| regex.is_match(&func.name)); | ||
| } | ||
|
|
||
| Ok(FunctionListResult { functions }) | ||
| }).await.map_err(|e| McpError::internal_error(e.to_string(), None))??; | ||
|
|
||
| Ok(Json(result)) | ||
| } | ||
| } | ||
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
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.