3
3
4
4
use crate :: mcp:: McpServer ;
5
5
use dsc_lib:: {
6
- DscManager ,
7
- discovery:: {
8
- command_discovery:: ImportedManifest ,
6
+ DscManager , discovery:: {
7
+ command_discovery:: ImportedManifest :: Resource ,
9
8
discovery_trait:: DiscoveryKind ,
10
- } ,
11
- progress:: ProgressFormat ,
9
+ } , dscresources:: resource_manifest:: Kind , progress:: ProgressFormat
12
10
} ;
13
11
use rmcp:: { ErrorData as McpError , Json , tool, tool_router} ;
14
12
use schemars:: JsonSchema ;
15
- use serde:: { Serialize , Deserialize } ;
13
+ use serde:: Serialize ;
14
+ use std:: collections:: BTreeMap ;
16
15
use tokio:: task;
17
16
18
- #[ derive( Serialize , Deserialize , JsonSchema ) ]
17
+ #[ derive( Serialize , JsonSchema ) ]
19
18
pub struct ResourceListResult {
20
- pub resources : Vec < ImportedManifest > ,
19
+ pub resources : Vec < ResourceSummary > ,
20
+ }
21
+
22
+ #[ derive( Serialize , JsonSchema ) ]
23
+ pub struct ResourceSummary {
24
+ pub r#type : String ,
25
+ pub kind : Kind ,
26
+ pub description : Option < String > ,
21
27
}
22
28
23
29
#[ tool_router]
@@ -30,9 +36,9 @@ impl McpServer {
30
36
}
31
37
32
38
#[ tool(
33
- description = "List all DSC resources available on the local machine" ,
39
+ description = "List summary of all DSC resources available on the local machine" ,
34
40
annotations(
35
- title = "Enumerate all available DSC resources on the local machine" ,
41
+ title = "Enumerate all available DSC resources on the local machine returning name, kind, and description. " ,
36
42
read_only_hint = true ,
37
43
destructive_hint = false ,
38
44
idempotent_hint = true ,
@@ -42,11 +48,18 @@ impl McpServer {
42
48
async fn list_dsc_resources ( & self ) -> Result < Json < ResourceListResult > , McpError > {
43
49
let result = task:: spawn_blocking ( move || {
44
50
let mut dsc = DscManager :: new ( ) ;
45
- let mut resources = Vec :: new ( ) ;
51
+ let mut resources = BTreeMap :: < String , ResourceSummary > :: new ( ) ;
46
52
for resource in dsc. list_available ( & DiscoveryKind :: Resource , "*" , "" , ProgressFormat :: None ) {
47
- resources. push ( resource) ;
53
+ if let Resource ( resource) = resource {
54
+ let summary = ResourceSummary {
55
+ r#type : resource. type_name . clone ( ) ,
56
+ kind : resource. kind . clone ( ) ,
57
+ description : resource. description . clone ( ) ,
58
+ } ;
59
+ resources. insert ( resource. type_name . to_lowercase ( ) , summary) ;
60
+ }
48
61
}
49
- ResourceListResult { resources }
62
+ ResourceListResult { resources : resources . into_values ( ) . collect ( ) }
50
63
} ) . await . map_err ( |e| McpError :: internal_error ( e. to_string ( ) , None ) ) ?;
51
64
52
65
Ok ( Json ( result) )
0 commit comments