Guide · Tooling

# Code Mode MCP: one tool surface for many tools

Every MCP server you add puts all of its tool descriptions into your agent's context. Code mode replaces them with a few tools: the agent writes short code that calls what it needs, and only the result comes back.

By Mitchell KellerNov. 10, 20266 min read

A classical marble bust in close-up.A classical marble bust in close-up.

[Download the blank worksheet](https://www.joinlegion.io/downloads/code-mode-mcp-one-tool-surface-checklist.md)[View Markdown](code-mode-mcp-one-tool-surface.md)

## Key answer

- Start with the light version: wrap the MCP servers you already use into one code-mode server. No Docker, no approval step.
- Move to the Docker version when you want every write to wait for your approval and an audit log on your own machine.
- Measure tokens before and after on your own servers. The saving depends on how many tools you carry.
- Code mode does not cap spending. Keep a campaign ceiling for that.

On this page

## Tool descriptions eat the context

An MCP server tells your agent about every tool it has, with a full description and schema for each one. Add a handful of servers and the agent is carrying hundreds of tool descriptions before it reads your task. That costs tokens on every turn and makes picking the right tool harder.

Code mode changes the shape. The agent gets a small set of tools, writes a short piece of TypeScript that calls the tools it needs, and the code runs in a sandbox. Only the final result comes back into the conversation. The open-source [pctx](https://github.com/portofcontext/pctx) engine is one way to run it.

How a code-mode call works

Your existing MCP servers, or any API with an OpenAPI spec, sit behind one code-mode server. The agent writes a short script against them. A sandbox runs the script and only the result returns to the agent. In the Docker version, any write the script tries to make pauses until you approve it, and every action is written to an audit log on your machine.

- Your MCP servers or an OpenAPI specwhat you already use
- Code-mode servera few tools in place of many
- Short codethe agent writes it
- Sandboxruns it, returns only the result
- Approval (Docker version)writes wait for you

## Start with the light version

The light version wraps the MCP servers you already run in Claude Code, Claude Desktop or Cursor into one code-mode server with three tools. Nothing runs in the background and there is no approval step. Your agent calls the same tools as before, through code.

In one test against a public filesystem MCP server, 14 tool descriptions (about 3,278 tokens) became 3 tools (about 753 tokens), a 77% cut. That is one server. Your number depends on what you run, so measure your own.

## Step up to Docker when writes need a gate

The Docker version gives your agent one endpoint on your own computer for the APIs you use. Reads run straight away. Every write (create, update, delete) waits until you approve it, and the pending writes and an audit log stay on your machine. It needs Docker running.

Which one to pick

| You want | Light version | Docker version

| Less context from MCP servers you already use | Yes | Yes

| To work with APIs that have an OpenAPI spec | Yes | Yes

| Every write to wait for your approval | No | Yes

| An audit log on your machine | No | Yes

| Nothing to install beyond Node.js | Yes | No, needs Docker

Not sure? Start light. If you later want a gate on writes, move to Docker.

## Six steps on one page

- Inventory your servers. List the MCP servers your agent loads and roughly how many tools each one adds.
- Decide what you need. Smaller context only, or smaller context plus approval on writes.
- Run one read-only test. Pick a task that only reads, such as listing files or fetching records, and run it through code mode.
- Compare tokens. Note the tool tokens before and after, and whether the agent still picked the right tool.
- Check the trail. On the Docker version, try one harmless write and confirm it waits for approval and shows up in the audit log.
- Decide. Adopt it for the servers where the saving is real, and leave small servers as they are.

### What code mode does not do

It does not limit what your tools cost. A write gate stops writes until you approve them; it does not cap paid reads. Put a [campaign ceiling](/resources/give-every-campaign-a-ceiling) in the workflow for that.

### When this is the wrong tool

If your agent only loads one or two small MCP servers, the saving is small and the extra layer is not worth it.

## Get the choice table and test checklist

Code mode choice table and test checklist (blank, Markdown)

The light versus Docker choice table, a server inventory to fill in, and the read-only test checklist from this guide. No install commands.

[Download the .md](https://www.joinlegion.io/downloads/code-mode-mcp-one-tool-surface-checklist.md)

## Source notes

This guide describes the two code-mode setups I use. The token figures come from one measured run against a public filesystem MCP server. pctx is an open-source project by its own maintainers. The Legion toolkit has both versions with a setup lesson for members; nothing here depends on it.

## Run your agency on agents you can check

Get one useful GTM email a week. Then join the community on Skool.

[Get the newsletter](https://waitlist.joinlegion.io/g/legion-waitlist)

## Start here: the agency path

- [Give every campaign a spend ceiling](/resources/give-every-campaign-a-ceiling): budget control.
- [Keys by person, project and client](/resources/access-by-person-project-and-client): access control.
- [One client code, one search boundary](/resources/one-client-code-one-search-boundary): client knowledge.
- [Code Mode MCP: one tool surface for many tools](/resources/code-mode-mcp-one-tool-surface): code mode mcp. (this guide)

[Back to resources](/resources)

## Bring the GTM job you need done. Build the run you can check.

Get one useful GTM email a week. Then join the community on Skool.

Get one useful GTM email a week. Then join the community on Skool.

[Get the newsletter](https://waitlist.joinlegion.io/g/legion-waitlist) [Join the community on Skool](https://www.skool.com/legion/about)
