Skip to main content

tokitai_mcp_server/
lib.rs

1//! Tokitai MCP Server - Build AI-callable tool servers with zero runtime overhead
2//!
3//! This crate provides scaffolding for building MCP (Model Context Protocol) servers
4//! using Tokitai's compile-time tool definitions.
5//!
6//! ## Features
7//!
8//! - **Zero Runtime Overhead** - Tool definitions generated at compile time
9//! - **Type Safe** - Rust's type system ensures AI parameters match your functions
10//! - **MCP Compliant** - Full support for MCP protocol
11//! - **Easy to Use** - Get started with just a few lines of code
12//!
13//! ## Quick Start
14//!
15//! ### 1. Define your tools
16//!
17//! ```rust,ignore
18//! use tokitai::tool;
19//!
20//! #[tool]
21//! struct Calculator;
22//!
23//! #[tool]
24//! impl Calculator {
25//!     /// Add two numbers together
26//!     pub fn add(&self, a: i32, b: i32) -> i32 {
27//!         a + b
28//!     }
29//! }
30//! ```
31//!
32//! ### 2. Create and run the server
33//!
34//! ```rust,ignore
35//! use tokitai_mcp_server::McpServerBuilder;
36//!
37//! #[tokio::main]
38//! async fn main() {
39//!     let server = McpServerBuilder::with_tool(Calculator::default())
40//!         .with_port(8080)
41//!         .build();
42//!
43//!     server.run().await.unwrap();
44//! }
45//! ```
46//!
47//! ### 3. Call from AI client
48//!
49//! ```python
50//! # Python MCP client example
51//! import requests
52//!
53//! # Get available tools
54//! response = requests.get("http://127.0.0.1:8080/tools")
55//! tools = response.json()
56//!
57//! # Call a tool
58//! response = requests.post("http://127.0.0.1:8080/call", json={
59//!     "name": "add",
60//!     "arguments": {"a": 10, "b": 20}
61//! })
62//! result = response.json()
63//! print(result["result"])  # 30
64//! ```
65//!
66//! ## Architecture
67//!
68//! ```text
69//! ┌─────────────────┐         ┌─────────────────────┐         ┌─────────────────┐
70//! │   AI Client     │         │  MCP Server         │         │  Business Logic │
71//! │   (Python/JS)   │ ──────> │  (tokitai-mcp)      │ ──────> │  (Rust tools)   │
72//! │                 │ <────── │                     │ <────── │  #[tool]        │
73//! └─────────────────┘         └─────────────────────┘         └─────────────────┘
74//!      │                           │                              │
75//!      │ 1. List tools             │                              │
76//!      │ 2. Call tool (JSON)       │                              │
77//!      │                           │ 3. Type-safe call            │
78//!      │                           │                              │
79//!      │ 4. Result (JSON)          │                              │
80//! ```
81//!
82//! ## Features
83//!
84//! | Feature | Description |
85//! |---------|-------------|
86//! | `default` | Default features |
87//!
88//! ## Requirements
89//!
90//! - **Rust Version**: 1.70+
91//! - **Edition**: 2021
92//!
93//! ## License
94//!
95//! Licensed under either of:
96//!
97//! - Apache License, Version 2.0 ([LICENSE-APACHE](../LICENSE))
98//! - MIT License ([LICENSE-MIT](../LICENSE))
99//!
100//! at your option.
101
102pub mod server;
103
104// Re-export commonly used types
105pub use server::{
106    McpServer, McpServerBuilder, McpServerConfig, MultiToolProvider, ServerError, ToolCallerDyn,
107};
108
109/// Library version
110pub const VERSION: &str = env!("CARGO_PKG_VERSION");