|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT License. |
| 3 | + |
| 4 | +use crate::mcp::McpServer; |
| 5 | +use dsc_lib::{ |
| 6 | + DscManager, |
| 7 | + discovery::{ |
| 8 | + command_discovery::ImportedManifest, |
| 9 | + discovery_trait::DiscoveryKind, |
| 10 | + }, |
| 11 | + progress::ProgressFormat, |
| 12 | +}; |
| 13 | +use rmcp::{ErrorData as McpError, Json, tool, tool_router}; |
| 14 | +use schemars::JsonSchema; |
| 15 | +use serde::{Serialize, Deserialize}; |
| 16 | +use tokio::task; |
| 17 | + |
| 18 | +#[derive(Serialize, Deserialize, JsonSchema)] |
| 19 | +pub struct ResourceListResult { |
| 20 | + pub resources: Vec<ImportedManifest>, |
| 21 | +} |
| 22 | + |
| 23 | +#[tool_router] |
| 24 | +impl McpServer { |
| 25 | + #[must_use] |
| 26 | + pub fn new() -> Self { |
| 27 | + Self { |
| 28 | + tool_router: Self::tool_router() |
| 29 | + } |
| 30 | + } |
| 31 | + |
| 32 | + #[tool( |
| 33 | + description = "List all DSC resources available on the local machine", |
| 34 | + annotations( |
| 35 | + title = "Enumerate all available DSC resources on the local machine", |
| 36 | + read_only_hint = true, |
| 37 | + destructive_hint = false, |
| 38 | + idempotent_hint = true, |
| 39 | + open_world_hint = true, |
| 40 | + ) |
| 41 | + )] |
| 42 | + async fn list_resources(&self) -> Result<Json<ResourceListResult>, McpError> { |
| 43 | + let result = task::spawn_blocking(move || { |
| 44 | + let mut dsc = DscManager::new(); |
| 45 | + let mut resources = Vec::new(); |
| 46 | + for resource in dsc.list_available(&DiscoveryKind::Resource, "*", "*", ProgressFormat::None) { |
| 47 | + resources.push(resource); |
| 48 | + } |
| 49 | + ResourceListResult { resources } |
| 50 | + }).await.map_err(|e| McpError::internal_error(e.to_string(), None))?; |
| 51 | + |
| 52 | + Ok(Json(result)) |
| 53 | + } |
| 54 | +} |
0 commit comments