Skip to main content
Glama

MCPtoCodeMode

An MCP server that sits in front of your other MCP servers. The model gets three tools, search, describe and execute, and calls your servers from a short JavaScript program. Only the program's result goes back into the conversation.

npx -y mcptocodemode demo    # offline comparison, no keys or config
npx -y mcptocodemode setup   # add it to your coding agents

setup finds Claude Code, Codex, Cursor, Grok, OpenCode, Pi and Claude Desktop, and asks which of them to configure. It reuses the MCP servers each agent already has, lists every file it will change, and writes nothing until you confirm. Restart the agents afterwards.

setup does not remove the servers you already had, so until you take them out the agent sees their tools as well as the three new ones. docs/agents.md shows how to take them out without losing their config.

When it helps

A program can page through results, aggregate records, or pass a file from one tool to another without any of it entering the conversation. For example, to total the paid orders in a folder of JSON files:

const listing = await filesystem.list_directory({ path: "/data/orders" });
const names = listing.content.split("\n").map((line) => line.replace("[FILE] ", ""));
const orders = await Promise.all(
  names.map(async (name) => JSON.parse((await filesystem.read_text_file({ path: `/data/orders/${name}` })).content)),
);
const paid = orders.filter((order) => order.status === "paid");
return { paid: paid.length, total: paid.reduce((sum, order) => sum + order.total, 0) };

Called directly, every file would come back into the conversation for the model to add up. Here only { paid, total } comes back.

For one call with a short answer, calling the tool directly is simpler.

Related MCP server: toolJev

Benchmarks

Claude Sonnet 5.5 on three tasks, three runs each, against seven reference servers that expose 55 tools:

Plain MCP

MCPtoCodeMode

Correct answers

9 / 9

9 / 9

Input tokens

531,480

94,002

Cost

$1.108

$0.222

Turns

21

29

Tool definitions in every prompt

31,179 bytes

2,996 bytes

Both setups answered every task correctly. MCPtoCodeMode took more turns because the model usually ran search first. A fourth task paged through mail and passed a 150 KB image between tools. Through plain MCP, Sonnet didn't produce a correct answer ($0.756, 79 s). Through MCPtoCodeMode it did ($0.061, 10 s), because the image went from one tool to the next as a handle and never entered the conversation.

REPORT.md has the method, raw data and limits: three small tasks, two models and one machine.

How it works

  • search finds methods by keyword and returns TypeScript signatures for the top results.

  • describe returns the signatures of one server ("notes") or one method ("notes.get").

  • execute runs JavaScript in which each server is a global, for example await notes.get({ id: "1" }). It returns the program's result, its console.log output and the list of methods it called. Anything the program puts on state is still there on the next run.

The program runs in a QuickJS sandbox with no network, filesystem or credentials, so it can only reach the world through your MCP servers. The tools themselves are not restricted: one that sends email still sends it. --read-only refuses any method its server does not mark as read-only. The full contract is in SPEC.md.

Commands

npm install -g mcptocodemode installs the cm and mcptocodemode commands. Without installing, run npx -y mcptocodemode <command>. Note that npx cm runs a different package.

Command

What it does

cm setup

Add MCPtoCodeMode to the agents you pick. --remove takes it out.

cm demo [--json]

Run the offline mail comparison.

cm doctor

Check configuration without starting servers.

cm list

Connect to every server and print the methods available.

cm find <words> · cm index

Search the official MCP registry, or download it for faster search.

cm add <name> · cm remove <server>

Add a registry server to your config, or remove one.

cm login <server> · cm logout <server>

Sign in to a remote server with OAuth, or sign out.

cm serve

Run the MCP server. Agents start this.

cm sdk --out api.d.ts

Write the TypeScript declarations for the sandbox.

docs/agents.md has the manual config for each agent. docs/configuration.md covers server discovery, options, the registry, OAuth, troubleshooting and limits.

Library

import { catalogFromServers, CodeMode } from "mcptocodemode";

const catalog = catalogFromServers([
  { name: "notes", tools: [{ name: "get", inputSchema: { type: "object", properties: { id: { type: "string" } } } }] },
]);
const mode = new CodeMode(catalog, async (call) => ({ id: call.input.id, title: "Buy milk" }));

await mode.execute(`return await notes.get({ id: "1" });`);
  • beforeCall can refuse a call before it runs. readOnlyPolicy(catalog) returns a beforeCall that blocks writes.

  • createCodeModeServer(mode) serves a CodeMode over MCP.

  • UpstreamPool connects to real MCP servers.

Contributing

CONTRIBUTING.md covers setup, tests and releases, and CHANGELOG.md lists every change. For questions see SUPPORT.md, and report vulnerabilities through SECURITY.md. MIT licensed.

The idea comes from Cloudflare's Code Mode. This project uses plain MCP, so it works with any MCP client.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      Not graded
      quality
      C
      maintenance
      Fronts every MCP server you have with two tools: search shortlists relevant tools, and execute runs sandboxed Python that calls upstream tools as mcp..(). It enables agents to make bulk, repeated, or conditional tool calls using calibrated decision-model choices instead of per-item LLM generation.
      3
      MIT
    • A
      license
      Not graded
      quality
      B
      maintenance
      Exposes a single execute tool so agents can discover, inspect schemas for, and compose calls to connected upstream MCP servers by writing JavaScript that runs in a fresh sandboxed QuickJS VM. Results from combined tool calls are returned as text or JSON, keeping large tool catalogs out of the agent's context.
      MIT
    • A
      license
      A
      quality
      B
      maintenance
      Enables agents to accomplish multi-step work by writing a single sandboxed JavaScript program that drives shell, filesystem, HTTP, and every tool of any configured MCP server, returning only a small summary instead of raw JSON. This collapses dozens of advertised tool schemas into one tool, cutting per-request context by roughly 26× while keeping disabled upstream servers reachable.
      1
      34 npm
      MIT