Airsc miễn phí cho tất cả. Nếu nó giúp bạn, hãy ủng hộ $2–$20.

Ủng hộ
MCP serverAn toànQuy trình & bộ nhớ agentCần cài đặt chút

code-mode

universal-tool-calling-protocol · universal-tool-calling-protocol/code-mode

Thư viện plug-and-play này cho phép các tác nhân AI gọi các công cụ MCP và UTCP hiệu quả hơn thông qua thực thi mã, giảm chi phí và số lần lặp.

Thư viện cắm và chạy để cho phép các tác nhân gọi các công cụ MCP và UTCP thông qua thực thi mã.

1.6k sao108Giấy phép: MPL-2.0Cập nhật 2 tháng trước0 lượt mở

Xem trước

▍

Bạn có thể làm gì với nó

  • Cải thiện tốc độ và hiệu quả chi phí của các tác nhân AI thực hiện các tác vụ đa bước.
  • Cho phép các tác nhân gộp nhiều lệnh gọi API vào một khối thực thi mã duy nhất.
  • Hợp lý hóa các dàn xếp công cụ phức tạp bằng cách để LLM tạo mã thực thi trực tiếp.

Kiểm tra an toàn

An toàn

Không thấy dấu hiệu rủi ro trong các file đã quét.

Quét tự động các file trong repo. Luôn xem lại code trước khi chạy.

Trích từ README

🤖 Code-Mode Library: First library for tool calls via code execution

Transform your AI agents from clunky tool callers into efficient code executors — in just 3 lines.

Why This Changes Everything

LLMs excel at writing code but struggle with tool calls. Instead of exposing hundreds of tools directly, give them ONE tool that executes TypeScript code with access to your entire toolkit.

Apple, Cloudflare, and Anthropic say that Code-Mode is a more efficient way to approach tool calling compared to the traditional dump function information and then extract a JSON for function calling.

Benchmarks

Independent Python benchmark study validates the performance claims with $9,536/year cost savings at 1,000 scenarios/day:

Scenario ComplexityTraditionalCode ModeImprovement
Simple (2-3 tools)3 iterations1 execution67% faster
Medium (4-7 tools)8 iterations1 execution75% faster
Complex (8+ tools)16 iterations1 execution88% faster

Why Code Mode Dominates:

Batching Advantage - Single code block replaces multiple API calls
Cognitive Efficiency - LLMs excel at code generation vs. tool orchestration
Computational Efficiency - No context re-processing between operations

Getting Started

Get Started in 3 Lines

import { CodeModeUtcpClient } from '@utcp/code-mode';

const client = await CodeModeUtcpClient.create();                    // 1. Initialize
await client.registerManual({ name: 'github', /* MCP config */ });  // 2. Add tools  
const { result } = await client.callToolChain(`/* TypeScript */`);   // 3. Execute code

That's it. Your AI agent can now execute complex workflows in a single request instead of dozens.

What You Get

Progressive Tool Discovery

// Agent discovers tools dynamically, loads only what it needs
const tools = await client.searchTools('github pull request');
// Instead of 500 tool definitions → 3 relevant tools

Natural Code Execution

const { result, logs } = await client.callToolChain(`
  // Chain multiple operations in one request
  const pr = await github.get_pull_request({ owner: 'microsoft', repo: 'vscode', pull_number: 1234 });
  const comments = await github.get_pull_request_comments({ owner: 'microsoft', repo: 'vscode', pull_number: 1234 });
  const reviews = await github.get_pull_request_reviews({ owner: 'microsoft', repo: 'vscode', pull_number: 1234 });
  
  // Process data efficiently in-sandbox
  return {
    title: pr.title,
    commentCount: comments.length,
    approvals: reviews.filter(r => r.state === 'APPROVED').length
  };
`);
// Single API call replaces 15+ traditional tool calls

Auto-Generated TypeScript Interfaces

namespace github {
  interface get_pull_requestInput {
    /** Repository owner */
    owner: string;
    /** Repository name */ 
    repo: string;
    /** Pull request number */
    pull_number: number;
  }
}

Enterprise-Ready

  • Secure VM Sandboxing – Node.js isolates prevent unauthorized access
  • Timeout Protection – Configurable execution limits prevent runaway code
  • Complete Observability – Full console output capture and error handling
  • Zero External Dependencies – Tools only accessible through registered UTCP/MCP servers
  • Runtime Introspection – Dynamic interface discovery for adaptive workflows

If you're working at an enterprise, and need support, book a consultation here.

Universal Protocol Support

Works with any tool ecosystem:

ProtocolDescriptionUsage
MCPModel Context Protocol serverscall_template_type: 'mcp'
HTTPREST APIs with auto-discoverycall_template_type: 'http'
FileLocal JSON/YAML configurationscall_template_type: 'file'
CLICommand-line tool executioncall_template_type: 'cli'

Installation

npm install @utcp/code-mode

Recommended for shell agents: the utcp CLI

If your agent can run shell commands (Claude Code, Cursor, Codex, Claude Cowork, etc.), the utcp CLI is the preferred way to use Code Mode — no MCP server, no client config, no env vars. The agent self-configures by writing a .utcp_config.json and drives everything from the shell.

Just point the agent at the built-in guide:

npx -y @utcp/code-mode-cli prompt

Hand it a description of the API to use — a UTCP call template, an OpenAPI spec, or a plain-English description — and it writes the config, discovers tools, runs tool-chains, and even completes interactive OAuth logins (e.g. Notion), all from the shell:

npx -y @utcp/code-mode-cli search "<task>"           # discover tools + TS interfaces
npx -y @utcp/code-mode-cli run <<'EOF'               # run a tool-chain
const r = await openlibrary.read_search_json_search_json_get({ q: "tolkien", limit: 3 });
return r.docs.map(b => b.title);
EOF
npx -y @utcp/code-mode-cli login <manual>            # interactive OAuth, writes token to .env

CLI vs MCP: prefer the CLI whenever the agent has shell access (most coding agents) — it's simpler and self-configuring. Use the MCP server (below) only for MCP-only clients like Claude Desktop. Both wrap the same @utcp/code-mode engine.

See code-mode-cli/ for full docs.

Ready-to-Use MCP Server

On an MCP-only client (e.g. Claude Desktop)? Use our plug-and-play

Xem mã nguồn trên GitHub