alexhancock/rmcp-tools-annotations (#3617)

This commit is contained in:
Alex Hancock
2025-07-24 14:58:14 -04:00
committed by GitHub
parent 7b2ca43c77
commit b4fc6f7cc8
65 changed files with 770 additions and 731 deletions
+32 -30
View File
@@ -1,10 +1,12 @@
use anyhow::Result;
use mcp_core::handler::{PromptError, ResourceError};
use mcp_core::tool::ToolAnnotations;
use mcp_core::{handler::ToolError, protocol::ServerCapabilities, tool::Tool};
use mcp_core::{handler::ToolError, protocol::ServerCapabilities};
use mcp_server::router::{CapabilitiesBuilder, RouterService};
use mcp_server::{ByteTransport, Router, Server};
use rmcp::model::{Content, JsonRpcMessage, Prompt, PromptArgument, RawResource, Resource};
use rmcp::model::{
Content, JsonRpcMessage, Prompt, PromptArgument, RawResource, Resource, Tool, ToolAnnotations,
};
use rmcp::object;
use serde_json::Value;
use std::{future::Future, pin::Pin, sync::Arc};
use tokio::sync::mpsc;
@@ -72,51 +74,51 @@ impl Router for CounterRouter {
Tool::new(
"increment".to_string(),
"Increment the counter by 1".to_string(),
serde_json::json!({
object!({
"type": "object",
"properties": {},
"required": []
}),
Some(ToolAnnotations {
title: Some("Increment Tool".to_string()),
read_only_hint: false,
destructive_hint: false,
idempotent_hint: false,
open_world_hint: false,
}),
),
)
.annotate(ToolAnnotations {
title: Some("Increment Tool".to_string()),
read_only_hint: Some(false),
destructive_hint: Some(false),
idempotent_hint: Some(false),
open_world_hint: Some(false),
}),
Tool::new(
"decrement".to_string(),
"Decrement the counter by 1".to_string(),
serde_json::json!({
object!({
"type": "object",
"properties": {},
"required": []
}),
Some(ToolAnnotations {
title: Some("Decrement Tool".to_string()),
read_only_hint: false,
destructive_hint: false,
idempotent_hint: false,
open_world_hint: false,
}),
),
)
.annotate(ToolAnnotations {
title: Some("Decrement Tool".to_string()),
read_only_hint: Some(false),
destructive_hint: Some(false),
idempotent_hint: Some(false),
open_world_hint: Some(false),
}),
Tool::new(
"get_value".to_string(),
"Get the current counter value".to_string(),
serde_json::json!({
object!({
"type": "object",
"properties": {},
"required": []
}),
Some(ToolAnnotations {
title: Some("Get Value Tool".to_string()),
read_only_hint: true,
destructive_hint: false,
idempotent_hint: false,
open_world_hint: false,
}),
),
)
.annotate(ToolAnnotations {
title: Some("Get Value Tool".to_string()),
read_only_hint: Some(true),
destructive_hint: Some(false),
idempotent_hint: Some(false),
open_world_hint: Some(false),
}),
]
}
+1 -1
View File
@@ -86,7 +86,7 @@ pub trait Router: Send + Sync + 'static {
// in the protocol, instructions are optional but we make it required
fn instructions(&self) -> String;
fn capabilities(&self) -> ServerCapabilities;
fn list_tools(&self) -> Vec<mcp_core::tool::Tool>;
fn list_tools(&self) -> Vec<rmcp::model::Tool>;
fn call_tool(
&self,
tool_name: &str,