diff --git a/Cargo.toml b/Cargo.toml index 1faa043a..317e479b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,4 +1,4 @@ -cargo-features = ["edition2024"] + [workspace] members = ["crates/rmcp", "crates/rmcp-macros", "examples/*"] diff --git a/crates/rmcp-macros/Cargo.toml b/crates/rmcp-macros/Cargo.toml index 9a277ffe..3f46bdf1 100644 --- a/crates/rmcp-macros/Cargo.toml +++ b/crates/rmcp-macros/Cargo.toml @@ -1,4 +1,4 @@ -cargo-features = ["edition2024"] + [package] name = "rmcp-macros" diff --git a/crates/rmcp-macros/src/tool.rs b/crates/rmcp-macros/src/tool.rs index 09b124df..feed5350 100644 --- a/crates/rmcp-macros/src/tool.rs +++ b/crates/rmcp-macros/src/tool.rs @@ -347,7 +347,7 @@ pub(crate) fn tool_fn_item(attr: TokenStream, mut input_fn: ItemFn) -> syn::Resu #input_fn_vis fn #tool_attr_fn_ident() -> rmcp::model::Tool { rmcp::model::Tool { name: #name.into(), - description: #description.into(), + description: Some(#description.into()), input_schema: #schema.into(), } } diff --git a/crates/rmcp/Cargo.toml b/crates/rmcp/Cargo.toml index ed426a0f..e8b95120 100644 --- a/crates/rmcp/Cargo.toml +++ b/crates/rmcp/Cargo.toml @@ -1,4 +1,4 @@ -cargo-features = ["edition2024"] + [package] name = "rmcp" @@ -95,5 +95,5 @@ path = "tests/test_with_python.rs" [[test]] name = "test_with_js" -required-features = ["server", "transport-sse-server"] +required-features = ["server", "client", "transport-sse-server", "transport-child-process"] path = "tests/test_with_js.rs" \ No newline at end of file diff --git a/crates/rmcp/src/model/tool.rs b/crates/rmcp/src/model/tool.rs index 864a30aa..cb3e359b 100644 --- a/crates/rmcp/src/model/tool.rs +++ b/crates/rmcp/src/model/tool.rs @@ -14,7 +14,8 @@ pub struct Tool { /// The name of the tool pub name: Cow<'static, str>, /// A description of what the tool does - pub description: Cow<'static, str>, + #[serde(skip_serializing_if = "Option::is_none")] + pub description: Option>, /// A JSON Schema object defining the expected parameters for the tool pub input_schema: Arc, } @@ -29,7 +30,7 @@ impl Tool { { Tool { name: name.into(), - description: description.into(), + description: Some(description.into()), input_schema: input_schema.into(), } } diff --git a/crates/rmcp/tests/test_deserialization.rs b/crates/rmcp/tests/test_deserialization.rs new file mode 100644 index 00000000..73621f48 --- /dev/null +++ b/crates/rmcp/tests/test_deserialization.rs @@ -0,0 +1,15 @@ +use rmcp::model::{JsonRpcResponse, ServerJsonRpcMessage, ServerResult}; +#[test] +fn test_tool_list_result() { + let json = std::fs::read("tests/test_deserialization/tool_list_result.json").unwrap(); + let result: ServerJsonRpcMessage = serde_json::from_slice(&json).unwrap(); + println!("{result:#?}"); + + assert!(matches!( + result, + ServerJsonRpcMessage::Response(JsonRpcResponse { + result: ServerResult::ListToolsResult(_), + .. + }) + )); +} diff --git a/crates/rmcp/tests/test_deserialization/tool_list_result.json b/crates/rmcp/tests/test_deserialization/tool_list_result.json new file mode 100644 index 00000000..674fdc05 --- /dev/null +++ b/crates/rmcp/tests/test_deserialization/tool_list_result.json @@ -0,0 +1,28 @@ +{ + "result": { + "tools": [ + { + "name": "add", + "inputSchema": { + "type": "object", + "properties": { + "a": { + "type": "number" + }, + "b": { + "type": "number" + } + }, + "required": [ + "a", + "b" + ], + "additionalProperties": false, + "$schema": "http://json-schema.org/draft-07/schema#" + } + } + ] + }, + "jsonrpc": "2.0", + "id": 2 +} \ No newline at end of file diff --git a/crates/rmcp/tests/test_with_js.rs b/crates/rmcp/tests/test_with_js.rs index fdc54d98..f5431bee 100644 --- a/crates/rmcp/tests/test_with_js.rs +++ b/crates/rmcp/tests/test_with_js.rs @@ -10,13 +10,13 @@ const BIND_ADDRESS: &str = "127.0.0.1:8000"; #[tokio::test] async fn test_with_js_client() -> anyhow::Result<()> { - tracing_subscriber::registry() + let _ = tracing_subscriber::registry() .with( tracing_subscriber::EnvFilter::try_from_default_env() .unwrap_or_else(|_| "debug".to_string().into()), ) .with(tracing_subscriber::fmt::layer()) - .init(); + .try_init(); tokio::process::Command::new("npm") .arg("install") .current_dir("tests/test_with_js") diff --git a/examples/clients/Cargo.toml b/examples/clients/Cargo.toml index d9c5640f..1cec3a2b 100644 --- a/examples/clients/Cargo.toml +++ b/examples/clients/Cargo.toml @@ -1,4 +1,4 @@ -cargo-features = ["edition2024"] + [package] name = "mcp-client-examples" diff --git a/examples/rig-integration/Cargo.toml b/examples/rig-integration/Cargo.toml index 9c21eb7c..e630bfa0 100644 --- a/examples/rig-integration/Cargo.toml +++ b/examples/rig-integration/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["edition2024"] - [package] name = "rig-integration" edition = { workspace = true } diff --git a/examples/rig-integration/src/mcp_adaptor.rs b/examples/rig-integration/src/mcp_adaptor.rs index 9f2a0dc6..6beb9aa5 100644 --- a/examples/rig-integration/src/mcp_adaptor.rs +++ b/examples/rig-integration/src/mcp_adaptor.rs @@ -1,6 +1,6 @@ use std::collections::HashMap; -use rig::tool::{ToolDyn as RigTool, ToolEmbeddingDyn, ToolSet}; +use rig::tool::{ToolDyn as RigTool, ToolSet}; use rmcp::{ RoleClient, model::{CallToolRequestParam, CallToolResult, Tool as McpTool}, @@ -24,7 +24,12 @@ impl RigTool for McpToolAdaptor { { Box::pin(std::future::ready(rig::completion::ToolDefinition { name: self.name(), - description: self.tool.description.to_string(), + description: self + .tool + .description + .as_deref() + .unwrap_or_default() + .to_string(), parameters: self.tool.schema_as_json_value(), })) } @@ -51,22 +56,6 @@ impl RigTool for McpToolAdaptor { } } -impl ToolEmbeddingDyn for McpToolAdaptor { - fn embedding_docs(&self) -> Vec { - vec![ - self.tool.description.clone().to_string(), - format!("Tool name: {}", self.tool.name), - format!("Tool capability: {}", self.tool.description), - ] - } - - fn context(&self) -> serde_json::Result { - Ok(serde_json::json!({ - "tool_name": self.tool.name, - })) - } -} - pub struct McpManager { pub clients: HashMap>, } diff --git a/examples/servers/Cargo.toml b/examples/servers/Cargo.toml index 4973871b..01569b88 100644 --- a/examples/servers/Cargo.toml +++ b/examples/servers/Cargo.toml @@ -1,4 +1,4 @@ -cargo-features = ["edition2024"] + [package] name = "mcp-server-examples" diff --git a/examples/transport/Cargo.toml b/examples/transport/Cargo.toml index 5c9dc9c0..06708bb9 100644 --- a/examples/transport/Cargo.toml +++ b/examples/transport/Cargo.toml @@ -1,5 +1,3 @@ -cargo-features = ["edition2024"] - [package] name = "transport" edition = { workspace = true } diff --git a/examples/wasi/Cargo.toml b/examples/wasi/Cargo.toml index 4daa1a3e..bf9b948a 100644 --- a/examples/wasi/Cargo.toml +++ b/examples/wasi/Cargo.toml @@ -1,4 +1,4 @@ -cargo-features = ["edition2024"] + [package] name = "wasi"