Repository navigation
Add Actions type of resource
#1734
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
Steve Lee (SteveL-MSFT)
wants to merge
24
commits into
PowerShell:main
Choose a base branch
from
SteveL-MSFT:actions
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 all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
a6d3f12
Add support for `Actions`
SteveL-MSFT 7f929a3
Implement action discovery
SteveL-MSFT 315cc5a
implement support for actions in configure get
SteveL-MSFT 08074e1
integrate actions into engine
SteveL-MSFT db3297e
fix loc and clippy
SteveL-MSFT bcc7ad2
Refactor DSC action descriptions and input validation
SteveL-MSFT 3c08323
address copilot feedback
SteveL-MSFT 7539cb9
refactor code to abstract actions and adapters as resources
SteveL-MSFT 16f42a4
Fix loc issues
SteveL-MSFT f955404
fix regression in detecting supporting filtering
SteveL-MSFT deccccc
Fix issue where adapter wasn't being found
SteveL-MSFT 131e08c
fix tests
SteveL-MSFT f818df7
Address PR feedback: action error handling, schema validation, locale…
SteveL-MSFT 6e96fd6
Don't write action input to stdin when passed via JSON arg
SteveL-MSFT cbc9d91
Allow discover extensions to return action manifests; scan action man…
SteveL-MSFT 4908805
Reuse already-loaded action schemas in list_dsc_actions
SteveL-MSFT 8847466
Add ActionManifest and DscAction imports
SteveL-MSFT 6124476
fix mishandling of path by making it an option
SteveL-MSFT 8824110
Address review: inline action directories, manifest lists, adapter re…
SteveL-MSFT 047be17
make action manifest directory option
SteveL-MSFT c0742c1
fix dscaction path allowed ot be Option
SteveL-MSFT ac3a58b
fix so dscresource path/directory is option
SteveL-MSFT fa7bed2
address copilot feedback
SteveL-MSFT c52670e
address copilot feedback
SteveL-MSFT 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
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
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,73 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
|
|
||
| use crate::server::mcp_server::McpServer; | ||
| use dsc_lib::{ | ||
| DscManager, configure::config_doc::ExecutionKind, | ||
| discovery::{ | ||
| discovery_trait::DiscoveryFilter, | ||
| ResourceKind, | ||
| }, | ||
| types::FullyQualifiedTypeName | ||
| }; | ||
| 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 serde_json::Value; | ||
| use tokio::task; | ||
|
|
||
| #[derive(Serialize, JsonSchema)] | ||
| pub struct InvokeDscActionResponse { | ||
| pub result: Value, | ||
| } | ||
|
|
||
| #[derive(Deserialize, JsonSchema)] | ||
| pub struct InvokeDscActionRequest { | ||
| #[schemars(description = "The type name of the DSC action to invoke")] | ||
| pub r#type: FullyQualifiedTypeName, | ||
| #[schemars(description = "The properties to pass to the DSC action as JSON. Must match the input schema from `show_dsc_action` tool.")] | ||
| pub properties_json: Option<String>, | ||
| #[schemars(description = "When true, request what-if (dry-run) execution. Only valid for actions that declare what-if support; otherwise the invocation fails.")] | ||
| #[serde(default)] | ||
| pub what_if: Option<bool>, | ||
| } | ||
|
|
||
| #[tool_router(router = invoke_dsc_action_router, vis = "pub")] | ||
| impl McpServer { | ||
| #[tool( | ||
| description = "Invoke a DSC action with specified properties in JSON format. Set 'what_if' to true to request what-if execution when supported.", | ||
| annotations( | ||
| title = "Invoke a DSC action with specified properties and optional what-if execution", | ||
| read_only_hint = false, | ||
| destructive_hint = true, | ||
| idempotent_hint = false, | ||
| open_world_hint = true, | ||
| ) | ||
| )] | ||
| pub async fn invoke_dsc_action(&self, Parameters(InvokeDscActionRequest { r#type: type_name, properties_json, what_if }): Parameters<InvokeDscActionRequest>) -> Result<Json<InvokeDscActionResponse>, McpError> { | ||
| let result = task::spawn_blocking(move || { | ||
| let execution_kind = match what_if { | ||
| Some(true) => ExecutionKind::WhatIf, | ||
| _ => ExecutionKind::Actual, | ||
| }; | ||
| let mut dsc = DscManager::new(); | ||
| let Some(resource) = dsc.find_resource(&DiscoveryFilter::new(&type_name, None, None)).unwrap_or(None) else { | ||
| return Err(McpError::invalid_request(t!("server.invoke_dsc_action.actionNotFound", resource = type_name), None)); | ||
| }; | ||
| if resource.kind() != ResourceKind::Action { | ||
| return Err(McpError::invalid_request(t!("server.invoke_dsc_action.resourceNotSupported", resource = type_name), None)); | ||
| } | ||
| let input = match properties_json { | ||
| Some(json) => json, | ||
| None => "".to_string(), | ||
| }; | ||
| match resource.invoke(&input, &execution_kind) { | ||
| Ok(result) => Ok(result), | ||
| Err(e) => Err(McpError::internal_error(e.to_string(), None)), | ||
| } | ||
| }).await.map_err(|e| McpError::internal_error(e.to_string(), None))??; | ||
|
|
||
| Ok(Json(InvokeDscActionResponse { 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
Oops, something went wrong.
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.