From a9c191832f7898f0ef4da6bdb52ba1c76e5169c7 Mon Sep 17 00:00:00 2001 From: Rik Huijzer Date: Thu, 10 Apr 2025 14:10:13 +0200 Subject: [PATCH] docs: simplify counter example --- examples/servers/src/common/counter.rs | 16 +++++++--------- examples/simple-chat-client/Cargo.toml | 2 +- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/examples/servers/src/common/counter.rs b/examples/servers/src/common/counter.rs index 7bed523ab..bfbe32fb0 100644 --- a/examples/servers/src/common/counter.rs +++ b/examples/servers/src/common/counter.rs @@ -1,8 +1,7 @@ use std::sync::Arc; use rmcp::{ - Error as McpError, RoleServer, ServerHandler, const_string, model::*, schemars, - service::RequestContext, tool, + Error as McpError, RoleServer, ServerHandler, model::*, schemars, service::RequestContext, tool, }; use serde_json::json; use tokio::sync::Mutex; @@ -26,10 +25,6 @@ impl Counter { } } - fn _create_resource_text(&self, uri: &str, name: &str) -> Resource { - RawResource::new(uri, name.to_string()).no_annotation() - } - #[tool(description = "Increment the counter by 1")] async fn increment(&self) -> Result { let mut counter = self.counter.lock().await; @@ -81,7 +76,7 @@ impl Counter { )])) } } -const_string!(Echo = "echo"); + #[tool(tool_box)] impl ServerHandler for Counter { fn get_info(&self) -> ServerInfo { @@ -102,10 +97,13 @@ impl ServerHandler for Counter { _request: Option, _: RequestContext, ) -> Result { + fn create_resource_text(uri: &str, name: &str) -> Resource { + RawResource::new(uri, name.to_string()).no_annotation() + } Ok(ListResourcesResult { resources: vec![ - self._create_resource_text("str:////Users/to/some/path/", "cwd"), - self._create_resource_text("memo://insights", "memo-name"), + create_resource_text("str:////Users/to/some/path/", "cwd"), + create_resource_text("memo://insights", "memo-name"), ], next_cursor: None, }) diff --git a/examples/simple-chat-client/Cargo.toml b/examples/simple-chat-client/Cargo.toml index 24bcb78bd..f957ebd3a 100644 --- a/examples/simple-chat-client/Cargo.toml +++ b/examples/simple-chat-client/Cargo.toml @@ -17,4 +17,4 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", features = [ "client", "transport-child-process", "transport-sse", -], no-default-features = true } \ No newline at end of file +] }