One program can replace several tool calls
A capability is a named action with a typed contract and a handler. Code mode combines calls to those actions in one program. MCP (Model Context Protocol27) lets an agent discover and call tools.ΒΆ
ratstack.sh already offers code mode:ΒΆ
One request runs an async function body that combines content calls. Joelβs reply asks for this alongside CLI, API, and MCP.ΒΆ
A live program
This program runs against the live HTTP endpoint.ΒΆ
The callable definitions are in apps/mischief/src/capabilities/index.ts at 445b1a20b51a5492f8e586daeb9306e8011b7673, lines 34β45. We wrote this read-only request.ΒΆ
const found = await tools.search({ query: "cartridges", limit: 1 });
const page = await tools.read({ id: found.matches[0].id });
const graph = await tools.backlinks({ slug: page.routePath.split("/").at(-1) });
return { title: page.title, id: page.id, links: graph.backlinks.length }; The program passes the search result directly to read and reduces the graph result before returning it.ΒΆ
POST /api/execute returned this response on 2026-10-02:ΒΆ
{"logs":[],"result":{"title":"Cartridges","id":"ratstack://lore/cartridges","links":31}} Three typed calls use one outer request. This run measures neither latency nor token savings.ΒΆ
The sandbox preserves the boundary
apps/site/src/capabilities/index.ts builds toExecuteCapability(contentCapabilities). That list contains search, read, backlinks, neighbors, mentions, and path.ΒΆ
joinInterest belongs to the outer API/MCP registry. It does not belong to the sandboxβs callable list.ΒΆ
packages/capability/src/to-code-mode.ts builds the catalog and TypeScript declarations. Every call from sandbox code returns to application code that validates input and runs the handler.
That code encodes the output or declared failure.ΒΆ
sandbox-worker-loader.ts runs a fresh Dynamic Worker, a Worker loaded to execute sandbox code, with:ΒΆ
Imports, exports, and fetch are unavailable.ΒΆ
The HTTP and MCP rate-limit checks use native rate limits:ΒΆ
- Six execute calls per IP per minute.ΒΆ
- 300 execute calls total per minute.ΒΆ
- Separate counters in each Cloudflare location.ΒΆ
Combining calls does not waive these limits.ΒΆ
Use the agent guide for the endpoint and call format. See MCP27 for the tool transport.ΒΆ
See how we do it with Effect9 for the whole path.ΒΆ
Sources
- Joel Hooks on code mode. Primary source. Joel Hooks on code mode Accessed 2026-10-02.
- apps/site/src/capabilities/index.ts. GitHub. apps/site/src/capabilities/index.ts Accessed 2026-10-02.
- packages/capability/src/to-code-mode.ts. GitHub. packages/capability/src/to-code-mode.ts Accessed 2026-10-02.
- apps/site/src/sandbox-worker-loader.ts. GitHub. apps/site/src/sandbox-worker-loader.ts Accessed 2026-10-02.
- apps/site/src/app.ts. GitHub. apps/site/src/app.ts Accessed 2026-10-02.
- Worker sandbox composition. GitHub. Provides the Worker Loader with sandboxLimits. Accessed 2026-10-02.
- Native execute rate limits. GitHub. Six per IP and 300 global per minute. Accessed 2026-10-02.
- Code mode HTTP endpoint documentation. ratstack.sh. Documents POST /api/execute. The program below was observed on 2026-10-02. Accessed 2026-10-02.
Last changed 2026-10-10 in 978dccc. Source on GitHub. Change log.
Linked from
- Agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
One program can replace several tool calls β Code mode combines typed content calls inside one bounded execute request.
- An MCP your users want. Rhys Sullivan's practical guide gives rat-stack a checklist for useful MCP tools.
It asks MCP authors to expose dashboard actions, keep code mode as a choice made by the agentβs client, and provide documentation search.
- Build and run rat-stack (README.md). What is in the repo, how the example works, and how to run it.
Code mode is the fourth projection.
- Capabilities. Named application actions exposed through generated interfaces share one definition and one server-side implementation.
Code mode, which combines capability calls in one program inside a restricted environment.
- Change log. What changed in the files served here, newest first.
One program can replace several tool calls β edited: docs: point live docs, skills and Brain pages at apps/site
- Effect keeps the surfaces on one contract. Schema owns values, projections build interfaces, and Layers supply implementations.
One program can replace several tool calls: combine content capabilities without widening their authority.ΒΆ
- Full agent guide. An Effect stack so pure (aspirational) Kit Langton will blush.
- Hexagonal architecture. Ports name the application's jobs; adapters connect them to the outside world.
One capability, every surface starts with a contract, binds a handler, and projects CLI, HTTP, MCP, RPC, and code mode.
- Hosted agent interfaces. Discovery documents, HTTP, MCP, A2A, and bounded code mode expose the public reference to agents.
Code mode runs several capability calls in one program inside a restricted environment.
- Infrastructure as effects. Sam Goodwin relates application operations to infrastructure requirements in one typed program.
Projections turn registered capabilities into command line, HTTP, MCP tools, browser RPC, and code mode surfaces.
- keep-or-cut. Learn which pieces depend on each other, then keep only the ones your project needs.
Code mode imports to-toolkit.ts.
- learn-rat-stack. Trace a capability through Effect, XState, five projections, the CLI, and Alchemy. Try hosted search and read.
Code mode lets agents compose calls in one program.ΒΆ
- MCP is another surface. MCP lists and calls schema-typed tools; rat-stack projects the same handlers instead of adding MCP-only behavior.
Use code mode to combine content calls.
- One capability, every surface. A schema-typed contract and one handler feed every interface rat-stack keeps.
The interfaces are command line, HTTP, MCP tools, browser RPC, and code mode.
- One schema, three surfaces. A capability contract feeds CLI, HTTP, and MCP; OpenAPI is generated output, not their input.
See MCP, OpenAPI, and code mode for each interface.ΒΆ
- Rat Stack lore | rat-stack. Short, source-grounded notes on the ideas and decisions behind rat-stack.
One program can replace several tool calls β Code mode combines typed content calls inside one bounded execute request.
- Rat Stack systems | rat-stack. The systems rat-stack ships, the standard each keeps, and how to check it.
Hosted agent interfaces β Discovery documents, HTTP, MCP, A2A, and bounded code mode expose the public reference to agents.
- rat-stack. An Effect stack so pure (aspirational) Kit Langton will blush.
Code mode is a way to run a program that calls tools inside a sandbox, a restricted execution environment.
- Schema projections: 2026-09-18 history. Historical Effect rc.115 proposal and implementation receipts from 2026-09-18; use the one-capability-every-surface lore page for the current pattern.
One Effect Schema definition can feed a CLI, REST API, MCP server, and code mode.
- Source change history (log.md). The generated change log as Markdown.
One program can replace several tool calls β edited: docs: point live docs, skills and Brain pages at apps/site
- use-a-prompt. Discover and read published rat-stack prompts before starting a task with one.
The same contracts project to CLI, HTTP, MCP tools, RPC, and code mode.
Unlinked mentions (5)
- Agent rules for rat-stack (AGENTS.md) β CLI, HTTP, MCP, RPC, and code mode are projections in packages/capability.
- Capabilities β Code mode reaches only capabilities, through their schemas.ΒΆ
- keep-or-cut β Cutting MCP therefore cuts code mode too; apply both lists.ΒΆ
- rat-stack β Agents use MCP, HTTP, or code mode.
- Schema projections: 2026-09-18 history β MCP surface: execute (code mode), skills (server-side guides for the model), tools search / describe / call, plus artifacts.
Content updated .