Skip to content

Commit 9dcddee

Browse files
committed
feat: Implement MCP code generation crate for TypeScript/Python wrappers
This commit implements Phase 1 of the Code Execution with MCP plan, creating the terraphim_mcp_codegen crate that generates typed wrappers for MCP tools to enable code-based tool usage instead of direct tool calls. New crate features: - terraphim_mcp_codegen: Code generation infrastructure - Tool introspection and metadata extraction - TypeScript code generator with full type definitions - Python code generator with type hints - MCP runtime bridge for JavaScript and Python - CLI tool (mcp-codegen) for generating code packages Generated code includes: - Typed interfaces/classes for all 17 MCP tools - Async/await patterns for tool calls - JSDoc/docstring documentation - Usage examples for each tool - Tool categorization and capability metadata This enables AI agents to write code that imports MCP tools as modules: ```typescript import { terraphim } from 'mcp-servers'; const results = await terraphim.search({ query: "rust patterns" }); const filtered = results.filter(r => r.rank > 0.8); return { count: filtered.length, top: filtered[0] }; ``` Expected outcome: 98% token reduction (150K → 2K tokens for workflows)
1 parent 0f376b7 commit 9dcddee

8 files changed

Lines changed: 2269 additions & 4 deletions

File tree

Cargo.lock

Lines changed: 145 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
[package]
2+
name = "terraphim_mcp_codegen"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "Code generator for MCP server tools - creates TypeScript and Python wrappers"
6+
license = "MIT"
7+
8+
[dependencies]
9+
# Workspace dependencies
10+
tokio = { workspace = true }
11+
serde = { workspace = true }
12+
serde_json = { workspace = true }
13+
thiserror = { workspace = true }
14+
anyhow = { workspace = true }
15+
16+
# Template engine for code generation
17+
tera = "1.19"
18+
19+
# Case conversion for naming conventions
20+
convert_case = "0.6"
21+
22+
# MCP server integration
23+
terraphim_mcp_server = { path = "../terraphim_mcp_server" }
24+
terraphim_config = { path = "../terraphim_config" }
25+
26+
# Runtime support
27+
rmcp = "0.2"
28+
29+
[[bin]]
30+
name = "mcp-codegen"
31+
path = "src/bin/codegen.rs"
32+
33+
[dev-dependencies]
34+
tempfile = "3.10"

0 commit comments

Comments
 (0)