Examples
AI Web Client
Use AI Web when one client connects to multiple MCP servers. It virtualizes their combined tool catalog and prevents compatible MCP Core servers from generating duplicate meta-tools.
import { IoAiWebFactory } from "@interopio/ai-web";
import { IoCodeModeFactory } from "@interopio/code-mode/browser";
const aiWeb = await IoAiWebFactory(io, {
agentServer: { baseUrl: "https://agent.example.com" },
codeMode: {
factory: IoCodeModeFactory,
config: { wasmLocation: "/quickjs/emscripten-module.wasm" },
},
});
MCP Core Server
Use server-side Code Mode only for clients that cannot provide their own implementation.
import { IoCodeModeFactory } from "@interopio/code-mode/node";
import { IoIntelMCPCoreFactory } from "@interopio/mcp-core";
const mcpCore = await IoIntelMCPCoreFactory(io, {
licenseKey,
transport: { type: "http" },
server: {
name: "io-intelligence-mcp",
codeMode: {
factory: IoCodeModeFactory,
config: { wasmLocation: quickJsWasmPath },
},
},
});
Configure Code Mode at the layer closest to the LLM whenever possible. For a client such as AI Web that aggregates tools from multiple MCP servers, enable Code Mode only in the client so it virtualizes and exposes the complete combined tool catalog. Do not configure the server example on multiple MCP servers used by the same Code Mode-unaware client: each server can contribute identically named getTools, getToolDefinition, and executeCode tools, which clash in the client's tool catalog.
Standalone Host
For a host that owns its model loop directly, create a session, register host tools, and pass the system instruction and returned meta-tools to the model SDK.
import { IoCodeModeFactory } from "@interopio/code-mode/browser";
const codeMode = await IoCodeModeFactory({
wasmLocation: "/quickjs/emscripten-module.wasm",
});
const session = codeMode.createSession();
session.setTools(hostTools);
const systemInstruction = codeMode.getSystemInstruction();
const toolsForModel = session.getLlmTools();
Keep the session alive through the model run. To cancel an executeCode call, pass the run's signal to its execute(args, { signal }) method. Remove the session with codeMode.removeSession(session.id) when the run ends.
const executeCode = toolsForModel.find((tool) => tool.name === "executeCode")!;
const controller = new AbortController();
const result = await executeCode.execute({ code: "return await tool_search({ query: 'orders' });", explanation: "Search for orders." }, { signal: controller.signal });
The registered tool_search function above is illustrative; use the exact tool name returned by getTools for your host's tool catalog. A cancelled run returns an error result. Create a new controller for each independently cancellable execution.