Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 10 additions & 2 deletions dsc/src/mcp/invoke_dsc_resource.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub enum DscOperation {
Set,
Test,
Export,
Delete,
}

#[derive(Serialize, JsonSchema)]
Expand All @@ -37,6 +38,7 @@ pub enum ResourceOperationResult {
SetResult(SetResult),
TestResult(TestResult),
ExportResult(ExportResult),
DeleteResult { success: bool },
}

#[derive(Serialize, JsonSchema)]
Expand All @@ -57,9 +59,9 @@ pub struct InvokeDscResourceRequest {
#[tool_router(router = invoke_dsc_resource_router, vis = "pub")]
impl McpServer {
#[tool(
description = "Invoke a DSC resource operation (Get, Set, Test, Export) with specified properties in JSON format",
description = "Invoke a DSC resource operation (Get, Set, Test, Export, Delete) with specified properties in JSON format",
annotations(
title = "Invoke a DSC resource operation (Get, Set, Test, Export) with specified properties in JSON format",
title = "Invoke a DSC resource operation (Get, Set, Test, Export, Delete) with specified properties in JSON format",
read_only_hint = false,
destructive_hint = true,
idempotent_hint = true,
Expand Down Expand Up @@ -94,6 +96,12 @@ impl McpServer {
};
Ok(ResourceOperationResult::TestResult(result))
},
DscOperation::Delete => {
match resource.delete(&properties_json) {
Ok(()) => Ok(ResourceOperationResult::DeleteResult { success: true }),
Err(e) => Err(McpError::internal_error(e.to_string(), None)),
}
},
DscOperation::Export => {
let result = match resource.export(&properties_json) {
Ok(res) => res,
Expand Down
28 changes: 27 additions & 1 deletion dsc/tests/dsc_mcp.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,7 @@ Describe 'Tests for MCP server' {
@{ operation = 'test'; property = 'desiredState' }
@{ operation = 'export'; property = 'actualState' }
) {
param($operation)
param($operation, $property)

$mcpRequest = @{
jsonrpc = "2.0"
Expand All @@ -333,4 +333,30 @@ Describe 'Tests for MCP server' {
$response.result.structuredContent.result.$property.action | Should -BeExactly $operation -Because $because
$response.result.structuredContent.result.$property.hello | Should -BeExactly "World" -Because $because
}

It 'Calling invoke_dsc_resource for delete operation' {
$mcpRequest = @{
jsonrpc = "2.0"
id = 12
method = "tools/call"
params = @{
name = "invoke_dsc_resource"
arguments = @{
type = 'Test/Operation'
operation = 'delete'
resource_type = 'Test/Operation'
properties_json = (@{
hello = "World"
action = 'delete'
} | ConvertTo-Json -Depth 20)
}
}
}

$response = Send-McpRequest -request $mcpRequest
$response.id | Should -Be 12
$because = ($response | ConvertTo-Json -Depth 20 | Out-String)
($response.result.structuredContent.psobject.properties | Measure-Object).Count | Should -Be 1 -Because $because
$response.result.structuredContent.result.success | Should -Be $true -Because $because
}
}
11 changes: 11 additions & 0 deletions tools/dsctest/dscoperation.dsc.resource.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,17 @@
}
]
},
"delete": {
"executable": "dsctest",
"args": [
"operation",
"--operation",
"delete",
{
"jsonInputArg": "--input"
}
]
},
"export": {
"executable": "dsctest",
"args": [
Expand Down