feat: add tool annotations for build-in tools (#1939)
This commit is contained in:
@@ -245,6 +245,7 @@ impl Capabilities {
|
||||
format!("{}__{}", name, tool.name),
|
||||
&tool.description,
|
||||
tool.input_schema,
|
||||
tool.annotations,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ use crate::agents::capabilities::Capabilities;
|
||||
use crate::message::{Message, MessageContent, ToolRequest};
|
||||
use chrono::Utc;
|
||||
use indoc::indoc;
|
||||
use mcp_core::tool::ToolAnnotations;
|
||||
use mcp_core::{tool::Tool, TextContent};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
@@ -50,6 +51,13 @@ fn create_read_only_tool() -> Tool {
|
||||
},
|
||||
"required": []
|
||||
}),
|
||||
Some(ToolAnnotations {
|
||||
title: Some("Check tool operation".to_string()),
|
||||
read_only_hint: true,
|
||||
destructive_hint: false,
|
||||
idempotent_hint: false,
|
||||
open_world_hint: false,
|
||||
}),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@ use anyhow::{anyhow, Result};
|
||||
use indoc::indoc;
|
||||
use mcp_core::prompt::Prompt;
|
||||
use mcp_core::protocol::GetPromptResult;
|
||||
use mcp_core::tool::Tool;
|
||||
use mcp_core::tool::{Tool, ToolAnnotations};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
/// Reference implementation of an Agent
|
||||
@@ -102,6 +102,13 @@ impl Agent for ReferenceAgent {
|
||||
"extension_name": {"type": "string", "description": "Optional extension name"}
|
||||
}
|
||||
}),
|
||||
Some(ToolAnnotations {
|
||||
title: Some("Read a resource".to_string()),
|
||||
read_only_hint: true,
|
||||
destructive_hint: false,
|
||||
idempotent_hint: false,
|
||||
open_world_hint: false,
|
||||
}),
|
||||
);
|
||||
|
||||
let list_resources_tool = Tool::new(
|
||||
@@ -120,6 +127,13 @@ impl Agent for ReferenceAgent {
|
||||
"extension_name": {"type": "string", "description": "Optional extension name"}
|
||||
}
|
||||
}),
|
||||
Some(ToolAnnotations {
|
||||
title: Some("List resources".to_string()),
|
||||
read_only_hint: true,
|
||||
destructive_hint: false,
|
||||
idempotent_hint: false,
|
||||
open_world_hint: false,
|
||||
}),
|
||||
);
|
||||
|
||||
if capabilities.supports_resources() {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
/// truncation method. Still cannot read resources.
|
||||
use async_trait::async_trait;
|
||||
use futures::stream::BoxStream;
|
||||
use mcp_core::tool::ToolAnnotations;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc;
|
||||
@@ -199,6 +200,13 @@ impl Agent for SummarizeAgent {
|
||||
"extension_name": {"type": "string", "description": "Optional extension name"}
|
||||
}
|
||||
}),
|
||||
Some(ToolAnnotations {
|
||||
title: Some("Read a resource".to_string()),
|
||||
read_only_hint: true,
|
||||
destructive_hint: false,
|
||||
idempotent_hint: false,
|
||||
open_world_hint: false,
|
||||
}),
|
||||
);
|
||||
|
||||
let list_resources_tool = Tool::new(
|
||||
@@ -217,6 +225,13 @@ impl Agent for SummarizeAgent {
|
||||
"extension_name": {"type": "string", "description": "Optional extension name"}
|
||||
}
|
||||
}),
|
||||
Some(ToolAnnotations {
|
||||
title: Some("List resources".to_string()),
|
||||
read_only_hint: true,
|
||||
destructive_hint: false,
|
||||
idempotent_hint: false,
|
||||
open_world_hint: false,
|
||||
}),
|
||||
);
|
||||
|
||||
if capabilities.supports_resources() {
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
/// It makes no attempt to handle context limits, and cannot read resources
|
||||
use async_trait::async_trait;
|
||||
use futures::stream::BoxStream;
|
||||
use mcp_core::tool::ToolAnnotations;
|
||||
use std::collections::HashMap;
|
||||
use std::sync::Arc;
|
||||
use tokio::sync::mpsc;
|
||||
@@ -195,6 +196,13 @@ impl Agent for TruncateAgent {
|
||||
"extension_name": {"type": "string", "description": "Optional extension name"}
|
||||
}
|
||||
}),
|
||||
Some(ToolAnnotations {
|
||||
title: Some("Read a resource".to_string()),
|
||||
read_only_hint: true,
|
||||
destructive_hint: false,
|
||||
idempotent_hint: false,
|
||||
open_world_hint: false,
|
||||
}),
|
||||
);
|
||||
|
||||
let list_resources_tool = Tool::new(
|
||||
@@ -213,6 +221,13 @@ impl Agent for TruncateAgent {
|
||||
"extension_name": {"type": "string", "description": "Optional extension name"}
|
||||
}
|
||||
}),
|
||||
Some(ToolAnnotations {
|
||||
title: Some("List resources".to_string()),
|
||||
read_only_hint: true,
|
||||
destructive_hint: false,
|
||||
idempotent_hint: false,
|
||||
open_world_hint: false,
|
||||
}),
|
||||
);
|
||||
|
||||
if capabilities.supports_resources() {
|
||||
|
||||
@@ -530,6 +530,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}),
|
||||
None,
|
||||
),
|
||||
Tool::new(
|
||||
"weather",
|
||||
@@ -543,6 +544,7 @@ mod tests {
|
||||
}
|
||||
}
|
||||
}),
|
||||
None,
|
||||
),
|
||||
];
|
||||
|
||||
|
||||
@@ -675,6 +675,7 @@ mod tests {
|
||||
},
|
||||
"required": ["input"]
|
||||
}),
|
||||
None,
|
||||
);
|
||||
|
||||
let spec = format_tools(&[tool])?;
|
||||
@@ -766,6 +767,7 @@ mod tests {
|
||||
},
|
||||
"required": ["input"]
|
||||
}),
|
||||
None,
|
||||
);
|
||||
|
||||
let tool2 = Tool::new(
|
||||
@@ -781,6 +783,7 @@ mod tests {
|
||||
},
|
||||
"required": ["input"]
|
||||
}),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = format_tools(&[tool1, tool2]);
|
||||
|
||||
@@ -351,6 +351,7 @@ mod tests {
|
||||
input_schema: json!({
|
||||
"properties": params
|
||||
}),
|
||||
annotations: None,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -494,6 +495,7 @@ mod tests {
|
||||
input_schema: json!({
|
||||
"properties": {}
|
||||
}),
|
||||
annotations: None,
|
||||
}];
|
||||
let result = format_tools(&tools);
|
||||
assert_eq!(result.len(), 1);
|
||||
|
||||
@@ -550,6 +550,7 @@ mod tests {
|
||||
},
|
||||
"required": ["input"]
|
||||
}),
|
||||
None,
|
||||
);
|
||||
|
||||
let spec = format_tools(&[tool])?;
|
||||
@@ -641,6 +642,7 @@ mod tests {
|
||||
},
|
||||
"required": ["input"]
|
||||
}),
|
||||
None,
|
||||
);
|
||||
|
||||
let tool2 = Tool::new(
|
||||
@@ -656,6 +658,7 @@ mod tests {
|
||||
},
|
||||
"required": ["input"]
|
||||
}),
|
||||
None,
|
||||
);
|
||||
|
||||
let result = format_tools(&[tool1, tool2]);
|
||||
|
||||
@@ -310,6 +310,7 @@ mod tests {
|
||||
},
|
||||
"required": ["location"]
|
||||
}),
|
||||
annotations: None,
|
||||
}];
|
||||
|
||||
let token_count_without_tools = counter.count_chat_tokens(system_prompt, &messages, &[]);
|
||||
|
||||
Reference in New Issue
Block a user