kodegen_mcp_tool
Memory-efficient, blazing-fast MCP tools for code generation agents.
A Rust library that provides a simple yet powerful Tool trait for building Model Context Protocol (MCP) tools that integrate seamlessly with the RMCP framework.
Features
- Simple API - Implement one trait, get RMCP integration, schema generation, and history tracking automatically
- Automatic JSON Schema - Derives from
JsonSchemawith global caching for zero overhead - Built-in Tool History - Fire-and-forget recording with persistent JSONL storage, never blocks execution
- Behavior Annotations - Declare tool semantics (
read_only,destructive,idempotent,open_world) - Prompting System - Teach agents how to use your tools with conversation-style prompts
- Performance Optimized - Schema caching, Arc optimizations, background I/O for maximum throughput
- Comprehensive Errors -
McpErrorenum with automatic conversion to RMCP error types - Production Ready - Thread-safe, async-first, with atomic file operations and rotation
Requirements
- Rust nightly - This library uses Rust edition 2024
- Tokio runtime - Async execution powered by Tokio
Installation
Add to your Cargo.toml:
[]
= "0.1.0"
Or install from git:
[]
= { = "https://github.com/cyrup-ai/kodegen-mcp-tool" }
Quick Start
Here's a minimal example of implementing a tool:
use ;
use ;
use JsonSchema;
use Value;
use ;
// 1. Define your tool struct (holds dependencies)
;
// 2. Define input arguments
// 3. Define prompt arguments
// 4. Implement the Tool trait
// 5. Register with RMCP router
use RouterService;
async
Behavior Annotations
Tools can declare their behavior by overriding trait methods:
These annotations are automatically converted to RMCP ToolAnnotations and help agents understand tool safety characteristics.
Tool History
Tool call history is automatically tracked for all tools:
// Initialize once at startup
init_global_history.await;
// Access anywhere in your code
if let Some = get_global_history
Features:
- Fire-and-forget recording (never blocks tool execution)
- In-memory cache (last 1000 entries)
- Persistent JSONL storage
- Automatic file rotation at 5000 entries
- Background disk I/O (1 second flush interval)
Documentation
Generate and view the API documentation:
For more detailed guidance on working with this codebase, see CLAUDE.md.
Architecture Highlights
- Struct-based Tools - Tools are stateful structs that hold their dependencies, not singletons or static functions
- Schema Caching - JSON schemas are computed once per tool type and cached globally using
LazyLock - Arc Optimization -
arc_into_tool_route()variants avoid double-Arc allocation for pre-wrapped tools - Background Processing - Tool history uses dedicated background task for all disk I/O
License
Dual-licensed under either:
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Links
- Homepage: https://kodegen.ai
- Repository: https://github.com/cyrup-ai/kodegen-mcp-tool
- Model Context Protocol: https://modelcontextprotocol.io
- RMCP SDK: https://github.com/modelcontextprotocol/rust-sdk
KODEGEN.ᴀɪ - Built by David Maple