镜像站点 · 本页由第三方 GitHub 只读镜像提供,非 GitHub 官方站点,不接受任何登录或凭据输入。前往 github.com
Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

13 Commits

Folders and files

Repository files navigation

AI Code Tool

An efficient alternative to MCP (Model Context Protocol) for AI-to-service communication.

Overview

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.log results

Quick Start

# Install all dependencies (uses pnpm workspaces)
pnpm install

# Build all packages
pnpm build

# Run the test example
pnpm test

Usage with Cursor

AI Code Tool includes an MCP server that works with Cursor, Claude Desktop, and other MCP-compatible clients.

1. Add to Cursor Settings

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.

2. Restart Cursor

After adding the configuration, restart Cursor to load the MCP server.

3. Use in Chat

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:

  1. Call find_service("echo") to get the TypeScript definitions
  2. Call exec with code like:
    const result = echo.reverse("Hello World");
    console.log(result);
  3. Return the output: dlroW olleH

Architecture

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

Tools

The runtime provides two tools for AI models:

find_service

Searches for services by keyword and returns TypeScript definitions.

find_service({ keyword: "echo" });
// Returns TypeScript definitions with JSDoc documentation

exec

Executes 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 }

Creating a Service

  1. 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"
  }
}
  1. 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;
  1. Implement the service:
// src/index.ts
const myService = {
  async doSomething(input: string) {
    return `Result: ${input}`;
  },
};
export default myService;
  1. Add to workspace and MCP server dependencies.

Programmatic Usage

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"],
});

Documentation

License

MIT

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages