33 lines
835 B
Rust
33 lines
835 B
Rust
use schemars::JsonSchema;
|
|
use serde_json::json;
|
|
|
|
pub fn success(id: serde_json::Value, result: serde_json::Value) -> serde_json::Value {
|
|
json!({
|
|
"jsonrpc": "2.0",
|
|
"id": id,
|
|
"result": result
|
|
})
|
|
}
|
|
|
|
pub fn error(id: serde_json::Value, code: i32, message: &str) -> serde_json::Value {
|
|
json!({
|
|
"jsonrpc": "2.0",
|
|
"id": id,
|
|
"error": {
|
|
"code": code,
|
|
"message": message
|
|
}
|
|
})
|
|
}
|
|
|
|
pub fn tool_def<T: JsonSchema>(name: &str, description: &str) -> serde_json::Value {
|
|
let schema = schemars::schema_for!(T);
|
|
let schema_val = serde_json::to_value(&schema).unwrap();
|
|
// MCP expects standard JSON schema. Schemars returns draft-07.
|
|
json!({
|
|
"name": name,
|
|
"description": description,
|
|
"inputSchema": schema_val
|
|
})
|
|
}
|