mcp-code-mode-e66311 — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited mcp-code-mode-e66311 (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
Code Mode is a server-side MCP architecture where the LLM writes code to orchestrate API calls instead of calling individual tools one at a time.
Standard MCP has two scaling problems:
tools = tens of thousands of tokens spent before the first user token. Cloudflare's full API would require 1.17 million tokens as individual tools — exceeding most model context windows entirely.
20 back-and-forth cycles, each burning latency and tokens on intermediate results that only exist to feed the next step.
Code Mode solves both by collapsing the entire API surface into two meta-tools:
operations on demand, without the full spec ever entering context.
conditionals and pagination, and returns only the final result. The script runs in a secure sandbox server-side.
The result: Typically ~1,000 tokens for discovery setup before task payloads, rather than loading every tool definition up front. One execution call can replace 20+ round-trips. API keys stay server-side and never appear in tool parameters.
LLMs are trained on millions of lines of real-world code. Tool-calling schemas are mostly synthetic training examples. Code is the LLM's native orchestration language — it can express conditionals, loops, error handling, and data transformation that tool-calling schemas cannot.
Every Code Mode implementation, regardless of language or framework, converges on the same two-tool surface:
Purpose: Let the LLM execute code to find what operations exist without loading the full catalog.
Typical names: search, docs_search, find_tools, get_schema
What it does: Takes an executable code snippet (or a callable) that filters the operation catalog and returns a scoped subset of available operations — names, descriptions, parameter schemas — at whatever detail level the LLM needs.
Key design choices:
when it's ready to write code.
the OpenAPI spec — giving the LLM full programmatic filtering power.
Purpose: Run LLM-generated code in a secure sandbox and return the result.
Typical names: execute, run, run_workflow
What it does: Accepts a code string, runs it in an isolated environment with call_tool(name, params) or an authenticated API client injected as the only callable, and returns the output.
Key design choices:
tool parameters the LLM sees.
Choose the pattern based on API surface area and complexity:
search(code) → get_schema(tool_names) → execute(code)Best for APIs with many tools. The LLM pays for schemas only for the tools it actually needs. Cloudflare uses a variant where search itself takes code to query the OpenAPI spec.
search(code, detail="detailed") → execute(code)Search returns parameter schemas inline. One fewer round-trip at the cost of more tokens per search result. Good for catalogs under ~50 tools.
execute(code) [tool descriptions baked into execute's description]Skip discovery entirely for very small or well-known APIs. Bake the available functions into the execute tool's description string.
get_tags() → search(code, tags=[...]) → get_schema(names) → execute(code)Add GetTags upfront when your tools are organized into meaningful categories. Helps the LLM orient itself before searching.
FastMCP 3.1+ has a first-class CodeMode transform. Wrap any existing server:
from fastmcp import FastMCP
from fastmcp.experimental.transforms.code_mode import CodeMode
mcp = FastMCP("MyServer", transforms=[CodeMode()])
@mcp.tool
def get_payment(payment_id: str) -> dict:
"""Retrieve a payment by ID."""
return payments_client.get(payment_id)Clients no longer see get_payment directly. They see CodeMode's meta-tools. The original tools are still there, accessed through the execution layer.
Install: pip install "fastmcp[code-mode]"
from fastmcp.experimental.transforms.code_mode import (
CodeMode, GetTags, Search, GetSchemas, ListTools
)
# Default (3-stage): Search + GetSchemas
mcp = FastMCP("Server", transforms=[CodeMode()])
# 4-stage with tags
code_mode = CodeMode(
discovery_tools=[GetTags(), Search(), GetSchemas()],
)
# 2-stage: search returns schemas inline
code_mode = CodeMode(
discovery_tools=[Search(default_detail="detailed"), GetSchemas()],
)
# Single-stage: no discovery, bake descriptions in
code_mode = CodeMode(
discovery_tools=[],
execute_description=(
"Available tools:\n"
"- get_payment(payment_id: str) -> dict\n"
"Write Python using `await call_tool(name, params)` and `return` the result."
),
)from fastmcp.experimental.transforms.code_mode import CodeMode, MontySandboxProvider
sandbox = MontySandboxProvider(
limits={
"max_duration_secs": 10,
"max_memory": 50_000_000,
"max_recursion_depth": 100,
}
)
mcp = FastMCP("Server", transforms=[CodeMode(sandbox_provider=sandbox)])The sandbox injects call_tool as the only callable. Code must be async and use return:
# LLM-generated code inside execute
a = await call_tool("get_payment", {"payment_id": "pay_123"})
b = await call_tool("create_refund", {"payment_id": a["id"], "amount": a["amount"]})
return b@cloudflare/codemode)import { Agent } from "agents";
import { CodeMode } from "@cloudflare/codemode";
export class MyAgent extends Agent<Env, State> {
// ...
}Install: npm install agents @cloudflare/codemode
The Cloudflare implementation uses Dynamic Worker Loader (V8 isolates) as the sandbox. The search tool in the Cloudflare MCP server accepts JavaScript async arrow functions that run against a pre-resolved OpenAPI spec object. The execute tool injects a cloudflare.request() client with scoped OAuth permissions.
Key characteristics:
spec object available in search sandbox (pre-resolved OpenAPI)cloudflare.request() available in execute sandbox (authenticated, scoped)// LLM-generated search code
async () => {
const results = [];
for (const [path, methods] of Object.entries(spec.paths)) {
if (path.includes('/zones/') && path.includes('rulesets')) {
for (const [method, op] of Object.entries(methods)) {
results.push({ method: method.toUpperCase(), path, summary: op.summary });
}
}
}
return results;
}// LLM-generated execution code
async () => {
const zones = await cloudflare.request({ method: "GET", path: "/zones" });
const zone = zones.result.find(z => z.name === "example.com");
const rulesets = await cloudflare.request({
method: "GET",
path: `/zones/${zone.id}/rulesets`
});
return rulesets.result.map(r => ({ name: r.name, phase: r.phase }));
}| Level | Output | Tokens |
|---|---|---|
"brief" | Tool names + one-line descriptions | Cheapest |
"detailed" | Compact markdown with param names, types, required markers | Medium |
"full" | Complete JSON schema | Most expensive |
Search defaults to "brief". GetSchemas defaults to "detailed". LLM can override per call.
Code Mode is more secure by design than standard MCP tool proliferation:
The LLM never sees them in tool parameters.
host filesystem, env vars, or arbitrary network.
cannot import arbitrary modules or call arbitrary code.
network call, the sandbox blocks unapproved outbound requests.
Discovery tools can be custom callables. Each receives get_catalog (a request-scoped accessor) and returns a Tool:
from fastmcp.experimental.transforms.code_mode import CodeMode, GetToolCatalog, GetSchemas
from fastmcp.server.context import Context
from fastmcp.tools.tool import Tool
def list_payment_tools(get_catalog: GetToolCatalog) -> Tool:
async def list_tools(ctx: Context) -> str:
"""List all available payment tool names."""
tools = await get_catalog(ctx)
return ", ".join(t.name for t in tools)
return Tool.from_function(fn=list_tools, name="list_tools")
code_mode = CodeMode(discovery_tools=[list_payment_tools, GetSchemas()])Code Mode originated at Cloudflare (server-side approach) and was independently explored by Anthropic as "Programmatic Tool Calling." It is currently implemented in:
@cloudflare/codemode) — TypeScript, V8 sandboxfastmcp[code-mode]) — Python, Monty sandboxThe pattern is spreading rapidly among any API with more tools than a context window can hold. Anthropic measured: 37% token reduction, knowledge retrieval accuracy improved from 25.6% to 28.5%, context overhead reduced from 77K to 8.7K tokens in their own internal tooling.
Use Code Mode when:
Stick with standard tools when:
max_duration_secs and max_memory.Without them, LLM-generated scripts can run indefinitely.
description defeats the purpose. Staged discovery keeps context lean.
GetSchemas available even whensearch returns detailed results. Deeply nested schemas need the full JSON occasionally.
sandbox's injected client, not in the tool description string the LLM sees.
or it will assume the search was exhaustive.
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.