Skip to content

Commit a9c1918

Browse files
committed
docs: simplify counter example
1 parent 19e6d45 commit a9c1918

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

examples/servers/src/common/counter.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
use std::sync::Arc;
22

33
use rmcp::{
4-
Error as McpError, RoleServer, ServerHandler, const_string, model::*, schemars,
5-
service::RequestContext, tool,
4+
Error as McpError, RoleServer, ServerHandler, model::*, schemars, service::RequestContext, tool,
65
};
76
use serde_json::json;
87
use tokio::sync::Mutex;
@@ -26,10 +25,6 @@ impl Counter {
2625
}
2726
}
2827

29-
fn _create_resource_text(&self, uri: &str, name: &str) -> Resource {
30-
RawResource::new(uri, name.to_string()).no_annotation()
31-
}
32-
3328
#[tool(description = "Increment the counter by 1")]
3429
async fn increment(&self) -> Result<CallToolResult, McpError> {
3530
let mut counter = self.counter.lock().await;
@@ -81,7 +76,7 @@ impl Counter {
8176
)]))
8277
}
8378
}
84-
const_string!(Echo = "echo");
79+
8580
#[tool(tool_box)]
8681
impl ServerHandler for Counter {
8782
fn get_info(&self) -> ServerInfo {
@@ -102,10 +97,13 @@ impl ServerHandler for Counter {
10297
_request: Option<PaginatedRequestParam>,
10398
_: RequestContext<RoleServer>,
10499
) -> Result<ListResourcesResult, McpError> {
100+
fn create_resource_text(uri: &str, name: &str) -> Resource {
101+
RawResource::new(uri, name.to_string()).no_annotation()
102+
}
105103
Ok(ListResourcesResult {
106104
resources: vec![
107-
self._create_resource_text("str:////Users/to/some/path/", "cwd"),
108-
self._create_resource_text("memo://insights", "memo-name"),
105+
create_resource_text("str:////Users/to/some/path/", "cwd"),
106+
create_resource_text("memo://insights", "memo-name"),
109107
],
110108
next_cursor: None,
111109
})

examples/simple-chat-client/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,4 @@ rmcp = { git = "https://github.com/modelcontextprotocol/rust-sdk", features = [
1717
"client",
1818
"transport-child-process",
1919
"transport-sse",
20-
], no-default-features = true }
20+
] }

0 commit comments

Comments
 (0)