@warlock.js/ai-tools 5.19.0 → 5.20.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/llms.txt CHANGED
@@ -6,6 +6,6 @@
6
6
 
7
7
  ## Skills
8
8
 
9
- - [connect-mcp-server](@warlock.js/ai-tools/connect-mcp-server/SKILL.md): Connect to an external MCP server (Direction A) in @warlock.js/ai-tools; use when you need to connect mcp server.
10
- - [expose-as-mcp-server](@warlock.js/ai-tools/expose-as-mcp-server/SKILL.md): Expose tools AS an MCP server (Direction B) in @warlock.js/ai-tools; use when you need to expose as mcp server.
11
- - [use-web-and-http-tools](@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md): Use the web + HTTP tool belt in @warlock.js/ai-tools; use when you need to use web and http tools.
9
+ - [connect-mcp-server](@warlock.js/ai-tools/connect-mcp-server/SKILL.md): (no description)
10
+ - [expose-as-mcp-server](@warlock.js/ai-tools/expose-as-mcp-server/SKILL.md): (no description)
11
+ - [use-web-and-http-tools](@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md): (no description)
package/package.json CHANGED
@@ -22,7 +22,7 @@
22
22
  "@modelcontextprotocol/sdk": "*",
23
23
  "@mozilla/readability": "*",
24
24
  "@tavily/core": "*",
25
- "@warlock.js/ai": "5.19.0",
25
+ "@warlock.js/ai": "5.20.0",
26
26
  "ajv": "*",
27
27
  "jsdom": "*"
28
28
  },
@@ -46,7 +46,7 @@
46
46
  "dependencies": {
47
47
  "@standard-schema/spec": "^1.0.0"
48
48
  },
49
- "version": "5.19.0",
49
+ "version": "5.20.0",
50
50
  "main": "./cjs/index.cjs",
51
51
  "module": "./esm/index.mjs",
52
52
  "types": "./esm/index.d.mts",
@@ -1,98 +1,98 @@
1
- ---
2
- name: connect-mcp-server
3
- description: "Connect to an external MCP server (Direction A) in @warlock.js/ai-tools; use when you need to connect mcp server."
4
- ---
5
-
6
- # Connect to an external MCP server (Direction A)
7
-
8
- `ai.mcp(server, options?)` opens a connection to any Model Context Protocol server, lists its tools, and adapts each one into a native `ToolContract` — so a remote MCP tool is indistinguishable from a local one and drops straight into `ai.agent({ tools: [...] })`.
9
-
10
- ```ts
11
- import "@warlock.js/ai-tools";
12
- import { ai } from "@warlock.js/ai";
13
-
14
- const github = ai.mcp(
15
- { type: "stdio", command: "npx", args: ["-y", "@modelcontextprotocol/server-github"] },
16
- { namePrefix: "github." },
17
- );
18
-
19
- const dev = ai.agent({
20
- model,
21
- systemPrompt: "Use the GitHub tools to triage issues.",
22
- tools: [...(await github.tools())], // handshake + tools/list, run once and cached
23
- maxTrips: 20,
24
- });
25
-
26
- await dev.execute("Find the oldest open 'bug' issue and propose a fix.");
27
-
28
- await github.close(); // on teardown — kills the child / ends the HTTP session
29
- ```
30
-
31
- ## The transport — `stdio` or `http`
32
-
33
- The `server` argument is discriminated by `type`:
34
-
35
- ```ts
36
- // Spawn a child process and speak JSON-RPC over its stdin/stdout.
37
- // Uses node:child_process + node:readline — NO dependency.
38
- { type: "stdio", command: "npx", args: ["-y", "@modelcontextprotocol/server-github"], env: { GITHUB_TOKEN: "…" } }
39
-
40
- // Streamable HTTP against an endpoint.
41
- { type: "http", url: "https://mcp.example.com/rpc", headers: { authorization: "Bearer …" } }
42
- ```
43
-
44
- > **stdio env is not inherited.** When you pass `env`, only those keys reach the child — pass what the server needs (e.g. its API token) explicitly.
45
-
46
- ## Client options
47
-
48
- ```ts
49
- ai.mcp(server, {
50
- namePrefix: "github.", // prepended to every remote tool name
51
- filter: (name) => name.startsWith("issues_"),// only adapt tools whose name passes
52
- timeoutMs: 30_000, // per tools/call deadline (default 30s)
53
- });
54
- ```
55
-
56
- - **`namePrefix`** is the collision mitigation — there is **no runtime tool-name collision guard** (the agent resolves a tool by first name match), so the author owns uniqueness. Prefix remote tools to keep them distinct from local ones.
57
- - **`filter`** receives each tool's *unprefixed* name; return `false` to drop it.
58
-
59
- ## What `tools()` does
60
-
61
- `client.tools()` is lazy and cached: the **first** call runs the `initialize` handshake, sends `notifications/initialized`, then `tools/list`, and maps each descriptor into a `ToolContract`. Repeat calls return the cached array without re-handshaking.
62
-
63
- For each remote tool:
64
- 1. its JSON-Schema `inputSchema` is wrapped as a Standard Schema via `jsonSchemaToStandard` (Ajv-backed — `ajv` is an optional peer needed only for the client);
65
- 2. `execute` issues `tools/call` honoring `ctx.signal` (cooperative abort) and the configured `timeoutMs`, then unwraps the result content (a single JSON text block is parsed back into an object);
66
- 3. an MCP `isError` result is thrown so the surrounding `tool()` wraps it as a `ToolExecutionError` — the agent reads it as `{ error }` data and self-corrects.
67
-
68
- ## `type`, never `kind`
69
-
70
- MCP's wire vocabulary uses `kind` in some content/capability descriptors. The client translates any inbound `kind` to `type` when normalizing content blocks, so a value a tool returns never carries MCP's `kind` — every discriminator the agent sees is `type`.
71
-
72
- ## Errors
73
-
74
- Connection / handshake failures surface **at agent-construction time** because the example `await`s `github.tools()` — you see them then, not mid-run. A `tools/call` failure raised mid-run is wrapped by `tool()` and reaches the model as data. Branch on `McpTransportError.type`:
75
-
76
- ```ts
77
- import { McpTransportError } from "@warlock.js/ai-tools";
78
-
79
- try {
80
- await github.tools();
81
- } catch (error) {
82
- if (error instanceof McpTransportError && error.type === "connect") {
83
- // the child failed to spawn, the endpoint was unreachable, or the handshake failed
84
- }
85
- }
86
- ```
87
-
88
- `McpTransportError.type`: `"connect"` | `"protocol"` | `"timeout"` | `"closed"` (plus an optional `.method` naming the in-flight JSON-RPC method).
89
-
90
- ## Optional peers
91
-
92
- The MCP client lazily imports `@modelcontextprotocol/sdk` (the protocol SDK) and `ajv` (runtime JSON-Schema validation) — both optional peers. A missing one surfaces a curated `npm install` string at first use, never a raw module-resolution crash at import time. The stdio transport itself needs no dependency.
93
-
94
- ## See also
95
-
96
- - [`@warlock.js/ai-tools/expose-as-mcp-server/SKILL.md`](@warlock.js/ai-tools/expose-as-mcp-server/SKILL.md) — the reverse direction: publish a local primitive AS an MCP server.
97
- - [`@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md`](@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md) — the built-in web / HTTP / calculator / date-time belt.
98
- - [`@warlock.js/ai/run-ai-agent/SKILL.md`](@warlock.js/ai/run-ai-agent/SKILL.md) — running the agent that consumes the adapted tools.
1
+ ---
2
+ name: connect-mcp-server
3
+ description: 'Connect a @warlock.js/ai agent to an external Model Context Protocol (MCP) server and adapt its tools as native agent tools (Direction A) with `ai.mcp(server)`. Triggers: `ai.mcp(`, `ai.mcp.serve` (the other direction), `mcp(`, `McpClient`, `McpClientOptions`, `McpTransport`, `client.tools()`, `client.close()`, `namePrefix`, `filter`, `McpTransportError`, `{ type: "stdio" }`, `{ type: "http" }`, `tools/list`, `tools/call`, `jsonSchemaToStandard`, `@modelcontextprotocol/sdk`, `ajv`; ''consume an MCP server'', ''use an external MCP server''s tools in my agent'', ''connect to the GitHub/Slack/Filesystem MCP server'', ''adapt MCP tools as agent tools'', ''bridge my agent to the MCP ecosystem'', ''run an MCP server over stdio/http''; typical import `import "@warlock.js/ai-tools"; import { ai } from "@warlock.js/ai"`. Skip: exposing YOUR agent/tools AS an MCP server (the reverse direction) — `@warlock.js/ai-tools/expose-as-mcp-server/SKILL.md`; the built-in web/HTTP/calc/date tools — `@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md`.'
4
+ ---
5
+
6
+ # Connect to an external MCP server (Direction A)
7
+
8
+ `ai.mcp(server, options?)` opens a connection to any Model Context Protocol server, lists its tools, and adapts each one into a native `ToolContract` — so a remote MCP tool is indistinguishable from a local one and drops straight into `ai.agent({ tools: [...] })`.
9
+
10
+ ```ts
11
+ import "@warlock.js/ai-tools";
12
+ import { ai } from "@warlock.js/ai";
13
+
14
+ const github = ai.mcp(
15
+ { type: "stdio", command: "npx", args: ["-y", "@modelcontextprotocol/server-github"] },
16
+ { namePrefix: "github." },
17
+ );
18
+
19
+ const dev = ai.agent({
20
+ model,
21
+ systemPrompt: "Use the GitHub tools to triage issues.",
22
+ tools: [...(await github.tools())], // handshake + tools/list, run once and cached
23
+ maxTrips: 20,
24
+ });
25
+
26
+ await dev.execute("Find the oldest open 'bug' issue and propose a fix.");
27
+
28
+ await github.close(); // on teardown — kills the child / ends the HTTP session
29
+ ```
30
+
31
+ ## The transport — `stdio` or `http`
32
+
33
+ The `server` argument is discriminated by `type`:
34
+
35
+ ```ts
36
+ // Spawn a child process and speak JSON-RPC over its stdin/stdout.
37
+ // Uses node:child_process + node:readline — NO dependency.
38
+ { type: "stdio", command: "npx", args: ["-y", "@modelcontextprotocol/server-github"], env: { GITHUB_TOKEN: "…" } }
39
+
40
+ // Streamable HTTP against an endpoint.
41
+ { type: "http", url: "https://mcp.example.com/rpc", headers: { authorization: "Bearer …" } }
42
+ ```
43
+
44
+ > **stdio env is not inherited.** When you pass `env`, only those keys reach the child — pass what the server needs (e.g. its API token) explicitly.
45
+
46
+ ## Client options
47
+
48
+ ```ts
49
+ ai.mcp(server, {
50
+ namePrefix: "github.", // prepended to every remote tool name
51
+ filter: (name) => name.startsWith("issues_"),// only adapt tools whose name passes
52
+ timeoutMs: 30_000, // per tools/call deadline (default 30s)
53
+ });
54
+ ```
55
+
56
+ - **`namePrefix`** is the collision mitigation — there is **no runtime tool-name collision guard** (the agent resolves a tool by first name match), so the author owns uniqueness. Prefix remote tools to keep them distinct from local ones.
57
+ - **`filter`** receives each tool's *unprefixed* name; return `false` to drop it.
58
+
59
+ ## What `tools()` does
60
+
61
+ `client.tools()` is lazy and cached: the **first** call runs the `initialize` handshake, sends `notifications/initialized`, then `tools/list`, and maps each descriptor into a `ToolContract`. Repeat calls return the cached array without re-handshaking.
62
+
63
+ For each remote tool:
64
+ 1. its JSON-Schema `inputSchema` is wrapped as a Standard Schema via `jsonSchemaToStandard` (Ajv-backed — `ajv` is an optional peer needed only for the client);
65
+ 2. `execute` issues `tools/call` honoring `ctx.signal` (cooperative abort) and the configured `timeoutMs`, then unwraps the result content (a single JSON text block is parsed back into an object);
66
+ 3. an MCP `isError` result is thrown so the surrounding `tool()` wraps it as a `ToolExecutionError` — the agent reads it as `{ error }` data and self-corrects.
67
+
68
+ ## `type`, never `kind`
69
+
70
+ MCP's wire vocabulary uses `kind` in some content/capability descriptors. The client translates any inbound `kind` to `type` when normalizing content blocks, so a value a tool returns never carries MCP's `kind` — every discriminator the agent sees is `type`.
71
+
72
+ ## Errors
73
+
74
+ Connection / handshake failures surface **at agent-construction time** because the example `await`s `github.tools()` — you see them then, not mid-run. A `tools/call` failure raised mid-run is wrapped by `tool()` and reaches the model as data. Branch on `McpTransportError.type`:
75
+
76
+ ```ts
77
+ import { McpTransportError } from "@warlock.js/ai-tools";
78
+
79
+ try {
80
+ await github.tools();
81
+ } catch (error) {
82
+ if (error instanceof McpTransportError && error.type === "connect") {
83
+ // the child failed to spawn, the endpoint was unreachable, or the handshake failed
84
+ }
85
+ }
86
+ ```
87
+
88
+ `McpTransportError.type`: `"connect"` | `"protocol"` | `"timeout"` | `"closed"` (plus an optional `.method` naming the in-flight JSON-RPC method).
89
+
90
+ ## Optional peers
91
+
92
+ The MCP client lazily imports `@modelcontextprotocol/sdk` (the protocol SDK) and `ajv` (runtime JSON-Schema validation) — both optional peers. A missing one surfaces a curated `npm install` string at first use, never a raw module-resolution crash at import time. The stdio transport itself needs no dependency.
93
+
94
+ ## See also
95
+
96
+ - [`@warlock.js/ai-tools/expose-as-mcp-server/SKILL.md`](@warlock.js/ai-tools/expose-as-mcp-server/SKILL.md) — the reverse direction: publish a local primitive AS an MCP server.
97
+ - [`@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md`](@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md) — the built-in web / HTTP / calculator / date-time belt.
98
+ - [`@warlock.js/ai/run-ai-agent/SKILL.md`](@warlock.js/ai/run-ai-agent/SKILL.md) — running the agent that consumes the adapted tools.
@@ -1,85 +1,85 @@
1
- ---
2
- name: expose-as-mcp-server
3
- description: "Expose tools AS an MCP server (Direction B) in @warlock.js/ai-tools; use when you need to expose as mcp server."
4
- ---
5
-
6
- # Expose tools AS an MCP server (Direction B)
7
-
8
- `ai.mcp.serve(source, options)` turns a local set of `ToolContract`s into a Model Context Protocol server — so Cursor, Claude Desktop, or any MCP client can call your warlock tools / agent over the wire.
9
-
10
- ```ts
11
- import "@warlock.js/ai-tools";
12
- import { ai } from "@warlock.js/ai";
13
-
14
- const server = ai.mcp.serve(
15
- [ai.tools.calculator(), ai.tools.dateTime()],
16
- { name: "warlock-utils", transport: { type: "stdio" } },
17
- );
18
-
19
- await server.start();
20
- // ...later, on teardown:
21
- await server.stop();
22
- ```
23
-
24
- ## The `source` — array or anything with `tools()`
25
-
26
- ```ts
27
- // A literal array of contracts:
28
- ai.mcp.serve([calc, dt], { name: "utils" });
29
-
30
- // Anything that can enumerate its ToolContracts — e.g. a workspace:
31
- ai.mcp.serve({ tools: () => ws.tools.all() }, { name: "acme-workspace" });
32
- ```
33
-
34
- The tools are snapshotted at construction (`source.tools()` is called once), so a stable surface is advertised for the life of the server.
35
-
36
- ## Serve options
37
-
38
- ```ts
39
- ai.mcp.serve(source, {
40
- name: "warlock-utils", // advertised in the initialize response (required)
41
- version: "1.0.0", // default: the package version
42
- transport: { type: "stdio" }, // default: stdio
43
- schemaTarget: "draft-2020-12", // JSON-Schema dialect for each tool's inputSchema
44
- });
45
- ```
46
-
47
- - **`schemaTarget`** defaults to `"draft-2020-12"` — a neutral MCP draft, deliberately overriding `extractJsonSchema`'s own `"openai-strict"` default. Set it to match a consuming client's expectation.
48
-
49
- ## How the protocol maps
50
-
51
- - **`initialize`** → advertises `{ name, version }` and `capabilities: { tools: {} }`.
52
- - **`tools/list`** → one descriptor per contract; each tool's `inputSchema` is produced by `extractJsonSchema(contract.input, { target: schemaTarget })`.
53
- - **`tools/call`** → routes to the named contract's `invoke()` and maps the **never-throwing** result: `data` becomes a `{ type: "text" }` content block (a string is sent verbatim, anything else is JSON-stringified), and `error` becomes an `isError: true` result. So a failing tool surfaces as a normal MCP tool error — the server never crashes on it. An unknown tool name answers with a JSON-RPC error.
54
-
55
- Everything the server emits uses `type`, never `kind`.
56
-
57
- ## Transport — stdio is auto-pumped; HTTP is host-owned
58
-
59
- ```ts
60
- { type: "stdio" } // default — reads JSON-RPC lines from process.stdin, writes to stdout
61
- { type: "http", port: 8080 } // accepted in options, but start() does NOT bind a socket
62
- ```
63
-
64
- `start()` over `stdio` wires a `node:readline` line reader on `process.stdin` and writes one-line JSON-RPC responses to `process.stdout` (notifications without an `id` are ignored). **Serving over HTTP is left to a server you own** — `start()` rejects an `http` transport. For that path, drive the pure protocol core yourself with `createServeHandler`:
65
-
66
- ```ts
67
- import { createServeHandler } from "@warlock.js/ai-tools";
68
-
69
- const handler = createServeHandler([calc, dt], { name: "warlock-utils" });
70
-
71
- // In your own HTTP handler:
72
- const response = await handler.handle(jsonRpcRequest); // request → response, no I/O
73
- ```
74
-
75
- `createServeHandler` is also the cleanest seam for unit tests: feed it a JSON-RPC request, assert the response — no real transport needed.
76
-
77
- ## Errors
78
-
79
- `McpTransportError` covers serve-side failures (`type: "connect"` when `start()` is asked to bind an unsupported transport; `type: "protocol"` for a malformed `tools/call` or an unknown tool name). Tool-level failures are *not* errors here — they come back as `isError: true` results, exactly as MCP expects.
80
-
81
- ## See also
82
-
83
- - [`@warlock.js/ai-tools/connect-mcp-server/SKILL.md`](@warlock.js/ai-tools/connect-mcp-server/SKILL.md) — the reverse direction: consume an external MCP server's tools.
84
- - [`@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md`](@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md) — the built-in tools you might expose.
85
- - [`@warlock.js/ai-workspace/use-a-workspace/SKILL.md`](@warlock.js/ai-workspace/use-a-workspace/SKILL.md) — a workspace whose `tools.all()` is a natural `serve` source.
1
+ ---
2
+ name: expose-as-mcp-server
3
+ description: 'Expose a @warlock.js/ai agent / supervisor / orchestrator (or a raw ToolContract[]) AS a Model Context Protocol (MCP) server other clients consume (Direction B) with `ai.mcp.serve(source, options)`. Triggers: `ai.mcp.serve(`, `serve(`, `createServeHandler`, `McpServer`, `McpServeOptions`, `McpServeSource`, `McpServeTransport`, `server.start()`, `server.stop()`, `schemaTarget`, `draft-2020-12`, `extractJsonSchema`, `tools/list`, `tools/call`, `{ type: "stdio" }`, `{ type: "http"; port }`; ''expose my agent as an MCP server'', ''publish my tools to Cursor/Claude Desktop'', ''make my warlock workspace an MCP server'', ''serve my ToolContract[] over MCP'', ''let other MCP clients call my agent''; typical import `import "@warlock.js/ai-tools"; import { ai } from "@warlock.js/ai"`. Skip: CONSUMING an external MCP server (the reverse direction) — `@warlock.js/ai-tools/connect-mcp-server/SKILL.md`; the built-in web/HTTP/calc/date tools — `@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md`.'
4
+ ---
5
+
6
+ # Expose tools AS an MCP server (Direction B)
7
+
8
+ `ai.mcp.serve(source, options)` turns a local set of `ToolContract`s into a Model Context Protocol server — so Cursor, Claude Desktop, or any MCP client can call your warlock tools / agent over the wire.
9
+
10
+ ```ts
11
+ import "@warlock.js/ai-tools";
12
+ import { ai } from "@warlock.js/ai";
13
+
14
+ const server = ai.mcp.serve(
15
+ [ai.tools.calculator(), ai.tools.dateTime()],
16
+ { name: "warlock-utils", transport: { type: "stdio" } },
17
+ );
18
+
19
+ await server.start();
20
+ // ...later, on teardown:
21
+ await server.stop();
22
+ ```
23
+
24
+ ## The `source` — array or anything with `tools()`
25
+
26
+ ```ts
27
+ // A literal array of contracts:
28
+ ai.mcp.serve([calc, dt], { name: "utils" });
29
+
30
+ // Anything that can enumerate its ToolContracts — e.g. a workspace:
31
+ ai.mcp.serve({ tools: () => ws.tools.all() }, { name: "acme-workspace" });
32
+ ```
33
+
34
+ The tools are snapshotted at construction (`source.tools()` is called once), so a stable surface is advertised for the life of the server.
35
+
36
+ ## Serve options
37
+
38
+ ```ts
39
+ ai.mcp.serve(source, {
40
+ name: "warlock-utils", // advertised in the initialize response (required)
41
+ version: "1.0.0", // default: the package version
42
+ transport: { type: "stdio" }, // default: stdio
43
+ schemaTarget: "draft-2020-12", // JSON-Schema dialect for each tool's inputSchema
44
+ });
45
+ ```
46
+
47
+ - **`schemaTarget`** defaults to `"draft-2020-12"` — a neutral MCP draft, deliberately overriding `extractJsonSchema`'s own `"openai-strict"` default. Set it to match a consuming client's expectation.
48
+
49
+ ## How the protocol maps
50
+
51
+ - **`initialize`** → advertises `{ name, version }` and `capabilities: { tools: {} }`.
52
+ - **`tools/list`** → one descriptor per contract; each tool's `inputSchema` is produced by `extractJsonSchema(contract.input, { target: schemaTarget })`.
53
+ - **`tools/call`** → routes to the named contract's `invoke()` and maps the **never-throwing** result: `data` becomes a `{ type: "text" }` content block (a string is sent verbatim, anything else is JSON-stringified), and `error` becomes an `isError: true` result. So a failing tool surfaces as a normal MCP tool error — the server never crashes on it. An unknown tool name answers with a JSON-RPC error.
54
+
55
+ Everything the server emits uses `type`, never `kind`.
56
+
57
+ ## Transport — stdio is auto-pumped; HTTP is host-owned
58
+
59
+ ```ts
60
+ { type: "stdio" } // default — reads JSON-RPC lines from process.stdin, writes to stdout
61
+ { type: "http", port: 8080 } // accepted in options, but start() does NOT bind a socket
62
+ ```
63
+
64
+ `start()` over `stdio` wires a `node:readline` line reader on `process.stdin` and writes one-line JSON-RPC responses to `process.stdout` (notifications without an `id` are ignored). **Serving over HTTP is left to a server you own** — `start()` rejects an `http` transport. For that path, drive the pure protocol core yourself with `createServeHandler`:
65
+
66
+ ```ts
67
+ import { createServeHandler } from "@warlock.js/ai-tools";
68
+
69
+ const handler = createServeHandler([calc, dt], { name: "warlock-utils" });
70
+
71
+ // In your own HTTP handler:
72
+ const response = await handler.handle(jsonRpcRequest); // request → response, no I/O
73
+ ```
74
+
75
+ `createServeHandler` is also the cleanest seam for unit tests: feed it a JSON-RPC request, assert the response — no real transport needed.
76
+
77
+ ## Errors
78
+
79
+ `McpTransportError` covers serve-side failures (`type: "connect"` when `start()` is asked to bind an unsupported transport; `type: "protocol"` for a malformed `tools/call` or an unknown tool name). Tool-level failures are *not* errors here — they come back as `isError: true` results, exactly as MCP expects.
80
+
81
+ ## See also
82
+
83
+ - [`@warlock.js/ai-tools/connect-mcp-server/SKILL.md`](@warlock.js/ai-tools/connect-mcp-server/SKILL.md) — the reverse direction: consume an external MCP server's tools.
84
+ - [`@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md`](@warlock.js/ai-tools/use-web-and-http-tools/SKILL.md) — the built-in tools you might expose.
85
+ - [`@warlock.js/ai-workspace/use-a-workspace/SKILL.md`](@warlock.js/ai-workspace/use-a-workspace/SKILL.md) — a workspace whose `tools.all()` is a natural `serve` source.
@@ -0,0 +1,18 @@
1
+ ---
2
+ description: "Ready-made tools for @warlock.js/ai agents: web search, URL fetch, HTTP requests, calculator, date-time, and MCP client and server support. Exports `webSearchTool`, `fetchUrlTool`, `httpRequestTool`, `calculatorTool`, `dateTimeTool`, `mcp`, `serve`, `createServeHandler`, `McpTransportError`. Use for: let an agent search the web, fetch a page, call an HTTP API, do math, get the current date, connect to an MCP server, expose my tools as an MCP server. Not this package: defining your own tool or the agent itself → @warlock.js/ai; file and shell tools → @warlock.js/ai-workspace."
3
+ ---
4
+ # @warlock.js/ai-tools
5
+
6
+ A belt of prebuilt tools for `@warlock.js/ai` agents plus the Model Context Protocol bridge in both directions. Importing the package attaches `ai.tools.*` and `ai.mcp` onto the shared `ai` object; the factories are also exported directly.
7
+
8
+ ## The 80% path
9
+ 1. Give an agent web or API access with the factories (`use-web-and-http-tools.md`); pass the results in the agent's `tools` array.
10
+ 2. Consume tools from an external MCP server (`connect-mcp-server.md`); they arrive as normal agent tools.
11
+ 3. Publish your own tools to MCP clients such as editors (`expose-as-mcp-server.md`).
12
+
13
+ ## Conventions and pitfalls
14
+ - Direction A (`connect-mcp-server.md`) consumes; Direction B (`expose-as-mcp-server.md`) serves. Do not mix them up.
15
+ - `fetchUrlTool` and `httpRequestTool` are policy-gated: set host allowlists and byte caps rather than opening them fully.
16
+ - `webSearchTool` needs a search provider choice and its API key (tavily, brave, or serpapi).
17
+ - Every error class extends the `AIError` of `@warlock.js/ai`; catch by subclass.
18
+ - Writing a custom tool with `ai.tool()` lives in `@warlock.js/ai` (`define-ai-tool.md`).