• Products
  • About
  • Test Blog Post
  • New Test

From Tool-Caller to Code-Writer

A sleek, cinematic composition of glowing speech bubbles, dynamic subtitles, and floating typography hovering around a soft-focus silhouette of a speaker, with translucent audio waveforms weaving through the text; rendered in a high-contrast, modern graphic design style with neon accents against a dark background.

From Tool-Caller to Code-Writer

Unlock a new execution model where your AI agent writes JavaScript instead of chaining repetitive tool calls. One sandboxed function handles complex multi-step edits, turning minutes of latency into milliseconds of execution.

Unlock a new execution model where your AI agent writes JavaScript instead of chaining repetitive tool calls.


One sandboxed function handles complex multi-step edits, turning minutes of latency into milliseconds of execution.

Trust the Sandbox

Run arbitrary agent-generated code with confidence. Each execution lives in a disposable V8 isolate with zero network access, while RPC stubs provide granular API controls. Security and flexibility are no longer a trade-off.

A serene landscape of a misty lake on a still morning, with the gentle ripples of the water reflecting the vibrant hues of a sunrise sky, symbolizing contemplation and introspection.
A vibrant, stylized illustration of a cityscape at sunset, with bold lines and bright colors to convey the energy and excitement of the subject matter.
A vibrant, swirling vortex of colors and lights that represent the dynamic and ever-changing nature of the conversation.

Real-Time Iteration at Scale

Broadcast live previews to connected CMS sessions or save directly for headless deployments. The result? A content workflow where you write, see, and ship in a single breath—no more guesswork between code and canvas.

Dynamic Workers: Code Mode for CMS

How we collapsed 15 sequential MCP tool calls into a single sandboxed JavaScript execution — and what it means for AI-driven content management.

The Problem: Death by Round-Trip

When an AI agent edits a StoryPress page via MCP, it makes sequential tool calls. Get the story. Get the schema. Get the field context. Update component one. Update component two. Update component three. Save. Each call is a full round-trip through the MCP protocol — HTTP request, serialization, response parsing, next request.

For a simple 'change the headline' task, that's fine. For 'rebuild the features section with 6 cards,' you're looking at 15-30 tool calls. The latency adds up. The agent spends more time waiting on protocol overhead than actually thinking about content.

The Insight: Code Is the Interface

Cloudflare's Dynamic Workers let a Worker spawn new Workers at runtime with arbitrary code. Each runs in its own V8 isolate — sandboxed, network-isolated, destroyed after execution. The key innovation: you can pass RPC stubs into the sandbox, giving it controlled access to your APIs without exposing credentials.

Instead of the agent calling tools one at a time, it writes a JavaScript function that does everything in one shot. The function runs in the sandbox with access to CMS operations via RPC. One MCP call replaces fifteen.

Agent Writes Code

The AI agent reads the page structure and schema, then generates a JavaScript function that performs all the changes. The agent is the brain — it decides what to do based on context.

Sandbox Executes

The code runs in an isolated V8 worker with no network access. It calls CMS methods via RPC stubs — the sandbox never sees raw tokens or credentials. Execution takes milliseconds.

Preview Updates Live

Write operations broadcast to the CMS editor via WebSocket. The user sees changes appear in real-time as the sandbox executes. Save when ready — or discard and iterate.

What We Built

The execute_code MCP tool wraps agent-generated JavaScript in a WorkerEntrypoint class, spawns a Dynamic Worker with globalOutbound: null (complete network isolation), and passes a CMSBridge RPC stub as env.CMS. The bridge delegates reads to ContentAPI and writes to the PreviewHub WebSocket fan-out.

The critical design decision: no credential duplication. A ContentAPIBridge WorkerEntrypoint owns the real ContentAPI instance (with token refresh callbacks). The CMSBridge receives it as an RPC stub — it can call methods but never access the underlying tokens. Three layers of RPC, zero credential exposure.

Connected vs Headless

We discovered that the first question an agent must answer is: does the user have the CMS editor open? A new get_session tool queries the SessionRegistry Durable Object for active WebSocket connections. This determines the entire workflow — surgical preview broadcasts for connected users, direct API saves for headless mobile users.

Schema as TypeScript

When an agent writes code, TypeScript types are a more precise prompt than markdown prose. We added a format parameter to get_schema — 'json' returns the raw source of truth, 'typescript' returns typed interfaces with union literals and constraint comments, 'summary' returns the existing markdown. The right format for the right task.

The Takeaway

Dynamic Workers didn't just reduce latency. They changed the execution model. The agent stops being a tool-caller and becomes a code-writer. The schema becomes a type system. The sandbox becomes a runtime. And the CMS becomes an API that code runs against — not a UI that humans click through.

This page was built in a single execute_code call.

LLMs.txt
by StoryPress, with