fix: strip and validate tool outputSchema and inputSchema (#860)
* fix: remove unnecessary fields from tools' outputSchema * fix: validate input schema root type per MCP spec
This commit is contained in:
parent
8f558d83be
commit
254f04a764
1 changed files with 158 additions and 65 deletions
|
|
@ -1,6 +1,7 @@
|
|||
#![cfg(all(feature = "server", feature = "macros", not(feature = "local")))]
|
||||
|
||||
use rmcp::{
|
||||
Json,
|
||||
handler::server::wrapper::Parameters,
|
||||
model::{ListToolsResult, NumberOrString, ServerJsonRpcMessage, ServerResult},
|
||||
};
|
||||
|
|
@ -14,10 +15,17 @@ struct AddRequest {
|
|||
b: f64,
|
||||
}
|
||||
|
||||
/// Result of adding two numbers.
|
||||
#[derive(Debug, serde::Serialize, schemars::JsonSchema)]
|
||||
struct AddResult {
|
||||
/// The sum of the two numbers.
|
||||
sum: f64,
|
||||
}
|
||||
|
||||
/// Add two numbers.
|
||||
#[rmcp::tool]
|
||||
fn add(Parameters(AddRequest { a, b }): Parameters<AddRequest>) -> String {
|
||||
(a + b).to_string()
|
||||
fn add(Parameters(AddRequest { a, b }): Parameters<AddRequest>) -> Json<AddResult> {
|
||||
Json(AddResult { sum: a + b })
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
@ -27,7 +35,7 @@ fn list_tools_result_matches_expected_json() {
|
|||
let expected: serde_json::Value =
|
||||
serde_json::from_slice(&expected_json).expect("invalid expected JSON fixture");
|
||||
|
||||
assert_eq!(add(Parameters(AddRequest { a: 1.0, b: 2.0 })), "3");
|
||||
assert_eq!(add(Parameters(AddRequest { a: 1.0, b: 2.0 })).0.sum, 3.0);
|
||||
|
||||
let result = ListToolsResult::with_all_items(vec![add_tool_attr()]);
|
||||
let response = ServerJsonRpcMessage::response(
|
||||
|
|
|
|||
Loading…
Reference in a new issue