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