fascicle 0.10.1 → 0.10.3
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/CHANGELOG.md +50 -0
- package/README.md +9 -9
- package/dist/adapters.d.ts +1 -1
- package/dist/agents.d.ts +4 -4
- package/dist/agents.js +1 -1
- package/dist/agents.js.map +1 -1
- package/dist/{core-DNH8ddMT.js → core-DkuJqLwd.js} +182 -96
- package/dist/core-DkuJqLwd.js.map +1 -0
- package/dist/index.d.ts +1124 -5
- package/dist/index.js +467 -939
- package/dist/index.js.map +1 -1
- package/dist/invoke-D9pxbZcu.js +451 -0
- package/dist/invoke-D9pxbZcu.js.map +1 -0
- package/dist/mcp.d.ts +25 -13
- package/dist/mcp.js +203 -121
- package/dist/mcp.js.map +1 -1
- package/dist/otel.d.ts +1 -1
- package/dist/stdio.d.ts +4 -4
- package/dist/stdio.js +30 -12
- package/dist/stdio.js.map +1 -1
- package/dist/{index-BNgtkeUf.d.ts → types-B3HIsBBD.d.ts} +7 -133
- package/dist/types-BCtKsxrX.d.ts +149 -0
- package/dist/types-BDSbSUAO.d.ts +63 -0
- package/dist/types-kO1JoGNZ.js +253 -0
- package/dist/types-kO1JoGNZ.js.map +1 -0
- package/dist/ui.d.ts +2 -2
- package/package.json +16 -5
- package/dist/core-DNH8ddMT.js.map +0 -1
- package/dist/index-SkPG_Rew.d.ts +0 -991
package/dist/mcp.js
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { z } from "zod";
|
|
1
|
+
import { k as run } from "./core-DkuJqLwd.js";
|
|
3
2
|
//#region src/mcp/errors.ts
|
|
4
3
|
/**
|
|
5
4
|
* Typed errors for the MCP adapter.
|
|
@@ -124,159 +123,241 @@ function stringify(value) {
|
|
|
124
123
|
//#endregion
|
|
125
124
|
//#region src/mcp/schema_bridge.ts
|
|
126
125
|
/**
|
|
127
|
-
*
|
|
126
|
+
* Builds a `ToolSchema` over an MCP server's advertised JSON Schema.
|
|
128
127
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* Two deliberate choices serve those goals. Objects are `looseObject` so extra
|
|
137
|
-
* keys survive to the server (which re-validates and is the real authority), and
|
|
138
|
-
* a freeform object maps to `z.looseObject({})` (emits `{type:"object"}`) rather
|
|
139
|
-
* than `z.unknown()` (emits `{}`), preserving the "takes an object" signal. Value
|
|
140
|
-
* constraints (min/max, length, pattern, format) are intentionally not modeled:
|
|
141
|
-
* they add rejection risk for marginal provider benefit, and the server enforces
|
|
142
|
-
* them anyway. Structure, types, enums, const, unions, and descriptions are
|
|
143
|
-
* preserved; anything unrecognized degrades to `z.unknown()`.
|
|
128
|
+
* The advertised schema is snapshotted once, deeply, and both faces of the
|
|
129
|
+
* returned object read that snapshot. A malformed or hostile schema degrades to
|
|
130
|
+
* the empty schema during the snapshot rather than propagating an error, since
|
|
131
|
+
* an arbitrary remote server's advertisement must never crash tool discovery,
|
|
132
|
+
* and it leaves both faces describing the same thing: accept anything, emit
|
|
133
|
+
* nothing.
|
|
144
134
|
*/
|
|
135
|
+
function json_schema_to_standard(schema) {
|
|
136
|
+
const advertised = snapshot(schema);
|
|
137
|
+
return { "~standard": {
|
|
138
|
+
version: 1,
|
|
139
|
+
vendor: "fascicle-mcp",
|
|
140
|
+
validate: (value) => {
|
|
141
|
+
const issues = check(advertised, value, []);
|
|
142
|
+
return issues.length === 0 ? { value } : { issues };
|
|
143
|
+
},
|
|
144
|
+
jsonSchema: {
|
|
145
|
+
input: () => clone_schema(advertised),
|
|
146
|
+
output: () => clone_schema(advertised)
|
|
147
|
+
}
|
|
148
|
+
} };
|
|
149
|
+
}
|
|
145
150
|
/**
|
|
146
|
-
*
|
|
151
|
+
* Deep-copies the advertised schema, or yields the empty schema when it is not
|
|
152
|
+
* an object or cannot be read.
|
|
147
153
|
*
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
* never crash tool discovery.
|
|
154
|
+
* Copying here means every later read walks plain data: a schema with throwing
|
|
155
|
+
* accessors or a cycle fails once, at discovery, instead of on some later call.
|
|
151
156
|
*/
|
|
152
|
-
function
|
|
157
|
+
function snapshot(schema) {
|
|
153
158
|
try {
|
|
154
|
-
|
|
159
|
+
const record = as_record(schema);
|
|
160
|
+
return record === void 0 ? {} : clone_schema(record);
|
|
155
161
|
} catch {
|
|
156
|
-
return
|
|
162
|
+
return {};
|
|
157
163
|
}
|
|
158
164
|
}
|
|
159
165
|
/**
|
|
160
|
-
*
|
|
166
|
+
* Deep-copies one JSON Schema node.
|
|
167
|
+
*/
|
|
168
|
+
function clone_schema(schema) {
|
|
169
|
+
const copy = {};
|
|
170
|
+
for (const [key, value] of Object.entries(schema)) copy[key] = clone_value(value);
|
|
171
|
+
return copy;
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Deep-copies a value inside a schema, recursing through arrays and objects and
|
|
175
|
+
* returning every other value as is.
|
|
176
|
+
*/
|
|
177
|
+
function clone_value(value) {
|
|
178
|
+
if (Array.isArray(value)) return value.map(clone_value);
|
|
179
|
+
return is_record(value) ? clone_schema(value) : value;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Checks one value against one JSON Schema node, returning the issues it
|
|
183
|
+
* violated, or an empty array when it passes.
|
|
161
184
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
* do. A `description` on the node carries through to the returned Zod type.
|
|
185
|
+
* A node that is not an object constrains nothing and accepts, which is what
|
|
186
|
+
* makes a construct this bridge does not model degrade rather than reject.
|
|
165
187
|
*/
|
|
166
|
-
function
|
|
188
|
+
function check(node, value, path) {
|
|
167
189
|
const schema = as_record(node);
|
|
168
|
-
if (schema === void 0) return
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
190
|
+
if (schema === void 0) return [];
|
|
191
|
+
return check_keywords(schema, value, path) ?? check_shape(schema, value, path);
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Checks the keywords that stand on their own, returning `undefined` when the
|
|
195
|
+
* node carries none of them.
|
|
196
|
+
*
|
|
197
|
+
* These are checked before `type` because they can appear without one and take
|
|
198
|
+
* precedence when they do: a node with both `enum` and `type` is constrained by
|
|
199
|
+
* the enum, which is the narrower of the two.
|
|
200
|
+
*/
|
|
201
|
+
function check_keywords(schema, value, path) {
|
|
202
|
+
if ("const" in schema) return check_const(schema["const"], value, path);
|
|
203
|
+
if (Array.isArray(schema["enum"])) return check_enum(schema["enum"], value, path);
|
|
204
|
+
if (Array.isArray(schema["anyOf"])) return check_any_of(schema["anyOf"], value, path);
|
|
205
|
+
if (Array.isArray(schema["oneOf"])) return check_any_of(schema["oneOf"], value, path);
|
|
206
|
+
if (Array.isArray(schema["allOf"])) return check_all_of(schema["allOf"], value, path);
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Checks the node's declared shape: its `type`, in either the single or the
|
|
210
|
+
* array form.
|
|
211
|
+
*
|
|
212
|
+
* A node with no `type` but declared `properties` is still an object; a node
|
|
213
|
+
* with neither says nothing structural and accepts.
|
|
214
|
+
*/
|
|
215
|
+
function check_shape(schema, value, path) {
|
|
178
216
|
const type = schema["type"];
|
|
179
|
-
if (Array.isArray(type)) return
|
|
180
|
-
if (typeof type === "string") return
|
|
181
|
-
if (is_record(schema["properties"])) return
|
|
182
|
-
return
|
|
183
|
-
}
|
|
184
|
-
/**
|
|
185
|
-
* Maps a single JSON Schema `type` keyword to the matching Zod primitive or
|
|
186
|
-
* container, falling back to `z.unknown()` for an unrecognized type.
|
|
187
|
-
*/
|
|
188
|
-
function for_type(type, schema) {
|
|
189
|
-
switch (type) {
|
|
190
|
-
case "object": return build_object(schema);
|
|
191
|
-
case "array": return build_array(schema);
|
|
192
|
-
case "string": return z.string();
|
|
193
|
-
case "number": return z.number();
|
|
194
|
-
case "integer": return z.number().int();
|
|
195
|
-
case "boolean": return z.boolean();
|
|
196
|
-
case "null": return z.null();
|
|
197
|
-
default: return z.unknown();
|
|
198
|
-
}
|
|
217
|
+
if (Array.isArray(type)) return check_type_union(type, schema, value, path);
|
|
218
|
+
if (typeof type === "string") return check_type(type, schema, value, path);
|
|
219
|
+
if (is_record(schema["properties"])) return check_object(schema, value, path);
|
|
220
|
+
return [];
|
|
199
221
|
}
|
|
200
222
|
/**
|
|
201
|
-
*
|
|
202
|
-
* `required`, marking any key absent from `required` as optional.
|
|
223
|
+
* Checks a `const`, which pins the value to one JSON literal.
|
|
203
224
|
*
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
225
|
+
* An object or array `const` accepts anything: matching it would mean a deep
|
|
226
|
+
* comparison the server performs itself, and rejecting a valid argument is the
|
|
227
|
+
* one failure mode this bridge must not have.
|
|
207
228
|
*/
|
|
208
|
-
function
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
for (const [key, prop] of Object.entries(properties)) {
|
|
213
|
-
const child = convert(prop);
|
|
214
|
-
shape[key] = required.has(key) ? child : child.optional();
|
|
215
|
-
}
|
|
216
|
-
return z.looseObject(shape);
|
|
229
|
+
function check_const(expected, value, path) {
|
|
230
|
+
if (expected === null) return value === null ? [] : [issue("expected null", path)];
|
|
231
|
+
if (typeof expected === "string" || typeof expected === "number" || typeof expected === "boolean") return value === expected ? [] : [issue(`expected ${JSON.stringify(expected)}`, path)];
|
|
232
|
+
return [];
|
|
217
233
|
}
|
|
218
234
|
/**
|
|
219
|
-
*
|
|
235
|
+
* Checks an `enum`, which pins the value to one of a list of JSON literals.
|
|
236
|
+
* An empty enum constrains nothing and accepts.
|
|
220
237
|
*/
|
|
221
|
-
function
|
|
222
|
-
return
|
|
238
|
+
function check_enum(values, value, path) {
|
|
239
|
+
if (values.length === 0) return [];
|
|
240
|
+
if (values.some((candidate) => check_const(candidate, value, path).length === 0)) return [];
|
|
241
|
+
return [issue(`expected one of ${values.map((v) => JSON.stringify(v)).join(", ")}`, path)];
|
|
223
242
|
}
|
|
224
243
|
/**
|
|
225
|
-
*
|
|
244
|
+
* Checks an `anyOf` or `oneOf`, which passes when any branch passes.
|
|
226
245
|
*
|
|
227
|
-
*
|
|
228
|
-
*
|
|
246
|
+
* `oneOf`'s exactly-one semantics are deliberately relaxed to at-least-one: the
|
|
247
|
+
* distinction only ever rejects a value the server would accept.
|
|
248
|
+
*
|
|
249
|
+
* A single-branch union reports that branch's own issues rather than a generic
|
|
250
|
+
* "no variant matched", since with one variant there is no ambiguity about
|
|
251
|
+
* which one failed.
|
|
252
|
+
*/
|
|
253
|
+
function check_any_of(nodes, value, path) {
|
|
254
|
+
if (nodes.length === 0) return [];
|
|
255
|
+
if (nodes.length === 1) return check(nodes[0], value, path);
|
|
256
|
+
if (nodes.some((node) => check(node, value, path).length === 0)) return [];
|
|
257
|
+
return [issue(`expected one of ${nodes.length} variants`, path)];
|
|
258
|
+
}
|
|
259
|
+
/**
|
|
260
|
+
* Checks an `allOf`, which passes only when every branch passes.
|
|
261
|
+
*/
|
|
262
|
+
function check_all_of(nodes, value, path) {
|
|
263
|
+
return nodes.flatMap((node) => check(node, value, path));
|
|
264
|
+
}
|
|
265
|
+
/**
|
|
266
|
+
* Checks the array form of `type` (`["string", "null"]`), which passes when the
|
|
267
|
+
* value matches any listed type. The other keywords on the node apply to
|
|
268
|
+
* whichever type matched, so each branch sees the whole node.
|
|
269
|
+
*/
|
|
270
|
+
function check_type_union(types, schema, value, path) {
|
|
271
|
+
if (types.length === 0) return [];
|
|
272
|
+
if (types.length === 1) return check_type(String(types[0]), schema, value, path);
|
|
273
|
+
if (types.some((type) => check_type(String(type), schema, value, path).length === 0)) return [];
|
|
274
|
+
return [issue(`expected one of ${types.map(String).join(", ")}`, path)];
|
|
275
|
+
}
|
|
276
|
+
/**
|
|
277
|
+
* The scalar `type` keywords, as predicates over the value.
|
|
278
|
+
*
|
|
279
|
+
* `number` rejects `NaN` and infinities because neither survives JSON, and
|
|
280
|
+
* `integer` is the same check narrowed to whole values.
|
|
229
281
|
*/
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
282
|
+
const SCALAR_TYPES = {
|
|
283
|
+
string: (value) => typeof value === "string",
|
|
284
|
+
number: (value) => typeof value === "number" && Number.isFinite(value),
|
|
285
|
+
integer: (value) => Number.isInteger(value),
|
|
286
|
+
boolean: (value) => typeof value === "boolean",
|
|
287
|
+
null: (value) => value === null
|
|
288
|
+
};
|
|
289
|
+
/**
|
|
290
|
+
* Checks one `type` keyword. `object` and `array` recurse into the node's own
|
|
291
|
+
* `properties` and `items`; everything else is a scalar predicate.
|
|
292
|
+
*
|
|
293
|
+
* An unrecognized type accepts, so a vendor extension cannot reject an argument
|
|
294
|
+
* the server would take.
|
|
295
|
+
*/
|
|
296
|
+
function check_type(type, schema, value, path) {
|
|
297
|
+
if (type === "object") return check_object(schema, value, path);
|
|
298
|
+
if (type === "array") return check_array(schema, value, path);
|
|
299
|
+
const matches = SCALAR_TYPES[type];
|
|
300
|
+
if (matches === void 0) return [];
|
|
301
|
+
return matches(value) ? [] : [type_issue(type, value, path)];
|
|
234
302
|
}
|
|
235
303
|
/**
|
|
236
|
-
*
|
|
237
|
-
*
|
|
304
|
+
* Checks an object against its `properties` and `required`.
|
|
305
|
+
*
|
|
306
|
+
* Keys the schema does not declare are left alone rather than rejected, so an
|
|
307
|
+
* argument this bridge did not anticipate still reaches the server, which
|
|
308
|
+
* re-validates and is the real authority. A `required` name with no entry in
|
|
309
|
+
* `properties` is likewise not enforced: there is nothing to check it against.
|
|
238
310
|
*/
|
|
239
|
-
function
|
|
240
|
-
|
|
311
|
+
function check_object(schema, value, path) {
|
|
312
|
+
if (!is_record(value)) return [type_issue("object", value, path)];
|
|
313
|
+
const properties = as_record(schema["properties"]) ?? {};
|
|
314
|
+
const required = new Set(string_array(schema["required"]));
|
|
315
|
+
const issues = [];
|
|
316
|
+
for (const [key, property] of Object.entries(properties)) {
|
|
317
|
+
const child = value[key];
|
|
318
|
+
if (child === void 0) {
|
|
319
|
+
if (required.has(key)) issues.push(issue("required", [...path, key]));
|
|
320
|
+
continue;
|
|
321
|
+
}
|
|
322
|
+
issues.push(...check(property, child, [...path, key]));
|
|
323
|
+
}
|
|
324
|
+
return issues;
|
|
241
325
|
}
|
|
242
326
|
/**
|
|
243
|
-
*
|
|
244
|
-
*
|
|
327
|
+
* Checks an array against its `items`.
|
|
328
|
+
*
|
|
329
|
+
* A positional-tuple `items` (an array rather than a node) is not a record, so
|
|
330
|
+
* every element accepts. Tuple schemas are rare in MCP tools and the server
|
|
331
|
+
* re-validates them anyway.
|
|
245
332
|
*/
|
|
246
|
-
function
|
|
247
|
-
|
|
333
|
+
function check_array(schema, value, path) {
|
|
334
|
+
if (!Array.isArray(value)) return [type_issue("array", value, path)];
|
|
335
|
+
return value.flatMap((item, index) => check(schema["items"], item, [...path, index]));
|
|
248
336
|
}
|
|
249
337
|
/**
|
|
250
|
-
*
|
|
338
|
+
* Builds a type-mismatch issue naming what was expected and what arrived.
|
|
251
339
|
*/
|
|
252
|
-
function
|
|
253
|
-
|
|
254
|
-
if (parts.length === 0) return z.unknown();
|
|
255
|
-
return parts.reduce((acc, part) => z.intersection(acc, part));
|
|
340
|
+
function type_issue(expected, value, path) {
|
|
341
|
+
return issue(`expected ${expected}, received ${describe(value)}`, path);
|
|
256
342
|
}
|
|
257
343
|
/**
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
* since `z.union` requires at least two.
|
|
344
|
+
* Names a value's type the way a JSON Schema reader would, separating `null`
|
|
345
|
+
* and arrays out of `typeof`'s `object`.
|
|
261
346
|
*/
|
|
262
|
-
function
|
|
263
|
-
|
|
264
|
-
if (
|
|
265
|
-
|
|
266
|
-
return z.union([
|
|
267
|
-
first,
|
|
268
|
-
second,
|
|
269
|
-
...rest
|
|
270
|
-
]);
|
|
347
|
+
function describe(value) {
|
|
348
|
+
if (value === null) return "null";
|
|
349
|
+
if (Array.isArray(value)) return "array";
|
|
350
|
+
return typeof value;
|
|
271
351
|
}
|
|
272
352
|
/**
|
|
273
|
-
*
|
|
274
|
-
* a
|
|
353
|
+
* Builds one issue, omitting the path entirely at the root so a failure about
|
|
354
|
+
* the value as a whole does not report an empty path.
|
|
275
355
|
*/
|
|
276
|
-
function
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
356
|
+
function issue(message, path) {
|
|
357
|
+
return path.length === 0 ? { message } : {
|
|
358
|
+
message,
|
|
359
|
+
path: [...path]
|
|
360
|
+
};
|
|
280
361
|
}
|
|
281
362
|
/**
|
|
282
363
|
* Filters a value down to the strings it contains, or an empty array when it
|
|
@@ -332,10 +413,11 @@ const DEFAULT_CLIENT_INFO = {
|
|
|
332
413
|
*
|
|
333
414
|
* Owns the connection lifecycle (config in, `{ tools, close }` out) so callers
|
|
334
415
|
* do not have to import SDK transport classes themselves. Each advertised MCP
|
|
335
|
-
* tool becomes an ordinary `Tool`: its JSON Schema is
|
|
336
|
-
* loop
|
|
337
|
-
* propagating the run's abort signal. For the
|
|
338
|
-
* caller keeps ownership of the connection, so
|
|
416
|
+
* tool becomes an ordinary `Tool`: its JSON Schema is wrapped as a `ToolSchema`
|
|
417
|
+
* the loop validates against and the provider receives back unchanged, and
|
|
418
|
+
* `execute` forwards to `callTool`, propagating the run's abort signal. For the
|
|
419
|
+
* `client` transport variant the caller keeps ownership of the connection, so
|
|
420
|
+
* `close` is a no-op.
|
|
339
421
|
*/
|
|
340
422
|
async function mcp_client(config, options = {}) {
|
|
341
423
|
const owns_client = config.transport !== "client";
|
|
@@ -391,7 +473,7 @@ function to_fascicle_tool(client, advertised, options) {
|
|
|
391
473
|
return {
|
|
392
474
|
name,
|
|
393
475
|
description: advertised.description ?? options.default_description?.(name) ?? `MCP tool ${name}`,
|
|
394
|
-
input_schema:
|
|
476
|
+
input_schema: json_schema_to_standard(advertised.inputSchema),
|
|
395
477
|
execute: async (input, ctx) => {
|
|
396
478
|
if (ctx.abort.aborted) throw ctx.abort.reason instanceof Error ? ctx.abort.reason : new mcp_error(`MCP tool ${name} aborted before invocation`, { tool_name: name });
|
|
397
479
|
return call_result_to_output(await client.callTool({
|
|
@@ -435,6 +517,6 @@ function serve_flow(options) {
|
|
|
435
517
|
});
|
|
436
518
|
}
|
|
437
519
|
//#endregion
|
|
438
|
-
export {
|
|
520
|
+
export { json_schema_to_standard, mcp_client, mcp_error, mcp_sdk_missing_error, serve_flow };
|
|
439
521
|
|
|
440
522
|
//# sourceMappingURL=mcp.js.map
|
package/dist/mcp.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcp.js","names":[],"sources":["../src/mcp/errors.ts","../src/mcp/internal.ts","../src/mcp/result_mapping.ts","../src/mcp/schema_bridge.ts","../src/mcp/sdk_loader.ts","../src/mcp/client.ts","../src/mcp/serve.ts"],"sourcesContent":["/**\n * Typed errors for the MCP adapter.\n *\n * Listed alongside src/core/errors.ts and src/engine/errors.ts in the\n * `no-class` rule ignores: `instanceof` branching is how callers distinguish a\n * missing optional peer from a tool-level failure surfaced over the wire.\n */\n\nexport class mcp_sdk_missing_error extends Error {\n readonly kind = 'mcp_sdk_missing_error' as const;\n constructor(\n message = '@modelcontextprotocol/sdk is required for fascicle/mcp; install it: pnpm add @modelcontextprotocol/sdk',\n ) {\n super(message)\n this.name = 'mcp_sdk_missing_error'\n }\n}\n\nexport class mcp_error extends Error {\n readonly kind = 'mcp_error' as const;\n readonly tool_name: string | undefined;\n constructor(message: string, metadata: { tool_name?: string } = {}) {\n super(message)\n this.name = 'mcp_error'\n this.tool_name = metadata.tool_name\n }\n}\n","/**\n * Small shared guards for the MCP adapter. Kept in one place so the client,\n * schema bridge, and result mapping do not each carry a copy.\n */\n\n/**\n * Narrows a value to a plain object: non-null, `typeof` object, not an array.\n */\nexport function is_record(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/**\n * Returns the value when it is a plain object, otherwise `undefined`.\n */\nexport function as_record(value: unknown): Record<string, unknown> | undefined {\n return is_record(value) ? value : undefined\n}\n","/**\n * Mapping between MCP `CallToolResult` payloads and fascicle tool values, in\n * both directions: inbound results from `mcp_client` tools, outbound results\n * for `serve_flow`.\n */\n\nimport { mcp_error } from './errors.js'\nimport { as_record, is_record } from './internal.js'\n\nexport type McpToolResult = {\n content: Array<{ type: 'text'; text: string }>\n structuredContent?: Record<string, unknown>\n}\n\n/**\n * Converts a remote tool's `CallToolResult` into the value a fascicle\n * `Tool.execute` returns.\n *\n * `isError: true` marks a tool-level failure, so it throws `mcp_error` rather\n * than returning, letting the tool loop's error policy feed it back to the\n * model. `structuredContent` is preferred over joined text parts when present;\n * with neither, the raw `content` (or `null`) is returned.\n */\nexport function call_result_to_output(result: unknown, tool_name?: string): unknown {\n const record = as_record(result) ?? {}\n\n if (record['isError'] === true) {\n const detail = join_text(record['content']) ?? 'MCP tool returned an error'\n throw new mcp_error(detail, tool_name !== undefined ? { tool_name } : {})\n }\n\n if (is_record(record['structuredContent'])) return record['structuredContent']\n\n const text = join_text(record['content'])\n if (text !== undefined) return text\n\n return record['content'] ?? null\n}\n\n/**\n * Converts a fascicle flow's output into a `CallToolResult` for `serve_flow`.\n *\n * A `to_result` override takes precedence over the default mapping. By\n * default, objects are emitted as both a JSON text part (every MCP host can\n * read text) and `structuredContent` (typed hosts get the object); everything\n * else becomes a single text part.\n */\nexport function output_to_call_result<o>(\n output: o,\n to_result?: (output: o) => { text: string; structured?: Record<string, unknown> },\n): McpToolResult {\n if (to_result !== undefined) {\n const shaped = to_result(output)\n return build_result(shaped.text, shaped.structured)\n }\n if (typeof output === 'string') return build_result(output)\n if (is_record(output)) return build_result(stringify(output), output)\n if (Array.isArray(output)) return build_result(stringify(output))\n return build_result(String(output))\n}\n\n/**\n * Assembles a `CallToolResult` with one text part and, when given, structured\n * content.\n */\nfunction build_result(text: string, structured?: Record<string, unknown>): McpToolResult {\n return structured !== undefined\n ? { content: [{ type: 'text', text }], structuredContent: structured }\n : { content: [{ type: 'text', text }] }\n}\n\n/**\n * Joins the `text` parts of an MCP content array with newlines, skipping\n * non-text parts; `undefined` when there is nothing to join.\n */\nfunction join_text(content: unknown): string | undefined {\n if (!Array.isArray(content)) return undefined\n const parts: string[] = []\n for (const part of content) {\n if (is_record(part) && part['type'] === 'text' && typeof part['text'] === 'string') {\n parts.push(part['text'])\n }\n }\n return parts.length > 0 ? parts.join('\\n') : undefined\n}\n\n/**\n * `JSON.stringify` that falls back to `String` instead of throwing on\n * unserializable values (circular references, BigInt).\n */\nfunction stringify(value: unknown): string {\n try {\n return JSON.stringify(value)\n } catch {\n return String(value)\n }\n}\n","/**\n * JSON Schema to Zod conversion for inbound MCP tools.\n *\n * An MCP tool advertises its input as JSON Schema, but a fascicle `Tool` carries\n * a Zod `input_schema` that the tool loop `safeParse`s before `execute` and the\n * engine serializes back to JSON Schema for the provider. So the converted Zod\n * must do two things at once: stay permissive enough never to reject an arg the\n * remote server would accept, and round-trip through `z.toJSONSchema` to a shape\n * the provider can fill.\n *\n * Two deliberate choices serve those goals. Objects are `looseObject` so extra\n * keys survive to the server (which re-validates and is the real authority), and\n * a freeform object maps to `z.looseObject({})` (emits `{type:\"object\"}`) rather\n * than `z.unknown()` (emits `{}`), preserving the \"takes an object\" signal. Value\n * constraints (min/max, length, pattern, format) are intentionally not modeled:\n * they add rejection risk for marginal provider benefit, and the server enforces\n * them anyway. Structure, types, enums, const, unions, and descriptions are\n * preserved; anything unrecognized degrades to `z.unknown()`.\n */\n\nimport { z } from 'zod'\nimport { as_record, is_record } from './internal.js'\n\n/**\n * Converts a JSON Schema node into a Zod type, never throwing.\n *\n * A malformed or unrecognized schema falls back to `z.unknown()` instead of\n * propagating an error, since an arbitrary remote MCP server's schema must\n * never crash tool discovery.\n */\nexport function json_schema_to_zod(schema: unknown): z.ZodType {\n try {\n return convert(schema)\n } catch {\n // An arbitrary remote schema must never crash tool discovery.\n return z.unknown()\n }\n}\n\n/**\n * Converts one JSON Schema node to a Zod type, recursing into nested schemas.\n *\n * Checks `const`, `enum`, `anyOf`, `oneOf`, and `allOf` before `type`, since\n * those keywords can appear without a `type` and take precedence when they\n * do. A `description` on the node carries through to the returned Zod type.\n */\nfunction convert(node: unknown): z.ZodType {\n const schema = as_record(node)\n if (schema === undefined) return z.unknown()\n\n const described = (inner: z.ZodType): z.ZodType => {\n const description = schema['description']\n return typeof description === 'string' ? inner.describe(description) : inner\n }\n\n if ('const' in schema) return described(literal_of(schema['const']))\n if (Array.isArray(schema['enum'])) return described(enum_of(schema['enum']))\n if (Array.isArray(schema['anyOf'])) return described(union_of(schema['anyOf']))\n if (Array.isArray(schema['oneOf'])) return described(union_of(schema['oneOf']))\n if (Array.isArray(schema['allOf'])) return described(intersection_of(schema['allOf']))\n\n const type = schema['type']\n if (Array.isArray(type)) {\n return described(union_of_types(type, schema))\n }\n if (typeof type === 'string') {\n return described(for_type(type, schema))\n }\n // No explicit type: an object with declared properties is still an object;\n // otherwise nothing structural is known, so stay permissive.\n if (is_record(schema['properties'])) return described(build_object(schema))\n return described(z.unknown())\n}\n\n/**\n * Maps a single JSON Schema `type` keyword to the matching Zod primitive or\n * container, falling back to `z.unknown()` for an unrecognized type.\n */\nfunction for_type(type: string, schema: Record<string, unknown>): z.ZodType {\n switch (type) {\n case 'object':\n return build_object(schema)\n case 'array':\n return build_array(schema)\n case 'string':\n return z.string()\n case 'number':\n return z.number()\n case 'integer':\n return z.number().int()\n case 'boolean':\n return z.boolean()\n case 'null':\n return z.null()\n default:\n return z.unknown()\n }\n}\n\n/**\n * Builds a Zod object type from a JSON Schema object's `properties` and\n * `required`, marking any key absent from `required` as optional.\n *\n * Uses `z.looseObject` rather than `z.object` so keys the remote server\n * accepts but this conversion did not anticipate still pass through instead\n * of being stripped or rejected.\n */\nfunction build_object(schema: Record<string, unknown>): z.ZodType {\n const properties = as_record(schema['properties']) ?? {}\n const required = new Set(string_array(schema['required']))\n const shape: Record<string, z.ZodType> = {}\n for (const [key, prop] of Object.entries(properties)) {\n const child = convert(prop)\n shape[key] = required.has(key) ? child : child.optional()\n }\n return z.looseObject(shape)\n}\n\n/**\n * Builds a Zod array type from a JSON Schema array's `items`.\n */\nfunction build_array(schema: Record<string, unknown>): z.ZodType {\n // A positional-tuple `items` array and a missing `items` both convert to\n // `z.unknown()`, so one permissive element type covers every case. Tuple\n // schemas are rare in MCP tools and the server re-validates them anyway.\n return z.array(convert(schema['items']))\n}\n\n/**\n * Converts a JSON Schema `enum` array to a Zod type.\n *\n * An all-string enum maps to `z.enum`; a mixed-type enum maps to a union of\n * literals instead, since `z.enum` only accepts strings.\n */\nfunction enum_of(values: unknown[]): z.ZodType {\n if (values.length === 0) return z.unknown()\n if (values.every((v): v is string => typeof v === 'string')) {\n return z.enum(values)\n }\n return combine_union(values.map(literal_of))\n}\n\n/**\n * Converts a JSON Schema `anyOf` or `oneOf` array to a Zod union, converting\n * each branch independently.\n */\nfunction union_of(nodes: unknown[]): z.ZodType {\n return combine_union(nodes.map(convert))\n}\n\n/**\n * Converts a JSON Schema `type` array (e.g. `[\"string\", \"null\"]`) to a Zod\n * union of the matching primitive types.\n */\nfunction union_of_types(types: unknown[], schema: Record<string, unknown>): z.ZodType {\n return combine_union(types.map((t) => for_type(String(t), schema)))\n}\n\n/**\n * Converts a JSON Schema `allOf` array to a Zod intersection of every branch.\n */\nfunction intersection_of(nodes: unknown[]): z.ZodType {\n const parts = nodes.map(convert)\n if (parts.length === 0) return z.unknown()\n return parts.reduce((acc, part) => z.intersection(acc, part))\n}\n\n/**\n * Builds a Zod union from a list of variants, collapsing the degenerate\n * cases: zero variants becomes `z.unknown()`, one variant is returned as is,\n * since `z.union` requires at least two.\n */\nfunction combine_union(variants: z.ZodType[]): z.ZodType {\n const [first, second, ...rest] = variants\n if (first === undefined) return z.unknown()\n if (second === undefined) return first\n return z.union([first, second, ...rest])\n}\n\n/**\n * Converts a single JSON value, as used in a `const` or an `enum` entry, to\n * a Zod literal.\n */\nfunction literal_of(value: unknown): z.ZodType {\n if (\n typeof value === 'string' ||\n typeof value === 'number' ||\n typeof value === 'boolean'\n ) {\n return z.literal(value)\n }\n if (value === null) return z.null()\n // Object and array literals are not expressible as z.literal; accept anything.\n return z.unknown()\n}\n\n/**\n * Filters a value down to the strings it contains, or an empty array when it\n * is not an array at all.\n */\nfunction string_array(value: unknown): string[] {\n return Array.isArray(value) ? value.filter((v): v is string => typeof v === 'string') : []\n}\n","/**\n * Lazy loader for the optional `@modelcontextprotocol/sdk` peer.\n *\n * `mcp_client` needs SDK values (the Client and transport constructors), so it\n * imports them dynamically rather than statically: a consumer can import\n * `fascicle/mcp` without the SDK installed and only pays the cost when they\n * actually connect. A missing peer surfaces as a typed `mcp_sdk_missing_error`\n * with install guidance, mirroring the engine's `load_optional_peer`.\n *\n * `serve_flow` is not covered here: it operates on a caller-constructed\n * `McpServer`, so it needs only a type-only import and no runtime SDK load.\n */\n\nimport { mcp_sdk_missing_error } from './errors.js'\n\nexport type McpClientSdk = Awaited<ReturnType<typeof load_client_sdk>>\n\n/**\n * Dynamically imports the `@modelcontextprotocol/sdk` client modules,\n * throwing a typed `mcp_sdk_missing_error` when the optional peer is not\n * installed.\n */\nexport async function load_client_sdk() {\n try {\n const [client_mod, stdio_mod, http_mod] = await Promise.all([\n import('@modelcontextprotocol/sdk/client/index.js'),\n import('@modelcontextprotocol/sdk/client/stdio.js'),\n import('@modelcontextprotocol/sdk/client/streamableHttp.js'),\n ])\n return {\n Client: client_mod.Client,\n StdioClientTransport: stdio_mod.StdioClientTransport,\n StreamableHTTPClientTransport: http_mod.StreamableHTTPClientTransport,\n }\n } catch (err: unknown) {\n const detail = err instanceof Error ? err.message : String(err)\n throw new mcp_sdk_missing_error(\n `@modelcontextprotocol/sdk is required for fascicle/mcp; install it: pnpm add @modelcontextprotocol/sdk (cause: ${detail})`,\n )\n }\n}\n","/**\n * Inbound MCP: connect to an external MCP server and surface its tools as plain\n * fascicle `Tool[]`.\n */\n\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'\nimport type { Tool, ToolExecContext } from '#engine'\nimport { mcp_error } from './errors.js'\nimport { is_record } from './internal.js'\nimport { call_result_to_output } from './result_mapping.js'\nimport { json_schema_to_zod } from './schema_bridge.js'\nimport { load_client_sdk, type McpClientSdk } from './sdk_loader.js'\n\nconst DEFAULT_CLIENT_INFO = { name: 'fascicle', version: '0.0.0' }\n\nexport type McpStdioConfig = {\n transport: 'stdio'\n command: string\n args?: string[]\n env?: Record<string, string>\n cwd?: string\n}\n\nexport type McpStreamableHttpConfig = {\n transport: 'http'\n url: string\n headers?: Record<string, string>\n}\n\n// Escape hatch: hand in an already-connected Client (a transport the adapter\n// does not build, a test harness, a shared connection). Its lifecycle stays\n// with the caller, so the returned `close` is a no-op for this variant.\nexport type McpExistingClientConfig = {\n transport: 'client'\n client: Client\n}\n\nexport type McpClientConfig =\n | McpStdioConfig\n | McpStreamableHttpConfig\n | McpExistingClientConfig\n\nexport type McpClientOptions = {\n // Identity sent in the MCP handshake; defaults to fascicle.\n client_info?: { name: string; version: string }\n // When set, only tools whose name is listed are surfaced.\n include?: ReadonlyArray<string>\n // Supplies a description for tools that advertise none.\n default_description?: (tool_name: string) => string\n}\n\nexport type McpClientHandle = {\n readonly tools: ReadonlyArray<Tool>\n readonly close: () => Promise<void>\n}\n\n/**\n * Connects to an MCP server and surfaces its advertised tools as fascicle\n * `Tool[]`, plus a `close` handle for the connection.\n *\n * Owns the connection lifecycle (config in, `{ tools, close }` out) so callers\n * do not have to import SDK transport classes themselves. Each advertised MCP\n * tool becomes an ordinary `Tool`: its JSON Schema is bridged to Zod for the\n * loop's `safeParse` and the provider, and `execute` forwards to `callTool`,\n * propagating the run's abort signal. For the `client` transport variant the\n * caller keeps ownership of the connection, so `close` is a no-op.\n */\nexport async function mcp_client(\n config: McpClientConfig,\n options: McpClientOptions = {},\n): Promise<McpClientHandle> {\n const owns_client = config.transport !== 'client'\n const client = await connect_client(config, options)\n\n const include = options.include !== undefined ? new Set(options.include) : undefined\n const listed = await client.listTools()\n const tools: Tool[] = []\n for (const advertised of listed.tools) {\n if (include !== undefined && !include.has(advertised.name)) continue\n tools.push(to_fascicle_tool(client, advertised, options))\n }\n\n return {\n tools,\n close: async () => {\n if (owns_client) await client.close()\n },\n }\n}\n\n/**\n * Returns the caller's already-connected client as-is, or lazily loads the\n * SDK and connects a fresh client over the configured transport.\n */\nasync function connect_client(\n config: McpClientConfig,\n options: McpClientOptions,\n): Promise<Client> {\n if (config.transport === 'client') return config.client\n const sdk = await load_client_sdk()\n const client = new sdk.Client(options.client_info ?? DEFAULT_CLIENT_INFO)\n await client.connect(build_transport(sdk, config))\n return client\n}\n\n/**\n * Constructs the SDK transport matching the config: a spawned child process\n * for `stdio`, a Streamable HTTP connection for `http`.\n */\nfunction build_transport(\n sdk: McpClientSdk,\n config: McpStdioConfig | McpStreamableHttpConfig,\n): Transport {\n if (config.transport === 'stdio') {\n return new sdk.StdioClientTransport({\n command: config.command,\n ...(config.args !== undefined ? { args: config.args } : {}),\n ...(config.env !== undefined ? { env: config.env } : {}),\n ...(config.cwd !== undefined ? { cwd: config.cwd } : {}),\n })\n }\n const opts = config.headers !== undefined ? { requestInit: { headers: config.headers } } : {}\n // The SDK declares this class `implements Transport`, but its `onmessage`\n // overload is narrower than the interface's, which only strict mode flags.\n // eslint-disable-next-line typescript-eslint/no-unsafe-type-assertion\n return new sdk.StreamableHTTPClientTransport(new URL(config.url), opts) as Transport\n}\n\n/**\n * Wraps one advertised MCP tool as a fascicle `Tool` whose `execute` forwards\n * to `callTool` on the shared client.\n *\n * An already-aborted signal short-circuits before the wire call; otherwise the\n * signal is passed through so cancelling the run cancels the remote call.\n */\nfunction to_fascicle_tool(\n client: Client,\n advertised: { name: string; description?: string | undefined; inputSchema: unknown },\n options: McpClientOptions,\n): Tool {\n const name = advertised.name\n const description =\n advertised.description ?? options.default_description?.(name) ?? `MCP tool ${name}`\n return {\n name,\n description,\n input_schema: json_schema_to_zod(advertised.inputSchema),\n execute: async (input: unknown, ctx: ToolExecContext) => {\n if (ctx.abort.aborted) {\n throw ctx.abort.reason instanceof Error\n ? ctx.abort.reason\n : new mcp_error(`MCP tool ${name} aborted before invocation`, { tool_name: name })\n }\n const result = await client.callTool(\n { name, arguments: is_record(input) ? input : undefined },\n undefined,\n { signal: ctx.abort },\n )\n return call_result_to_output(result, name)\n },\n }\n}\n","/**\n * Outbound MCP: expose a composed fascicle flow as an MCP tool.\n *\n * `serve_flow` registers onto a caller-constructed `McpServer` (the caller owns\n * the transport, identity, and lifecycle, and can host many flows on one\n * server), so it needs only a type-only SDK import. The registered handler\n * drives the existing `run`, threading the per-request abort signal so an MCP\n * client cancellation aborts the in-flight flow, and maps the result into a\n * `CallToolResult`. A thrown flow becomes an `isError` result rather than a\n * JSON-RPC protocol error.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { z } from 'zod'\nimport { run } from '#core'\nimport type { Step, TrajectoryLogger } from '#core'\nimport { output_to_call_result } from './result_mapping.js'\n\nexport type ServeFlowOptions<i, o> = {\n server: McpServer\n flow: Step<i, o>\n name: string\n description: string\n input_schema: z.ZodType<i>\n trajectory?: TrajectoryLogger\n // Overrides the default value-to-CallToolResult mapping.\n to_result?: (output: o) => { text: string; structured?: Record<string, unknown> }\n}\n\n/**\n * Registers a fascicle flow as a tool on a caller-owned MCP server.\n *\n * Drives the flow with `run`, threading the per-request abort signal so an\n * MCP client cancellation aborts the in-flight flow, and maps the result\n * into a `CallToolResult`. A thrown flow becomes an `isError` result rather\n * than a JSON-RPC protocol error.\n */\nexport function serve_flow<i, o>(options: ServeFlowOptions<i, o>): void {\n const { server, flow, name, description, input_schema, trajectory, to_result } = options\n server.registerTool(\n name,\n { description, inputSchema: input_schema },\n async (input: i, extra) => {\n try {\n const output = await run(flow, input, {\n install_signal_handlers: false,\n abort: extra.signal,\n ...(trajectory !== undefined ? { trajectory } : {}),\n })\n return output_to_call_result(output, to_result)\n } catch (err: unknown) {\n return {\n isError: true,\n content: [{ type: 'text', text: err instanceof Error ? err.message : String(err) }],\n }\n }\n },\n )\n}\n"],"mappings":";;;;;;;;;;AAQA,IAAa,wBAAb,cAA2C,MAAM;CAC/C,OAAgB;CAChB,YACE,UAAU,0GACV;EACA,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAEA,IAAa,YAAb,cAA+B,MAAM;CACnC,OAAgB;CAChB;CACA,YAAY,SAAiB,WAAmC,CAAC,GAAG;EAClE,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,YAAY,SAAS;CAC5B;AACF;;;;;;;;;;AClBA,SAAgB,UAAU,OAAkD;CAC1E,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;;;AAKA,SAAgB,UAAU,OAAqD;CAC7E,OAAO,UAAU,KAAK,IAAI,QAAQ,KAAA;AACpC;;;;;;;;;;;;;;;;;ACMA,SAAgB,sBAAsB,QAAiB,WAA6B;CAClF,MAAM,SAAS,UAAU,MAAM,KAAK,CAAC;CAErC,IAAI,OAAO,eAAe,MAExB,MAAM,IAAI,UADK,UAAU,OAAO,UAAU,KAAK,8BACnB,cAAc,KAAA,IAAY,EAAE,UAAU,IAAI,CAAC,CAAC;CAG1E,IAAI,UAAU,OAAO,oBAAoB,GAAG,OAAO,OAAO;CAE1D,MAAM,OAAO,UAAU,OAAO,UAAU;CACxC,IAAI,SAAS,KAAA,GAAW,OAAO;CAE/B,OAAO,OAAO,cAAc;AAC9B;;;;;;;;;AAUA,SAAgB,sBACd,QACA,WACe;CACf,IAAI,cAAc,KAAA,GAAW;EAC3B,MAAM,SAAS,UAAU,MAAM;EAC/B,OAAO,aAAa,OAAO,MAAM,OAAO,UAAU;CACpD;CACA,IAAI,OAAO,WAAW,UAAU,OAAO,aAAa,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Aa,GACzC,OAAO,OAAU,UAAU;EACzB,IAAI;GAMF,OAAO,sBAAsB,MALR,IAAI,MAAM,OAAO;IACpC,yBAAyB;IACzB,OAAO,MAAM;IACb,GAAI,eAAe,KAAA,IAAY,EAAE,WAAW,IAAI,CAAC;GACnD,CAAC,GACoC,SAAS;EAChD,SAAS,KAAc;GACrB,OAAO;IACL,SAAS;IACT,SAAS,CAAC;KAAE,MAAM;KAAQ,MAAM,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;IAAE,CAAC;GACpF;EACF;CACF,CACF;AACF"}
|
|
1
|
+
{"version":3,"file":"mcp.js","names":[],"sources":["../src/mcp/errors.ts","../src/mcp/internal.ts","../src/mcp/result_mapping.ts","../src/mcp/schema_bridge.ts","../src/mcp/sdk_loader.ts","../src/mcp/client.ts","../src/mcp/serve.ts"],"sourcesContent":["/**\n * Typed errors for the MCP adapter.\n *\n * Listed alongside src/core/errors.ts and src/engine/errors.ts in the\n * `no-class` rule ignores: `instanceof` branching is how callers distinguish a\n * missing optional peer from a tool-level failure surfaced over the wire.\n */\n\nexport class mcp_sdk_missing_error extends Error {\n readonly kind = 'mcp_sdk_missing_error' as const;\n constructor(\n message = '@modelcontextprotocol/sdk is required for fascicle/mcp; install it: pnpm add @modelcontextprotocol/sdk',\n ) {\n super(message)\n this.name = 'mcp_sdk_missing_error'\n }\n}\n\nexport class mcp_error extends Error {\n readonly kind = 'mcp_error' as const;\n readonly tool_name: string | undefined;\n constructor(message: string, metadata: { tool_name?: string } = {}) {\n super(message)\n this.name = 'mcp_error'\n this.tool_name = metadata.tool_name\n }\n}\n","/**\n * Small shared guards for the MCP adapter. Kept in one place so the client,\n * schema bridge, and result mapping do not each carry a copy.\n */\n\n/**\n * Narrows a value to a plain object: non-null, `typeof` object, not an array.\n */\nexport function is_record(value: unknown): value is Record<string, unknown> {\n return typeof value === 'object' && value !== null && !Array.isArray(value)\n}\n\n/**\n * Returns the value when it is a plain object, otherwise `undefined`.\n */\nexport function as_record(value: unknown): Record<string, unknown> | undefined {\n return is_record(value) ? value : undefined\n}\n","/**\n * Mapping between MCP `CallToolResult` payloads and fascicle tool values, in\n * both directions: inbound results from `mcp_client` tools, outbound results\n * for `serve_flow`.\n */\n\nimport { mcp_error } from './errors.js'\nimport { as_record, is_record } from './internal.js'\n\nexport type McpToolResult = {\n content: Array<{ type: 'text'; text: string }>\n structuredContent?: Record<string, unknown>\n}\n\n/**\n * Converts a remote tool's `CallToolResult` into the value a fascicle\n * `Tool.execute` returns.\n *\n * `isError: true` marks a tool-level failure, so it throws `mcp_error` rather\n * than returning, letting the tool loop's error policy feed it back to the\n * model. `structuredContent` is preferred over joined text parts when present;\n * with neither, the raw `content` (or `null`) is returned.\n */\nexport function call_result_to_output(result: unknown, tool_name?: string): unknown {\n const record = as_record(result) ?? {}\n\n if (record['isError'] === true) {\n const detail = join_text(record['content']) ?? 'MCP tool returned an error'\n throw new mcp_error(detail, tool_name !== undefined ? { tool_name } : {})\n }\n\n if (is_record(record['structuredContent'])) return record['structuredContent']\n\n const text = join_text(record['content'])\n if (text !== undefined) return text\n\n return record['content'] ?? null\n}\n\n/**\n * Converts a fascicle flow's output into a `CallToolResult` for `serve_flow`.\n *\n * A `to_result` override takes precedence over the default mapping. By\n * default, objects are emitted as both a JSON text part (every MCP host can\n * read text) and `structuredContent` (typed hosts get the object); everything\n * else becomes a single text part.\n */\nexport function output_to_call_result<o>(\n output: o,\n to_result?: (output: o) => { text: string; structured?: Record<string, unknown> },\n): McpToolResult {\n if (to_result !== undefined) {\n const shaped = to_result(output)\n return build_result(shaped.text, shaped.structured)\n }\n if (typeof output === 'string') return build_result(output)\n if (is_record(output)) return build_result(stringify(output), output)\n if (Array.isArray(output)) return build_result(stringify(output))\n return build_result(String(output))\n}\n\n/**\n * Assembles a `CallToolResult` with one text part and, when given, structured\n * content.\n */\nfunction build_result(text: string, structured?: Record<string, unknown>): McpToolResult {\n return structured !== undefined\n ? { content: [{ type: 'text', text }], structuredContent: structured }\n : { content: [{ type: 'text', text }] }\n}\n\n/**\n * Joins the `text` parts of an MCP content array with newlines, skipping\n * non-text parts; `undefined` when there is nothing to join.\n */\nfunction join_text(content: unknown): string | undefined {\n if (!Array.isArray(content)) return undefined\n const parts: string[] = []\n for (const part of content) {\n if (is_record(part) && part['type'] === 'text' && typeof part['text'] === 'string') {\n parts.push(part['text'])\n }\n }\n return parts.length > 0 ? parts.join('\\n') : undefined\n}\n\n/**\n * `JSON.stringify` that falls back to `String` instead of throwing on\n * unserializable values (circular references, BigInt).\n */\nfunction stringify(value: unknown): string {\n try {\n return JSON.stringify(value)\n } catch {\n return String(value)\n }\n}\n","/**\n * A Standard Schema over an inbound MCP tool's advertised JSON Schema.\n *\n * An MCP tool advertises its input as JSON Schema, and a fascicle `Tool` carries\n * a `ToolSchema` that the tool loop validates before `execute` and the engine\n * emits back to the provider as JSON Schema. Those are two faces of one object,\n * so this bridge builds both directly over the schema the server sent: emission\n * hands the advertised schema back unchanged, and validation walks it.\n *\n * The old bridge converted the advertised schema into Zod so the provider path\n * could convert it back, a round trip that was lossy by construction. Verbatim\n * emission is strictly higher fidelity: whatever the server declared is what the\n * model is told, including the constraints (`minLength`, `format`, `pattern`)\n * the Zod conversion dropped.\n *\n * Validation stays deliberately loose, unchanged from the Zod bridge's reach:\n * structure, types, enums, const, unions, and required keys are checked, value\n * constraints are not, extra keys pass through to the server, and anything\n * unrecognized accepts. The remote server re-validates its own arguments and is\n * the authority on them, so this check is a guard against an obviously wrong\n * call, not the contract.\n */\n\nimport type { SchemaIssue, ToolSchema } from '#schema'\nimport { as_record, is_record } from './internal.js'\n\n/**\n * Builds a `ToolSchema` over an MCP server's advertised JSON Schema.\n *\n * The advertised schema is snapshotted once, deeply, and both faces of the\n * returned object read that snapshot. A malformed or hostile schema degrades to\n * the empty schema during the snapshot rather than propagating an error, since\n * an arbitrary remote server's advertisement must never crash tool discovery,\n * and it leaves both faces describing the same thing: accept anything, emit\n * nothing.\n */\nexport function json_schema_to_standard(schema: unknown): ToolSchema {\n const advertised = snapshot(schema)\n return {\n '~standard': {\n version: 1,\n vendor: 'fascicle-mcp',\n validate: (value: unknown) => {\n const issues = check(advertised, value, [])\n return issues.length === 0 ? { value } : { issues }\n },\n jsonSchema: {\n // `target` is ignored in both directions: fascicle applies no transform,\n // so there is no re-targeting to do, and the dialect on the wire is\n // whichever one the server chose to advertise. Each call returns a fresh\n // copy because consumers mutate what they are handed (the AI SDK stamps\n // `additionalProperties` onto it in place), and a shared snapshot would\n // stop being verbatim after the first turn.\n input: () => clone_schema(advertised),\n output: () => clone_schema(advertised),\n },\n },\n }\n}\n\n/**\n * Deep-copies the advertised schema, or yields the empty schema when it is not\n * an object or cannot be read.\n *\n * Copying here means every later read walks plain data: a schema with throwing\n * accessors or a cycle fails once, at discovery, instead of on some later call.\n */\nfunction snapshot(schema: unknown): Record<string, unknown> {\n try {\n const record = as_record(schema)\n return record === undefined ? {} : clone_schema(record)\n } catch {\n return {}\n }\n}\n\n/**\n * Deep-copies one JSON Schema node.\n */\nfunction clone_schema(schema: Record<string, unknown>): Record<string, unknown> {\n const copy: Record<string, unknown> = {}\n for (const [key, value] of Object.entries(schema)) copy[key] = clone_value(value)\n return copy\n}\n\n/**\n * Deep-copies a value inside a schema, recursing through arrays and objects and\n * returning every other value as is.\n */\nfunction clone_value(value: unknown): unknown {\n if (Array.isArray(value)) return value.map(clone_value)\n return is_record(value) ? clone_schema(value) : value\n}\n\n/**\n * Checks one value against one JSON Schema node, returning the issues it\n * violated, or an empty array when it passes.\n *\n * A node that is not an object constrains nothing and accepts, which is what\n * makes a construct this bridge does not model degrade rather than reject.\n */\nfunction check(node: unknown, value: unknown, path: ReadonlyArray<PropertyKey>): SchemaIssue[] {\n const schema = as_record(node)\n if (schema === undefined) return []\n return check_keywords(schema, value, path) ?? check_shape(schema, value, path)\n}\n\n/**\n * Checks the keywords that stand on their own, returning `undefined` when the\n * node carries none of them.\n *\n * These are checked before `type` because they can appear without one and take\n * precedence when they do: a node with both `enum` and `type` is constrained by\n * the enum, which is the narrower of the two.\n */\nfunction check_keywords(\n schema: Record<string, unknown>,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] | undefined {\n if ('const' in schema) return check_const(schema['const'], value, path)\n if (Array.isArray(schema['enum'])) return check_enum(schema['enum'], value, path)\n if (Array.isArray(schema['anyOf'])) return check_any_of(schema['anyOf'], value, path)\n if (Array.isArray(schema['oneOf'])) return check_any_of(schema['oneOf'], value, path)\n if (Array.isArray(schema['allOf'])) return check_all_of(schema['allOf'], value, path)\n return undefined\n}\n\n/**\n * Checks the node's declared shape: its `type`, in either the single or the\n * array form.\n *\n * A node with no `type` but declared `properties` is still an object; a node\n * with neither says nothing structural and accepts.\n */\nfunction check_shape(\n schema: Record<string, unknown>,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n const type = schema['type']\n if (Array.isArray(type)) return check_type_union(type, schema, value, path)\n if (typeof type === 'string') return check_type(type, schema, value, path)\n if (is_record(schema['properties'])) return check_object(schema, value, path)\n return []\n}\n\n/**\n * Checks a `const`, which pins the value to one JSON literal.\n *\n * An object or array `const` accepts anything: matching it would mean a deep\n * comparison the server performs itself, and rejecting a valid argument is the\n * one failure mode this bridge must not have.\n */\nfunction check_const(\n expected: unknown,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n if (expected === null) return value === null ? [] : [issue('expected null', path)]\n if (\n typeof expected === 'string' ||\n typeof expected === 'number' ||\n typeof expected === 'boolean'\n ) {\n return value === expected ? [] : [issue(`expected ${JSON.stringify(expected)}`, path)]\n }\n return []\n}\n\n/**\n * Checks an `enum`, which pins the value to one of a list of JSON literals.\n * An empty enum constrains nothing and accepts.\n */\nfunction check_enum(\n values: unknown[],\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n if (values.length === 0) return []\n if (values.some((candidate) => check_const(candidate, value, path).length === 0)) return []\n return [issue(`expected one of ${values.map((v) => JSON.stringify(v)).join(', ')}`, path)]\n}\n\n/**\n * Checks an `anyOf` or `oneOf`, which passes when any branch passes.\n *\n * `oneOf`'s exactly-one semantics are deliberately relaxed to at-least-one: the\n * distinction only ever rejects a value the server would accept.\n *\n * A single-branch union reports that branch's own issues rather than a generic\n * \"no variant matched\", since with one variant there is no ambiguity about\n * which one failed.\n */\nfunction check_any_of(\n nodes: unknown[],\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n if (nodes.length === 0) return []\n if (nodes.length === 1) return check(nodes[0], value, path)\n if (nodes.some((node) => check(node, value, path).length === 0)) return []\n return [issue(`expected one of ${nodes.length} variants`, path)]\n}\n\n/**\n * Checks an `allOf`, which passes only when every branch passes.\n */\nfunction check_all_of(\n nodes: unknown[],\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n return nodes.flatMap((node) => check(node, value, path))\n}\n\n/**\n * Checks the array form of `type` (`[\"string\", \"null\"]`), which passes when the\n * value matches any listed type. The other keywords on the node apply to\n * whichever type matched, so each branch sees the whole node.\n */\nfunction check_type_union(\n types: unknown[],\n schema: Record<string, unknown>,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n if (types.length === 0) return []\n if (types.length === 1) return check_type(String(types[0]), schema, value, path)\n if (types.some((type) => check_type(String(type), schema, value, path).length === 0)) return []\n return [issue(`expected one of ${types.map(String).join(', ')}`, path)]\n}\n\n/**\n * The scalar `type` keywords, as predicates over the value.\n *\n * `number` rejects `NaN` and infinities because neither survives JSON, and\n * `integer` is the same check narrowed to whole values.\n */\nconst SCALAR_TYPES: Record<string, (value: unknown) => boolean> = {\n string: (value) => typeof value === 'string',\n number: (value) => typeof value === 'number' && Number.isFinite(value),\n integer: (value) => Number.isInteger(value),\n boolean: (value) => typeof value === 'boolean',\n null: (value) => value === null,\n}\n\n/**\n * Checks one `type` keyword. `object` and `array` recurse into the node's own\n * `properties` and `items`; everything else is a scalar predicate.\n *\n * An unrecognized type accepts, so a vendor extension cannot reject an argument\n * the server would take.\n */\nfunction check_type(\n type: string,\n schema: Record<string, unknown>,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n if (type === 'object') return check_object(schema, value, path)\n if (type === 'array') return check_array(schema, value, path)\n const matches = SCALAR_TYPES[type]\n if (matches === undefined) return []\n return matches(value) ? [] : [type_issue(type, value, path)]\n}\n\n/**\n * Checks an object against its `properties` and `required`.\n *\n * Keys the schema does not declare are left alone rather than rejected, so an\n * argument this bridge did not anticipate still reaches the server, which\n * re-validates and is the real authority. A `required` name with no entry in\n * `properties` is likewise not enforced: there is nothing to check it against.\n */\nfunction check_object(\n schema: Record<string, unknown>,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n if (!is_record(value)) return [type_issue('object', value, path)]\n const properties = as_record(schema['properties']) ?? {}\n const required = new Set(string_array(schema['required']))\n const issues: SchemaIssue[] = []\n for (const [key, property] of Object.entries(properties)) {\n const child = value[key]\n if (child === undefined) {\n if (required.has(key)) issues.push(issue('required', [...path, key]))\n continue\n }\n issues.push(...check(property, child, [...path, key]))\n }\n return issues\n}\n\n/**\n * Checks an array against its `items`.\n *\n * A positional-tuple `items` (an array rather than a node) is not a record, so\n * every element accepts. Tuple schemas are rare in MCP tools and the server\n * re-validates them anyway.\n */\nfunction check_array(\n schema: Record<string, unknown>,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue[] {\n if (!Array.isArray(value)) return [type_issue('array', value, path)]\n return value.flatMap((item, index) => check(schema['items'], item, [...path, index]))\n}\n\n/**\n * Builds a type-mismatch issue naming what was expected and what arrived.\n */\nfunction type_issue(\n expected: string,\n value: unknown,\n path: ReadonlyArray<PropertyKey>,\n): SchemaIssue {\n return issue(`expected ${expected}, received ${describe(value)}`, path)\n}\n\n/**\n * Names a value's type the way a JSON Schema reader would, separating `null`\n * and arrays out of `typeof`'s `object`.\n */\nfunction describe(value: unknown): string {\n if (value === null) return 'null'\n if (Array.isArray(value)) return 'array'\n return typeof value\n}\n\n/**\n * Builds one issue, omitting the path entirely at the root so a failure about\n * the value as a whole does not report an empty path.\n */\nfunction issue(message: string, path: ReadonlyArray<PropertyKey>): SchemaIssue {\n return path.length === 0 ? { message } : { message, path: [...path] }\n}\n\n/**\n * Filters a value down to the strings it contains, or an empty array when it\n * is not an array at all.\n */\nfunction string_array(value: unknown): string[] {\n return Array.isArray(value) ? value.filter((v): v is string => typeof v === 'string') : []\n}\n","/**\n * Lazy loader for the optional `@modelcontextprotocol/sdk` peer.\n *\n * `mcp_client` needs SDK values (the Client and transport constructors), so it\n * imports them dynamically rather than statically: a consumer can import\n * `fascicle/mcp` without the SDK installed and only pays the cost when they\n * actually connect. A missing peer surfaces as a typed `mcp_sdk_missing_error`\n * with install guidance, mirroring the engine's `load_optional_peer`.\n *\n * `serve_flow` is not covered here: it operates on a caller-constructed\n * `McpServer`, so it needs only a type-only import and no runtime SDK load.\n */\n\nimport { mcp_sdk_missing_error } from './errors.js'\n\nexport type McpClientSdk = Awaited<ReturnType<typeof load_client_sdk>>\n\n/**\n * Dynamically imports the `@modelcontextprotocol/sdk` client modules,\n * throwing a typed `mcp_sdk_missing_error` when the optional peer is not\n * installed.\n */\nexport async function load_client_sdk() {\n try {\n const [client_mod, stdio_mod, http_mod] = await Promise.all([\n import('@modelcontextprotocol/sdk/client/index.js'),\n import('@modelcontextprotocol/sdk/client/stdio.js'),\n import('@modelcontextprotocol/sdk/client/streamableHttp.js'),\n ])\n return {\n Client: client_mod.Client,\n StdioClientTransport: stdio_mod.StdioClientTransport,\n StreamableHTTPClientTransport: http_mod.StreamableHTTPClientTransport,\n }\n } catch (err: unknown) {\n const detail = err instanceof Error ? err.message : String(err)\n throw new mcp_sdk_missing_error(\n `@modelcontextprotocol/sdk is required for fascicle/mcp; install it: pnpm add @modelcontextprotocol/sdk (cause: ${detail})`,\n )\n }\n}\n","/**\n * Inbound MCP: connect to an external MCP server and surface its tools as plain\n * fascicle `Tool[]`.\n */\n\nimport type { Client } from '@modelcontextprotocol/sdk/client/index.js'\nimport type { Transport } from '@modelcontextprotocol/sdk/shared/transport.js'\nimport type { Tool, ToolExecContext } from '#engine'\nimport { mcp_error } from './errors.js'\nimport { is_record } from './internal.js'\nimport { call_result_to_output } from './result_mapping.js'\nimport { json_schema_to_standard } from './schema_bridge.js'\nimport { load_client_sdk, type McpClientSdk } from './sdk_loader.js'\n\nconst DEFAULT_CLIENT_INFO = { name: 'fascicle', version: '0.0.0' }\n\nexport type McpStdioConfig = {\n transport: 'stdio'\n command: string\n args?: string[]\n env?: Record<string, string>\n cwd?: string\n}\n\nexport type McpStreamableHttpConfig = {\n transport: 'http'\n url: string\n headers?: Record<string, string>\n}\n\n// Escape hatch: hand in an already-connected Client (a transport the adapter\n// does not build, a test harness, a shared connection). Its lifecycle stays\n// with the caller, so the returned `close` is a no-op for this variant.\nexport type McpExistingClientConfig = {\n transport: 'client'\n client: Client\n}\n\nexport type McpClientConfig =\n | McpStdioConfig\n | McpStreamableHttpConfig\n | McpExistingClientConfig\n\nexport type McpClientOptions = {\n // Identity sent in the MCP handshake; defaults to fascicle.\n client_info?: { name: string; version: string }\n // When set, only tools whose name is listed are surfaced.\n include?: ReadonlyArray<string>\n // Supplies a description for tools that advertise none.\n default_description?: (tool_name: string) => string\n}\n\nexport type McpClientHandle = {\n readonly tools: ReadonlyArray<Tool>\n readonly close: () => Promise<void>\n}\n\n/**\n * Connects to an MCP server and surfaces its advertised tools as fascicle\n * `Tool[]`, plus a `close` handle for the connection.\n *\n * Owns the connection lifecycle (config in, `{ tools, close }` out) so callers\n * do not have to import SDK transport classes themselves. Each advertised MCP\n * tool becomes an ordinary `Tool`: its JSON Schema is wrapped as a `ToolSchema`\n * the loop validates against and the provider receives back unchanged, and\n * `execute` forwards to `callTool`, propagating the run's abort signal. For the\n * `client` transport variant the caller keeps ownership of the connection, so\n * `close` is a no-op.\n */\nexport async function mcp_client(\n config: McpClientConfig,\n options: McpClientOptions = {},\n): Promise<McpClientHandle> {\n const owns_client = config.transport !== 'client'\n const client = await connect_client(config, options)\n\n const include = options.include !== undefined ? new Set(options.include) : undefined\n const listed = await client.listTools()\n const tools: Tool[] = []\n for (const advertised of listed.tools) {\n if (include !== undefined && !include.has(advertised.name)) continue\n tools.push(to_fascicle_tool(client, advertised, options))\n }\n\n return {\n tools,\n close: async () => {\n if (owns_client) await client.close()\n },\n }\n}\n\n/**\n * Returns the caller's already-connected client as-is, or lazily loads the\n * SDK and connects a fresh client over the configured transport.\n */\nasync function connect_client(\n config: McpClientConfig,\n options: McpClientOptions,\n): Promise<Client> {\n if (config.transport === 'client') return config.client\n const sdk = await load_client_sdk()\n const client = new sdk.Client(options.client_info ?? DEFAULT_CLIENT_INFO)\n await client.connect(build_transport(sdk, config))\n return client\n}\n\n/**\n * Constructs the SDK transport matching the config: a spawned child process\n * for `stdio`, a Streamable HTTP connection for `http`.\n */\nfunction build_transport(\n sdk: McpClientSdk,\n config: McpStdioConfig | McpStreamableHttpConfig,\n): Transport {\n if (config.transport === 'stdio') {\n return new sdk.StdioClientTransport({\n command: config.command,\n ...(config.args !== undefined ? { args: config.args } : {}),\n ...(config.env !== undefined ? { env: config.env } : {}),\n ...(config.cwd !== undefined ? { cwd: config.cwd } : {}),\n })\n }\n const opts = config.headers !== undefined ? { requestInit: { headers: config.headers } } : {}\n // The SDK declares this class `implements Transport`, but its `onmessage`\n // overload is narrower than the interface's, which only strict mode flags.\n // eslint-disable-next-line typescript-eslint/no-unsafe-type-assertion\n return new sdk.StreamableHTTPClientTransport(new URL(config.url), opts) as Transport\n}\n\n/**\n * Wraps one advertised MCP tool as a fascicle `Tool` whose `execute` forwards\n * to `callTool` on the shared client.\n *\n * An already-aborted signal short-circuits before the wire call; otherwise the\n * signal is passed through so cancelling the run cancels the remote call.\n */\nfunction to_fascicle_tool(\n client: Client,\n advertised: { name: string; description?: string | undefined; inputSchema: unknown },\n options: McpClientOptions,\n): Tool {\n const name = advertised.name\n const description =\n advertised.description ?? options.default_description?.(name) ?? `MCP tool ${name}`\n return {\n name,\n description,\n input_schema: json_schema_to_standard(advertised.inputSchema),\n execute: async (input: unknown, ctx: ToolExecContext) => {\n if (ctx.abort.aborted) {\n throw ctx.abort.reason instanceof Error\n ? ctx.abort.reason\n : new mcp_error(`MCP tool ${name} aborted before invocation`, { tool_name: name })\n }\n const result = await client.callTool(\n { name, arguments: is_record(input) ? input : undefined },\n undefined,\n { signal: ctx.abort },\n )\n return call_result_to_output(result, name)\n },\n }\n}\n","/**\n * Outbound MCP: expose a composed fascicle flow as an MCP tool.\n *\n * `serve_flow` registers onto a caller-constructed `McpServer` (the caller owns\n * the transport, identity, and lifecycle, and can host many flows on one\n * server), so it needs only a type-only SDK import. The registered handler\n * drives the existing `run`, threading the per-request abort signal so an MCP\n * client cancellation aborts the in-flight flow, and maps the result into a\n * `CallToolResult`. A thrown flow becomes an `isError` result rather than a\n * JSON-RPC protocol error.\n */\n\nimport type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'\nimport type { z } from 'zod'\nimport { run } from '#core'\nimport type { Step, TrajectoryLogger } from '#core'\nimport { output_to_call_result } from './result_mapping.js'\n\nexport type ServeFlowOptions<i, o> = {\n server: McpServer\n flow: Step<i, o>\n name: string\n description: string\n /**\n * Stays zod rather than joining the rest of the surface on `ToolSchema`.\n * `McpServer.registerTool` types `inputSchema` as a zod schema and offers no\n * JSON Schema entry point, and the SDK carries zod as a hard runtime\n * dependency, so a `serve_flow` caller already has zod resolved. Widening\n * this to a neutral schema would typecheck and then fail inside the SDK.\n */\n input_schema: z.ZodType<i>\n trajectory?: TrajectoryLogger\n // Overrides the default value-to-CallToolResult mapping.\n to_result?: (output: o) => { text: string; structured?: Record<string, unknown> }\n}\n\n/**\n * Registers a fascicle flow as a tool on a caller-owned MCP server.\n *\n * Drives the flow with `run`, threading the per-request abort signal so an\n * MCP client cancellation aborts the in-flight flow, and maps the result\n * into a `CallToolResult`. A thrown flow becomes an `isError` result rather\n * than a JSON-RPC protocol error.\n */\nexport function serve_flow<i, o>(options: ServeFlowOptions<i, o>): void {\n const { server, flow, name, description, input_schema, trajectory, to_result } = options\n server.registerTool(\n name,\n { description, inputSchema: input_schema },\n async (input: i, extra) => {\n try {\n const output = await run(flow, input, {\n install_signal_handlers: false,\n abort: extra.signal,\n ...(trajectory !== undefined ? { trajectory } : {}),\n })\n return output_to_call_result(output, to_result)\n } catch (err: unknown) {\n return {\n isError: true,\n content: [{ type: 'text', text: err instanceof Error ? err.message : String(err) }],\n }\n }\n },\n )\n}\n"],"mappings":";;;;;;;;;AAQA,IAAa,wBAAb,cAA2C,MAAM;CAC/C,OAAgB;CAChB,YACE,UAAU,0GACV;EACA,MAAM,OAAO;EACb,KAAK,OAAO;CACd;AACF;AAEA,IAAa,YAAb,cAA+B,MAAM;CACnC,OAAgB;CAChB;CACA,YAAY,SAAiB,WAAmC,CAAC,GAAG;EAClE,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,KAAK,YAAY,SAAS;CAC5B;AACF;;;;;;;;;;AClBA,SAAgB,UAAU,OAAkD;CAC1E,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;AAC5E;;;;AAKA,SAAgB,UAAU,OAAqD;CAC7E,OAAO,UAAU,KAAK,IAAI,QAAQ,KAAA;AACpC;;;;;;;;;;;;;;;;;ACMA,SAAgB,sBAAsB,QAAiB,WAA6B;CAClF,MAAM,SAAS,UAAU,MAAM,KAAK,CAAC;CAErC,IAAI,OAAO,eAAe,MAExB,MAAM,IAAI,UADK,UAAU,OAAO,UAAU,KAAK,8BACnB,cAAc,KAAA,IAAY,EAAE,UAAU,IAAI,CAAC,CAAC;CAG1E,IAAI,UAAU,OAAO,oBAAoB,GAAG,OAAO,OAAO;CAE1D,MAAM,OAAO,UAAU,OAAO,UAAU;CACxC,IAAI,SAAS,KAAA,GAAW,OAAO;CAE/B,OAAO,OAAO,cAAc;AAC9B;;;;;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el.d.ts
CHANGED
package/dist/stdio.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { r as Step, s as TrajectoryLogger } from "./types-BDSbSUAO.js";
|
|
2
|
+
import { t as AnySchema } from "./types-BCtKsxrX.js";
|
|
3
3
|
|
|
4
4
|
//#region src/stdio/execute_stdio.d.ts
|
|
5
5
|
type RunStdioOptions<i, o> = {
|
|
6
|
-
readonly input_schema?:
|
|
7
|
-
readonly output_schema?:
|
|
6
|
+
readonly input_schema?: AnySchema<i>;
|
|
7
|
+
readonly output_schema?: AnySchema<o>;
|
|
8
8
|
readonly engine?: {
|
|
9
9
|
readonly dispose: () => Promise<void>;
|
|
10
10
|
};
|