Skip to content

Commit d311aae

Browse files
authored
Merge pull request #1173 from Gijsreyn/gh-1093/main/invoke-mcp-delete
Add missing delete for MCP server invoke
2 parents 997c35f + 549e10a commit d311aae

File tree

3 files changed

+48
-3
lines changed

3 files changed

+48
-3
lines changed

dsc/src/mcp/invoke_dsc_resource.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ pub enum DscOperation {
2828
Set,
2929
Test,
3030
Export,
31+
Delete,
3132
}
3233

3334
#[derive(Serialize, JsonSchema)]
@@ -37,6 +38,7 @@ pub enum ResourceOperationResult {
3738
SetResult(SetResult),
3839
TestResult(TestResult),
3940
ExportResult(ExportResult),
41+
DeleteResult { success: bool },
4042
}
4143

4244
#[derive(Serialize, JsonSchema)]
@@ -57,9 +59,9 @@ pub struct InvokeDscResourceRequest {
5759
#[tool_router(router = invoke_dsc_resource_router, vis = "pub")]
5860
impl McpServer {
5961
#[tool(
60-
description = "Invoke a DSC resource operation (Get, Set, Test, Export) with specified properties in JSON format",
62+
description = "Invoke a DSC resource operation (Get, Set, Test, Export, Delete) with specified properties in JSON format",
6163
annotations(
62-
title = "Invoke a DSC resource operation (Get, Set, Test, Export) with specified properties in JSON format",
64+
title = "Invoke a DSC resource operation (Get, Set, Test, Export, Delete) with specified properties in JSON format",
6365
read_only_hint = false,
6466
destructive_hint = true,
6567
idempotent_hint = true,
@@ -94,6 +96,12 @@ impl McpServer {
9496
};
9597
Ok(ResourceOperationResult::TestResult(result))
9698
},
99+
DscOperation::Delete => {
100+
match resource.delete(&properties_json) {
101+
Ok(()) => Ok(ResourceOperationResult::DeleteResult { success: true }),
102+
Err(e) => Err(McpError::internal_error(e.to_string(), None)),
103+
}
104+
},
97105
DscOperation::Export => {
98106
let result = match resource.export(&properties_json) {
99107
Ok(res) => res,

dsc/tests/dsc_mcp.tests.ps1

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -306,7 +306,7 @@ Describe 'Tests for MCP server' {
306306
@{ operation = 'test'; property = 'desiredState' }
307307
@{ operation = 'export'; property = 'actualState' }
308308
) {
309-
param($operation)
309+
param($operation, $property)
310310

311311
$mcpRequest = @{
312312
jsonrpc = "2.0"
@@ -333,4 +333,30 @@ Describe 'Tests for MCP server' {
333333
$response.result.structuredContent.result.$property.action | Should -BeExactly $operation -Because $because
334334
$response.result.structuredContent.result.$property.hello | Should -BeExactly "World" -Because $because
335335
}
336+
337+
It 'Calling invoke_dsc_resource for delete operation' {
338+
$mcpRequest = @{
339+
jsonrpc = "2.0"
340+
id = 12
341+
method = "tools/call"
342+
params = @{
343+
name = "invoke_dsc_resource"
344+
arguments = @{
345+
type = 'Test/Operation'
346+
operation = 'delete'
347+
resource_type = 'Test/Operation'
348+
properties_json = (@{
349+
hello = "World"
350+
action = 'delete'
351+
} | ConvertTo-Json -Depth 20)
352+
}
353+
}
354+
}
355+
356+
$response = Send-McpRequest -request $mcpRequest
357+
$response.id | Should -Be 12
358+
$because = ($response | ConvertTo-Json -Depth 20 | Out-String)
359+
($response.result.structuredContent.psobject.properties | Measure-Object).Count | Should -Be 1 -Because $because
360+
$response.result.structuredContent.result.success | Should -Be $true -Because $because
361+
}
336362
}

tools/dsctest/dscoperation.dsc.resource.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,17 @@
3535
}
3636
]
3737
},
38+
"delete": {
39+
"executable": "dsctest",
40+
"args": [
41+
"operation",
42+
"--operation",
43+
"delete",
44+
{
45+
"jsonInputArg": "--input"
46+
}
47+
]
48+
},
3849
"export": {
3950
"executable": "dsctest",
4051
"args": [

0 commit comments

Comments
 (0)