use crate::auditor::{AuditConfig, Auditor};
use crate::model::{AuditReport, Catalog, ToolHints, ToolSpec};
impl From<&rmcp::model::Tool> for ToolSpec {
fn from(tool: &rmcp::model::Tool) -> Self {
let annotations = tool.annotations.as_ref().map(|a| ToolHints {
title: a.title.clone(),
read_only_hint: a.read_only_hint,
destructive_hint: a.destructive_hint,
idempotent_hint: a.idempotent_hint,
open_world_hint: a.open_world_hint,
});
Self {
name: tool.name.to_string(),
title: tool.title.clone(),
description: tool.description.as_ref().map(|d| d.to_string()),
input_schema: (*tool.input_schema).clone(),
output_schema: tool.output_schema.as_ref().map(|s| (**s).clone()),
annotations,
source_location: None,
source_server: None,
}
}
}
impl From<rmcp::model::Tool> for ToolSpec {
fn from(tool: rmcp::model::Tool) -> Self {
ToolSpec::from(&tool)
}
}
impl Catalog {
pub fn from_rmcp<'a>(tools: impl IntoIterator<Item = &'a rmcp::model::Tool>) -> Self {
Self::new(tools.into_iter().map(ToolSpec::from))
}
}
#[must_use]
pub fn audit_rmcp(tools: &[rmcp::model::Tool]) -> AuditReport {
let catalog = Catalog::from_rmcp(tools);
Auditor::new(AuditConfig::default()).audit(&catalog)
}
pub fn assert_rmcp_tools_clean(tools: &[rmcp::model::Tool]) {
let report = audit_rmcp(tools);
assert!(
report.passed(),
"mcp-vol audit failed for rmcp tools:\n{}",
report.to_repair_plan().to_markdown()
);
}