use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct McpTool {
pub name: String,
pub description: String,
pub input_schema: String,
}
impl McpTool {
pub fn new(
name: impl Into<String>,
description: impl Into<String>,
input_schema: impl Into<String>,
) -> Self {
Self {
name: name.into(),
description: description.into(),
input_schema: input_schema.into(),
}
}
pub fn from_handler_name(name: impl Into<String>) -> Self {
let name = name.into();
let description = format!("Tool: {}", name);
let input_schema = r#"{"type": "object", "properties": {}}"#.to_string();
Self {
name,
description,
input_schema,
}
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_tool_creation() {
let tool = McpTool::new("test", "Test tool", r#"{"type": "object"}"#);
assert_eq!(tool.name, "test");
assert_eq!(tool.description, "Test tool");
assert_eq!(tool.input_schema, r#"{"type": "object"}"#);
}
#[test]
fn test_tool_from_handler_name() {
let tool = McpTool::from_handler_name("my_handler");
assert_eq!(tool.name, "my_handler");
assert!(!tool.description.is_empty());
assert!(tool.input_schema.contains("object"));
}
}