@ ax-llm/ ax-工具
Ax LLM框架的节点.js特有工具.
概览
此软件包提供了无法包含的 Node.js 特定功能
主体 @ax-llm/ax 由于浏览器兼容性要求,软件包。 这个
主软件包设计在节点.js和浏览器环境中同时工作,同时
此软件包提供Node.js- only特性.
特征
MCP 工具
AxMCPSTDio 运输
与 MCP 通信的示范背景协议的传输 通过 stdin/ stdout 服务器。 这样可以将本地 MCP 服务器作为孩子运行 进程.
持续事件运行时间存储
@ax-llm/ax-tools/event/sqlite 出口 AxSQLiteEventStore 财务报告和审定财务报表
AX_SQLITE_EVENT_STANDARD_RETENTION。它支持合作节点进程
共享本地 SQLite 文件。 它不用于网络文件系统 .
函数工具
AxJSRuntime 已移动到 @ax-llm/ax。 。 。 .
安装
npm install @ax-llm/ax-tools
使用量
MCP 基础运输
import { ax, AxMCPClient } from "@ax-llm/ax";
import { AxMCPStdioTransport } from "@ax-llm/ax-tools";
// Create a stdio transport for an MCP server
const transport = new AxMCPStdioTransport({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-memory"],
env: process.env,
});
// Create MCP client
const client = new AxMCPClient(transport, { debug: true });
await client.init();
// Attach the live client natively to AxGen, AxAgent, or AxFlow.
const program = ax('question:string -> answer:string', { mcp: client });
有工厂功能
import { axCreateMCPStdioTransport } from "@ax-llm/ax-tools";
const transport = axCreateMCPStdioTransport({
command: "uvx",
args: ["blender-mcp"],
});
JavaScript 代码执行
使用 AxJSRuntime 从 @ax-llm/ax数字 :
import { ai, AxJSRuntime, AxJSRuntimePermission } from "@ax-llm/ax";
配置选项
MCP 运输
interface StdioTransportConfig {
command: string; // The command to execute
args?: string[]; // Optional arguments
env?: NodeJS.ProcessEnv; // Optional environment variables
}
JS 口译员权限
见 @ax-llm/ax 文档 AxJSRuntimePermission。 。 。 .
实例
内存服务器
import { ai, AxAgent, AxMCPClient } from "@ax-llm/ax";
import { AxMCPStdioTransport } from "@ax-llm/ax-tools";
// Initialize MCP client with memory server
const transport = new AxMCPStdioTransport({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-memory"],
});
const client = new AxMCPClient(transport, { debug: false });
await client.init();
// Create agent with memory capabilities
const agent = new AxAgent({
name: "MemoryAgent",
description: "An agent that can remember information",
signature: "userMessage -> response",
functions: [client],
});
// Use with AI
const ai = ai({
name: "openai",
apiKey: process.env.OPENAI_APIKEY!,
});
const result = await agent.forward(ai, {
userMessage: "Remember that my favorite color is blue",
});
清理
完成后总是清理运输:
// Terminate the child process
await transport.terminate();
API 参考
AxMCPSTDio 运输
构造器
new AxMCPStdioTransport(config: StdioTransportConfig)
方法
send(message: AxMCPJSONRPCRequest): Promise<AxMCPJSONRPCResponse>- 发送一个 请求sendNotification(message: AxMCPJSONRPCNotification): Promise<void>- 发送一个 通知connect(): Promise<void>- 连接(Stdio不开放)terminate(): Promise<void>- 终止儿童程序
ax 创建MCPSTDio 运输
创建新运输实例的工厂功能:
axCreateMCPStdioTransport(config: StdioTransportConfig): AxMCPStdioTransport
许可证
阿帕奇 - 2.0