← Projects

mcpcode

TypeScript code generation for MCP servers

Overview

mcpcode generates type-safe TypeScript wrappers for MCP (Model Context Protocol) servers. Instead of loading all tool definitions into an agent's context window, the generated code can be imported on-demand, reducing token usage by up to 98%.

Problem

When connecting agents to multiple MCP servers, loading all tool definitions upfront consumes significant context. This limits the number of tools an agent can access and increases costs.

Solution

mcpcode reads your MCP server configuration and generates TypeScript modules for each server. Agents can then:

  • Import only the tools they need
  • Process data in code before returning results
  • Use familiar programming constructs
  • Keep intermediate results private

Usage

Install the CLI tool and run it against your mcp.config.json:

npm install -g @abmalk/mcpcode mcpcode generate

This generates a servers/ directory with typed functions for each tool. Import and call them directly in your agent code.

Features

  • STDIO, HTTP, and SSE transport support
  • Full TypeScript type inference
  • Watch mode for development
  • Search utilities for tool discovery
  • IDE integration rules for AI coding assistants