Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo-features = ["edition2024"]


[workspace]
members = ["crates/rmcp", "crates/rmcp-macros", "examples/*"]
Expand Down
2 changes: 1 addition & 1 deletion crates/rmcp-macros/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo-features = ["edition2024"]


[package]
name = "rmcp-macros"
Expand Down
2 changes: 1 addition & 1 deletion crates/rmcp-macros/src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
}
}
Expand Down
4 changes: 2 additions & 2 deletions crates/rmcp/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo-features = ["edition2024"]


[package]
name = "rmcp"
Expand Down Expand Up @@ -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"
5 changes: 3 additions & 2 deletions crates/rmcp/src/model/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Cow<'static, str>>,
/// A JSON Schema object defining the expected parameters for the tool
pub input_schema: Arc<JsonObject>,
}
Expand All @@ -29,7 +30,7 @@ impl Tool {
{
Tool {
name: name.into(),
description: description.into(),
description: Some(description.into()),
input_schema: input_schema.into(),
}
}
Expand Down
15 changes: 15 additions & 0 deletions crates/rmcp/tests/test_deserialization.rs
Original file line number Diff line number Diff line change
@@ -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(_),
..
})
));
}
28 changes: 28 additions & 0 deletions crates/rmcp/tests/test_deserialization/tool_list_result.json
Original file line number Diff line number Diff line change
@@ -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
}
4 changes: 2 additions & 2 deletions crates/rmcp/tests/test_with_js.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
2 changes: 1 addition & 1 deletion examples/clients/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo-features = ["edition2024"]


[package]
name = "mcp-client-examples"
Expand Down
2 changes: 0 additions & 2 deletions examples/rig-integration/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[package]
name = "rig-integration"
edition = { workspace = true }
Expand Down
25 changes: 7 additions & 18 deletions examples/rig-integration/src/mcp_adaptor.rs
Original file line number Diff line number Diff line change
@@ -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},
Expand All @@ -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(),
}))
}
Expand All @@ -51,22 +56,6 @@ impl RigTool for McpToolAdaptor {
}
}

impl ToolEmbeddingDyn for McpToolAdaptor {
fn embedding_docs(&self) -> Vec<String> {
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<serde_json::Value> {
Ok(serde_json::json!({
"tool_name": self.tool.name,
}))
}
}

pub struct McpManager {
pub clients: HashMap<String, RunningService<RoleClient, ()>>,
}
Expand Down
2 changes: 1 addition & 1 deletion examples/servers/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo-features = ["edition2024"]


[package]
name = "mcp-server-examples"
Expand Down
2 changes: 0 additions & 2 deletions examples/transport/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
cargo-features = ["edition2024"]

[package]
name = "transport"
edition = { workspace = true }
Expand Down
2 changes: 1 addition & 1 deletion examples/wasi/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cargo-features = ["edition2024"]


[package]
name = "wasi"
Expand Down
Loading