WS-F: MCP server with 8 tools, prompts, resources

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01YShymaPrXmc3KYRUg2HMSs
This commit is contained in:
ariandClaude Sonnet 5.5 committed 2026-10-15 18:33:15 -04:00
1 parent 2d57fb1a78
commit e96bd716a6
5 files changed
+685 -24

No files matched your search

+47
View File
@@ -0,0 +1,47 @@
//! MCP resources (WS-F). Resolved live on every read; not subscribable (DEC-5).
use rmcp::model::{ReadResourceResult, Resource, ResourceContents};
use crate::error::AppError;
use crate::state::AppState;
pub const FAILED_UNITS_URI: &str = "systemd://units/failed";
pub const CONTAINERS_URI: &str = "docker://containers";
/// Resources advertised by `resources/list`.
pub fn list() -> Vec<Resource> {
vec![
Resource::new(FAILED_UNITS_URI, "failed-units")
.with_title("Failed systemd units")
.with_description("Units currently in the failed active state.")
.with_mime_type("application/json"),
Resource::new(CONTAINERS_URI, "containers")
.with_title("Docker containers")
.with_description("All containers (running and stopped) with state and health.")
.with_mime_type("application/json"),
]
}
/// Read a resource by URI, querying the source on each call.
pub async fn read(state: &AppState, uri: &str) -> Result<ReadResourceResult, AppError> {
let json = match uri {
FAILED_UNITS_URI => {
let units = state.systemd.list_units(Some("failed")).await?;
serde_json::to_string_pretty(&units)
}
CONTAINERS_URI => {
let cs = state.docker.ps(true).await?;
serde_json::to_string_pretty(&cs)
}
other => return Err(AppError::NotFound(format!("unknown resource '{other}'"))),
}
.map_err(|e| AppError::Internal(e.to_string()))?;
Ok(ReadResourceResult::new(vec![
ResourceContents::TextResourceContents {
uri: uri.to_owned(),
mime_type: Some("application/json".into()),
text: json,
meta: None,
},
]))
}