Implements outputSchema validation (#566)
* feat: implement output schema validation * fix: calculator example comply MCP spec * refactor: merge cached_schema_for_output into schema_for_output
This commit is contained in:
parent
3c62ee8952
commit
df84555065
3 changed files with 122 additions and 10 deletions
|
|
@ -96,3 +96,7 @@ path = "src/simple_auth_streamhttp.rs"
|
|||
[[example]]
|
||||
name = "servers_complex_auth_streamhttp"
|
||||
path = "src/complex_auth_streamhttp.rs"
|
||||
|
||||
[[example]]
|
||||
name = "servers_calculator_stdio"
|
||||
path = "src/calculator_stdio.rs"
|
||||
|
|
|
|||
26
examples/servers/src/calculator_stdio.rs
Normal file
26
examples/servers/src/calculator_stdio.rs
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
use anyhow::Result;
|
||||
use common::calculator::Calculator;
|
||||
use rmcp::{ServiceExt, transport::stdio};
|
||||
use tracing_subscriber::{self, EnvFilter};
|
||||
mod common;
|
||||
|
||||
/// npx @modelcontextprotocol/inspector cargo run -p mcp-server-examples --example servers_calculator_stdio
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<()> {
|
||||
// Initialize the tracing subscriber with file and stdout logging
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(EnvFilter::from_default_env().add_directive(tracing::Level::DEBUG.into()))
|
||||
.with_writer(std::io::stderr)
|
||||
.with_ansi(false)
|
||||
.init();
|
||||
|
||||
tracing::info!("Starting Calculator MCP server");
|
||||
|
||||
// Create an instance of our calculator router
|
||||
let service = Calculator::new().serve(stdio()).await.inspect_err(|e| {
|
||||
tracing::error!("serving error: {:?}", e);
|
||||
})?;
|
||||
|
||||
service.waiting().await?;
|
||||
Ok(())
|
||||
}
|
||||
|
|
@ -2,10 +2,7 @@
|
|||
|
||||
use rmcp::{
|
||||
ServerHandler,
|
||||
handler::server::{
|
||||
router::tool::ToolRouter,
|
||||
wrapper::{Json, Parameters},
|
||||
},
|
||||
handler::server::{router::tool::ToolRouter, wrapper::Parameters},
|
||||
model::{ServerCapabilities, ServerInfo},
|
||||
schemars, tool, tool_handler, tool_router,
|
||||
};
|
||||
|
|
@ -44,8 +41,8 @@ impl Calculator {
|
|||
}
|
||||
|
||||
#[tool(description = "Calculate the difference of two numbers")]
|
||||
fn sub(&self, Parameters(SubRequest { a, b }): Parameters<SubRequest>) -> Json<i32> {
|
||||
Json(a - b)
|
||||
fn sub(&self, Parameters(SubRequest { a, b }): Parameters<SubRequest>) -> String {
|
||||
(a - b).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue