@agntn/tools 0.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present oritwoen
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,114 @@
1
+ # @agntn/tools
2
+
3
+ [![npm version](https://npmx.dev/api/registry/badge/version/@agntn/tools)](https://npmx.dev/package/@agntn/tools)
4
+ [![npm downloads](https://npmx.dev/api/registry/badge/downloads/@agntn/tools)](https://npmx.dev/package/@agntn/tools)
5
+ [![license](https://npmx.dev/api/registry/badge/license/@agntn/tools)](https://npmx.dev/package/@agntn/tools)
6
+ [![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/agntn/tools)
7
+
8
+ ๐Ÿงฐ Four hosts, one definition. You write the tool once. MCP, Pi, OMP and the AI SDK each get it the way they like it.
9
+
10
+ Want to watch it happen? [tools.agntn.dev](https://tools.agntn.dev) has the docs and a playground. One call, four hosts, all live in your tab.
11
+
12
+ ## Why?
13
+
14
+ 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.
15
+
16
+ ## โœจ Features
17
+
18
+ - ๐Ÿ“ **One definition.** Name, schema, effect and `execute`. That's the whole tool.
19
+ - ๐Ÿ”Œ **Four adapters.** `createMcpServer`, `registerPiTools`, `registerOmpTools` and `toAiTool`. One call each.
20
+ - ๐Ÿ›ก๏ธ **Validation on every host.** The core checks each call before your code runs. Even when the host skips its own check.
21
+ - ๐Ÿ—ฃ๏ธ **Errors a model can use.** A misspelled key names itself and the keys you do take. An enum lists its values.
22
+ - ๐Ÿงต **One line per error.** Newlines, escape codes and bidi tricks in echoed text get flattened. No forged lines.
23
+ - ๐Ÿชค **The OMP TypeBox trap, defused.** TypeBox is bundled, so OMP has nothing left to rewrite behind your back.
24
+ - ๐Ÿงช **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.
25
+ - ๐ŸŒ **Runs anywhere.** No `node:*` import in the core or the adapters. The docs site runs all of it in a browser tab.
26
+
27
+ ## ๐Ÿ“ฆ Install
28
+
29
+ ```bash
30
+ pnpm add @agntn/tools
31
+ ```
32
+
33
+ Node.js 24 or newer. Then add the hosts you serve. Each one is an optional peer.
34
+
35
+ ## ๐Ÿš€ First call
36
+
37
+ ```ts
38
+ import { defineTool, Type } from "@agntn/tools";
39
+ import { createMcpServer } from "@agntn/tools/mcp";
40
+ import { Client, InMemoryTransport } from "@modelcontextprotocol/client";
41
+
42
+ const slugTool = defineTool({
43
+ name: "text_slug",
44
+ title: "Text Slug",
45
+ description: "Turn a title into a lowercase URL slug.",
46
+ effect: "read",
47
+ input: Type.Object({ text: Type.String({ minLength: 1 }) }, { additionalProperties: false }),
48
+ execute: ({ text }) => {
49
+ const slug =
50
+ text
51
+ .toLowerCase()
52
+ .match(/[a-z0-9]+/g)
53
+ ?.join("-") ?? "";
54
+ return { content: [{ type: "text", text: slug }], details: { slug } };
55
+ },
56
+ });
57
+
58
+ const server = createMcpServer({ name: "slugs", version: "1.0.0" }, [slugTool]);
59
+ const client = new Client({ name: "demo", version: "1.0.0" });
60
+ const [clientSide, serverSide] = InMemoryTransport.createLinkedPair();
61
+ await Promise.all([server.connect(serverSide), client.connect(clientSide)]);
62
+
63
+ console.log(await client.callTool({ name: "text_slug", arguments: { text: "Hello, World" } }));
64
+ console.log(await client.callTool({ name: "text_slug", arguments: { txt: "Hello, World" } }));
65
+ ```
66
+
67
+ ```text
68
+ { content: [ { type: 'text', text: 'hello-world' } ] }
69
+ {
70
+ content: [
71
+ {
72
+ type: 'text',
73
+ text: 'Invalid arguments: unknown property "txt"; takes text\n' +
74
+ 'Invalid arguments at /: must have required properties text'
75
+ }
76
+ ],
77
+ isError: true
78
+ }
79
+ ```
80
+
81
+ 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](https://tools.agntn.dev/guide/validation) has the table.
82
+
83
+ ## ๐Ÿค– Hosts
84
+
85
+ | Host | Adapter | Peer |
86
+ | ------ | ------------------------------------------ | --------------------------------- |
87
+ | MCP | `createMcpServer` from `@agntn/tools/mcp` | `@modelcontextprotocol/server` |
88
+ | Pi | `registerPiTools` from `@agntn/tools/pi` | `@earendil-works/pi-coding-agent` |
89
+ | OMP | `registerOmpTools` from `@agntn/tools/omp` | `@oh-my-pi/pi-coding-agent` |
90
+ | AI SDK | `toAiTool` from `@agntn/tools/ai` | `ai` |
91
+
92
+ 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](https://tools.agntn.dev/hosts).
93
+
94
+ ## ๐Ÿšซ What this does not do
95
+
96
+ It doesn't run your server or pick a transport. Stdio, HTTP, in memory, your call. And it isn't a schema library. TypeBox does that part, this just makes sure every host sees the same one.
97
+
98
+ ## ๐Ÿ› ๏ธ Development
99
+
100
+ ```bash
101
+ pnpm install
102
+ pnpm lint # vp lint and vp fmt --check
103
+ pnpm typecheck # tsc over the source and the tests
104
+ pnpm test # vp test run
105
+ pnpm build # obuild, TypeBox bundled into dist
106
+ ```
107
+
108
+ ## ๐Ÿ’› Thanks
109
+
110
+ Written with a lot of help from [Claude for Open Source](https://claude.com/contact-sales/claude-for-oss) and [Codex for Open Source](https://developers.openai.com/community/codex-for-oss). Both keep open source maintainers going for free. Cheers <3
111
+
112
+ ## ๐Ÿ“„ License
113
+
114
+ [MIT](./LICENSE)
@@ -0,0 +1,36 @@
1
+ # Licenses of Bundled Dependencies
2
+
3
+ The published artifact additionally contains code with the following licenses:
4
+ MIT
5
+
6
+ # Bundled Dependencies
7
+
8
+ ## typebox
9
+
10
+ License: MIT
11
+ By: sinclairzx81
12
+ Repository: https://github.com/sinclairzx81/typebox
13
+
14
+ > TypeBox
15
+ >
16
+ > The MIT License (MIT)
17
+ >
18
+ > Copyright (c) 2017-2026 Haydn Paterson
19
+ >
20
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
21
+ > of this software and associated documentation files (the "Software"), to deal
22
+ > in the Software without restriction, including without limitation the rights
23
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
24
+ > copies of the Software, and to permit persons to whom the Software is
25
+ > furnished to do so, subject to the following conditions:
26
+ >
27
+ > The above copyright notice and this permission notice shall be included in
28
+ > all copies or substantial portions of the Software.
29
+ >
30
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
31
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
32
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
33
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
34
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
35
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
36
+ > THE SOFTWARE.