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
23
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.
+2,369
−592
Open
Changes from 13 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
ea43ae9
Add support for `Actions`
SteveL-MSFT d478e5b
Implement action discovery
SteveL-MSFT 46d07e1
implement support for actions in configure get
SteveL-MSFT 2b5d5fe
integrate actions into engine
SteveL-MSFT f2cad19
fix loc and clippy
SteveL-MSFT 66aeef7
Refactor DSC action descriptions and input validation
SteveL-MSFT 14c6a8d
address copilot feedback
SteveL-MSFT d65df71
refactor code to abstract actions and adapters as resources
SteveL-MSFT b0a1e2a
Fix loc issues
SteveL-MSFT f9091e9
fix regression in detecting supporting filtering
SteveL-MSFT 2b84ccf
Fix issue where adapter wasn't being found
SteveL-MSFT 83de1eb
fix tests
SteveL-MSFT fa0d286
Address PR feedback: action error handling, schema validation, locale…
SteveL-MSFT 45fdbc2
Don't write action input to stdin when passed via JSON arg
SteveL-MSFT 78fec92
Allow discover extensions to return action manifests; scan action man…
SteveL-MSFT 20d218a
Reuse already-loaded action schemas in list_dsc_actions
SteveL-MSFT 78e6e50
Add ActionManifest and DscAction imports
SteveL-MSFT a8f8a7a
fix mishandling of path by making it an option
SteveL-MSFT 687a354
Address review: inline action directories, manifest lists, adapter re…
SteveL-MSFT be1de15
Merge branch 'actions' of https://github.com/PowerShell/DSC into actions
SteveL-MSFT 29a6301
make action manifest directory option
SteveL-MSFT b8eb5f2
fix dscaction path allowed ot be Option
SteveL-MSFT 05ca910
fix so dscresource path/directory is option
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 = true, | ||
| 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.