@warlock.js/ai-tools 5.30.0 → 5.32.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.
Files changed (86) hide show
  1. package/CHANGELOG.md +53 -1
  2. package/README.md +25 -13
  3. package/cjs/index.cjs +968 -122
  4. package/cjs/index.cjs.map +1 -1
  5. package/esm/contracts/http.type.d.mts +4 -5
  6. package/esm/contracts/http.type.d.mts.map +1 -1
  7. package/esm/contracts/index.d.mts +3 -1
  8. package/esm/contracts/mcp-serve.type.d.mts +285 -0
  9. package/esm/contracts/mcp-serve.type.d.mts.map +1 -0
  10. package/esm/contracts/mcp.type.d.mts +44 -77
  11. package/esm/contracts/mcp.type.d.mts.map +1 -1
  12. package/esm/contracts/utility.type.d.mts +7 -8
  13. package/esm/contracts/utility.type.d.mts.map +1 -1
  14. package/esm/contracts/web.type.d.mts +9 -10
  15. package/esm/contracts/web.type.d.mts.map +1 -1
  16. package/esm/errors.d.mts +62 -22
  17. package/esm/errors.d.mts.map +1 -1
  18. package/esm/errors.mjs +20 -1
  19. package/esm/errors.mjs.map +1 -1
  20. package/esm/http/http-request.d.mts +2 -3
  21. package/esm/http/http-request.d.mts.map +1 -1
  22. package/esm/http/http-request.mjs +7 -5
  23. package/esm/http/http-request.mjs.map +1 -1
  24. package/esm/index.d.mts +10 -4
  25. package/esm/index.mjs +4 -2
  26. package/esm/mcp/client.mjs +37 -6
  27. package/esm/mcp/client.mjs.map +1 -1
  28. package/esm/mcp/index.d.mts +17 -9
  29. package/esm/mcp/index.d.mts.map +1 -1
  30. package/esm/mcp/index.mjs +3 -1
  31. package/esm/mcp/index.mjs.map +1 -1
  32. package/esm/mcp/json-schema-to-standard.d.mts +1 -3
  33. package/esm/mcp/json-schema-to-standard.d.mts.map +1 -1
  34. package/esm/mcp/protocol.d.mts +15 -0
  35. package/esm/mcp/protocol.d.mts.map +1 -0
  36. package/esm/mcp/protocol.mjs +23 -0
  37. package/esm/mcp/protocol.mjs.map +1 -0
  38. package/esm/mcp/result.d.mts +17 -0
  39. package/esm/mcp/result.d.mts.map +1 -0
  40. package/esm/mcp/result.mjs +85 -0
  41. package/esm/mcp/result.mjs.map +1 -0
  42. package/esm/mcp/serve-http.mjs +444 -0
  43. package/esm/mcp/serve-http.mjs.map +1 -0
  44. package/esm/mcp/serve.d.mts +46 -27
  45. package/esm/mcp/serve.d.mts.map +1 -1
  46. package/esm/mcp/serve.mjs +339 -96
  47. package/esm/mcp/serve.mjs.map +1 -1
  48. package/esm/mcp/transport.d.mts +4 -5
  49. package/esm/mcp/transport.d.mts.map +1 -1
  50. package/esm/mcp/transport.mjs +12 -6
  51. package/esm/mcp/transport.mjs.map +1 -1
  52. package/esm/mcp/transport.type.d.mts +2 -2
  53. package/esm/mcp/transport.type.d.mts.map +1 -1
  54. package/esm/register.d.mts +15 -5
  55. package/esm/register.d.mts.map +1 -1
  56. package/esm/register.mjs +3 -2
  57. package/esm/register.mjs.map +1 -1
  58. package/esm/schema.mjs.map +1 -1
  59. package/esm/utility/calculator.d.mts +1 -3
  60. package/esm/utility/calculator.d.mts.map +1 -1
  61. package/esm/utility/calculator.mjs.map +1 -1
  62. package/esm/utility/date-time.d.mts +3 -5
  63. package/esm/utility/date-time.d.mts.map +1 -1
  64. package/esm/utility/date-time.mjs +2 -1
  65. package/esm/utility/date-time.mjs.map +1 -1
  66. package/esm/utility/index.d.mts +2 -1
  67. package/esm/utility/index.mjs +1 -1
  68. package/esm/utility/schema.mjs.map +1 -1
  69. package/esm/web/fetch-url.d.mts +2 -3
  70. package/esm/web/fetch-url.d.mts.map +1 -1
  71. package/esm/web/fetch-url.mjs +2 -1
  72. package/esm/web/fetch-url.mjs.map +1 -1
  73. package/esm/web/index.d.mts +2 -1
  74. package/esm/web/index.mjs +1 -1
  75. package/esm/web/schema.mjs.map +1 -1
  76. package/esm/web/web-search.d.mts +2 -3
  77. package/esm/web/web-search.d.mts.map +1 -1
  78. package/esm/web/web-search.mjs +3 -4
  79. package/esm/web/web-search.mjs.map +1 -1
  80. package/llms-full.txt +245 -56
  81. package/llms.txt +3 -3
  82. package/package.json +2 -6
  83. package/skills/connect-mcp-server/SKILL.md +28 -6
  84. package/skills/expose-as-mcp-server/SKILL.md +168 -35
  85. package/skills/index.md +5 -2
  86. package/skills/use-web-and-http-tools/SKILL.md +49 -15
@@ -8,13 +8,13 @@
8
8
  * default policy allows only `"GET"`; mutating methods are opt-in via
9
9
  * {@link HttpRequestOptions.allowMethods}.
10
10
  */
11
- type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
11
+ export type HttpMethod = "GET" | "POST" | "PUT" | "PATCH" | "DELETE";
12
12
  /**
13
13
  * Construction options for `ai.tools.http`. These bound what the model
14
14
  * is allowed to do — the model supplies the per-call URL / method /
15
15
  * body within these rails.
16
16
  */
17
- interface HttpRequestOptions {
17
+ export interface HttpRequestOptions {
18
18
  /**
19
19
  * Override the tool name exposed to the LLM.
20
20
  *
@@ -68,7 +68,7 @@ interface HttpRequestOptions {
68
68
  /**
69
69
  * The validated input shape the model passes to `http_request`.
70
70
  */
71
- interface HttpRequestInput {
71
+ export interface HttpRequestInput {
72
72
  /**
73
73
  * HTTP method. Must be one of {@link HttpRequestOptions.allowMethods}
74
74
  * (defaults to `"GET"` when omitted).
@@ -90,7 +90,7 @@ interface HttpRequestInput {
90
90
  /**
91
91
  * The `http_request` tool's output.
92
92
  */
93
- interface HttpRequestResult {
93
+ export interface HttpRequestResult {
94
94
  /** HTTP status code of the response. */
95
95
  status: number;
96
96
  /** Response headers, lower-cased keys. */
@@ -104,5 +104,4 @@ interface HttpRequestResult {
104
104
  truncated: boolean;
105
105
  }
106
106
  //#endregion
107
- export { HttpMethod, HttpRequestInput, HttpRequestOptions, HttpRequestResult };
108
107
  //# sourceMappingURL=http.type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"http.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-tools/src/contracts/http.type.ts"],"mappings":";;AAUA;;;;AAAsB;AAOtB;;;KAPY,UAAA;;;;;;UAOK,kBAAA;EAqCf;;;;;EA/BA,IAAA;EAiDe;;;;EA5Cf,OAAA;EAiDS;;;;;;EA1CT,YAAA,GAAe,UAAA;EA4DA;;;;;EAtDf,UAAA;EA0DS;;;;AAOA;;;;;;EAtDT,mBAAA;;EAEA,OAAA,GAAU,MAAM;;;;;;EAMhB,SAAA;;;;;;EAMA,QAAA;AAAA;;;;UAMe,gBAAA;;;;;EAKf,MAAA,GAAS,UAAA;;;;;EAKT,GAAA;;EAEA,OAAA,GAAU,MAAM;;;;;EAKhB,IAAA;AAAA;;;;UAMe,iBAAA;;EAEf,MAAA;;EAEA,OAAA,EAAS,MAAM;;;;;EAKf,IAAA;;EAEA,SAAA;AAAA"}
1
+ {"version":3,"file":"http.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-tools/src/contracts/http.type.ts"],"mappings":";;;;;;;;;;YAUY;;;;;;iBAOK;;;;;;EAMf;;;;;EAKA;;;;;;;EAOA,eAAe;;;;;;EAMf;;;;;;;;;;;EAWA;;EAEA,UAAU;;;;;;EAMV;;;;;;EAMA;;;;;iBAMe;;;;;EAKf,SAAS;;;;;EAKT;;EAEA,UAAU;;;;;EAKV;;;;;iBAMe;;EAEf;;EAEA,SAAS;;;;;EAKT;;EAEA"}
@@ -1,4 +1,6 @@
1
1
  import { FetchUrlExtract, FetchUrlInput, FetchUrlOptions, FetchUrlResult, SearchProvider, WebSearchInput, WebSearchOptions, WebSearchResult, WebSearchResultItem } from "./web.type.mjs";
2
2
  import { HttpMethod, HttpRequestInput, HttpRequestOptions, HttpRequestResult } from "./http.type.mjs";
3
3
  import { CalculatorInput, CalculatorOptions, CalculatorResult, DateTimeInput, DateTimeOp, DateTimeOptions, DateTimeResult } from "./utility.type.mjs";
4
- import { JsonRpcError, JsonRpcId, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcVersion, McpClient, McpClientOptions, McpContentBlock, McpServeOptions, McpServeSource, McpServeTransport, McpServer, McpToolCallResult, McpToolDescriptor, McpTransport } from "./mcp.type.mjs";
4
+ import { JsonRpcError, JsonRpcId, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcVersion, McpClient, McpClientOptions, McpContentBlock, McpToolCallResult, McpToolDescriptor, McpTransport } from "./mcp.type.mjs";
5
+ import { McpGroupedToolSource, McpHttpAuth, McpHttpRequestInfo, McpHttpServeHandle, McpHttpServeTransport, McpPromptArgument, McpPromptMessage, McpServeCallContext, McpServeHandle, McpServeOptions, McpServePrompt, McpServeResource, McpServeSource, McpServeTransport, McpServer, McpToolSource } from "./mcp-serve.type.mjs";
6
+ export type { CalculatorInput, CalculatorOptions, CalculatorResult, DateTimeInput, DateTimeOp, DateTimeOptions, DateTimeResult, FetchUrlExtract, FetchUrlInput, FetchUrlOptions, FetchUrlResult, HttpMethod, HttpRequestInput, HttpRequestOptions, HttpRequestResult, JsonRpcError, JsonRpcId, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcVersion, McpClient, McpClientOptions, McpContentBlock, McpGroupedToolSource, McpHttpAuth, McpHttpRequestInfo, McpHttpServeHandle, McpHttpServeTransport, McpPromptArgument, McpPromptMessage, McpServeCallContext, McpServeHandle, McpServeOptions, McpServePrompt, McpServeResource, McpServeSource, McpServeTransport, McpServer, McpToolCallResult, McpToolDescriptor, McpToolSource, McpTransport, SearchProvider, WebSearchInput, WebSearchOptions, WebSearchResult, WebSearchResultItem };
@@ -0,0 +1,285 @@
1
+ import { McpContentBlock } from "./mcp.type.mjs";
2
+ import { JsonSchemaTarget, ToolContract, ToolRequestContext } from "@warlock.js/ai";
3
+ //#region ../../packages/ai-tools/src/contracts/mcp-serve.type.d.ts
4
+ /**
5
+ * Type contracts for `ai.mcp.serve(source, options)` — exposing local
6
+ * tools (plus optional resources and prompts) AS a Model Context Protocol
7
+ * server over stdio or Streamable HTTP. Pure declarations only; the
8
+ * factories live in `../mcp/serve.ts` and `../mcp/serve-http.ts`.
9
+ */
10
+ /**
11
+ * One set of tools: an object that can enumerate its `ToolContract`s (a
12
+ * built agent / supervisor / orchestrator / workspace), or a literal array.
13
+ */
14
+ export type McpToolSource = {
15
+ tools(): ToolContract[];
16
+ } | ToolContract[];
17
+ /**
18
+ * Several named tool sets served by one server. Each key names a group;
19
+ * with `prefixToolNames` the group name is prepended to its tools' names
20
+ * so equal names from different groups stay distinct.
21
+ *
22
+ * @example
23
+ * { groups: { github: githubAgent, files: [readFile, writeFile] } }
24
+ */
25
+ export type McpGroupedToolSource = {
26
+ /** Tool sets keyed by group name. */
27
+ groups: Record<string, McpToolSource>;
28
+ };
29
+ /**
30
+ * What `ai.mcp.serve` exposes as tools — one tool set, or several named
31
+ * groups. Every exposed tool name must be unique: a duplicate throws an
32
+ * {@link import("../errors").McpServeError} (`type: "collision"`) when
33
+ * `serve()` is called.
34
+ */
35
+ export type McpServeSource = McpToolSource | McpGroupedToolSource;
36
+ /**
37
+ * Normalised metadata of an inbound HTTP request, handed to a custom
38
+ * {@link McpHttpAuth.authorize} hook. Tools receive the same headers on
39
+ * `ctx.request` (see `ToolRequestContext` in `@warlock.js/ai`).
40
+ */
41
+ export type McpHttpRequestInfo = ToolRequestContext & {
42
+ /** The HTTP method, upper-case (`"POST"`, `"GET"`, …). */
43
+ method: string;
44
+ /** The request path, without the query string. */
45
+ path: string;
46
+ };
47
+ /**
48
+ * Authentication for an HTTP-served MCP endpoint. At least one of
49
+ * `bearer` / `authorize` is required; when both are set, a request must
50
+ * pass both. A request that fails gets HTTP 401 before its body is read.
51
+ */
52
+ export type McpHttpAuth = {
53
+ /**
54
+ * Accepted bearer token(s), matched against
55
+ * `Authorization: Bearer <token>`. Compared in constant time over
56
+ * SHA-256 digests, so neither the token's content nor its length leaks
57
+ * through response timing. Several tokens allow rotation without
58
+ * downtime. Empty strings are rejected when the server starts.
59
+ */
60
+ bearer?: string | readonly string[];
61
+ /**
62
+ * Custom check run for every request (after `bearer`, when both are
63
+ * set). Return `true` to allow. A hook that throws or rejects denies the
64
+ * request (fails closed).
65
+ */
66
+ authorize?: (request: McpHttpRequestInfo) => boolean | Promise<boolean>;
67
+ };
68
+ /**
69
+ * Serve over the MCP Streamable HTTP transport.
70
+ *
71
+ * Binds `127.0.0.1` by default. Binding any non-loopback address
72
+ * requires `auth`; `start()` throws otherwise.
73
+ */
74
+ export type McpHttpServeTransport = {
75
+ /** Streamable HTTP transport. */
76
+ type: "http";
77
+ /**
78
+ * Interface to bind. Loopback (`127.0.0.1`, `::1`, `localhost`) needs
79
+ * no auth; anything else (`0.0.0.0`, a LAN address) requires `auth`.
80
+ *
81
+ * @default "127.0.0.1"
82
+ */
83
+ host?: string;
84
+ /**
85
+ * Port to bind. `0` picks a free ephemeral port; read the result from
86
+ * the `url` that `start()` resolves.
87
+ *
88
+ * @default 0
89
+ */
90
+ port?: number;
91
+ /**
92
+ * The single MCP endpoint path. Other paths answer 404.
93
+ *
94
+ * @default "/mcp"
95
+ */
96
+ path?: string;
97
+ /** Bearer token(s) and/or a custom authorize hook. Required off loopback. */
98
+ auth?: McpHttpAuth;
99
+ /**
100
+ * Extra browser origins allowed to call the endpoint, as full origins
101
+ * (`"https://app.example.com"`). Loopback origins (`http://localhost:*`,
102
+ * `http://127.0.0.1:*`, `http://[::1]:*`) are always allowed; any other
103
+ * `Origin` header is refused with 403, which blocks DNS-rebinding
104
+ * attacks from web pages. Requests without an `Origin` header (non-browser
105
+ * clients) are unaffected.
106
+ */
107
+ allowedOrigins?: readonly string[];
108
+ /**
109
+ * Extra `Host` header names accepted while bound to loopback (where only
110
+ * `localhost`, `127.0.0.1` and `[::1]` are accepted by default — the
111
+ * second DNS-rebinding guard). When bound off loopback, setting this
112
+ * restricts `Host` to exactly these names.
113
+ */
114
+ allowedHosts?: readonly string[];
115
+ /**
116
+ * Maximum accepted request body, in bytes. Larger bodies get 413.
117
+ *
118
+ * @default 1_048_576 (1 MiB)
119
+ */
120
+ maxBodyBytes?: number;
121
+ /**
122
+ * How long `close()` waits for in-flight requests to finish before it
123
+ * aborts their `ctx.signal` and destroys the remaining connections.
124
+ *
125
+ * @default 5_000
126
+ */
127
+ drainTimeoutMs?: number;
128
+ };
129
+ /**
130
+ * Where an `ai.mcp.serve` server listens. Discriminated by `type`.
131
+ *
132
+ * - `"stdio"` — serve JSON-RPC over this process's stdin/stdout.
133
+ * - `"http"` — serve MCP Streamable HTTP (see {@link McpHttpServeTransport}).
134
+ */
135
+ export type McpServeTransport = {
136
+ type: "stdio";
137
+ } | McpHttpServeTransport;
138
+ /**
139
+ * Per-call context handed to resource readers and prompt builders (tools
140
+ * receive the same data on their `ToolContext`).
141
+ */
142
+ export type McpServeCallContext = {
143
+ /** The inbound HTTP request; absent over stdio. */
144
+ request?: McpHttpRequestInfo;
145
+ /** Aborted when an HTTP server's `close()` gives up draining. */
146
+ signal?: AbortSignal;
147
+ };
148
+ /**
149
+ * A static MCP resource served by `resources/list` + `resources/read`.
150
+ */
151
+ export type McpServeResource = {
152
+ /** Unique resource URI, e.g. `"docs://handbook"`. */
153
+ uri: string;
154
+ /** Resource name. */
155
+ name: string;
156
+ /** Optional display title. */
157
+ title?: string;
158
+ /** Optional description. */
159
+ description?: string;
160
+ /** Optional MIME type, echoed on the read result. */
161
+ mimeType?: string;
162
+ /**
163
+ * Produce the resource's contents. A string is sent as `text`; bytes
164
+ * are sent base64-encoded as `blob`.
165
+ */
166
+ read(context: McpServeCallContext): string | Uint8Array | Promise<string | Uint8Array>;
167
+ };
168
+ /** One declared argument of an {@link McpServePrompt}. */
169
+ export type McpPromptArgument = {
170
+ /** Argument name. */
171
+ name: string;
172
+ /** Optional description shown to the user. */
173
+ description?: string;
174
+ /** When `true`, `prompts/get` without it answers an invalid-params error. */
175
+ required?: boolean;
176
+ };
177
+ /** One message of a prompt returned by `prompts/get`. */
178
+ export type McpPromptMessage = {
179
+ /** Who speaks the message. */
180
+ role: "user" | "assistant";
181
+ /** The content block (`{ type: "text", text }` for plain text). */
182
+ content: McpContentBlock;
183
+ };
184
+ /**
185
+ * A prompt template served by `prompts/list` + `prompts/get`.
186
+ */
187
+ export type McpServePrompt = {
188
+ /** Unique prompt name. */
189
+ name: string;
190
+ /** Optional display title. */
191
+ title?: string;
192
+ /** Optional description. */
193
+ description?: string;
194
+ /** Declared arguments. */
195
+ arguments?: McpPromptArgument[];
196
+ /**
197
+ * Build the prompt. A string becomes one `user` text message.
198
+ *
199
+ * @param args - The client's arguments (string values per the MCP spec).
200
+ */
201
+ get(args: Record<string, string>, context: McpServeCallContext): string | McpPromptMessage[] | Promise<string | McpPromptMessage[]>;
202
+ };
203
+ /**
204
+ * Options for `ai.mcp.serve(source, options)` (Direction B: local
205
+ * primitive → MCP server other clients can consume).
206
+ */
207
+ export interface McpServeOptions {
208
+ /** Server name advertised in the `initialize` response. */
209
+ name: string;
210
+ /**
211
+ * Server version advertised in `initialize`.
212
+ *
213
+ * @default the package version
214
+ */
215
+ version?: string;
216
+ /**
217
+ * Where to listen.
218
+ *
219
+ * @default { type: "stdio" }
220
+ */
221
+ transport?: McpServeTransport;
222
+ /**
223
+ * JSON-Schema dialect emitted for each tool's `inputSchema`. Defaults
224
+ * to a neutral MCP draft rather than `extractJsonSchema`'s own
225
+ * `"openai-strict"` default.
226
+ *
227
+ * @default "draft-2020-12"
228
+ */
229
+ schemaTarget?: JsonSchemaTarget;
230
+ /**
231
+ * Opt in to native MCP result detection for objects containing `content`,
232
+ * `isError`, `structuredContent` or `_meta`. Other values still become text.
233
+ * Override per tool with `meta.mcpResults: "native" | "text"`.
234
+ * Explicit `mcpResult()` values always pass through after validation.
235
+ *
236
+ * @default "text"
237
+ */
238
+ results?: "text" | "native";
239
+ /**
240
+ * Prefix each tool of a grouped source (`{ groups: { … } }`) with its
241
+ * group name. `true` exposes `<group>_<tool>`; a function builds the
242
+ * exposed name itself. Only valid with a grouped source.
243
+ *
244
+ * @default false — names are exposed as-is and duplicates throw
245
+ */
246
+ prefixToolNames?: boolean | ((group: string, toolName: string) => string);
247
+ /** Static resources to serve. Omit to leave the `resources` capability off. */
248
+ resources?: McpServeResource[];
249
+ /** Prompt templates to serve. Omit to leave the `prompts` capability off. */
250
+ prompts?: McpServePrompt[];
251
+ }
252
+ /**
253
+ * What a started server resolves with. Over HTTP, `url` is the full
254
+ * endpoint (`http://127.0.0.1:53211/mcp`); over stdio it is absent.
255
+ */
256
+ export interface McpServeHandle {
257
+ /** The endpoint URL (HTTP only). */
258
+ url?: string;
259
+ /**
260
+ * Stop serving. Over HTTP: stop accepting connections, let in-flight
261
+ * requests finish (up to `drainTimeoutMs`), then free the port.
262
+ * Idempotent.
263
+ */
264
+ close(): Promise<void>;
265
+ }
266
+ /** The handle of an HTTP-served MCP endpoint — `url` is always set. */
267
+ export interface McpHttpServeHandle extends McpServeHandle {
268
+ /** The endpoint URL, e.g. `http://127.0.0.1:53211/mcp`. */
269
+ url: string;
270
+ }
271
+ /**
272
+ * A `ai.mcp.serve` server. Nothing listens until `start()`.
273
+ */
274
+ export interface McpServer<THandle extends McpServeHandle = McpServeHandle> {
275
+ /**
276
+ * Begin serving. Over HTTP, resolves once the port is bound with
277
+ * `{ url, close }`. Calling it again while running resolves the same
278
+ * handle.
279
+ */
280
+ start(): Promise<THandle>;
281
+ /** Stop serving and release the transport (same as `handle.close()`). */
282
+ stop(): Promise<void>;
283
+ }
284
+ //#endregion
285
+ //# sourceMappingURL=mcp-serve.type.d.mts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-serve.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-tools/src/contracts/mcp-serve.type.ts"],"mappings":";;;;;;;;;;;;;YAcY;EAAkB,SAAS;IAAmB;;;;;;;;;YAU9C;;EAEV,QAAQ,eAAe;;;;;;;;YASb,iBAAiB,gBAAgB;;;;;;YAOjC,qBAAqB;;EAE/B;;EAEA;;;;;;;YAQU;;;;;;;;EAQV;;;;;;EAMA,aAAa,SAAS,iCAAiC;;;;;;;;YAS7C;;EAEV;;;;;;;EAOA;;;;;;;EAOA;;;;;;EAMA;;EAEA,OAAO;;;;;;;;;EASP;;;;;;;EAOA;;;;;;EAMA;;;;;;;EAOA;;;;;;;;YASU;EAAsB;IAAkB;;;;;YAMxC;;EAEV,UAAU;;EAEV,SAAS;;;;;YAMC;;EAEV;;EAEA;;EAEA;;EAEA;;EAEA;;;;;EAKA,KAAK,SAAS,+BAA+B,aAAa,iBAAiB;;;YAIjE;;EAEV;;EAEA;;EAEA;;;YAIU;;EAEV;;EAEA,SAAS;;;;;YAMC;;EAEV;;EAEA;;EAEA;;EAEA,YAAY;;;;;;EAMZ,IACE,MAAM,wBACN,SAAS,+BACC,qBAAqB,iBAAiB;;;;;;iBAOnC;;EAEf;;;;;;EAMA;;;;;;EAMA,YAAY;;;;;;;;EAQZ,eAAe;;;;;;;;;EASf;;;;;;;;EAQA,8BAA8B,eAAe;;EAE7C,YAAY;;EAEZ,UAAU;;;;;;iBAOK;;EAEf;;;;;;EAMA,SAAS;;;iBAIM,2BAA2B;;EAE1C;;;;;iBAMe,UAAU,gBAAgB,iBAAiB;;;;;;EAM1D,SAAS,QAAQ;;EAEjB,QAAQ"}
@@ -1,5 +1,4 @@
1
- import { JsonSchemaTarget, ToolContract } from "@warlock.js/ai";
2
-
1
+ import { ToolContract } from "@warlock.js/ai";
3
2
  //#region ../../packages/ai-tools/src/contracts/mcp.type.d.ts
4
3
  /**
5
4
  * Type contracts for the Model Context Protocol surface — the
@@ -19,9 +18,12 @@ import { JsonSchemaTarget, ToolContract } from "@warlock.js/ai";
19
18
  * `node:readline`; no dependency).
20
19
  * - `"http"` — Streamable HTTP transport against `url`.
21
20
  */
22
- type McpTransport = {
23
- /** stdio transport — a spawned child process. */type: "stdio"; /** Executable to spawn (e.g. `"npx"`). */
24
- command: string; /** Arguments passed to `command`. */
21
+ export type McpTransport = {
22
+ /** stdio transport — a spawned child process. */
23
+ type: "stdio";
24
+ /** Executable to spawn (e.g. `"npx"`). */
25
+ command: string;
26
+ /** Arguments passed to `command`. */
25
27
  args?: string[];
26
28
  /**
27
29
  * Additional environment for the child. Explicit values override the
@@ -30,15 +32,18 @@ type McpTransport = {
30
32
  */
31
33
  env?: Record<string, string>;
32
34
  } | {
33
- /** Streamable HTTP transport. */type: "http"; /** The server endpoint URL. */
34
- url: string; /** Static headers sent with every request (e.g. auth). */
35
+ /** Streamable HTTP transport. */
36
+ type: "http";
37
+ /** The server endpoint URL. */
38
+ url: string;
39
+ /** Static headers sent with every request (e.g. auth). */
35
40
  headers?: Record<string, string>;
36
41
  };
37
42
  /**
38
43
  * Options for the `ai.mcp(server, options)` client (Direction A:
39
44
  * external server → local agent tools).
40
45
  */
41
- interface McpClientOptions {
46
+ export interface McpClientOptions {
42
47
  /**
43
48
  * Prefix prepended to each remote tool name to avoid colliding with
44
49
  * local tools, e.g. `"github."`. The author owns uniqueness — there
@@ -53,11 +58,25 @@ interface McpClientOptions {
53
58
  * @default 30_000
54
59
  */
55
60
  timeoutMs?: number;
61
+ /**
62
+ * Bind the client's lifetime to a run. When it aborts, the client
63
+ * closes its transport (kills the stdio child / ends the HTTP session),
64
+ * in-flight requests reject, and later `tools()` / tool calls fail with
65
+ * an `McpTransportError` of type `"closed"`. Every `tools/call` also
66
+ * honors it, alongside the per-call `ctx.signal` the agent passes.
67
+ *
68
+ * @example
69
+ * const controller = new AbortController();
70
+ * const github = ai.mcp(server, { signal: controller.signal });
71
+ * await agent.execute(task, { signal: controller.signal, tools: await github.tools() });
72
+ * controller.abort(); // also shuts the MCP server down
73
+ */
74
+ signal?: AbortSignal;
56
75
  }
57
76
  /**
58
77
  * The client handle returned by `ai.mcp(server, options)`.
59
78
  */
60
- interface McpClient {
79
+ export interface McpClient {
61
80
  /**
62
81
  * Lazily run the `initialize` handshake + `tools/list`, mapping each
63
82
  * remote tool to a {@link ToolContract}. Cached after the first call.
@@ -66,71 +85,14 @@ interface McpClient {
66
85
  /** Close the underlying transport (kills the child / ends the HTTP session). */
67
86
  close(): Promise<void>;
68
87
  }
69
- /**
70
- * A source of tools to expose via `ai.mcp.serve` — either an object that
71
- * can enumerate its `ToolContract`s (a built agent / supervisor /
72
- * orchestrator), or a literal array of contracts.
73
- */
74
- type McpServeSource = {
75
- tools(): ToolContract[];
76
- } | ToolContract[];
77
- /**
78
- * Where an `ai.mcp.serve` server listens. Discriminated by `type`.
79
- *
80
- * - `"stdio"` — serve JSON-RPC over this process's stdin/stdout.
81
- * - `"http"` — serve Streamable HTTP on `port`.
82
- */
83
- type McpServeTransport = {
84
- type: "stdio";
85
- } | {
86
- type: "http";
87
- port: number;
88
- };
89
- /**
90
- * Options for `ai.mcp.serve(source, options)` (Direction B: local
91
- * primitive → MCP server other clients can consume).
92
- */
93
- interface McpServeOptions {
94
- /** Server name advertised in the `initialize` response. */
95
- name: string;
96
- /**
97
- * Server version advertised in `initialize`.
98
- *
99
- * @default the package version
100
- */
101
- version?: string;
102
- /**
103
- * Where to listen.
104
- *
105
- * @default { type: "stdio" }
106
- */
107
- transport?: McpServeTransport;
108
- /**
109
- * JSON-Schema dialect emitted for each tool's `inputSchema`. Defaults
110
- * to a neutral MCP draft rather than `extractJsonSchema`'s own
111
- * `"openai-strict"` default.
112
- *
113
- * @default "draft-2020-12"
114
- */
115
- schemaTarget?: JsonSchemaTarget;
116
- }
117
- /**
118
- * A running `ai.mcp.serve` server.
119
- */
120
- interface McpServer {
121
- /** Begin accepting connections / reading the transport. */
122
- start(): Promise<void>;
123
- /** Stop serving and release the transport. */
124
- stop(): Promise<void>;
125
- }
126
88
  /** The JSON-RPC version literal every message carries. */
127
- type JsonRpcVersion = "2.0";
89
+ export type JsonRpcVersion = "2.0";
128
90
  /** A JSON-RPC id — a string or number (we never send notifications with `null`). */
129
- type JsonRpcId = string | number;
91
+ export type JsonRpcId = string | number;
130
92
  /**
131
93
  * A JSON-RPC request: a method invocation that expects a response.
132
94
  */
133
- interface JsonRpcRequest<TParams = unknown> {
95
+ export interface JsonRpcRequest<TParams = unknown> {
134
96
  jsonrpc: JsonRpcVersion;
135
97
  id: JsonRpcId;
136
98
  /** The RPC method name, e.g. `"tools/list"`. */
@@ -141,7 +103,7 @@ interface JsonRpcRequest<TParams = unknown> {
141
103
  /**
142
104
  * A JSON-RPC notification: a method invocation with no response.
143
105
  */
144
- interface JsonRpcNotification<TParams = unknown> {
106
+ export interface JsonRpcNotification<TParams = unknown> {
145
107
  jsonrpc: JsonRpcVersion;
146
108
  /** The RPC method name. */
147
109
  method: string;
@@ -151,7 +113,7 @@ interface JsonRpcNotification<TParams = unknown> {
151
113
  /**
152
114
  * A JSON-RPC error object, carried in an error response.
153
115
  */
154
- interface JsonRpcError {
116
+ export interface JsonRpcError {
155
117
  /** Numeric error code per the JSON-RPC spec. */
156
118
  code: number;
157
119
  /** Human-readable error message. */
@@ -162,7 +124,7 @@ interface JsonRpcError {
162
124
  /**
163
125
  * A JSON-RPC response — exactly one of `result` / `error` is present.
164
126
  */
165
- interface JsonRpcResponse<TResult = unknown> {
127
+ export interface JsonRpcResponse<TResult = unknown> {
166
128
  jsonrpc: JsonRpcVersion;
167
129
  id: JsonRpcId;
168
130
  /** Present on success. */
@@ -173,19 +135,21 @@ interface JsonRpcResponse<TResult = unknown> {
173
135
  /**
174
136
  * Any inbound JSON-RPC message the transport may surface.
175
137
  */
176
- type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
138
+ export type JsonRpcMessage = JsonRpcRequest | JsonRpcNotification | JsonRpcResponse;
177
139
  /**
178
140
  * One tool descriptor as returned by an MCP server's `tools/list`. Its
179
141
  * `inputSchema` is a JSON Schema object the client converts into a
180
142
  * Standard Schema for the adapted {@link ToolContract}.
181
143
  */
182
- interface McpToolDescriptor {
144
+ export interface McpToolDescriptor {
183
145
  /** The remote tool's name (before any `namePrefix`). */
184
146
  name: string;
185
147
  /** Human-readable description forwarded to the LLM. */
186
148
  description?: string;
187
149
  /** JSON Schema for the tool's arguments. */
188
150
  inputSchema?: Record<string, unknown>;
151
+ /** JSON Schema for structured results, when declared by the server. */
152
+ outputSchema?: Record<string, unknown>;
189
153
  }
190
154
  /**
191
155
  * One content block in an MCP `tools/call` result. MCP's wire field is
@@ -193,7 +157,7 @@ interface McpToolDescriptor {
193
157
  * `kind` for a content variant, the client maps it onto `type` so our
194
158
  * shapes only ever expose `type`.
195
159
  */
196
- interface McpContentBlock {
160
+ export interface McpContentBlock {
197
161
  /** The content variant (`"text"`, `"image"`, `"resource"`, …). */
198
162
  type: string;
199
163
  /** Text payload, present for `type: "text"`. */
@@ -206,12 +170,15 @@ interface McpContentBlock {
206
170
  * tool-level failure the client rethrows so `tool()` wraps it as a
207
171
  * {@link import("@warlock.js/ai").ToolExecutionError}.
208
172
  */
209
- interface McpToolCallResult {
173
+ export interface McpToolCallResult {
210
174
  /** Ordered content blocks produced by the tool. */
211
175
  content: McpContentBlock[];
212
176
  /** True when the call represents a tool-level error. */
213
177
  isError?: boolean;
178
+ /** Structured tool output (governed by the tool's outputSchema, if present). */
179
+ structuredContent?: Record<string, unknown>;
180
+ /** Protocol metadata forwarded without interpretation. */
181
+ _meta?: Record<string, unknown>;
214
182
  }
215
183
  //#endregion
216
- export { JsonRpcError, JsonRpcId, JsonRpcMessage, JsonRpcNotification, JsonRpcRequest, JsonRpcResponse, JsonRpcVersion, McpClient, McpClientOptions, McpContentBlock, McpServeOptions, McpServeSource, McpServeTransport, McpServer, McpToolCallResult, McpToolDescriptor, McpTransport };
217
184
  //# sourceMappingURL=mcp.type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"mcp.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-tools/src/contracts/mcp.type.ts"],"mappings":";;;;;AAqBA;;;;;;;;;;;;;;AAqBsB;AAOtB;KA5BY,YAAA;mDAGN,IAAA,WA+BJ;EA7BI,OAAA,UA+BM;EA7BN,IAAA;EAmCK;AAAA;AAMX;;;EAnCM,GAAA,GAAM,MAAA;AAAA;EA0CD,iCAtCL,IAAA,UAsCY;EApCZ,GAAA,UAkCK;EAhCL,OAAA,GAAU,MAAM;AAAA;;;AAkCJ;AAQlB;UAnCiB,gBAAA;;;;;;EAMf,UAAA;EA+Bc;EA7Bd,MAAA,IAAU,QAAA;EAqCiB;;;;;EA/B3B,SAAA;AAAA;AAiCsB;AAMxB;;AANwB,UA3BP,SAAA;EAuDgB;;;;EAlD/B,KAAA,IAAS,OAAA,CAAQ,YAAA;EAkDjB;EAhDA,KAAA,IAAS,OAAA;AAAA;AAgDsB;AAMjC;;;;AANiC,KAxCrB,cAAA;EACN,KAAA,IAAS,YAAA;AAAA,IACX,YAAY;;;AAgDC;AAYjB;;;KApDY,iBAAA;EACN,IAAA;AAAA;EACA,IAAA;EAAc,IAAA;AAAA;AAqDC;AAKrB;;;AALqB,UA/CJ,eAAA;EAsDX;EApDJ,IAAA;EAwDgB;;;;;EAlDhB,OAAA;EA8CI;;;;;EAxCJ,SAAA,GAAY,iBAAA;EAkDG;;;;;;;EA1Cf,YAAA,GAAe,gBAAgB;AAAA;;;AA+Cf;UAzCD,SAAA;EA+CY;EA7C3B,KAAA,IAAS,OAAA;EA6CkB;EA3C3B,IAAA,IAAQ,OAAO;AAAA;;KAYL,cAAA;AAqCN;AAAA,KAlCM,SAAA;;;;UAKK,cAAA;EACf,OAAA,EAAS,cAAA;EACT,EAAA,EAAI,SAAA;EAuCgB;EArCpB,MAAA;EA+B+B;EA7B/B,MAAA,GAAS,OAAA;AAAA;;;;UAMM,mBAAA;EACf,OAAA,EAAS,cAAA;EA4BD;EA1BR,MAAA;EA0BoB;EAxBpB,MAAA,GAAS,OAAO;AAAA;;;;UAMD,YAAA;EA2BE;EAzBjB,IAAA;EAuBE;EArBF,OAAA;EAuBE;EArBF,IAAA;AAAA;AA4BF;;;AAAA,UAtBiB,eAAA;EACf,OAAA,EAAS,cAAA;EACT,EAAA,EAAI,SAAA;EA0BJ;EAxBA,MAAA,GAAS,OAAA;EAwBW;EAtBpB,KAAA,GAAQ,YAAA;AAAA;;;;KAME,cAAA,GACR,cAAA,GACA,mBAAA,GACA,eAAA;;;;AA4BY;AAQhB;UA7BiB,iBAAA;;EAEf,IAAA;EA6BA;EA3BA,WAAA;EA6BA;EA3BA,WAAA,GAAc,MAAM;AAAA;;;;;;;UASL,eAAA;;EAEf,IAAA;;EAEA,IAAA;;GAEC,KAAA;AAAA;;;;;;UAQc,iBAAA;;EAEf,OAAA,EAAS,eAAe;;EAExB,OAAA;AAAA"}
1
+ {"version":3,"file":"mcp.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-tools/src/contracts/mcp.type.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;YAqBY;;EAGN;;EAEA;;EAEA;;;;;;EAMA,MAAM;;;EAIN;;EAEA;;EAEA,UAAU;;;;;;iBAOC;;;;;;EAMf;;EAEA,UAAU;;;;;;EAMV;;;;;;;;;;;;;;EAcA,SAAS;;;;;iBAMM;;;;;EAKf,SAAS,QAAQ;;EAEjB,SAAS;;;YAYC;;YAGA;;;;iBAKK,eAAe;EAC9B,SAAS;EACT,IAAI;;EAEJ;;EAEA,SAAS;;;;;iBAMM,oBAAoB;EACnC,SAAS;;EAET;;EAEA,SAAS;;;;;iBAMM;;EAEf;;EAEA;;EAEA;;;;;iBAMe,gBAAgB;EAC/B,SAAS;EACT,IAAI;;EAEJ,SAAS;;EAET,QAAQ;;;;;YAME,iBAAiB,iBAAiB,sBAAsB;;;;;;iBAOnD;;EAEf;;EAEA;;EAEA,cAAc;;EAEd,eAAe;;;;;;;;iBASA;;EAEf;;EAEA;;GAEC;;;;;;;iBAQc;;EAEf,SAAS;;EAET;;EAEA,oBAAoB;;EAEpB,QAAQ"}
@@ -7,7 +7,7 @@
7
7
  /**
8
8
  * Construction options for `ai.tools.calculator`.
9
9
  */
10
- interface CalculatorOptions {
10
+ export interface CalculatorOptions {
11
11
  /**
12
12
  * Override the tool name exposed to the LLM.
13
13
  *
@@ -18,14 +18,14 @@ interface CalculatorOptions {
18
18
  /**
19
19
  * The validated input shape the model passes to `calculator`.
20
20
  */
21
- interface CalculatorInput {
21
+ export interface CalculatorInput {
22
22
  /** An arithmetic expression to evaluate, e.g. `"(3 + 4) * 2"`. */
23
23
  expression: string;
24
24
  }
25
25
  /**
26
26
  * The `calculator` tool's output.
27
27
  */
28
- interface CalculatorResult {
28
+ export interface CalculatorResult {
29
29
  /** The numeric result of evaluating the expression. */
30
30
  result: number;
31
31
  }
@@ -37,11 +37,11 @@ interface CalculatorResult {
37
37
  * - `"diff"` — difference between two instants, in `unit`.
38
38
  * - `"format"` — render `iso` per `format`.
39
39
  */
40
- type DateTimeOp = "now" | "add" | "diff" | "format";
40
+ export type DateTimeOp = "now" | "add" | "diff" | "format";
41
41
  /**
42
42
  * Construction options for `ai.tools.dateTime`.
43
43
  */
44
- interface DateTimeOptions {
44
+ export interface DateTimeOptions {
45
45
  /**
46
46
  * Override the tool name exposed to the LLM.
47
47
  *
@@ -59,7 +59,7 @@ interface DateTimeOptions {
59
59
  * The validated input shape the model passes to `date_time`. Which
60
60
  * fields are required depends on `op` (validated at the seal layer).
61
61
  */
62
- interface DateTimeInput {
62
+ export interface DateTimeInput {
63
63
  /** Which date-time operation to perform. */
64
64
  op: DateTimeOp;
65
65
  /** ISO-8601 instant the operation acts on (`add` / `diff` / `format`). */
@@ -84,7 +84,7 @@ interface DateTimeInput {
84
84
  /**
85
85
  * The `date_time` tool's output.
86
86
  */
87
- interface DateTimeResult {
87
+ export interface DateTimeResult {
88
88
  /**
89
89
  * The result, rendered as a string — an ISO instant, a formatted
90
90
  * date, or a stringified numeric difference depending on `op`.
@@ -92,5 +92,4 @@ interface DateTimeResult {
92
92
  value: string;
93
93
  }
94
94
  //#endregion
95
- export { CalculatorInput, CalculatorOptions, CalculatorResult, DateTimeInput, DateTimeOp, DateTimeOptions, DateTimeResult };
96
95
  //# sourceMappingURL=utility.type.d.mts.map
@@ -1 +1 @@
1
- {"version":3,"file":"utility.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-tools/src/contracts/utility.type.ts"],"mappings":";;AASA;;;;AAMM;AAMN;;AANM,UANW,iBAAA;EAcL;AAAA;AAMZ;;;EAdE,IAAI;AAAA;AA2BN;;;AAAA,UArBiB,eAAA;EAqBK;EAnBpB,UAAU;AAAA;;;AAoCK;UA9BA,gBAAA;EAqCa;EAnC5B,MAAM;AAAA;;;;;;;;;KAWI,UAAA;;AA4CJ;AAMR;UA7CiB,eAAA;;;AAkDV;;;EA5CL,IAAA;;;;;;EAMA,eAAe;AAAA;;;;;UAOA,aAAA;;EAEf,EAAA,EAAI,UAAU;;EAEd,GAAA;;;;;;EAMA,IAAA;;EAEA,EAAA;;EAEA,MAAA;;EAEA,IAAA;;EAEA,QAAA;;EAEA,MAAA;AAAA;;;;UAMe,cAAA;;;;;EAKf,KAAK;AAAA"}
1
+ {"version":3,"file":"utility.type.d.mts","names":[],"sources":["../../../../../../../../packages/ai-tools/src/contracts/utility.type.ts"],"mappings":";;;;;;;;;iBASiB;;;;;;EAMf;;;;;iBAMe;;EAEf;;;;;iBAMe;;EAEf;;;;;;;;;;YAWU;;;;iBAKK;;;;;;EAMf;;;;;;EAMA;;;;;;iBAOe;;EAEf,IAAI;;EAEJ;;;;;;EAMA;;EAEA;;EAEA;;EAEA;;EAEA;;EAEA;;;;;iBAMe;;;;;EAKf"}