/meta:create-mcpfrom meta
Author Code Mode MCP servers that wrap multiple host functions behind one code-generating tool, replacing per-call JSON tool dispatch with a single executed JavaScript function.
Ships in meta. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
Build a local MCP server that exposes a single code tool. Claude Code (as the LLM host) writes one async () => { ... } per turn that calls your tools through a typed codemode.* SDK, and your server executes it in a local sandbox. N tool calls collapse into one round-trip.
Inspired by Apple's CodeAct paper. LLMs have seen millions of lines of real code and relatively few JSON tool-call schemas, so generating code is more reliable than dispatching structured tool calls. For a local server, @cloudflare/codemode gives you two pieces:
codeMcpServer({ server, executor }) — wraps an upstream McpServer into a new one exposing a single code tool whose description carries TypeScript declarations for every upstream toolExecutor interface — where the code runs; the Cloudflare DynamicWorkerExecutor is one implementation, you write another for local useThe Executor contract is deliberately minimal so Node VM, subprocess, and container executors are all first-class. The authoritative signature lives in node_modules/@cloudflare/codemode/dist/executor-*.d.ts after install.
code tool instead of N individual toolsNon-goals: Cloudflare Workers deployment, hosted MCP endpoints, other LLM providers (Claude Code is the only target).
mkdir my-codemode-tool && cd my-codemode-tool
pnpm init
pnpm pkg set type=module
pnpm add @cloudflare/codemode @modelcontextprotocol/sdk @cfworker/json-schema zod
pnpm add -D typescript tsx @types/node
mkdir src
cp ${CLAUDE_SKILL_DIR}/templates/server.ts src/server.ts
@cfworker/json-schema is an optional peer of the MCP SDK that @cloudflare/codemode/mcp imports unconditionally; without it the server dies at startup with Cannot find package '@cfworker/json-schema'. ai is not needed for this path.
The copied file is templates/server.ts. Edit its createUpstream() function to add your own tools, then register with Claude Code:
claude mcp add --scope user codemode-local-dev -- pnpm dlx tsx "$(pwd)/src/server.ts"
Restart Claude Code. Your server now advertises one code tool whose description contains the typed signatures of every tool in createUpstream(). See references/mcp-wiring.md for the production (compiled) registration and scope choice.
Use templates/server.ts verbatim — it is the reference. Do not hand-roll a smaller version from memory. Three details the first-draft executor keeps getting wrong are load-bearing:
codeMcpServer passes the model's code verbatim and keys fns by raw MCP tool names, while the tool description advertises sanitized names (get-user becomes codemode.get_user). Skip the sanitizing and every hyphenated tool fails with codemode.get_user is not a function; skip normalizing and fenced or bare-statement code fails to parse. DynamicWorkerExecutor does both internally, which is why Worker examples never show it.@cloudflare/codemode. The root entry imports cloudflare:workers at runtime, so a value import crashes Node with ERR_UNSUPPORTED_ESM_URL_SCHEME. That rules out the library's own normalizeCode and sanitizeToolName; the template carries local equivalents. See references/gotchas.md.console inside the sandbox. An in-process executor shares the host console, so a generated console.log writes to stdout and corrupts the MCP stream. The template binds a capturing console that collects logs instead.The shape of the template's executor:
class NodeVMExecutor implements Executor {
async execute(code, providersOrFns): Promise<ExecuteResult> {
const providers = Array.isArray(providersOrFns)
? providersOrFns
: [{ name: "codemode", fns: providersOrFns }]; // deprecated flat form
const logs: string[] = [];
const names = ["console"];
const values: unknown[] = [sandboxConsole]; // pushes into logs
for (const p of providers) {
// (template first rejects invalid or duplicate provider names)
const fns = {};
for (const [tool, fn] of Object.entries(p.fns)) fns[sanitizeToolName(tool)] = fn;
names.push(p.name);
values.push(fns);
}
try {
return { result: await compile(names, code)(...values), logs }; // normalizes code
} catch (err) {
return { result: undefined, error: err instanceof Error ? err.message : String(err), logs };
}
}
}
Tools are authored with McpServer.registerTool. codeMcpServer unwraps each result before sandbox code sees it: structuredContent is returned as-is, all-text content is JSON.parsed (or returned as the raw string), isError: true throws a catchable Error, and mixed text/binary content comes through as the raw CallToolResult. So returning JSON.stringify(data) as the text content gives sandbox code data.
What loads under plain Node is decided by entry point, not by function — the root and /ai entries import cloudflare:workers at module load (verified against 0.5.x):
| Loads in Node | Workers-only at runtime (ignore or replace) |
|---|---|
@cloudflare/codemode/mcp: codeMcpServer, openApiMcpServer | Root entry values: DynamicWorkerExecutor, ToolDispatcher, normalizeCode, sanitizeToolName, generateTypesFromJsonSchema, truncateResult, runCode |
Type-only root imports: Executor, ExecuteResult, ResolvedProvider | Durable runtime: createCodemodeRuntime, CodemodeRuntime, connectors (CodemodeConnector, McpConnector, OpenApiConnector), snippets |
@cloudflare/codemode/ai: createCodeTool, generateTypes, toolSetConnector | |
WorkerLoader binding, worker_loaders in wrangler.jsonc, AIChatAgent, agents/mcp, agents/tsconfig |
Write a local Executor to replace DynamicWorkerExecutor; codeMcpServer is the drop-in. @cloudflare/codemode/browser (IframeSandboxExecutor) also loads but needs a DOM. See references/local-executor.md for three executor options (AsyncFunction, node:vm, subprocess) and their trade-offs.
codeMcpServer has no approval flow and exposes every upstream tool, so each runs the moment sandbox code calls it. Durable approvals exist only in the Workers CodemodeRuntime. Route approval-required tools through a separate, non-codemode MCP server.codemode.* from host code. It only exists inside generated code during execute(). Host code calls your tool functions directly.codeMcpServer hands execute() raw code and raw names; host code must not pre-process either.stdout except the MCP protocol. StdioServerTransport owns it. Route diagnostics to stderr via console.error.AsyncFunction and vm.runInContext run with full host capabilities. Acceptable for personal use; if you ever expose the server to untrusted input, move to the subprocess executor.| File | Contents |
|---|---|
| references/local-executor.md | Three executor implementations, log capture, security trade-offs |
| references/mcp-wiring.md | Stdio transport, Claude Code registration, scope, tsconfig |
| references/gotchas.md | Line-by-line Cloudflare-to-local translations, behavioral traps |
| templates/server.ts | Runnable skeleton with NodeVMExecutor + two example tools |
Authoritative sources, in order of preference:
node_modules/@cloudflare/codemode/dist/*.d.ts and dist/mcp.js — the installed package; mcp.js is short and shows exactly what codeMcpServer hands your executornode_modules/@cloudflare/codemode/docs/ and README.md — package docs, shipped in the tarball since 0.4.2Executor signature as of 0.5.5 but trail new releasescodemode-mcp example in Cloudflare's published examples — the closest Worker-shaped reference; port per references/gotchas.mdWhat SKILL.md sets; muted values are Claude Code's defaults
9 skills in this plugin
/brainstorm-modsBrainstorm mods and plugins worth building, for one project or globally, then design and build the one you pick./claude-docsAnswer Claude Code questions (CLI, Agent SDK, plugins, hooks, skills, slash commands, MCP, settings) from a locally cached copy of the official docs./create-agentsDesigning, authoring, and auditing Claude Code subagents — frontmatter, tool scoping, model choice, and memory. Use when creating, editing, or auditing an agent file in `.claude/agents/`.Other plugins' skills for the same job
npx claudepluginhub sustinbebustin/.dotfiles --plugin meta