Skip to main content

Module rmcp

Module rmcp 

Source
Expand description

rmcp (the MCP Rust SDK) tool arguments validated by vld.

rmcp deserializes tool arguments with serde and never checks them against the advertised schema. Here the arguments go through the vld schema, and a failure is returned as a tool result with isError: true whose text is VldError::llm_feedback (SEP-1303), so the model can correct the call.

ⓘ
use rmcp::{handler::server::router::tool::ToolRouter, model::JsonObject, tool, tool_router};
use vld_web::rmcp::{VldParameters, VldToolError, input_schema, parse_args};

vld::schema! {
    #[derive(Debug)]
    pub struct Forecast {
        pub city: String => vld::string().min(2),
        pub days: u8 => vld::u8().min(1).max(14),
    }
}

#[tool_router]
impl Weather {
    #[tool(description = "Weather forecast", input_schema = input_schema::<Forecast>())]
    async fn forecast(&self, VldParameters(f): VldParameters<Forecast>) -> String {
        format!("{} days in {}", f.days, f.city)
    }

    #[tool(description = "Same, parsed in the body", input_schema = input_schema::<Forecast>())]
    async fn forecast2(&self, args: JsonObject) -> Result<String, VldToolError> {
        let f: Forecast = parse_args(args)?;
        Ok(format!("{} days in {}", f.days, f.city))
    }
}

Structs§

VldParameters
Tool arguments validated by vld; a failure becomes an isError result with the feedback text. Set the tool’s schema with #[tool(input_schema = input_schema::<T>())] (rmcp derives it only for its own Parameters).
VldToolError
Validation failure of tool arguments, returned to the client as a tool result with isError: true: the text is the feedback lines, the structured content {"issues": [{path, expected, received, hint}]}.

Functions§

input_schema
The tool’s inputSchema: T’s JSON Schema (draft 2020-12, nested types in $defs), for #[tool(input_schema = input_schema::<T>())] or Tool::new.
parse_args
Parse tool arguments as T.