replicate-mcp-code-mode: When MCP Stops Picking Tools and Starts Writing Code

Replicate’s experimental server swaps endpoint sprawl for a two-step workflow: search the docs, write TypeScript, execute it in a local Deno sandbox.

8 min read • View on GitHub • More from replicate

A vast wall of tiny drawers stands behind a sparse workbench. In front, a single sheet of TypeScript and a drafting compass replace the need to open dozens of compartments. The scene explains the article’s core idea: large APIs stop feeling manageable when every endpoint becomes its own tool.
The shift is not from one tool to a better tool. It is from tool selection to code generation.
Key Takeaways

The real problem is tool sprawl

Traditional MCP assumes the model should pick from a menu of explicit tools. That works until the API surface gets large, the workflows get chained, and the tool list starts eating the context window before the task even begins.

Replicate is a bad candidate for the old pattern in the best possible way. It has a broad model catalog, many narrow operations, and plenty of multi-step jobs where the model would otherwise bounce between search, fetch, transform, and predict.

The old path fans out into many tool calls. The new one collapses the middle into a single code-bearing loop.

Replicate’s answer is not more tools

The repository’s central move is simple: expose a docs search tool and a code execution tool, then let the model bridge the gap. The LLM looks up the SDK details it needs, writes TypeScript, and runs that code in a local Deno sandbox.

That is why the project feels more like an abstraction reset than an incremental MCP server. The model is no longer navigating a shelf of endpoints. It is writing the integration layer it needs for the specific job in front of it.

import Replicate from "replicate";

const replicate = new Replicate({ auth: Deno.env.get("REPLICATE_API_TOKEN")! });

const output = await replicate.run("some-model", {
  input: {
    prompt: "A small red fox in snowfall"
  }
});

console.log(output);

The exact script changes with the request, but the shape matters more than the details. Search, synthesize, execute, return the result. The code block becomes the place where state, branching, retries, and composition live.

Why Deno is the quiet enabler

Letting an LLM write code is only interesting if the execution boundary is constrained. Deno matters because it gives the project a sandboxed runtime with a security model that is built around explicit permissions, not silent trust.

That makes the workflow legible. The model can assemble logic, but it does not get to roam the machine freely. In this design, the sandbox is not a footnote. It is the reason the pattern is usable at all.

A sealed glass chamber contains a strip of TypeScript entering from one side and a finished artifact leaving from the other. Around the chamber are locked gates for file access, network access, and system access. The image explains how sandboxing makes model-written code safer to execute.
The security story is not perfect trust. It is constrained execution with visible boundaries.

What this changes about MCP

Code Mode is procedural where traditional MCP is descriptive. One model asks, "Which tool should I call?" The other asks, "What code should I write to finish the job?" That is a different abstraction boundary, and it is the interesting one.

ModeTool surfaceContext usageExecution modelBest fit
Traditional MCPOne tool per API methodHigh, because the catalog is always presentMany small calls with intermediate JSONNarrow, stable APIs
Replicate Code ModeDocs search plus TypeScript executionLow, because the model only pulls what it needsOne code block that can chain operationsLarge, dynamic API surfaces
Cloudflare-style code modeCode-first, interface-heavyModerate to highWrite code against loaded interfacesTooling where the API is already well known
goose-style extensible agentsExtensions activated as neededVariableAgent plus modular extensionsGeneral-purpose local automation

The table is not about declaring a winner. It is about matching mechanism to problem size. Replicate is optimizing for a broad and changing API where chained workflows are common, so the model needs composition more than it needs a bigger menu.

Where Replicate’s version fits in the broader code-mode conversation

Cloudflare engineers recently coined the term "code mode" in a blog post: Code Mode: the better way to use MCP. The approach described there is similar, but our current implementation is slightly different: Replicate's MCP server (created by Stainless) uses a "docs search" tool to teach the LLM about the SDK, rather than loading the full TypeScript interface into the context window.

replicate/replicate-mcp-code-mode Repository, Project Documentation · replicate-mcp-code-mode README

That distinction matters. Replicate is not just borrowing the label. It is making a pragmatic version of the idea for a platform where the SDK is the product surface and the model catalog keeps moving.

The repository reads like a proof that the bottleneck was never "how do we expose more tools?" It was "why are we forcing models to choose tools when they could write the glue themselves?"

The bigger bet

If this pattern spreads, agent design will shift from enumerating capabilities to composing them on demand. The durable lesson is not that every MCP server should become a code runner. It is that the model may already be better used as a small software engineer than as a picker from a crowded toolbar.