codemode
Programmatic tool calling / Code Mode for MCP — turn any OpenAPI spec into two sandboxed tools (search + execute).
claude mcp add --transport stdio cnap-tech-codemode node path/to/server.js \ --env NAMESPACE="Optional sandbox client namespace (default: api)" \ --env OPENAPI_SPEC="URL or module that provides the OpenAPI spec (async getter supported by CodeMode)" \ --env REQUEST_HANDLER="A fetch-compatible handler, e.g., app.request.bind(app) or equivalent in your runtime"
How to use
codemode exposes two MCP tools that together let an AI agent explore and call your API defined by an OpenAPI spec. The search tool analyzes the spec (with $refs resolved) to discover endpoints, parameters, and schemas, returning a concise list of candidate operations. The execute tool provides an injected API client inside a sandboxed environment so the agent can call those endpoints without network hops. This approach lets you expose hundreds of endpoints with just two tools, reducing context window usage while preserving realistic API interactions. To integrate, wire the CodeMode instance into your MCP server workflow as shown in the integration example, then use codemode.callTool('search', { code }) to discover endpoints and codemode.callTool('execute', { code }) to perform calls against your in-process API handler.
How to install
Prerequisites:
- Node.js (recommended LTS) and a package manager (pnpm or npm)
- Access to a project where you will run the MCP server
Installation steps:
-
Clone your MCP-enabled project and navigate to it git clone https://github.com/yourorg/your-mcp-server.git cd your-mcp-server
-
Install CodeMode and its sandbox runtime as dependencies pnpm add @robinbraemer/codemode pnpm add isolated-vm
-
Ensure you have a working OpenAPI 3.x spec accessible (URL or module)
configure via environment or code accordingly
-
Add or configure the MCP server integration for CodeMode (see usage example in README). You may adapt the provided TypeScript integration snippet to your setup.
-
Start the MCP server (adjust to your project’s commands) npm run build npm start
Additional notes
Tips and known considerations:
- The CodeMode sandbox runs with no I/O by default. Inject needed globals (spec and api.request) for search and execute respectively.
- Each tool call uses a fresh sandbox; no state is preserved between calls unless you implement state to the sandbox yourself.
- Ensure your OPENAPI_SPEC source is reliable, as the search tool relies on it to enumerate endpoints and schemas.
- For security, control which headers and external calls are allowed via sandbox options and the environment you provide to the MCP server.
- If you encounter issues with large specs, consider increasing maxRefDepth or adjusting sandbox memory/time limits in CodeMode options.
Related MCP Servers
augments
Comprehensive MCP server providing real-time framework documentation access for Claude Code with intelligent caching, multi-source integration, and context-aware assistance.
mcp-n8n-builder
🪄 MCP server for programmatic creation and management of n8n workflows. Enables AI assistants to build, modify, and manage workflows without direct user intervention through a comprehensive set of tools and resources for interacting with n8n's REST API.
mcp-memory-libsql
🧠 High-performance persistent memory system for Model Context Protocol (MCP) powered by libSQL. Features vector search, semantic knowledge storage, and efficient relationship management - perfect for AI agents and knowledge graph applications.
ironcurtain
A secure* runtime for autonomous AI agents. Policy from plain-English constitutions. (*https://ironcurtain.dev)
vikunja
Model Context Protocol server for Vikunja task management. Enables AI assistants to interact with Vikunja instances via MCP.
mcp -text-editor
An open source implementation of the Claude built-in text editor tool