rmcp (the official MCP Rust SDK) deserializes tool arguments with serde and does not check them against the advertised schema. vld_web::rmcp validates them with a vld schema and, per MCP SEP-1303, returns a failure as a tool result with isError: true (not a protocol error), whose text is llm_feedback(), so the model can fix the call.
Install
[dependencies]
vld = "0.8"
vld-web = { version = "0.8", features = ["rmcp"] }
rmcp = { version = "3.11", features = ["server", "macros"] }
The feature enables vld/llm. rmcp 3 needs Rust 1.88.
| Item | What |
|---|---|
input_schema::<T>() | Arc<JsonObject> for #[tool(input_schema = ...)] / Tool::new: T's JSON Schema (draft 2020-12, nested types in $defs) |
VldParameters<T> | argument extractor (like rmcp's Parameters<T>); a failure becomes an isError result |
parse_args::<T>(JsonObject) | parse inside the tool, Result<T, VldToolError> |
VldToolError | IntoCallToolResult: isError: true, text = feedback lines, structuredContent = {"issues": [{path, expected, received, hint}]} |
Example
use rmcp::{handler::server::router::tool::ToolRouter, model::JsonObject, tool, tool_handler, tool_router, ServerHandler};
use vld_web::rmcp::{input_schema, parse_args, VldParameters, VldToolError};
vld::schema! {
#[derive(Debug)]
pub struct Forecast {
pub city: String => vld::string().min(2),
pub days: u8 => vld::u8().min(1).max(14),
}
}
#[derive(Clone)]
struct Weather { tool_router: ToolRouter<Self> }
#[tool_router]
impl Weather {
// Extractor: bad arguments never reach the body.
#[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)
}
// Parse in the body: the error result also carries structured issues.
#[tool(description = "Weather forecast", 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))
}
}
#[tool_handler(router = self.tool_router)]
impl ServerHandler for Weather {}
rmcp derives a tool's schema only for its own Parameters<T>, so set input_schema = input_schema::<T>() on tools that use VldParameters<T>; without it the tool advertises an empty object.
A call with {"city": "O", "days": 30} returns:
{
"isError": true,
"content": [{ "type": "text", "text": "city: expected string length >= 2, got \"O\"\ndays: expected number <= 14, got 30" }],
"structuredContent": { "issues": [
{ "path": "city", "expected": "expected string length >= 2", "received": "\"O\"", "hint": null },
{ "path": "days", "expected": "expected number <= 14", "received": "30", "hint": null }
]}
}
With VldParameters the text starts with failed to deserialize parameters: (rmcp's router turns that error into an isError result) and there is no structured content.