@agntn/tools

中文文档
0.3.0发布于 2026/11/03MITTypeScriptES Module零依赖构建来源已验证近 30 天下载 4612

One tool definition for MCP, Pi, OMP and the AI SDK

原始使用文档
文档目录9 节
  1. Why?
  2. ✨ Features
  3. 📦 Install
  4. 🚀 First call
  5. 🤖 Hosts
  6. 🚫 What this does not do
  7. 🛠️ Development
  8. 💛 Thanks
  9. 📄 License

@agntn/tools

npm version npm downloads license Ask DeepWiki

🧰 Four hosts, one definition. You write the tool once. MCP, Pi, OMP and the AI SDK each get it the way they like it.

Want to watch it happen? tools.agntn.dev has the docs and a playground. One call, four hosts, all live in your tab.

Why?

MCP wants an inputSchema. Pi wants parameters and a prompt snippet. OMP swaps your TypeBox for its own. The AI SDK wants yet another schema. So every tool lived in four files, and four files drift. Now it lives in one.

✨ Features

  • 📝 One definition. Name, schema, effect and execute. That's the whole tool.
  • 🔌 Four host adapters. createMcpServer, registerPiTools, registerOmpTools and toAiTool. One call each.
  • 🛡️ Validation on every host. The core checks each call before your code runs. Even when the host skips its own check.
  • 🗣️ Errors a model can use. A misspelled key names itself and the keys you do take. An enum lists its values.
  • 🧵 One line per error. Newlines, escape codes and bidi tricks in echoed text get flattened. No forged lines.
  • 🪤 The OMP TypeBox trap, defused. TypeBox is bundled, so OMP has nothing left to rewrite behind your back.
  • 🧪 Schema rules at definition time. An open object or a union of literals fails in defineTool. Not three weeks later in a model's hands.
  • ⏳ Progress that gets somewhere. progress?.("still at it") turns into onUpdate in Pi and OMP, notifications/progress in MCP and one live line in your terminal. A slow call stops looking like a dead one.
  • 🙋 Ask the person, not the model. ask?.({ message, schema }) becomes MCP elicitation, or one dialog per field in Pi and OMP. Three puzzles match? Let them pick instead of letting the model guess.
  • ⌨️ A CLI on the side. runCli turns the same tools into commands, no CLI library needed. Flags come from the schema. Hints add positionals, short flags and stdin.
  • 🌐 Runs anywhere. No node:* import in the core or the host adapters. The docs site runs them in a browser tab. The CLI is the one Node part, as a CLI should be.

📦 Install

pnpm add @agntn/tools

Node.js 26 or newer. Then add the hosts you serve. Each one is an optional peer.

🚀 First call

import { defineTool, Type } from "@agntn/tools";
import { createMcpServer } from "@agntn/tools/mcp";
import { Client, InMemoryTransport } from "@modelcontextprotocol/client";

const slugTool = defineTool({
  name: "text_slug",
  title: "Text Slug",
  description: "Turn a title into a lowercase URL slug.",
  effect: "read",
  input: Type.Object({ text: Type.String({ minLength: 1 }) }, { additionalProperties: false }),
  execute: ({ text }) => {
    const slug =
      text
        .toLowerCase()
        .match(/[a-z0-9]+/g)
        ?.join("-") ?? "";
    return { content: [{ type: "text", text: slug }], details: { slug } };
  },
});

const server = createMcpServer({ name: "slugs", version: "1.0.0" }, [slugTool]);
const client = new Client({ name: "demo", version: "1.0.0" });
const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
await Promise.all([server.connect(serverSide), client.connect(clientSide)]);

console.log(await client.callTool({ name: "text_slug", arguments: { text: "Hello, World" } }));
console.log(await client.callTool({ name: "text_slug", arguments: { txt: "Hello, World" } }));
{ content: [ { type: 'text', text: 'hello-world' } ] }
{
  content: [
    {
      type: 'text',
      text: 'Invalid arguments: unknown property "txt"; takes text\n' +
        'Invalid arguments at /: must have required properties text'
    }
  ],
  isError: true
}

The typo never reached execute. The model gets told what it did wrong and what the tool takes. Pi, OMP and the AI SDK hand it the same two lines, only through their own error channel. Validation and errors has the table.

🤖 Hosts

HostAdapterPeer
MCPcreateMcpServer from @agntn/tools/mcp@modelcontextprotocol/server
H3toH3Tools from @agntn/tools/h3h3-mcp
DocustoToolkitTools from @agntn/tools/toolkitzod, beside @nuxtjs/mcp-toolkit
PiregisterPiTools from @agntn/tools/pi@earendil-works/pi-coding-agent
OMPregisterOmpTools from @agntn/tools/omp@oh-my-pi/pi-coding-agent
AI SDKtoAiTool from @agntn/tools/aiai
CLIrunCli from @agntn/tools/clinone

Install only what you ship. An MCP server doesn't need the AI SDK, and nobody makes it pretend. Every host has its own page with the gotchas: tools.agntn.dev/hosts.

🚫 What this does not do

It doesn't run your server or pick a transport. Stdio, HTTP, in memory, your call. Unless you ask runCli for its mcp command. That one is stdio. And it isn't a schema library. TypeBox does that part, this just makes sure every host sees the same one.

🛠️ Development

pnpm install
pnpm lint         # vp lint and vp fmt --check
pnpm typecheck    # tsc over the source and the tests
pnpm test         # vp test run
pnpm build        # obuild, TypeBox bundled into dist

💛 Thanks

Written with a lot of help from Claude for Open Source and Codex for Open Source. Both keep open source maintainers going for free. Cheers <3

📄 License

MIT

版本与发布记录

@agntn/tools 共发布 9 个版本,首次发布于 2026/09/30;过去 12 个月发布了 9 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
0.3.0latest2026/11/032 天前
0.2.42026/10/1323 天前
0.2.32026/10/1027 天前
0.2.22026/10/0828 天前
0.2.12026/10/0729 天前
0.2.02026/10/0630 天前

关于 @agntn/tools 的常见问题

@agntn/tools 是什么?

One tool definition for MCP, Pi, OMP and the AI SDK

如何安装 @agntn/tools?

在项目目录运行 npm install @agntn/tools,或使用 pnpm add / yarn add / bun add。

@agntn/tools 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@agntn/tools 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@agntn/tools 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=26。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@agntn/tools 可以商用吗?

@agntn/tools 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@agntn/tools 的下载量有多少?

根据 npm 官方下载统计,@agntn/tools 在 2026/10/05 – 2026/11/03 这 30 天内被下载 4,612 次,日均约 154 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@agntn/tools 还在维护吗?

最新版本 0.3.0 发布于 2026/11/03(2 天前);至今共发布 9 个版本,其中过去 12 个月发布了 9 个;首次发布于 2026/09/30。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。