Get the FREE Ultimate OpenClaw Setup Guide →

codemode

Programmatic tool calling / Code Mode for MCP — turn any OpenAPI spec into two sandboxed tools (search + execute).

Installation
Run this command in your terminal to add the MCP server to Claude Code.
Run in terminal:
Command
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:

  1. Clone your MCP-enabled project and navigate to it git clone https://github.com/yourorg/your-mcp-server.git cd your-mcp-server

  2. Install CodeMode and its sandbox runtime as dependencies pnpm add @robinbraemer/codemode pnpm add isolated-vm

  3. Ensure you have a working OpenAPI 3.x spec accessible (URL or module)

    configure via environment or code accordingly

  4. 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.

  5. 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

Sponsor this space

Reach thousands of developers