mcp_execution_codegen/progressive/mod.rs
1//! Progressive loading code generation module.
2//!
3//! Generates TypeScript code for progressive loading where each tool
4//! is in a separate file. This enables Claude Code to load only the
5//! tools it needs, achieving significant token savings.
6//!
7//! # Architecture
8//!
9//! Progressive loading differs from the traditional WASM approach:
10//!
11//! **Traditional (WASM)**:
12//! - All tools in one large file
13//! - Loaded upfront (all 30 tools at once)
14//! - ~30,000 tokens per server
15//!
16//! **Progressive Loading**:
17//! - One file per tool
18//! - Loaded on-demand (`ls`, `cat` specific tool)
19//! - ~500-1,500 tokens per tool (98% savings)
20//!
21//! # File Structure
22//!
23//! For a server with tools `create_issue`, `update_issue`:
24//!
25//! ```text
26//! ~/.claude/servers/github/
27//! ├── index.ts # Re-exports all tools
28//! ├── createIssue.ts # Individual tool (loaded on-demand)
29//! ├── updateIssue.ts # Individual tool (loaded on-demand)
30//! └── _runtime/
31//! └── mcp-bridge.ts # Runtime helper for MCP calls
32//! ```
33//!
34//! # Examples
35//!
36//! ## Basic Usage
37//!
38//! ```no_run
39//! use mcp_execution_codegen::progressive::ProgressiveGenerator;
40//! use mcp_execution_introspector::{Introspector, ServerInfo};
41//! use mcp_execution_core::{ServerId, ServerConfig};
42//!
43//! # async fn example() -> Result<(), Box<dyn std::error::Error>> {
44//! // Introspect server
45//! let mut introspector = Introspector::new();
46//! let server_id = ServerId::new("github");
47//! let config = ServerConfig::builder()
48//! .command("/path/to/github-server".to_string())
49//! .build();
50//! let info = introspector.discover_server(server_id, &config).await?;
51//!
52//! // Generate progressive loading files
53//! let generator = ProgressiveGenerator::new()?;
54//! let code = generator.generate(&info)?;
55//!
56//! // Files are generated, ready to write to disk
57//! for file in &code.files {
58//! println!("Generated: {}", file.path);
59//! // Write to ~/.claude/servers/github/
60//! }
61//! # Ok(())
62//! # }
63//! ```
64//!
65//! ## Progressive Loading Pattern
66//!
67//! Once files are written to disk, Claude Code can discover and load tools progressively:
68//!
69//! ```bash
70//! # Step 1: Discover available servers
71//! $ ls ~/.claude/servers/
72//! github/ google-drive/
73//!
74//! # Step 2: Discover available tools in github server
75//! $ ls ~/.claude/servers/github/
76//! index.ts createIssue.ts updateIssue.ts getIssue.ts
77//!
78//! # Step 3: Load ONLY the tool you need
79//! $ cat ~/.claude/servers/github/createIssue.ts
80//! // TypeScript code for createIssue tool
81//! ```
82//!
83//! This achieves 98% token savings compared to loading all tools upfront.
84//!
85//! # Feature Flag
86//!
87//! This module is only available when the `progressive` feature is enabled:
88//!
89//! ```toml
90//! [dependencies]
91//! mcp-codegen = { version = "0.1", features = ["progressive"] }
92//! ```
93
94pub mod generator;
95pub mod types;
96
97// Re-export main types
98pub use generator::ProgressiveGenerator;
99pub use types::{
100 BridgeContext, CategoryInfo, IndexContext, PropertyInfo, ToolCategorization, ToolContext,
101 ToolSummary,
102};