Skip to content

Commit 0eea9aa

Browse files
authored
fix(test): fix tool deserialization error (modelcontextprotocol#68)
1 parent ac1b8c6 commit 0eea9aa

File tree

14 files changed

+63
-34
lines changed

14 files changed

+63
-34
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[workspace]
44
members = ["crates/rmcp", "crates/rmcp-macros", "examples/*"]

crates/rmcp-macros/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[package]
44
name = "rmcp-macros"

crates/rmcp-macros/src/tool.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub(crate) fn tool_fn_item(attr: TokenStream, mut input_fn: ItemFn) -> syn::Resu
347347
#input_fn_vis fn #tool_attr_fn_ident() -> rmcp::model::Tool {
348348
rmcp::model::Tool {
349349
name: #name.into(),
350-
description: #description.into(),
350+
description: Some(#description.into()),
351351
input_schema: #schema.into(),
352352
}
353353
}

crates/rmcp/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[package]
44
name = "rmcp"
@@ -95,5 +95,5 @@ path = "tests/test_with_python.rs"
9595

9696
[[test]]
9797
name = "test_with_js"
98-
required-features = ["server", "transport-sse-server"]
98+
required-features = ["server", "client", "transport-sse-server", "transport-child-process"]
9999
path = "tests/test_with_js.rs"

crates/rmcp/src/model/tool.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,8 @@ pub struct Tool {
1414
/// The name of the tool
1515
pub name: Cow<'static, str>,
1616
/// A description of what the tool does
17-
pub description: Cow<'static, str>,
17+
#[serde(skip_serializing_if = "Option::is_none")]
18+
pub description: Option<Cow<'static, str>>,
1819
/// A JSON Schema object defining the expected parameters for the tool
1920
pub input_schema: Arc<JsonObject>,
2021
}
@@ -29,7 +30,7 @@ impl Tool {
2930
{
3031
Tool {
3132
name: name.into(),
32-
description: description.into(),
33+
description: Some(description.into()),
3334
input_schema: input_schema.into(),
3435
}
3536
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
use rmcp::model::{JsonRpcResponse, ServerJsonRpcMessage, ServerResult};
2+
#[test]
3+
fn test_tool_list_result() {
4+
let json = std::fs::read("tests/test_deserialization/tool_list_result.json").unwrap();
5+
let result: ServerJsonRpcMessage = serde_json::from_slice(&json).unwrap();
6+
println!("{result:#?}");
7+
8+
assert!(matches!(
9+
result,
10+
ServerJsonRpcMessage::Response(JsonRpcResponse {
11+
result: ServerResult::ListToolsResult(_),
12+
..
13+
})
14+
));
15+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{
2+
"result": {
3+
"tools": [
4+
{
5+
"name": "add",
6+
"inputSchema": {
7+
"type": "object",
8+
"properties": {
9+
"a": {
10+
"type": "number"
11+
},
12+
"b": {
13+
"type": "number"
14+
}
15+
},
16+
"required": [
17+
"a",
18+
"b"
19+
],
20+
"additionalProperties": false,
21+
"$schema": "http://json-schema.org/draft-07/schema#"
22+
}
23+
}
24+
]
25+
},
26+
"jsonrpc": "2.0",
27+
"id": 2
28+
}

crates/rmcp/tests/test_with_js.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,13 @@ const BIND_ADDRESS: &str = "127.0.0.1:8000";
1010

1111
#[tokio::test]
1212
async fn test_with_js_client() -> anyhow::Result<()> {
13-
tracing_subscriber::registry()
13+
let _ = tracing_subscriber::registry()
1414
.with(
1515
tracing_subscriber::EnvFilter::try_from_default_env()
1616
.unwrap_or_else(|_| "debug".to_string().into()),
1717
)
1818
.with(tracing_subscriber::fmt::layer())
19-
.init();
19+
.try_init();
2020
tokio::process::Command::new("npm")
2121
.arg("install")
2222
.current_dir("tests/test_with_js")

examples/clients/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[package]
44
name = "mcp-client-examples"

examples/rig-integration/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["edition2024"]
2-
31
[package]
42
name = "rig-integration"
53
edition = { workspace = true }

examples/rig-integration/src/mcp_adaptor.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use std::collections::HashMap;
22

3-
use rig::tool::{ToolDyn as RigTool, ToolEmbeddingDyn, ToolSet};
3+
use rig::tool::{ToolDyn as RigTool, ToolSet};
44
use rmcp::{
55
RoleClient,
66
model::{CallToolRequestParam, CallToolResult, Tool as McpTool},
@@ -24,7 +24,12 @@ impl RigTool for McpToolAdaptor {
2424
{
2525
Box::pin(std::future::ready(rig::completion::ToolDefinition {
2626
name: self.name(),
27-
description: self.tool.description.to_string(),
27+
description: self
28+
.tool
29+
.description
30+
.as_deref()
31+
.unwrap_or_default()
32+
.to_string(),
2833
parameters: self.tool.schema_as_json_value(),
2934
}))
3035
}
@@ -51,22 +56,6 @@ impl RigTool for McpToolAdaptor {
5156
}
5257
}
5358

54-
impl ToolEmbeddingDyn for McpToolAdaptor {
55-
fn embedding_docs(&self) -> Vec<String> {
56-
vec![
57-
self.tool.description.clone().to_string(),
58-
format!("Tool name: {}", self.tool.name),
59-
format!("Tool capability: {}", self.tool.description),
60-
]
61-
}
62-
63-
fn context(&self) -> serde_json::Result<serde_json::Value> {
64-
Ok(serde_json::json!({
65-
"tool_name": self.tool.name,
66-
}))
67-
}
68-
}
69-
7059
pub struct McpManager {
7160
pub clients: HashMap<String, RunningService<RoleClient, ()>>,
7261
}

examples/servers/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[package]
44
name = "mcp-server-examples"

examples/transport/Cargo.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
cargo-features = ["edition2024"]
2-
31
[package]
42
name = "transport"
53
edition = { workspace = true }

examples/wasi/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
cargo-features = ["edition2024"]
1+
22

33
[package]
44
name = "wasi"

0 commit comments

Comments
 (0)