An efficient alternative to MCP (Model Context Protocol) for AI-to-service communication.
Instead of multiple individual tool calls, AI models write JavaScript code that executes in a secure sandbox with access to registered services. This approach:
- Saves tokens by reducing the number of round-trips
- Enables state through JavaScript variables within execution
- Supports logic via loops, conditions, and transformations
- Filters output by only returning
console.logresults
# Install all dependencies (uses pnpm workspaces)
pnpm install
# Build all packages
pnpm build
# Run the test example
pnpm testAI Code Tool includes an MCP server that works with Cursor, Claude Desktop, and other MCP-compatible clients.
Open Cursor Settings → MCP → Add Server, or edit ~/.cursor/mcp.json:
{
"mcpServers": {
"ai-code-tool": {
"command": "node",
"args": ["/path/to/ai-code-tool/packages/mcp-server/dist/index.js"],
"cwd": "/your/working/directory"
}
}
}Replace /path/to/ai-code-tool with the actual path to this repository.
After adding the configuration, restart Cursor to load the MCP server.
Now you can ask Cursor to use the tools:
Use find_service to find the echo service, then use exec to reverse the string "Hello World"
The AI will:
- Call
find_service("echo")to get the TypeScript definitions - Call
execwith code like:const result = echo.reverse("Hello World"); console.log(result);
- Return the output:
dlroW olleH
ai-code-tool/
├── packages/
│ ├── runtime/ # Core runtime with sandbox
│ ├── mcp-server/ # MCP server for Cursor/Claude
│ └── services/
│ ├── echo/ # Example: Echo service
│ └── filesystem/ # Example: Filesystem service
├── example/ # Example integration
└── docs/
├── concept.md # Concept documentation
└── spec.md # Technical specification
The runtime provides two tools for AI models:
Searches for services by keyword and returns TypeScript definitions.
find_service({ keyword: "echo" });
// Returns TypeScript definitions with JSDoc documentationExecutes JavaScript code with access to specified services.
exec({
code: `
const files = await filesystem.listDir(".");
for (const file of files) {
console.log(file.name);
}
`,
services: ["filesystem"],
});
// Returns: { output: "file1.txt\nfile2.txt\n...", error?: string }- Create a new package in
packages/services/:
{
"name": "@ai-code-tool/my-service",
"type": "module",
"aiCodeTool": {
"keywords": ["myservice", "api"],
"types": "./types/index.d.ts",
"main": "./dist/index.js"
}
}- Create TypeScript definitions with JSDoc:
// types/index.d.ts
/**
* My Service description.
* @example
* const result = await myService.doSomething("input");
* console.log(result);
*/
declare const myService: {
/** Does something useful */
doSomething(input: string): Promise<string>;
};
export = myService;- Implement the service:
// src/index.ts
const myService = {
async doSomething(input: string) {
return `Result: ${input}`;
},
};
export default myService;- Add to workspace and MCP server dependencies.
import { createRuntime } from "@ai-code-tool/runtime";
const runtime = createRuntime({
services: ["@ai-code-tool/echo", "@ai-code-tool/filesystem"],
timeout: 30000,
});
await runtime.initialize(process.cwd());
// Get tool definitions for AI
const tools = runtime.getToolDefinitions();
// Handle AI tool calls
const result = await runtime.handleToolCall("exec", {
code: 'console.log(echo.reverse("Hello"))',
services: ["echo"],
});- Concept - Detailed concept and motivation
- Specification - Technical specification
- Creating Services - Developer guide for building services
MIT