pi-mcp-extension 1.12.0 → 1.12.1

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "pi-mcp-extension",
3
- "version": "1.12.0",
3
+ "version": "1.12.1",
4
4
  "description": "Full-featured, lightweight MCP extension for the Pi coding agent: stdio, SSE & Streamable HTTP transports, OAuth 2.1 (PKCE + DCR), lazy/eager lifecycles — minimal dependencies, zero bloat.",
5
5
  "type": "module",
6
6
  "keywords": [
@@ -371,16 +371,65 @@ function convertMultiTypeSchema(
371
371
  return Type.Union(orderUnionMembers(members), opts);
372
372
  }
373
373
 
374
+ /**
375
+ * Convert one tuple rest schema (an object schema or a boolean) to a TypeBox schema.
376
+ * Any other value (`undefined`, `null`, a number, a string, an array) is not a schema
377
+ * keyword: later positions stay unconstrained instead of inheriting the closed default.
378
+ */
379
+ function convertTupleRestSchema(rest: unknown, ctx: ConversionContext): TSchema | boolean {
380
+ if (typeof rest === "boolean") {
381
+ return rest;
382
+ }
383
+ if (isPlainObject(rest)) {
384
+ return convertJsonSchemaToTypebox(rest, ctx.rootDefs, ctx.effectiveRoot, ctx.seenRefs);
385
+ }
386
+ return true;
387
+ }
388
+
389
+ /**
390
+ * Add a tuple's rest schema to its TypeBox options as `additionalItems`.
391
+ * WHY: `Type.Tuple` forces `additionalItems: false`, so a variadic tuple such as
392
+ * `{ prefixItems: [{ type: "string" }], items: { type: "integer" } }` (`[string, ...integer[]]`)
393
+ * rejects every rest element with `schema is false` in Pi's `validateToolArguments`.
394
+ * TypeBox types `TTuple.additionalItems` as the literal `false` and `Type.TupleOptions()`
395
+ * drops the key, so this override is runtime-only: any `Type.Instantiate`-style rebuild of a
396
+ * tuple loses it and has to re-apply it. The rest schema is also validated but never
397
+ * `Value.Convert`-coerced — TypeBox's tuple converter only visits the declared positions —
398
+ * so `["ls", "1"]` stays a string and is rejected where a plain array would coerce it.
399
+ */
400
+ function withTupleRestSchema(
401
+ rest: unknown,
402
+ opts: Record<string, unknown>,
403
+ ctx: ConversionContext,
404
+ ): Record<string, unknown> {
405
+ return { ...opts, additionalItems: convertTupleRestSchema(rest, ctx) };
406
+ }
407
+
408
+ /**
409
+ * The rest keyword of a tuple: 2020-12 `items` after `prefixItems` (falling back to a legacy
410
+ * sibling `additionalItems`), or draft-07 `additionalItems` after an array `items`.
411
+ * WHY: both drafts leave later positions unconstrained when that keyword is absent, while
412
+ * `Type.Tuple` defaults to `additionalItems: false` — which would reject every rest element
413
+ * with the same `schema is false` failure this conversion exists to prevent. A tuple is closed
414
+ * only when the source schema says so (`items: false` / `additionalItems: false`).
415
+ */
416
+ function tupleRestKeyword(hasPrefixItems: boolean, schema: Record<string, unknown>): unknown {
417
+ if (!hasPrefixItems) {
418
+ return schema["additionalItems"];
419
+ }
420
+ return schema["items"] ?? schema["additionalItems"];
421
+ }
422
+
374
423
  function convertArraySchema(
375
424
  schema: Record<string, unknown>,
376
425
  opts: Record<string, unknown>,
377
426
  ctx: ConversionContext,
378
427
  ): TSchema {
379
- const tupleItems = Array.isArray(schema["prefixItems"])
428
+ const prefixItems = Array.isArray(schema["prefixItems"])
380
429
  ? (schema["prefixItems"] as unknown[])
381
- : Array.isArray(schema["items"])
382
- ? (schema["items"] as unknown[])
383
- : undefined;
430
+ : undefined;
431
+ const tupleItems =
432
+ prefixItems ?? (Array.isArray(schema["items"]) ? (schema["items"] as unknown[]) : undefined);
384
433
  if (tupleItems) {
385
434
  return Type.Tuple(
386
435
  tupleItems.map((item) =>
@@ -391,7 +440,7 @@ function convertArraySchema(
391
440
  ctx.seenRefs,
392
441
  ),
393
442
  ),
394
- opts,
443
+ withTupleRestSchema(tupleRestKeyword(prefixItems !== undefined, schema), opts, ctx),
395
444
  );
396
445
  }
397
446
  const items = schema["items"];
@@ -655,7 +704,9 @@ function resolveNonTypedSchema(
655
704
  * Convert a JSON Schema object to a TypeBox schema.
656
705
  * Handles the common subset used by real-world MCP servers:
657
706
  * - Primitives (string, number, integer, boolean, null)
658
- * - Arrays, tuples (prefixItems / array items), objects (with required/optional/additionalProperties)
707
+ * - Arrays, tuples (prefixItems / array items, with a variadic `items` after
708
+ * `prefixItems` or `additionalItems` after a draft-07 tuple), objects
709
+ * (with required/optional/additionalProperties)
659
710
  * - Enums and const (string, numeric, boolean, and nullable enums → Union of Literals)
660
711
  * - Nullable and multi-type arrays ("type": ["string", "null"]) with Type.Null() ordered first
661
712
  * - Cycle-safe $ref (#, #/$defs/, #/definitions/, and arbitrary RFC 6901 JSON Pointers)