Expand description
Core Tool trait and error types for MCP tool implementations
This crate provides the fundamental abstractions for building MCP tools:
- The
Tooltrait that defines tool behavior and RMCP integration - The
McpErrortype for tool execution errors - The
tool_historymodule for tracking tool call history
§Example
use kodegen_mcp_tool::{Tool, error::McpError};
use serde::{Deserialize, Serialize};
use schemars::JsonSchema;
use serde_json::Value;
use rmcp::model::{PromptArgument, PromptMessage};
pub struct MyTool;
#[derive(Deserialize, Serialize, JsonSchema)]
pub struct MyArgs {
message: String,
}
#[derive(Deserialize, Serialize, JsonSchema)]
pub struct MyPromptArgs {}
impl Tool for MyTool {
type Args = MyArgs;
type PromptArgs = MyPromptArgs;
fn name() -> &'static str { "my_tool" }
fn description() -> &'static str { "Example tool" }
async fn execute(&self, args: Self::Args) -> Result<Value, McpError> {
Ok(serde_json::json!({ "message": args.message }))
}
fn prompt_arguments() -> Vec<PromptArgument> {
vec![]
}
async fn prompt(&self, _args: Self::PromptArgs) -> Result<Vec<PromptMessage>, McpError> {
Ok(vec![])
}
}