# Codemode Workers

> Expose any API to an LLM agent as two sandboxed MCP tools (search + execute) on Cloudflare Workers.

- **Type:** MCP server
- **Install:** `agentstack add mcp-ancs21-codemode-workers`
- **Verified:** Yes — security-reviewed for prompt injection and unsafe behavior
- **Seller:** [ancs21](https://agentstack.voostack.com/s/ancs21)
- **Installs:** 0
- **Category:** [Cloud & Infrastructure](https://agentstack.voostack.com/c/cloud-infrastructure)
- **Latest version:** 0.1.0
- **License:** MIT
- **Upstream author:** [ancs21](https://github.com/ancs21)
- **Source:** https://github.com/ancs21/codemode-workers
- **Website:** https://codemode-workers.pages.dev

## Install

```sh
agentstack add mcp-ancs21-codemode-workers
```

Requires the [AgentStack CLI](https://agentstack.voostack.com/docs/cli). Works with Claude Code, Cursor, and any MCP-compatible agent.

## About

# codemode-workers

Expose any API to an LLM agent as two sandboxed MCP tools (search + execute) on Cloudflare Workers.

[](https://github.com/ancs21/codemode-workers/actions/workflows/ci.yml)
[](https://codecov.io/gh/ancs21/codemode-workers)
[](https://www.npmjs.com/package/codemode-workers)
[](https://www.npmjs.com/package/codemode-workers)
[](https://codemode-workers.pages.dev)
[](./LICENSE)

Instead of registering thousands of tool schemas, you register two tools (`search` + `execute`). The catalog stays on the server; the agent writes JavaScript that runs in a fresh, sandboxed isolate. Same pattern as [cloudflare-mcp](https://github.com/cloudflare/mcp), packaged for any API.

Docs: **[codemode-workers.pages.dev](https://codemode-workers.pages.dev)**

## Why

One tool per endpoint dumps every schema into the model's context. Code mode keeps the spec server-side and sends two tools, so the context cost stays flat however big the API is. Against the Urantia Papers API (58 endpoints):

| Approach                    | Tools | Tokens |
| --------------------------- | ----- | ------ |
| One tool per endpoint, full | 58    | 3,489  |
| Code mode                   | 2     | 184    |

Run `bun run eval:tokens ` to measure it for your own API.

## Install

```
npm install codemode-workers
```

Bring your own MCP server SDK (e.g. `@modelcontextprotocol/server`). The library only needs a `registerTool(name, config, cb)`.

## Usage

```jsonc
// wrangler.jsonc
{
  "worker_loaders": [{ "binding": "LOADER" }],
  "services": [
    {
      "binding": "GATE_SELF",
      "service": "",
      "entrypoint": "Gate",
    },
  ],
}
```

```ts
import { exports } from 'cloudflare:workers'
import {
  createGate,
  processSpec,
  registerCodemodeTools,
} from 'codemode-workers'

export const Gate = createGate({ allowedHosts: ['api.example.com'] })

registerCodemodeTools(server, {
  loader: env.LOADER,
  catalog: {
    get: async () => processSpec(await (await fetch(SPEC_URL)).json()),
  },
  api: {
    baseUrl: 'https://api.example.com/v1',
    outbound: () =>
      exports.Gate({
        props: { headers: { Authorization: `Bearer ${env.API_TOKEN}` } },
      }),
  },
})
```

`search` runs code over your catalog with no network. `execute` calls the API through the gate, which allowlists your host and injects the credential that the agent never sees. Full walkthrough and API reference in the [docs](https://codemode-workers.pages.dev).

## Security

The credential lives in the gate, outside the sandbox, so agent code cannot read the token or reach any host but yours. `search` has no network. Every call is a fresh isolate. Details and residual risks: [codemode-workers.pages.dev/security](https://codemode-workers.pages.dev/security).

## Develop

```
bun install
bun run check   # typecheck + tests (workerd via @cloudflare/vitest-pool-workers)
```

## License

MIT. See [LICENSE](./LICENSE).

## Source & license

This open-source MCP server is cataloged on AgentStack and links to its original source — we do not rehost the code.

- **Author:** [ancs21](https://github.com/ancs21)
- **Source:** [ancs21/codemode-workers](https://github.com/ancs21/codemode-workers)
- **License:** MIT
- **Homepage:** https://codemode-workers.pages.dev

Install and usage instructions live in the source repository linked above.

## Pricing

- **Free** — Free

## Security capabilities

Automated source analysis of v0.1.0 — what this tool can access:

- **Network access:** yes
- **Filesystem access:** no
- **Shell / process execution:** no
- **Environment & secrets:** no
- **Dynamic code execution:** no

*"Yes" means the capability is present in the source — more access means more to trust, not that it is unsafe.*


## Versions

- **0.1.0** — security scan: passed — Imported from the upstream source.

## Links

- Listing page: https://agentstack.voostack.com/l/mcp-ancs21-codemode-workers
- Seller: https://agentstack.voostack.com/s/ancs21
- Browse the marketplace: https://agentstack.voostack.com/browse

---
Listed on AgentStack — the marketplace for AI agent skills and MCP servers. Every listing is security-reviewed. Creators keep 70%.
