kodegen-mcp-client
A Rust client library for interacting with MCP (Model Context Protocol) servers, specifically designed for KODEGEN.ᴀɪ database query and schema exploration tools.
Features
✨ Type-Safe MCP Client
- Strongly-typed response structures for all 75+ KODEGEN tools
- Compile-time type checking with
call_tool_typed<T>() - Support for both
camelCaseandsnake_casefield names
🚀 Async & Efficient
- Built on Tokio for high-performance async operations
- Cheap-to-clone client handles (Arc-based internally)
- Configurable timeouts with sensible defaults
🔌 Multiple Transports
- HTTP/SSE (Server-Sent Events)
- Streamable HTTP
- Easy transport selection
🛡️ Robust Error Handling
- Comprehensive error types with context
- Clear error messages for debugging
- Timeout tracking with operation details
Installation
Add to your Cargo.toml:
[]
= "0.1"
Requirements:
- Rust nightly toolchain
- Tokio async runtime
Quick Start
use ;
use json;
async
Usage Examples
Type-Safe Tool Calls
Use strongly-typed responses instead of manual JSON parsing:
use StartSearchResponse;
use tools;
// Type-safe tool call with automatic deserialization
let response: StartSearchResponse = client
.call_tool_typed
.await?;
// Use the typed response
println!;
Clone-able Client Handles
Client handles are cheap to clone and can be shared across tasks:
let = create_streamable_client.await?;
// Clone the client for concurrent operations
let client2 = client.clone;
spawn;
// Original client still works
client.call_tool.await?;
Custom Timeouts
use Duration;
let = create_streamable_client.await?;
// Set custom timeout (default is 30 seconds)
let client = client.with_timeout;
GitHub Integration
use ;
let response: GitHubIssuesResponse = client
.call_tool_typed
.await?;
for issue in response.issues
Database Operations
use tools;
// Execute SQL query
let result = client.call_tool.await?;
// Get table schema
let schema = client.call_tool.await?;
Architecture
Handle + Connection Pattern
The library uses a two-struct pattern for resource management:
-
KodegenClient: Cheap-to-clone handle for performing MCP operations- Clone freely and share across async tasks
- Wraps
Arcinternally for efficient cloning - Thread-safe and shareable
-
KodegenConnection: Non-clonable lifecycle manager- Must be held as long as the connection should remain active
- Provides
close()for graceful shutdown - Automatically cancels connection when dropped
let = create_streamable_client.await?;
// client: Clone freely
// _conn: Hold until shutdown desired (auto-cleanup on drop)
Available Tool Categories
The library provides type-safe access to 75+ KODEGEN.ᴀɪ tools across multiple categories:
- Filesystem (14 tools): File operations, search, directory management
- Terminal (5 tools): Command execution, process management
- Database (7 tools): Schema exploration, query execution, connection pooling
- Git (20 tools): Repository operations, branching, commits, worktrees
- GitHub (25 tools): Issues, PRs, reviews, code search, repositories
- Claude Agents (5 tools): Multi-agent orchestration, spawning, communication
- Web Crawling (4 tools): Site crawling, search, content extraction
- Configuration (2 tools): Server config management
- Prompts (4 tools): Template management and rendering
- Sequential Thinking (1 tool): Chain-of-thought reasoning
All tool names are available as constants in the tools module.
Error Handling
The library provides comprehensive error types with context:
use ClientError;
match client.call_tool.await
Error variants:
Protocol: MCP protocol errorsTimeout: Operation timeouts (includes duration)ParseError: Response deserialization failuresConnection: Transport connection failuresServiceError,InitError,Io,JoinError: Lower-level errors
Transport Options
Streamable HTTP (Recommended)
use create_streamable_client;
let = create_streamable_client.await?;
HTTP/SSE (Server-Sent Events)
use create_http_client;
let = create_http_client.await?;
Development
Building
Testing
Linting & Formatting
Documentation
License
Dual-licensed under Apache 2.0 OR MIT terms.
See LICENSE.md for details.
Links
- Homepage: https://kodegen.ai
- Repository: https://github.com/cyrup-ai/kodegen-mcp-client
- MCP Protocol: https://modelcontextprotocol.io
Copyright © 2025 David Maple / KODEGEN.ᴀɪ