Date: 2025-09-30 Research Goal: Investigate existing solutions for generating TypeScript APIs from MCP tool schemas to enable IDE autocomplete and type safety
The research reveals that Cloudflare's "Code Mode" approach exists as a concept but lacks open-source implementation details. While the community has built several frameworks for MCP server development with TypeScript, no existing solution automatically generates TypeScript client APIs from MCP schemas for IDE autocomplete.
Key Finding: This represents a greenfield opportunity to build a first-class TypeScript code generation system that bridges MCP schemas to IDE-friendly type definitions.
Status:
What They Claim:
- Automatically converts MCP server schemas → TypeScript APIs
- Generates interfaces, doc comments, and type-safe method signatures
- Uses V8 isolates for sandboxed execution
- Provides "bindings" to MCP servers within sandbox
What's Missing:
- ❌ No public implementation or source code
- ❌ No details on schema → TypeScript conversion algorithm
- ❌ No code generation tool available
- ❌ Appears to be integrated into Cloudflare Workers (proprietary)
Source: Code Mode: the better way to use MCP
Key Quote:
"When you connect to an MCP server in 'code mode', the Agents SDK will fetch the MCP server's schema, and then convert it into a TypeScript API, complete with doc comments based on the schema."
Repository: https://github.com/jx-codes/codemode-mcp Status: ✅ Working implementation, but limited
What It Does:
- Provides HTTP proxy for MCP server access (
localhost:3001) - Uses Deno as sandbox runtime for code execution
- Exposes
execute_codetool for LLMs to write TypeScript/JavaScript - Lists available servers and tools via REST API
What It Doesn't Do:
- ❌ No automatic TypeScript API generation from schemas
- ❌ No IDE autocomplete support
- ❌ LLMs must use
fetch()to call proxy endpoints (not typed APIs) - ❌ No code generation from MCP tool schemas
Architecture:
LLM writes code → Deno sandbox → HTTP proxy → MCP servers
↑
No TypeScript
API generation
Key Limitation: README explicitly states that automatic TypeScript API generation is "a potential future enhancement" not currently implemented.
Repository: https://github.com/modelcontextprotocol/typescript-sdk Purpose: Build MCP servers and clients
Schema Definition Approach:
- Uses Zod for runtime schema validation
- Tool registration includes
inputSchemawith Zod types - Provides runtime type checking, not compile-time type generation
Example:
server.registerTool("calculate-bmi", {
title: "BMI Calculator",
description: "Calculate Body Mass Index",
inputSchema: {
weightKg: z.number(),
heightM: z.number()
}
}, async ({ weightKg, heightM }) => ({
content: [{ type: "text", text: String(weightKg / (heightM * heightM)) }]
}));Limitation for Our Use Case:
- ✅ Defines schemas for building MCP servers
- ❌ Does NOT generate TypeScript client APIs for consuming MCP servers
- ❌ No codegen tool for schema → TypeScript types
Repository: https://github.com/QuantGeekDev/mcp-framework
Features:
- Directory-based discovery for tools
- Automatic TypeScript type inference from Zod schemas
- Enforces description requirements for better documentation
Key Feature:
// TypeScript automatically infers types from Zod schema
const myTool = defineTool({
name: "my-tool",
description: "...",
input: z.object({
message: z.string().describe("Input message")
})
}, async ({ message }) => {
// `message` is automatically typed as string
return { content: [{ type: "text", text: message }] };
});Limitation:
- ✅ Great for server-side type safety
- ❌ Does NOT generate client-side TypeScript APIs
- ❌ Type inference only works within server definition, not for consumers
Repository: https://github.com/punkpeye/fastmcp
Features:
- Framework for building MCP servers
- Supports Zod and Valibot for schema validation
- Automatic schema generation in both cases
Limitation: Same as mcp-framework - server-side only, no client codegen
Repository: https://github.com/punkpeye/mcp-types
Purpose: Static TypeScript types for MCP protocol
What It Provides:
- Zod schemas for MCP protocol types (
Tool,Resource,Prompt) - Static TypeScript types generated via
zod-to-typescript - Drop-in replacement for official SDK types
Example:
import type { Tool, Resource, Prompt } from "mcp-types";
import { ToolSchema, ResourceSchema, PromptSchema } from "mcp-types";Limitation:
- ✅ Provides protocol-level types (Tool, Resource, Prompt)
- ❌ Does NOT generate types for specific tool implementations
- ❌ No codegen from individual MCP server schemas
- ✅ MCP protocol specification and TypeScript SDK
- ✅ Runtime schema validation with Zod
- ✅ Server-side type inference within tool definitions
- ✅ HTTP proxy implementations for MCP access
- ✅ Sandboxed code execution environments (Deno, Bun, QuickJS)
- ❌ Client-side TypeScript API generation from MCP schemas
- ❌ IDE autocomplete for MCP tool calls
- ❌ Compile-time type checking for tool arguments
- ❌ Automatic TypeScript declaration file (
.d.ts) generation - ❌ Developer tooling for schema → TypeScript codegen workflow
Thread: Code Mode: the better way to use MCP
Key Insights:
- Community is interested in Code Mode but frustrated by lack of implementation details
- Developers recognize that "LLMs are better at writing code than tool calling"
- Some skepticism about whether it's truly revolutionary vs. incremental improvement
- Questions about security implications of sandboxed code execution
Thread: Show HN: I built an MCP server using Cloudflare's code mode pattern
Key Insights:
- Community appreciated the open-source attempt (jx-codes/codemode-mcp)
- Developers noted the gap between Cloudflare's claims and available implementations
- Interest in Deno as sandbox runtime for TypeScript execution
Limited Discussion Found: Search for MCP and Code Mode on r/programming and r/MachineLearning yielded minimal results
General Sentiment:
- MCP adoption is still early stage
- Developers are experimenting with MCP servers but tooling is immature
- Mixed reactions to Anthropic's MCP - some see it as convenient, others skeptical of "game-changer" claims
Positive Signs:
- Companies like Block, Apollo, Zed, Replit, Codeium, Sourcegraph integrating MCP
- Growing ecosystem of MCP servers (100+ implementations on GitHub)
- Active development of frameworks (mcp-framework, FastMCP, mcp-ts-template)
Challenges:
- Tooling ecosystem is fragmented
- No standard approach to type generation
- Steep learning curve for MCP protocol
- Security concerns about running untrusted code
Based on blog posts and documentation, Cloudflare likely:
- Schema Fetching: Calls MCP
tools/listto get tool schemas - AST Generation: Converts JSON schemas → TypeScript AST
- Type Declaration: Generates interface definitions for inputs/outputs
- Doc Comment Injection: Transforms schema descriptions → TSDoc comments
- Binding Generation: Creates runtime proxy objects with typed interfaces
- V8 Isolate Integration: Injects bindings into sandboxed execution context
Inferred Architecture:
MCP Server Schema
↓
[Schema Parser]
↓
[TypeScript AST Generator]
↓
[Type Declaration Writer]
↓
interface GeneratedAPI {
/** Tool description from schema */
toolName(args: {
param1: string;
param2: number;
}): Promise<ToolResult>;
}
↓
[Runtime Binding Generator]
↓
const mcp = {
serverName: {
toolName: async (args) => callMCPTool('serverName', 'toolName', args)
}
}What We Have:
// MCP Manager discovers tools
mcpManager.getTools() → [
{ namespace: "automem.store_memory", schema: {...} },
{ namespace: "context7.resolve-library-id", schema: {...} }
]
// Code execution receives MCP proxy
const mcp = {
automem: {
store_memory: async (args) => __mcpCall('automem.store_memory', args)
}
}Limitation: No TypeScript type definitions for mcp object!
- ❌ No open-source tools for MCP schema → TypeScript codegen
- ❌ Cloudflare's solution is proprietary/unavailable
-
OpenAPI → TypeScript Codegen (e.g., openapi-typescript)
- Mature ecosystem for REST API type generation
- Could be adapted for MCP schemas
-
JSON Schema → TypeScript (e.g., json-schema-to-typescript)
- Core technology for schema transformation
- MCP schemas are JSON Schema compatible
-
GraphQL Code Generators (e.g., graphql-codegen)
- Similar problem: schema → typed client APIs
- Proven patterns for IDE autocomplete support
Why:
- ✅ Clear market gap - no existing solution
- ✅ Strong developer demand (based on community discussions)
- ✅ Proven patterns from adjacent domains (OpenAPI, GraphQL)
- ✅ We already have the infrastructure (codemode-unified MCP bridge)
Value Proposition:
- First-class TypeScript support for MCP consumers
- IDE autocomplete for all MCP tools
- Compile-time type checking for tool calls
- Automatic declaration file generation
┌─────────────────────────────────────────────────┐
│ MCP Schema Discovery │
│ (Fetch schemas from all connected MCP servers) │
└───────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Schema → TypeScript Transformer │
│ • Parse JSON Schema input definitions │
│ • Generate TypeScript interfaces │
│ • Create TSDoc comments from descriptions │
│ • Handle unions, optionals, arrays, objects │
└───────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Declaration File Generator │
│ • Write .d.ts files for each MCP server │
│ • Export typed namespaces │
│ • Include return type definitions │
└───────────────┬─────────────────────────────────┘
│
▼
┌─────────────────────────────────────────────────┐
│ Runtime Proxy Generator │
│ • Create proxy objects matching types │
│ • Inject into code execution context │
│ • Maintain type safety at runtime │
└─────────────────────────────────────────────────┘- Design schema → TypeScript transformer
- Build prototype for single MCP server (AutoMem)
- Generate
.d.tsfile with IDE autocomplete support - Test with real code execution in codemode-unified
- Support all MCP schema types (unions, optionals, arrays, nested objects)
- Generate declaration files for all connected MCP servers
- Integrate with build system for automatic regeneration
- Add CLI tool for manual codegen (
npx mcp-codegen)
- Package as standalone npm library (
@companykit/mcp-codegen) - Integrate into codemode-unified startup
- Write documentation and examples
- Publish to npm and promote to MCP community
MCP tools use JSON Schema for inputSchema:
{
"type": "object",
"properties": {
"content": {
"type": "string",
"description": "Memory content to store"
},
"tags": {
"type": "array",
"items": { "type": "string" },
"description": "Optional tags"
}
},
"required": ["content"]
}declare namespace mcp {
namespace automem {
/**
* Store a memory with optional tags and metadata
*/
function store_memory(args: {
/** Memory content to store */
content: string;
/** Optional tags */
tags?: string[];
/** Importance score 0-1 */
importance?: number;
}): Promise<MCPToolResult>;
}
}- json-schema-to-typescript: Convert JSON Schema → TypeScript types
- TypeScript Compiler API: Generate declaration files programmatically
- prettier: Format generated TypeScript code
- ajv: Validate MCP schemas before transformation
- ✅ JSON Schema → TypeScript is well-understood problem
- ✅ We control both schema source and execution environment
- ✅ Incremental adoption (works alongside existing proxy approach)
⚠️ MCP schema complexity (recursive types, unions, complex validation)⚠️ Keeping generated types in sync with schema changes⚠️ Tool result types are less standardized than inputs
- 🚨 None identified - this is a greenfield opportunity with proven patterns
The opportunity is clear: Build the first open-source, production-ready TypeScript code generation system for MCP schemas. This will:
- Fill a critical gap in the MCP ecosystem
- Provide first-class TypeScript support for codemode-unified
- Enable IDE autocomplete for all MCP tools
- Position CompanyKit as a leader in MCP tooling innovation
The technical path is well-understood, risks are manageable, and community demand is strong. This is a greenfield opportunity worth pursuing.
Next Document: TYPESCRIPT_CODEGEN_DESIGN.md - Detailed technical design and implementation plan