diff --git a/Cargo.lock b/Cargo.lock index aebf797..cbac5ad 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -303,6 +303,41 @@ version = "0.8.7" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b" +[[package]] +name = "darling" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9cdf337090841a411e2a7f3deb9187445851f91b309c0c0a29e05f74a00a48c0" +dependencies = [ + "darling_core", + "darling_macro", +] + +[[package]] +name = "darling_core" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1247195ecd7e3c85f83c8d2a366e4210d588e802133e1e355180a9870b517ea4" +dependencies = [ + "fnv", + "ident_case", + "proc-macro2", + "quote", + "strsim", + "syn", +] + +[[package]] +name = "darling_macro" +version = "0.21.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d38308df82d1080de0afee5d069fa14b0326a88c14f15c5ccda35b4a6c414c81" +dependencies = [ + "darling_core", + "quote", + "syn", +] + [[package]] name = "displaydoc" version = "0.2.5" @@ -797,6 +832,12 @@ dependencies = [ "syn", ] +[[package]] +name = "ident_case" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" + [[package]] name = "idna" version = "1.0.3" @@ -1220,7 +1261,7 @@ dependencies = [ "once_cell", "socket2", "tracing", - "windows-sys 0.52.0", + "windows-sys 0.59.0", ] [[package]] @@ -1276,6 +1317,26 @@ dependencies = [ "bitflags", ] +[[package]] +name = "ref-cast" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a0ae411dbe946a674d89546582cea4ba2bb8defac896622d6496f14c23ba5cf" +dependencies = [ + "ref-cast-impl", +] + +[[package]] +name = "ref-cast-impl" +version = "1.0.24" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1165225c21bff1f3bbce98f5a1f889949bc902d3575308cc7b0de30b4f6d27c7" +dependencies = [ + "proc-macro2", + "quote", + "syn", +] + [[package]] name = "reqwest" version = "0.12.15" @@ -1343,8 +1404,9 @@ dependencies = [ [[package]] name = "rmcp" -version = "0.1.5" -source = "git+https://github.com/modelcontextprotocol/rust-sdk.git?rev=4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451#4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1f521fbd040eba82684b17d787d423f43afb6e97974029b51f679157a589592a" dependencies = [ "axum", "base64", @@ -1375,9 +1437,11 @@ dependencies = [ [[package]] name = "rmcp-macros" -version = "0.1.5" -source = "git+https://github.com/modelcontextprotocol/rust-sdk.git?rev=4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451#4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451" +version = "0.6.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c162bf8a2846f70464ded6dda6430b60d1e2fb4b0e371f0906e39f63916641b9" dependencies = [ + "darling", "proc-macro2", "quote", "serde_json", @@ -1475,12 +1539,13 @@ dependencies = [ [[package]] name = "schemars" -version = "0.8.22" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fbf2ae1b8bc8e02df939598064d22402220cd5bbcca1c76f7d6a310974d5615" +checksum = "82d20c4491bc164fa2f6c5d44565947a52ad80b9505d8e36f8d54c27c739fcd0" dependencies = [ "chrono", "dyn-clone", + "ref-cast", "schemars_derive", "serde", "serde_json", @@ -1488,9 +1553,9 @@ dependencies = [ [[package]] name = "schemars_derive" -version = "0.8.22" +version = "1.0.4" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "32e265784ad618884abaea0600a9adf15393368d840e0222d101a072f3f7534d" +checksum = "33d020396d1d138dc19f1165df7545479dcd58d93810dc5d646a16e55abefa80" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 8eda27e..f949cb6 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -4,13 +4,13 @@ version = "0.2.2" edition = "2024" [dependencies] -rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk.git", rev = "4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451", features = [ +rmcp = { version = "0.6.1", features = [ "server", "client", "reqwest", "client-side-sse", - "transport-sse-client", - "transport-streamable-http-client", + "transport-sse-client-reqwest", + "transport-streamable-http-client-reqwest", "transport-worker", "transport-child-process" ] } @@ -29,12 +29,12 @@ version = "0.9" features = ["vendored"] [dev-dependencies] -rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk.git", rev = "4c34b64b7f8dcabf94d52a9c6518c6b49c1f0451", features = [ +rmcp = { version = "0.6.1", features = [ "server", "client", "reqwest", "client-side-sse", - "transport-sse-client", + "transport-sse-client-reqwest", "transport-sse-server", "transport-child-process", "transport-streamable-http-server", diff --git a/examples/echo.rs b/examples/echo.rs index 6a8bd72..67387b5 100644 --- a/examples/echo.rs +++ b/examples/echo.rs @@ -4,22 +4,34 @@ use rmcp::transport::SseServer; use tracing_subscriber::FmtSubscriber; use rmcp::{ - ServerHandler, - model::{ServerCapabilities, ServerInfo}, - schemars, tool, + ErrorData as McpError, + handler::server::{router::tool::ToolRouter, wrapper::Parameters}, + model::*, + tool, tool_handler, tool_router, }; + #[derive(Debug, Clone, Default)] -pub struct Echo; -#[tool(tool_box)] +pub struct Echo { + tool_router: ToolRouter, +} +#[tool_router] impl Echo { + fn new() -> Self { + Self { + tool_router: Self::tool_router(), + } + } + #[tool(description = "Echo a message")] - fn echo(&self, #[tool(param)] message: String) -> String { - message + fn echo(&self, Parameters(object): Parameters) -> Result { + Ok(CallToolResult::success(vec![Content::text( + serde_json::Value::Object(object).to_string(), + )])) } } -#[tool(tool_box)] -impl ServerHandler for Echo { +#[tool_handler] +impl rmcp::ServerHandler for Echo { fn get_info(&self) -> ServerInfo { ServerInfo { instructions: Some("A simple echo server".into()), @@ -51,7 +63,7 @@ async fn main() -> anyhow::Result<()> { let ct = SseServer::serve(args.address) .await? - .with_service(Echo::default); + .with_service_directly(Echo::new); tokio::signal::ctrl_c().await?; ct.cancel(); diff --git a/examples/echo_streamable.rs b/examples/echo_streamable.rs index 0307cf1..d0e8875 100644 --- a/examples/echo_streamable.rs +++ b/examples/echo_streamable.rs @@ -6,26 +6,34 @@ use rmcp::transport::streamable_http_server::{ use tracing_subscriber::FmtSubscriber; use rmcp::{ - ServerHandler, - model::{ServerCapabilities, ServerInfo}, - schemars, tool, + ErrorData as McpError, + handler::server::{router::tool::ToolRouter, wrapper::Parameters}, + model::*, + tool, tool_handler, tool_router, }; + #[derive(Debug, Clone, Default)] -pub struct Echo; -#[tool(tool_box)] +pub struct Echo { + tool_router: ToolRouter, +} +#[tool_router] impl Echo { - pub fn new() -> Self { - Self {} + fn new() -> Self { + Self { + tool_router: Self::tool_router(), + } } #[tool(description = "Echo a message")] - fn echo(&self, #[tool(param)] message: String) -> String { - message + fn echo(&self, Parameters(object): Parameters) -> Result { + Ok(CallToolResult::success(vec![Content::text( + serde_json::Value::Object(object).to_string(), + )])) } } -#[tool(tool_box)] -impl ServerHandler for Echo { +#[tool_handler] +impl rmcp::ServerHandler for Echo { fn get_info(&self) -> ServerInfo { ServerInfo { instructions: Some("A simple echo server".into()), diff --git a/src/core.rs b/src/core.rs index 180ef42..5815b08 100644 --- a/src/core.rs +++ b/src/core.rs @@ -65,6 +65,7 @@ pub(crate) async fn connect_with_streamable(app_state: &AppState) -> Result anyhow::Result<()> { let ct = SseServer::serve(BIND_ADDRESS.parse()?) .await? - .with_service(echo::Echo::default); + .with_service_directly(Echo::new); let transport = TokioChildProcess::new( tokio::process::Command::new("./target/debug/mcp-proxy").configure(|cmd| { diff --git a/tests/echo/mod.rs b/tests/echo/mod.rs index 5713d5e..5f44343 100644 --- a/tests/echo/mod.rs +++ b/tests/echo/mod.rs @@ -1,20 +1,33 @@ use rmcp::{ - ServerHandler, - model::{ServerCapabilities, ServerInfo}, - schemars, tool, + ErrorData as McpError, + handler::server::{router::tool::ToolRouter, wrapper::Parameters}, + model::*, + tool, tool_handler, tool_router, }; + #[derive(Debug, Clone, Default)] -pub struct Echo; -#[tool(tool_box)] +pub struct Echo { + tool_router: ToolRouter, +} +#[tool_router] impl Echo { + #[allow(dead_code)] + pub fn new() -> Self { + Self { + tool_router: Self::tool_router(), + } + } + #[tool(description = "Echo a message")] - fn echo(&self, #[tool(param)] message: String) -> String { - message + fn echo(&self, Parameters(object): Parameters) -> Result { + Ok(CallToolResult::success(vec![Content::text( + serde_json::Value::Object(object).to_string(), + )])) } } -#[tool(tool_box)] -impl ServerHandler for Echo { +#[tool_handler] +impl rmcp::ServerHandler for Echo { fn get_info(&self) -> ServerInfo { ServerInfo { instructions: Some("A simple echo server".into()),