Skip to main content

mcp_execution_codegen/
lib.rs

1//! Progressive loading code generation for MCP tools.
2//!
3//! This crate generates TypeScript files for progressive loading pattern,
4//! where each MCP tool is a separate file. This enables Claude Code to
5//! discover and load tools on-demand, achieving 98% token savings.
6//!
7//! # Architecture
8//!
9//! The progressive loading pattern works as follows:
10//!
11//! 1. **Tool Discovery**: Claude Code lists files in `~/.claude/servers/{server-id}/`
12//! 2. **Selective Loading**: Claude Code reads only the tools it needs
13//! 3. **Execution**: Generated TypeScript code calls MCP tools via bridge
14//!
15//! # Example
16//!
17//! ```no_run
18//! use mcp_execution_codegen::progressive::ProgressiveGenerator;
19//! use mcp_execution_introspector::ServerInfo;
20//!
21//! # fn example() -> Result<(), Box<dyn std::error::Error>> {
22//! let generator = ProgressiveGenerator::new()?;
23//! // generator.generate(&server_info)?;
24//! # Ok(())
25//! # }
26//! ```
27//!
28//! # Generated Structure
29//!
30//! For a server with 3 tools, generates:
31//! ```text
32//! ~/.claude/servers/github/
33//! ├── index.ts              # Re-exports all tools
34//! ├── createIssue.ts       # Individual tool file
35//! ├── updateIssue.ts       # Individual tool file
36//! └── _runtime/
37//!     └── mcp-bridge.ts    # Runtime helper
38//! ```
39//!
40//! # Token Savings
41//!
42//! - **Traditional**: Load all 30 tools upfront = 30,000 tokens
43//! - **Progressive**: Load on-demand = ~2,000 tokens per tool
44//! - **Savings**: 93-98%
45
46#![deny(unsafe_code)]
47#![warn(missing_docs, missing_debug_implementations)]
48
49// Core modules (always available)
50pub mod common;
51pub mod progressive;
52pub mod template_engine;
53
54// Re-export main types
55pub use common::types::{GeneratedCode, GeneratedFile, TemplateContext, ToolDefinition};
56pub use progressive::ProgressiveGenerator;
57pub use template_engine::TemplateEngine;