Skip to content

paddo/mcp-code-wrapper

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

59 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

MCP Code Wrapper

License: MIT npm version GitHub issues PRs Welcome

⚠️ EXPERIMENTAL: This project is in active development and not production-ready. APIs may change without notice. Use at your own risk. Contributions and feedback welcome!

Transform MCP tool definitions into progressive discovery APIs (96% context savings)

Generate code execution wrappers for Model Context Protocol servers with automatic progressive tool discovery. Reduces context usage by up to 96% while maintaining full MCP functionality.

The Problem

Loading MCP servers directly into Claude Code bloats context with ALL tool definitions:

Chrome DevTools MCP:    17,500 tokens (26 tools)
MSSQL Database (Γ—2):    11,200 tokens (16 tools)
─────────────────────────────────────────────
Total:                  28,700 tokens (14.5% of 200k context)

With 3-4 MCP servers, you easily hit 50k+ tokens before doing any actual work.

The Solution

Progressive Discovery via Filesystem Structure

Instead of loading all tools upfront, present them as a TypeScript API filesystem that Claude explores on-demand:

api-universal/
β”œβ”€β”€ index.ts              # Root discovery (~100 tokens)
β”œβ”€β”€ navigation/           # 6 tools
β”‚   β”œβ”€β”€ navigate_page.ts  # Load only when needed
β”‚   └── index.ts
β”œβ”€β”€ debugging/            # 5 tools
└── ...

Claude reads only what it needs:

  1. Read root index β†’ discover categories
  2. Explore category β†’ see available tools
  3. Read specific tools β†’ get documentation
  4. Use the APIs β†’ execute via MCP

Result: ~550 tokens for a typical 2-tool task (vs 28,700 tokens)

Quick Start

Install

# Via npx (no install needed)
npx mcp-code-wrapper .                # Current directory
npx mcp-code-wrapper /path/to/project # Specific project
npx mcp-code-wrapper --global         # Global ~/.claude/ MCPs
npx mcp-code-wrapper --help           # Show help

# Or clone and run locally
git clone https://github.com/paddo/mcp-code-wrapper
cd mcp-code-wrapper
pnpm install
pnpm run generate /path/to/project

Usage

Project Mode (converts MCPs in a project):

npx mcp-code-wrapper .                # Current directory (interactive selection)
npx mcp-code-wrapper /path/to/project # Specific directory (interactive selection)
npx mcp-code-wrapper . --all          # Generate all servers without prompting
npx mcp-code-wrapper . --servers mssql-main,chrome-devtools  # Specific servers

Interactive mode (default):

  • Shows list of available MCP servers
  • Select which servers to generate wrappers for
  • Useful when you only want specific MCPs

All mode (--all flag):

  • Generates wrappers for all MCPs without prompting
  • Useful for automation/scripts

What it does:

  1. Discovers all MCP servers in .mcp.json
  2. Prompts for server selection (unless --all flag)
  3. Generates code wrappers in .mcp-wrappers/
  4. Creates Claude Code Skills for each MCP
  5. Disables MCPs (keeps config for executor)
  6. Updates .gitignore

Global Mode (explicit flag required):

npx mcp-code-wrapper --global

Looks for ~/.claude/mcp.json and generates wrappers in ~/.claude/.mcp-wrappers/

After Generation

Restart Claude Code to load new Skills:

claude -c

⚠️ Important: When Claude Code restarts and prompts to enable MCPs, decline/toggle them OFF. The Skills use progressive discovery - MCPs stay disabled and are spawned on-demand by the wrapper.

Skills will use .mcp.json config to spawn servers on-demand with progressive discovery.

Verify Skills Are Loaded

After restarting, ask Claude what skills it has:

> what skills do you have?

I have access to three specialized skills:

1. mcp-chrome-devtools - Browser automation and testing
   - Navigate pages, fill forms, take screenshots
   - Inspect network traffic, debug JavaScript

2. mcp-mssql-dev - Database operations on 'app_dev' database
   - Execute SQL queries, read/write data
   - Manage tables and schemas

3. mcp-mssql-prod - Database operations on 'app_prod' database
   - Same SQL capabilities, production database

Token Economics

Real-World Example

Before (Direct MCP):

  • Chrome DevTools: 26 tools = 17,500 tokens
  • Database Server 1: 8 tools = 5,600 tokens
  • Database Server 2: 8 tools = 5,600 tokens
  • Total: 28,700 tokens (14.5% of context)

After (Progressive Discovery):

  • Root indexes: ~200 tokens
  • 2 tool definitions: ~350 tokens
  • Total: ~550 tokens
  • Savings: 98% (28,150 tokens freed)

Scalability

Workflow Tools Used Direct MCP Progressive Savings
Simple task 2 tools 28,700 tokens 550 tokens 98%
Medium task 5 tools 28,700 tokens 950 tokens 97%
Complex task 10 tools 28,700 tokens 1,650 tokens 94%

Even complex workflows save 90%+ of context.

How It Works

1. Add MCPs to Your Project

// .mcp.json
{
  "mcpServers": {
    "chrome-devtools": {
      "type": "stdio",
      "command": "npx",
      "args": ["chrome-devtools-mcp@latest"],
      "env": {}
    },
    "database-server": {
      "type": "stdio",
      "command": "node",
      "args": [".mcp-server/dist/index.js"],
      "env": {
        "DB_HOST": "your-host",
        "DB_NAME": "your-database",
        "DB_USER": "your-user",
        "DB_PASSWORD": "***"
      }
    }
  }
}

2. Generate Wrappers

npx mcp-code-wrapper /path/to/project

Output:

πŸ” Discovering MCP servers in /path/to/project
βœ… Found .mcp.json

πŸ“¦ Discovered 2 MCP servers:
   - chrome-devtools
   - database-server

πŸ”§ Generating wrapper for: chrome-devtools
   βœ… 26 tools in 7 categories
🎯 Creating Claude Code Skill wrapper...

πŸ”§ Generating wrapper for: database-server
   βœ… 8 tools in 1 category
🎯 Creating Claude Code Skill wrapper...

βœ… Generated wrappers for 2 MCP servers
πŸ“ Output: /path/to/project/.mcp-wrappers/

πŸ”• Disabled 2 MCP servers in .mcp.json
πŸ”• Disabled MCPs in settings.local.json
   MCPs stay in .mcp.json for executor reference
   Restore with: npx mcp-code-wrapper --restore

⚠️  IMPORTANT: Restart Claude Code to load new Skills
   Run: claude -c

3. Generated Structure

/path/to/project/
β”œβ”€β”€ .mcp.json                    # MCPs disabled (in-place)
β”œβ”€β”€ .mcp-wrappers/               # Generated code wrappers
β”‚   β”œβ”€β”€ chrome-devtools/
β”‚   β”‚   β”œβ”€β”€ navigation/
β”‚   β”‚   β”‚   β”œβ”€β”€ navigate_page.ts
β”‚   β”‚   β”‚   β”œβ”€β”€ take_screenshot.ts
β”‚   β”‚   β”‚   └── index.ts
β”‚   β”‚   β”œβ”€β”€ debugging/
β”‚   β”‚   └── index.ts
β”‚   └── database-server/
β”‚       β”œβ”€β”€ queries/
β”‚       β”‚   β”œβ”€β”€ read_data.ts
β”‚       β”‚   β”œβ”€β”€ insert_data.ts
β”‚       β”‚   └── index.ts
β”‚       └── index.ts
└── .claude/
    β”œβ”€β”€ settings.local.json      # MCPs disabled (in-place)
    └── skills/                  # Auto-generated Skills
        β”œβ”€β”€ mcp-chrome-devtools/
        β”‚   β”œβ”€β”€ skill.json
        β”‚   └── instructions.md
        └── mcp-database-server/
            β”œβ”€β”€ skill.json
            └── instructions.md

4. Progressive Discovery in Action

When you invoke a Skill:

// Claude reads root index (100 tokens)
import * as db from './.mcp-wrappers/database-server/index.ts';
// Discovers: { queries: {...} }

// Explores category (50 tokens)
import * as queries from './.mcp-wrappers/database-server/queries/index.ts';
// Discovers: { read_data, insert_data, ... }

// Reads specific tool (200 tokens)
import { read_data } from './.mcp-wrappers/database-server/queries/read_data.ts';
// Gets full documentation and API

// Uses tool
const result = await read_data({ query: 'SELECT * FROM users' });

Total: 350 tokens (vs 5,600 tokens loading all tools)

Key Features

βœ… Universal: Works with ANY MCP server (npm, Python, binaries, custom) βœ… Auto-discovery: Finds all MCPs in .mcp.json automatically βœ… Skills integration: Auto-generates Claude Code Skills βœ… Config preservation: Disables MCPs but keeps config for executor βœ… Token efficient: 96%+ context savings βœ… Git-safe: Auto-updates .gitignore for generated code βœ… No secrets committed: Env vars stay in .mcp.json (not tracked) βœ… Auto-normalized responses: Runtime executor automatically unwraps MCP response formats

Use Cases

1. Multi-Database Projects

Convert multiple database MCPs without context bloat:

# Project with 3 database connections
npx mcp-code-wrapper /path/to/project

# Before: 3 databases Γ— 5.6k tokens = 16.8k tokens
# After: Root + 3 tools = ~800 tokens
# Savings: 95%

2. Browser Automation

Use Chrome DevTools MCP without loading all 26 tools:

# Before: 17.5k tokens
# After (using 2 tools): 650 tokens
# Savings: 96%

3. Global MCP Management

Convert all your global MCPs once:

npx mcp-code-wrapper --global

# Skills available in all projects
# MCPs disabled globally
# Context savings across all sessions

Advanced Usage

Restore Original MCPs

Remove all generated wrappers and Skills, re-enable MCPs:

# Restore current directory
npx mcp-code-wrapper --restore

# Restore specific project
npx mcp-code-wrapper --restore /path/to/project

This will:

  • Remove .mcp-wrappers/ directory
  • Remove all mcp-* Skills from .claude/skills/
  • Re-enable MCPs in .mcp.json (removes "disabled": true)
  • Re-enable MCPs in .claude/settings.local.json

No backup files created - operates on config in-place to avoid accidentally committing secrets.

Keep MCPs Enabled

By default, MCPs are disabled after wrapper generation. To keep them enabled:

npx mcp-code-wrapper /path/to/project --no-disable

This generates wrappers but leaves MCPs active in both .mcp.json and .claude/settings.local.json.

Generate All Without Prompting

To skip interactive server selection and generate all at once:

npx mcp-code-wrapper /path/to/project --all

This is useful for automation, CI/CD, or when you always want all MCPs wrapped.

Generate Specific Servers

To generate wrappers for specific servers without prompting:

npx mcp-code-wrapper /path/to/project --servers mssql-main,chrome-devtools

This is useful when you:

  • Only want specific MCPs wrapped
  • Are automating wrapper generation in scripts
  • Want to regenerate just one server without interactive prompts

Generate for Specific MCP

# Traditional command mode (for testing)
pnpm run generate --from-mcp-json /path/to/.mcp.json --server database-server

Generate with Custom Environment

DB_HOST=your-host DB_NAME=your-database pnpm run generate node /path/to/mcp-server.js

Project Structure

mcp-code-wrapper/
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ cli.ts                    # npx entry point
β”‚   β”œβ”€β”€ generator-universal.ts    # Universal MCP generator
β”‚   β”œβ”€β”€ executor.ts               # MCP client & code executor
β”‚   β”œβ”€β”€ measure-tokens.ts         # Token comparison tool
β”‚   └── index.ts                  # Demo workflow
β”œβ”€β”€ USAGE.md                      # Detailed usage guide
β”œβ”€β”€ FINDINGS.md                   # Experiment analysis
β”œβ”€β”€ CONTEXT.md                    # Project context
└── UNIVERSAL_GENERATOR.md        # Technical details

Documentation

Workflow Comparison

Without Code Wrapper

Session Start
└─ Load all MCP tool definitions (28.7k tokens)
   └─ Use 2 tools
      └─ 26.7k tokens wasted on unused tools

With Code Wrapper

Session Start
└─ Load Skills (50 tokens)
   └─ Read root index (100 tokens)
      └─ Navigate to category (50 tokens)
         └─ Read 2 tool files (350 tokens)
            └─ Use tools
Total: 550 tokens (98% savings)

Requirements

  • Node.js 18+
  • Claude Code (for Skills integration)
  • Project with .mcp.json or global ~/.claude/mcp.json

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

This is an experimental project. See CONTEXT.md for current status and next steps.

License

MIT

Related Work

Credits

Built by @paddo based on Anthropic's code execution pattern.

About

Universal MCP code execution wrapper - 96% token reduction through progressive discovery

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages