Skip to content

Commit ededda3

Browse files
committed
fix query and add tests
1 parent c6ebafd commit ededda3

File tree

2 files changed

+101
-1
lines changed

2 files changed

+101
-1
lines changed

dsc/src/mcp/list_resources.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ impl McpServer {
4343
let result = task::spawn_blocking(move || {
4444
let mut dsc = DscManager::new();
4545
let mut resources = Vec::new();
46-
for resource in dsc.list_available(&DiscoveryKind::Resource, "*", "*", ProgressFormat::None) {
46+
for resource in dsc.list_available(&DiscoveryKind::Resource, "*", "", ProgressFormat::None) {
4747
resources.push(resource);
4848
}
4949
ResourceListResult { resources }

dsc/tests/dsc_mcp.tests.ps1

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# Copyright (c) Microsoft Corporation.
2+
# Licensed under the MIT License.
3+
4+
Describe 'Tests for MCP server' {
5+
BeforeAll {
6+
$processStartInfo = [System.Diagnostics.ProcessStartInfo]::new()
7+
$processStartInfo.FileName = "dsc"
8+
$processStartInfo.Arguments = "--trace-format plaintext mcp"
9+
$processStartInfo.RedirectStandardError = $true
10+
$processStartInfo.RedirectStandardOutput = $true
11+
$processStartInfo.RedirectStandardInput = $true
12+
$mcp = [System.Diagnostics.Process]::Start($processStartInfo)
13+
14+
function Send-McpRequest($request, [switch]$notify) {
15+
$request = $request | ConvertTo-Json -Compress -Depth 10
16+
$mcp.StandardInput.WriteLine($request)
17+
$mcp.StandardInput.Flush()
18+
if (!$notify) {
19+
while ($mcp.StandardOutput.Peek() -eq -1) {
20+
Start-Sleep -Milliseconds 100
21+
}
22+
$stdout = $mcp.StandardOutput.ReadLine()
23+
return ($stdout | ConvertFrom-Json -Depth 30)
24+
}
25+
}
26+
}
27+
28+
AfterAll {
29+
$mcp.StandardInput.Close()
30+
$mcp.WaitForExit()
31+
}
32+
33+
It 'Initialization works' {
34+
$mcpRequest = @{
35+
jsonrpc = "2.0"
36+
id = 1
37+
method = "initialize"
38+
params = @{
39+
protocolVersion = "2024-11-05"
40+
capabilities = @{
41+
tools = @{}
42+
}
43+
clientInfo = @{
44+
name = "Test Client"
45+
version = "1.0.0"
46+
}
47+
}
48+
}
49+
50+
$response = Send-McpRequest -request $mcpRequest
51+
52+
$response.id | Should -Be 1
53+
$response.result.capabilities.tools | Should -Not -Be $null
54+
$response.result.instructions | Should -Not -BeNullOrEmpty
55+
56+
$notifyInitialized = @{
57+
jsonrpc = "2.0"
58+
method = "notifications/initialized"
59+
}
60+
61+
Send-McpRequest -request $notifyInitialized -notify
62+
}
63+
64+
It 'Tools/List works' {
65+
$mcpRequest = @{
66+
jsonrpc = "2.0"
67+
id = 2
68+
method = "tools/list"
69+
params = @{}
70+
}
71+
72+
$response = Send-McpRequest -request $mcpRequest
73+
74+
$response.id | Should -Be 2
75+
$response.result.tools.Count | Should -Be 1
76+
$response.result.tools[0].name | Should -BeExactly 'list_resources'
77+
}
78+
79+
It 'Calling list_resources works' {
80+
$mcpRequest = @{
81+
jsonrpc = "2.0"
82+
id = 3
83+
method = "tools/call"
84+
params = @{
85+
name = "list_resources"
86+
arguments = @{}
87+
}
88+
}
89+
90+
$response = Send-McpRequest -request $mcpRequest
91+
$response.id | Should -Be 3
92+
$resources = dsc resource list | ConvertFrom-Json -Depth 20
93+
$response.result.structuredContent.resources.Count | Should -Be $resources.Count
94+
for ($i = 0; $i -lt $resources.Count; $i++) {
95+
$response.result.structuredContent.resources[$i].Resource.type | Should -BeExactly $resources[$i].type
96+
$response.result.structuredContent.resources[$i].Resource.version | Should -BeExactly $resources[$i].version
97+
$response.result.structuredContent.resources[$i].Resource.path | Should -BeExactly $resources[$i].path
98+
}
99+
}
100+
}

0 commit comments

Comments
 (0)