Getting started¶
Requirements¶
- Python 3.11 or newer, on Windows, macOS or Linux.
- Internet access the first time, to download Pyodide (about 10 MB). After that everything runs offline.
- No separate Deno install: the
denowheel from PyPI is installed automatically.
1. Install¶
Optional extras:
| Extra | Adds |
|---|---|
openai |
openai SDK, for codemode-mcp chat / benchmark and run_openai() with any OpenAI-compatible API |
anthropic |
anthropic SDK, for --provider anthropic and run_anthropic() |
tokens |
tiktoken, for exact token counts (otherwise about 4 characters per token) |
all |
All of the above |
2. Prepare the sandbox¶
codemode-mcp setup
# Preparing sandbox (first run downloads Pyodide, ~10 MB)...
# Python 3.14.2 ready
3. Tell it about your MCP servers¶
If you already use MCP servers in a client, import them:
Or write mcp.json yourself. It uses the same format as Claude Desktop:
mcp.json
{
"mcpServers": {
"github": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-github"],
"env": {"GITHUB_PERSONAL_ACCESS_TOKEN": "${GITHUB_TOKEN}"}
},
"filesystem": {
"command": "npx",
"args": ["-y", "@modelcontextprotocol/server-filesystem", "/path/to/projects"]
}
}
}
${GITHUB_TOKEN} is read from your environment, so secrets never have to be written into
the file.
4. Check what you'll save¶
The output looks like this (shown for the bundled 306-tool example, examples/mcp.big.json):
Servers: 2 Tools: 306 Strategy: search Tokenizer: tiktoken:o200k_base
Tool-definition tokens per LLM request, classic MCP : 78,933
Tool-definition tokens per LLM request, Code Mode : 1,697
Saved per request (definitions only) : 97.9%
5. Try a script yourself¶
This runs exactly what an LLM would send:
codemode-mcp search -c mcp.json "list issues"
codemode-mcp run -c mcp.json "issues = await github.list_issues(owner='me', repo='app', state='open')
[i['title'] for i in issues][:5]"
6. Connect your LLM¶
Restart the client. It now sees
run_code (and search_tools) instead of all your
tools. See Use with MCP clients.
from codemode_mcp import CodeMode
from codemode_mcp.agent import run_openai
async with CodeMode.from_config("mcp.json") as cm:
result = await run_openai(cm, "Summarise my open issues", model="gpt-4.1-mini")
print(result.text, cm.usage())
7. Watch the savings¶
codemode-mcp usage # terminal summary
codemode-mcp dashboard # web dashboard at http://127.0.0.1:8765
Next: How it works.