feat: add tool annotations for build-in tools (#1939)

This commit is contained in:
Yingjie He
2025-03-31 16:46:55 -07:00
committed by GitHub
parent f184449f81
commit 680523297b
23 changed files with 369 additions and 9 deletions

View File

@@ -2,6 +2,7 @@ use anyhow::Result;
use mcp_core::content::Content;
use mcp_core::handler::{PromptError, ResourceError};
use mcp_core::prompt::{Prompt, PromptArgument};
use mcp_core::tool::ToolAnnotations;
use mcp_core::{handler::ToolError, protocol::ServerCapabilities, resource::Resource, tool::Tool};
use mcp_server::router::{CapabilitiesBuilder, RouterService};
use mcp_server::{ByteTransport, Router, Server};
@@ -76,6 +77,13 @@ impl Router for CounterRouter {
"properties": {},
"required": []
}),
Some(ToolAnnotations {
title: Some("Increment Tool".to_string()),
read_only_hint: false,
destructive_hint: false,
idempotent_hint: false,
open_world_hint: false,
}),
),
Tool::new(
"decrement".to_string(),
@@ -85,6 +93,13 @@ impl Router for CounterRouter {
"properties": {},
"required": []
}),
Some(ToolAnnotations {
title: Some("Decrement Tool".to_string()),
read_only_hint: false,
destructive_hint: false,
idempotent_hint: false,
open_world_hint: false,
}),
),
Tool::new(
"get_value".to_string(),
@@ -94,6 +109,13 @@ impl Router for CounterRouter {
"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,
}),
),
]
}

View File

@@ -116,7 +116,7 @@ pub trait Router: Send + Sync + 'static {
) -> impl Future<Output = Result<JsonRpcResponse, RouterError>> + Send {
async move {
let result = InitializeResult {
protocol_version: "2024-11-05".to_string(),
protocol_version: "2025-03-26".to_string(),
capabilities: self.capabilities().clone(),
server_info: Implementation {
name: self.name(),