@ikijs/mcp 0.38.2 → 0.39.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/dist/cli.js CHANGED
@@ -30,6 +30,7 @@ var importMetaUrl = /* @__PURE__ */ getImportMetaUrl();
30
30
  // src/server.ts
31
31
  var import_mcp = require("@modelcontextprotocol/sdk/server/mcp.js");
32
32
  var import_zod = require("zod");
33
+ var import_format13 = require("@ikijs/format");
33
34
 
34
35
  // src/tools.ts
35
36
  var import_node_fs6 = require("fs");
@@ -607,6 +608,9 @@ var Spring = class {
607
608
  }
608
609
  }
609
610
  };
611
+ function eyeSpring() {
612
+ return new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
613
+ }
610
614
  var IdleMotion = class {
611
615
  /**
612
616
  * Every parameter id {@link update} and `emitRestingPose` write, in write
@@ -632,8 +636,8 @@ var IdleMotion = class {
632
636
  // Gaze state: the scheduled pick starts at eye contact, (0, 0), until the
633
637
  // first retarget. A host target, while set, replaces the pick as what the
634
638
  // eyes and head chase; the schedule keeps picking underneath it.
635
- eyeX = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
636
- eyeY = new Spring(EYE_SPRING_OMEGA, EYE_SPRING_ZETA);
639
+ eyeX = eyeSpring();
640
+ eyeY = eyeSpring();
637
641
  gazeTargetX = 0;
638
642
  gazeTargetY = 0;
639
643
  nextGazeRetargetMs;
@@ -4493,6 +4497,7 @@ function describeIki(model) {
4493
4497
  motions,
4494
4498
  bustScale
4495
4499
  };
4500
+ if (m.generator !== void 0) summary.generator = m.generator;
4496
4501
  const face = m.parts.find((p) => p.id === "face");
4497
4502
  if (face !== void 0) summary.faceWidth = face.width;
4498
4503
  return { ok: true, summary };
@@ -4682,6 +4687,14 @@ async function renderAtlasPage(crops, quantizeColors) {
4682
4687
  }
4683
4688
  async function autoRigFromLayers(input) {
4684
4689
  try {
4690
+ if (input.generator !== void 0) {
4691
+ try {
4692
+ (0, import_format11.parseIkiGenerator)(input.generator);
4693
+ } catch (e) {
4694
+ if (e instanceof import_format11.IkiFormatError) throw new AutoRigInputError(e.message);
4695
+ throw e;
4696
+ }
4697
+ }
4685
4698
  const layers = input.layers;
4686
4699
  if (!Array.isArray(layers) || layers.length === 0) {
4687
4700
  throw new AutoRigInputError("layers must be a non-empty array");
@@ -4947,7 +4960,9 @@ async function autoRigFromLayers(input) {
4947
4960
  patched.parts.find((p) => p.id === crop.id).texture.index = pages.length;
4948
4961
  }
4949
4962
  }
4950
- const finalModel = (0, import_format11.parseIkiModel)(patched);
4963
+ const finalModel = (0, import_format11.parseIkiModel)(
4964
+ input.generator === void 0 ? patched : { ...patched, generator: input.generator }
4965
+ );
4951
4966
  const bakes = bakeReports === void 0 ? void 0 : checkBakes(finalModel, bakeReports);
4952
4967
  writeFileAtomic(outPath, JSON.stringify(finalModel));
4953
4968
  const folds = checkModelFolds(finalModel);
@@ -5093,6 +5108,8 @@ var import_node_path9 = __toESM(require("path"));
5093
5108
  // src/measure-arms.ts
5094
5109
  var import_node_path6 = __toESM(require("path"));
5095
5110
  var import_editor6 = require("@ikijs/editor");
5111
+ var UPPER_BODY = 0.35;
5112
+ var NARROW_ROW = 0.6;
5096
5113
  var ARM_ROLES = ["arm_L", "arm_R"];
5097
5114
  var CAP_OVERLAP = 0.5;
5098
5115
  var px = (v) => `${Number(v.toFixed(1))}`;
@@ -5158,6 +5175,19 @@ function capWarning(arm, g, body) {
5158
5175
  const overlap = g.shoulderRadius - g.side * (pivotX - edge);
5159
5176
  const need = CAP_OVERLAP * g.shoulderRadius;
5160
5177
  if (overlap >= need) return void 0;
5178
+ const crop = row - body.bbox.y;
5179
+ const width = (r) => r === void 0 || r.length === 0 ? 0 : r[r.length - 1] - r[0];
5180
+ const here = width(runs);
5181
+ let below = 0;
5182
+ let belowRow = row;
5183
+ const end = Math.ceil(UPPER_BODY * body.bbox.h);
5184
+ for (let k = crop + 1; k < end; k++) {
5185
+ const w = width(body.rowRuns?.[k]);
5186
+ if (w > below) [below, belowRow] = [w, body.bbox.y + k];
5187
+ }
5188
+ if (here < NARROW_ROW * below) {
5189
+ return `${arm}: its shoulder cap reaches ${px(overlap)} px under the torso's edge on its pivot row (y=${row}), under half its radius (${px(need)} px), and the body is ${here} px wide there against ${below} px at y=${belowRow}. Read the shoulder line off preview.png: if that row is the neck, move layout.${arm}.cy down by the px the shoulder line lies under y=${row} (free) \u2014 not its cx, which hangs the arm from the neck; if it is the shoulders over a wider garment, move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
5190
+ }
5161
5191
  return `${arm}: its shoulder cap reaches ${px(overlap)} px under the torso's edge on its pivot row (y=${row}), under half its radius (${px(need)} px) \u2014 a gap opens beside the shoulder once the arm raises. Move layout.${arm}.cx ${Math.ceil(need - overlap)} px toward the body (free).`;
5162
5192
  }
5163
5193
 
@@ -5620,6 +5650,15 @@ function keyGreen(rgba, W, H) {
5620
5650
  }
5621
5651
  return out;
5622
5652
  }
5653
+ var SPILL_REACH = 3;
5654
+ function despill(rgba, only) {
5655
+ for (let i = 0; i < rgba.length; i += 4) {
5656
+ if (only !== void 0 && !only[i >> 2]) continue;
5657
+ const cap = Math.max(rgba[i], rgba[i + 2]);
5658
+ if (rgba[i + 1] > cap) rgba[i + 1] = cap;
5659
+ }
5660
+ return rgba;
5661
+ }
5623
5662
  var GROUND_TOLERANCE = 4;
5624
5663
  var GROUND_LIGHT = 200;
5625
5664
  var GROUND_MIN = 238;
@@ -5852,6 +5891,21 @@ async function splitLipSet(keyedPng, w, h, interior) {
5852
5891
  const alpha = (p) => frame[p * 4 + 3];
5853
5892
  const { label, main: main2, box: hb } = enclosedHole(frame, w, h);
5854
5893
  const holeW = hb.x1 - hb.x0 + 1;
5894
+ const near = new Uint8Array(n);
5895
+ for (let y = Math.max(0, hb.y0 - SPILL_REACH); y <= Math.min(h - 1, hb.y1 + SPILL_REACH); y++) {
5896
+ for (let x = Math.max(0, hb.x0 - SPILL_REACH); x <= Math.min(w - 1, hb.x1 + SPILL_REACH); x++) {
5897
+ if (label[y * w + x] !== main2) continue;
5898
+ for (let dy = -SPILL_REACH; dy <= SPILL_REACH; dy++) {
5899
+ const yy = y + dy;
5900
+ if (yy < 0 || yy >= h) continue;
5901
+ for (let dx = -SPILL_REACH; dx <= SPILL_REACH; dx++) {
5902
+ const xx = x + dx;
5903
+ if (xx >= 0 && xx < w) near[yy * w + xx] = 1;
5904
+ }
5905
+ }
5906
+ }
5907
+ }
5908
+ const paint = despill(Buffer.from(frame), near);
5855
5909
  const top = new Int32Array(w).fill(-1);
5856
5910
  const bot = new Int32Array(w).fill(-1);
5857
5911
  for (let y = 0; y < h; y++) {
@@ -5911,7 +5965,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5911
5965
  const inner = Buffer.alloc(n * 4);
5912
5966
  const tongue = Buffer.alloc(n * 4);
5913
5967
  const teeth = Buffer.alloc(n * 4);
5914
- const copy = (to, p) => frame.copy(to, p * 4, p * 4, p * 4 + 4);
5968
+ const copy = (to, p) => paint.copy(to, p * 4, p * 4, p * 4 + 4);
5915
5969
  for (let y = 0; y < h; y++) {
5916
5970
  for (let x = 0; x < w; x++) {
5917
5971
  const p = y * w + x;
@@ -5937,7 +5991,7 @@ async function splitLipSet(keyedPng, w, h, interior) {
5937
5991
  }
5938
5992
  if ((inM[p] || wall[x]) && !faintUpper(p, x, y)) {
5939
5993
  const a = alpha(p) / 255;
5940
- for (let c = 0; c < 3; c++) out[c] += (frame[p * 4 + c] - out[c]) * a;
5994
+ for (let c = 0; c < 3; c++) out[c] += (paint[p * 4 + c] - out[c]) * a;
5941
5995
  }
5942
5996
  inner[p * 4] = Math.round(out[0]);
5943
5997
  inner[p * 4 + 1] = Math.round(out[1]);
@@ -6039,7 +6093,9 @@ async function closedLips(upper, lower, shift, left, top) {
6039
6093
  var isLipLayerRole = (role) => import_editor10.LIP_ROLES.includes(role) || (0, import_editor10.isLipInsideRole)(role);
6040
6094
  var MIN_OPENING_ROWS = 8;
6041
6095
  var MIN_LINE_ROWS = 2;
6042
- var GREEN_EXCESS = 40;
6096
+ var GREEN_EXCESS = 16;
6097
+ var KEY_GREEN_EXCESS = 40;
6098
+ var EDGE_REACH = 3;
6043
6099
  var INTERIOR_GAP_FRACTION = 0.05;
6044
6100
  var columns = (cols) => `${cols.length} column${cols.length === 1 ? "" : "s"} (first at x=${cols[0]})`;
6045
6101
  async function lipWarnings(absDir, layers, inPlace = false) {
@@ -6100,17 +6156,49 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6100
6156
  });
6101
6157
  const set = /* @__PURE__ */ new Map();
6102
6158
  const green = [];
6159
+ const pixels = /* @__PURE__ */ new Map();
6103
6160
  for (const role of import_editor10.LIP_ROLES) {
6104
6161
  const fileName = `${role}.png`;
6105
6162
  const { rgba } = await decodePng(import_node_path7.default.join(absDir, fileName));
6106
6163
  set.set(role, measurer.add({ role, fileName, rgba }));
6164
+ pixels.set(role, rgba);
6107
6165
  for (let i = 0; i < rgba.length; i += 4) {
6108
- if (rgba[i + 3] >= import_editor10.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > GREEN_EXCESS) {
6166
+ if (rgba[i + 3] >= import_editor10.ALPHA_OPAQUE && rgba[i + 1] - Math.max(rgba[i], rgba[i + 2]) > KEY_GREEN_EXCESS) {
6109
6167
  green.push(role);
6110
6168
  break;
6111
6169
  }
6112
6170
  }
6113
6171
  }
6172
+ {
6173
+ const W = inner.canvasW;
6174
+ const H = inner.canvasH;
6175
+ const cavity2 = pixels.get("mouth_inner");
6176
+ const edge = new Uint8Array(W * H);
6177
+ for (let p = 0; p < W * H; p++) {
6178
+ if (cavity2[p * 4 + 3] < 128) continue;
6179
+ const x = p % W;
6180
+ const y = (p - x) / W;
6181
+ for (let dy = -EDGE_REACH; dy <= EDGE_REACH; dy++) {
6182
+ const yy = y + dy;
6183
+ if (yy < 0 || yy >= H) continue;
6184
+ for (let dx = -EDGE_REACH; dx <= EDGE_REACH; dx++) {
6185
+ const xx = x + dx;
6186
+ if (xx >= 0 && xx < W) edge[yy * W + xx] = 1;
6187
+ }
6188
+ }
6189
+ }
6190
+ for (const role of ["lip_upper", "lip_lower"]) {
6191
+ if (green.includes(role)) continue;
6192
+ const rgba = pixels.get(role);
6193
+ for (let p = 0; p < W * H; p++) {
6194
+ const i = p * 4;
6195
+ if (edge[p] && (rgba[i + 1] - Math.max(rgba[i], rgba[i + 2])) * rgba[i + 3] / 255 > GREEN_EXCESS) {
6196
+ green.push(role);
6197
+ break;
6198
+ }
6199
+ }
6200
+ }
6201
+ }
6114
6202
  let opening;
6115
6203
  try {
6116
6204
  opening = (0, import_editor10.mouthOpening)(set);
@@ -6188,7 +6276,11 @@ async function lipWarnings(absDir, layers, inPlace = false) {
6188
6276
  }
6189
6277
  if (!inPlace && green.length > 0) {
6190
6278
  warnings.push(
6191
- `${green.join("/")}: opaque green left (key green, g exceeds r and b by over ${GREEN_EXCESS}) \u2014 it shows as a green fringe on the lips. Regenerate mouth_keyed.png with the green only inside the opening, or mouth_interior.png without green in it. Billed.`
6279
+ `${green.join("/")}: green left (key green: g over r and b by more than ${KEY_GREEN_EXCESS} in an opaque pixel, or by more than ${GREEN_EXCESS} at the pixel's alpha on the opening's edge) \u2014 it shows as a green fringe on the lips. ${recompose(
6280
+ "mouth_keyed.png",
6281
+ // mouth_inner's fill is the interior's own paint, which the composer keeps as drawn.
6282
+ green.includes("mouth_inner") ? "with the green only inside the opening, or mouth_interior.png without green in it" : "with the green only inside the opening"
6283
+ )}`
6192
6284
  );
6193
6285
  }
6194
6286
  if (!inPlace && area > 0 && hollow > INTERIOR_GAP_FRACTION * area) {
@@ -7900,6 +7992,27 @@ async function composeLayersFromParts(input) {
7900
7992
  }
7901
7993
  }
7902
7994
 
7995
+ // src/generator.ts
7996
+ var import_editor15 = require("@ikijs/editor");
7997
+ var import_format12 = require("@ikijs/format");
7998
+ var PLUGIN_ENV = "IKI_PLUGIN";
7999
+ function toolGenerator(env = process.env) {
8000
+ const generator = {
8001
+ tool: `@ikijs/mcp@${"0.39.1"}`,
8002
+ rigger: `@ikijs/editor@${import_editor15.EDITOR_VERSION}`
8003
+ };
8004
+ const plugin = env[PLUGIN_ENV];
8005
+ if (plugin === void 0 || plugin === "") return generator;
8006
+ try {
8007
+ return (0, import_format12.parseIkiGenerator)({ ...generator, plugin });
8008
+ } catch (e) {
8009
+ if (!(e instanceof import_format12.IkiFormatError)) throw e;
8010
+ throw new import_format12.IkiFormatError(
8011
+ `the ${PLUGIN_ENV} environment variable is no label for a model: ${e.message}`
8012
+ );
8013
+ }
8014
+ }
8015
+
7903
8016
  // src/hair-side-report.ts
7904
8017
  function signedPx(px2) {
7905
8018
  const s = px2.toFixed(1);
@@ -11025,7 +11138,7 @@ function cutFeatures(ctx, lipSet = false) {
11025
11138
  }
11026
11139
 
11027
11140
  // src/illustration-landmarks.ts
11028
- var import_editor15 = require("@ikijs/editor");
11141
+ var import_editor16 = require("@ikijs/editor");
11029
11142
  var DEFAULT_BROW_HALF_WIDTH = 8;
11030
11143
  var DEFAULT_BROW_TAIL_HALF_WIDTH = 5;
11031
11144
  var KEYS = {
@@ -11179,11 +11292,11 @@ function brow(path12, v, canvas) {
11179
11292
  tailHalfWidth: o.tailHalfWidth === void 0 ? DEFAULT_BROW_TAIL_HALF_WIDTH : positive(`${path12}.tailHalfWidth`, o.tailHalfWidth)
11180
11293
  };
11181
11294
  }
11182
- var YIELDED_PART_IDS = new Set(ARM_ROLES.flatMap((r) => (0, import_editor15.partIdsOfRole)(r)));
11295
+ var YIELDED_PART_IDS = new Set(ARM_ROLES.flatMap((r) => (0, import_editor16.partIdsOfRole)(r)));
11183
11296
  function isReservedId(id) {
11184
11297
  if (YIELDED_PART_IDS.has(id)) return true;
11185
11298
  try {
11186
- (0, import_editor15.partIdsOfRole)(id);
11299
+ (0, import_editor16.partIdsOfRole)(id);
11187
11300
  return true;
11188
11301
  } catch {
11189
11302
  return false;
@@ -12556,7 +12669,7 @@ function formatBakeChecks(bakes) {
12556
12669
  );
12557
12670
  }
12558
12671
  function createIkiMcpServer() {
12559
- const server = new import_mcp.McpServer({ name: "iki", version: "0.38.2" });
12672
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.39.1" });
12560
12673
  server.registerTool(
12561
12674
  "validate_iki",
12562
12675
  {
@@ -12583,7 +12696,7 @@ function createIkiMcpServer() {
12583
12696
  server.registerTool(
12584
12697
  "describe_iki",
12585
12698
  {
12586
- description: "Summarizes a valid model's canvas/params/parts/deformers and its expressions and motion clips (with the descriptions a host picks them by); returns an error for an invalid model. It is also the patch writer's view of a rigged model: each part's rest box in model px and in bust-render px, each part's warp stops, each warp2d's stops, and faceWidth, which is what an auto_rig_from_layers `patches` op is aimed with. Pass exactly one of model or modelPath; prefer modelPath for a written rig so a large model never crosses your context.",
12699
+ description: "Summarizes a valid model's canvas/params/parts/deformers and its expressions and motion clips (with the descriptions a host picks them by), and its `generator` (what wrote it: tool, rigger and plugin, each name@version) when it records one; returns an error for an invalid model. It is also the patch writer's view of a rigged model: each part's rest box in model px and in bust-render px, each part's warp stops, each warp2d's stops, and faceWidth, which is what an auto_rig_from_layers `patches` op is aimed with. Pass exactly one of model or modelPath; prefer modelPath for a written rig so a large model never crosses your context.",
12587
12700
  inputSchema: {
12588
12701
  model: import_zod.z.unknown().optional().describe("Raw .iki model JSON (object or JSON string)"),
12589
12702
  modelPath: import_zod.z.string().optional().describe(
@@ -12648,7 +12761,7 @@ function createIkiMcpServer() {
12648
12761
  server.registerTool(
12649
12762
  "auto_rig_from_layers",
12650
12763
  {
12651
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, hair_side_L/hair_side_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, a side lock needs hair_front, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. With side locks and a `nose` (which `turn` needs) the `HAIRSIDE` lines follow the `PHYSICS` lines (the result's `turn.hairSide`), each naming the lock's role, report-only as well. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error. `customParts` adds parts the rig has no role for (a twin tail, a hairpin), each from a canvas-sized PNG of its own, as an unrigged mesh on `headDeformer` after its `after` role's parts; it needs @ikijs/mcp 0.34.0, and an older server drops the field and returns no `customParts`. A part can declare `occlusion` (hidden where named roles' paint covers it, by an amount keyed on a parameter; it needs 0.35.0, and an older server refuses the key as `INVALID: customParts[i]\u2026`); its `CUSTOM <id>:` line then ends `, hidden by <id>,<id>\u2026 on <parameter> at <value>:<amount> <value>:<amount>\u2026`, and the result's part carries `occlusion` (`by` as the part ids written, `parameter`, `stops`). The result's `customParts` (`parts`: `id`, rest `box`, `mesh`, `order`, atlas `page`) is present whenever the input was passed, `[]` included, and one `CUSTOM <id>: \u2026` line per part follows the `HAIRSIDE` lines. `bakes` (see its field) moves the custom parts with a parameter and needs `customParts`; each part and parameter it moves then prints one `BAKE <part> <param>: <n> vertices, stops <values>, error <px> px` line after the `CUSTOM` lines (the result's `customParts.bakes`: `part`, `param`, `vertices`, `stops`, `errorPx`), the written model having been landed through the engine, and a stop off by 0.1 px or more comes back as `INVALID: BAKE ERROR <part> <param>=<value>: \u2026`, and a part the bake moves at rest as `INVALID: BAKE ERROR <part> at rest: \u2026`, with nothing written (the rig and the engine disagree: report it as a bug in the packages). Whenever `customParts` was passed, the written model is also measured per custom part (the result's `customParts.gate`: `ok`, `limits`, `parts`, `failed`) and the text ends with its lines, `CUSTOM <id> FOLDS|TIE|SLIDE|EXPOSED|RIGID|TIP: \u2026` then `CUSTOM GATE pass` or `CUSTOM GATE FAIL: <part LINE, \u2026>`, always the last line: a part's least triangle area ratio, its tie's displacement against the anchor where the head does not turn and where it does, the hidden art showing, how far a rigid part bends and where its free end lands, each in px and face widths with its worst pose; `TIP` never fails the gate and the other lines do. The model is written either way; from 0.34.0 on `customParts` always carries `gate` (a gate that throws still writes the file and ends the text `CUSTOM GATE FAIL: gate error: <message>`), so a result without `customParts` is from an older server and was never gated. The custom layers are not role layers: they are left out of the head's width and turn measurements, and an empty or wrong-size one, or an entry the rig refuses, comes back as `INVALID: customParts[i]\u2026` with nothing written. A missing field or one of the wrong type (a `tie` that is not two numbers, say) is refused by the schema itself, as the SDK's input validation error.",
12764
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R and either mouth or the lip set (mouth_inner + lip_lower + lip_upper, a mouth that folds open instead of crossfading) required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, forearm_pose_L/forearm_pose_R, hair_side_L/hair_side_R, mouth_tongue/mouth_teeth (only with the lip set: drawn under its lips and clipped to mouth_inner), etc. optional; an arm needs the body, a pose forearm needs its arm, a side lock needs hair_front, and a partial lip set, one mixed with mouth/mouth_open, or mouth_tongue/mouth_teeth without it is refused) into a renderable .iki written to disk. Pass full-canvas PNG file paths; returns the output path + summary (the model is NOT inlined). Filenames map to roles unless `fileName` is given. The result's `folds` is the written rig's fold report, printed after the path the way render_poses prints it, and report-only: a fold never refuses the rig. The `RIGPLAN:` line (the result's `rigPlan`: `effective`, `clamped`, `overriddenBy`) follows the path and precedes the `PATCH` lines. The `PHYSICS` lines follow the fold report (the result's `physics`), one per physics rig output \u2014 a spring's, or each chain segment's \u2014 reading ok, frozen or unstable with the step and idle amplitudes, or `PHYSICS: no rigs`; report-only too. With side locks and a `nose` (which `turn` needs) the `HAIRSIDE` lines follow the `PHYSICS` lines (the result's `turn.hairSide`), each naming the lock's role, report-only as well. `patches` (see its field) adds displacements to existing keyform stops of the freshly generated rig; each op then prints one line between the path and the fold report \u2014 `PATCH <i> <target> at <Param=v \u2026>: <moved> of <of> points (cols a-b, rows c-d), largest move <maxPx> model px`, with `(vertices)` in place of the columns and rows for a mesh part \u2014 and the result's `patches` carries the same reports (`index`, `target`, `at`, `moved`, `of`, `cols`/`rows` for a grid, `maxPx`), present whenever `patches` was passed, `[]` included. An op the input schema accepts but the rig refuses comes back as `INVALID: patches[i]\u2026` and nothing is written; an op with a missing field or a field of the wrong type is the SDK's input validation error. `customParts` adds parts the rig has no role for (a twin tail, a hairpin), each from a canvas-sized PNG of its own, as an unrigged mesh on `headDeformer` after its `after` role's parts; it needs @ikijs/mcp 0.34.0, and an older server drops the field and returns no `customParts`. A part can declare `occlusion` (hidden where named roles' paint covers it, by an amount keyed on a parameter; it needs 0.35.0, and an older server refuses the key as `INVALID: customParts[i]\u2026`); its `CUSTOM <id>:` line then ends `, hidden by <id>,<id>\u2026 on <parameter> at <value>:<amount> <value>:<amount>\u2026`, and the result's part carries `occlusion` (`by` as the part ids written, `parameter`, `stops`). The result's `customParts` (`parts`: `id`, rest `box`, `mesh`, `order`, atlas `page`) is present whenever the input was passed, `[]` included, and one `CUSTOM <id>: \u2026` line per part follows the `HAIRSIDE` lines. `bakes` (see its field) moves the custom parts with a parameter and needs `customParts`; each part and parameter it moves then prints one `BAKE <part> <param>: <n> vertices, stops <values>, error <px> px` line after the `CUSTOM` lines (the result's `customParts.bakes`: `part`, `param`, `vertices`, `stops`, `errorPx`), the written model having been landed through the engine, and a stop off by 0.1 px or more comes back as `INVALID: BAKE ERROR <part> <param>=<value>: \u2026`, and a part the bake moves at rest as `INVALID: BAKE ERROR <part> at rest: \u2026`, with nothing written (the rig and the engine disagree: report it as a bug in the packages). Whenever `customParts` was passed, the written model is also measured per custom part (the result's `customParts.gate`: `ok`, `limits`, `parts`, `failed`) and the text ends with its lines, `CUSTOM <id> FOLDS|TIE|SLIDE|EXPOSED|RIGID|TIP: \u2026` then `CUSTOM GATE pass` or `CUSTOM GATE FAIL: <part LINE, \u2026>`, always the last line: a part's least triangle area ratio, its tie's displacement against the anchor where the head does not turn and where it does, the hidden art showing, how far a rigid part bends and where its free end lands, each in px and face widths with its worst pose; `TIP` never fails the gate and the other lines do. The model is written either way; from 0.34.0 on `customParts` always carries `gate` (a gate that throws still writes the file and ends the text `CUSTOM GATE FAIL: gate error: <message>`), so a result without `customParts` is from an older server and was never gated. The custom layers are not role layers: they are left out of the head's width and turn measurements, and an empty or wrong-size one, or an entry the rig refuses, comes back as `INVALID: customParts[i]\u2026` with nothing written. A missing field or one of the wrong type (a `tie` that is not two numbers, say) is refused by the schema itself, as the SDK's input validation error. The written model records what made it as `generator`: this server and the auto-rigger, each name@version, and the plugin named in the server's IKI_PLUGIN environment variable, if any; it is no input.",
12652
12765
  inputSchema: {
12653
12766
  layers: import_zod.z.array(
12654
12767
  import_zod.z.object({
@@ -12792,8 +12905,19 @@ function createIkiMcpServer() {
12792
12905
  },
12793
12906
  async (args) => {
12794
12907
  try {
12908
+ let generator;
12909
+ try {
12910
+ generator = toolGenerator();
12911
+ } catch (e) {
12912
+ if (!(e instanceof import_format13.IkiFormatError)) throw e;
12913
+ return {
12914
+ content: [{ type: "text", text: `INVALID: ${e.message}` }],
12915
+ structuredContent: { ok: false, error: e.message }
12916
+ };
12917
+ }
12795
12918
  const r = await autoRigFromLayers({
12796
12919
  ...args,
12920
+ generator,
12797
12921
  // `.length(2)` makes each region span a pair, which its inferred
12798
12922
  // `number[]` cannot say.
12799
12923
  patches: args.patches,
@@ -12827,7 +12951,7 @@ function createIkiMcpServer() {
12827
12951
  server.registerTool(
12828
12952
  "compose_layers_from_parts",
12829
12953
  {
12830
- description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair), hair_side (one hair_side.png makes the hair_side_L/hair_side_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). The hair_side.png is the front side lock on the screen LEFT, hanging beside the ear with its root at the image's top: hair_side_R is as drawn and hair_side_L mirrored, both drawn over the face, brows and lashes and under hair_front, and without the file both are listed in `skipped`. One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge, and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
12954
+ description: "Composes AI-generated part PNGs into canvas-aligned, role-named PNG layers on disk, ready for auto_rig_from_layers (the eyewhite split, alpha-trim/white-key, and placement pipeline the character-generation skill needs), with the same geometry report measure_layers returns standalone included inline. face, eyewhite, iris, brow, hair_front are required, with mouth.png \u2014 or the lip set's mouth_keyed.png (the open mouth, its inside painted flat #00FF00) + mouth_interior.png (the cavity, teeth and tongue alone), which the composer keys and splits into mouth_inner / lip_lower / lip_upper on one frame so auto_rig_from_layers folds the mouth open like the eyelid, the interior's light paint (luma 100 and over) written as mouth_tongue and mouth_teeth on the same frame, riding the opening's bottom and the upper line and clipped to the cavity (listed in `skipped` when the interior has none); the two routes cannot be mixed, one keyed file without the other is refused, and a key that fails (no green, green outside the opening, an outline not closed round it, more than one opening, no skin under the opening, an interior that is only lips, or one drawn opaque on a non-white or noisy ground) is refused naming the regeneration; with the lip set neither mouth nor mouth_open is written and preview.png shows the mouth closed, as the rig draws the rest pose. hair_back, body, mouth_open (legacy route only), blush (one blush.png makes the blush_L/blush_R pair), hair_side (one hair_side.png makes the hair_side_L/hair_side_R pair) and nose are optional \u2014 without a nose layer the head still turns on the rig's default profile, but it has no nose to lead the turn, and `auto_rig_from_layers` fits no turn to the art (`turnTargets` is inert, no `turn` report). The hair_side.png is the front side lock on the screen LEFT, hanging beside the ear with its root at the image's top: hair_side_R is as drawn and hair_side_L mirrored, both drawn over the face, brows and lashes and under hair_front, and without the file both are listed in `skipped`. One arm.png \u2014 the arm on the screen LEFT, drawn hanging with its shoulder at the top \u2014 makes both arms of a full body: arm_R takes it as drawn and arm_L mirrored. The arms are opt-in: without arm.png the compose is a bust's and `skipped` never lists them. arm.png needs body.png, and each arm is hung on the body's shoulder by default (see `layout`). One forearm_pose.png \u2014 the arm's forearm raised, on the screen LEFT, standing up from its elbow with the hand at the top \u2014 makes both pose forearms (forearm_pose_R as drawn, forearm_pose_L mirrored): each is scaled so its elbow end is as wide as its arm's elbow run and pinned on that arm's elbow (see `layout`), and it needs arm.png. With one, preview-pose.png shows the switch at 1 as the rig draws it (the hanging forearms hidden below the elbow, the pose forearms over everything) while preview.png stays the rest pose; without one it is removed. The inline report carries the full-body checks too: a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge (with both readings \u2014 a neck, or shoulders over a wider garment \u2014 when its pivot row is much narrower than the body below it), and a pose forearm without its arm or off its arm's elbow in pivot, width or length. A nose whose dense core is a speck \u2014 under a quarter of its trimmed part's width or height, such as a lone nostril mark or highlight \u2014 is sized and placed whole, and the inline report warns of it. A light mark drawn detached above the eye white, such as a double-eyelid crease, is dropped from the sclera (the iris's clip); dark strokes there stay lash ink. The eyewhite's dark lower lid \u2014 its line and lashes \u2014 becomes lash_lower_L/lash_lower_R, drawn over the iris; a white with none writes none and lists them in `skipped`.",
12831
12955
  inputSchema: {
12832
12956
  partsDir: import_zod.z.string().describe(
12833
12957
  "Directory of the source part PNGs (resolved against cwd)."
@@ -12875,7 +12999,7 @@ function createIkiMcpServer() {
12875
12999
  server.registerTool(
12876
13000
  "measure_layers",
12877
13001
  {
12878
- description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row, a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, a front side lock without hair_front, one whose top row shows past the bangs at rest, one covering the eye white's outer corner at rest, one whose lean on the turn away from it would bare columns neither hair_back nor the face paints, a hair_side.png drawing two locks, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
13002
+ description: "Reports read-only geometry checks over an already-composed layers directory \u2014 the same checks compose_layers_from_parts returns inline (iris ratio/offset, eye aspect, cropped/cut edges, a nose whose dense core is a speck of its crop, missing optional roles, a body whose feet a tall canvas's bottom cuts off, an arm without a body, an arm whose shoulder cap does not reach under the torso's edge on its shoulder pivot's row (with both readings \u2014 a neck, or shoulders over a wider garment \u2014 when that row is much narrower than the body below it), a pose forearm without its arm or whose elbow end is off its arm's elbow in pivot, width or length, a front side lock without hair_front, one whose top row shows past the bangs at rest, one covering the eye white's outer corner at rest, one whose lean on the turn away from it would bare columns neither hair_back nor the face paints, a hair_side.png drawing two locks, and the lip set: a partial one or one beside mouth/mouth_open, the fold's contract per column of the opening, an opening too narrow or short, a line too thin, green left, an interior with holes, and of mouth_tongue/mouth_teeth: one with no lip set, one on another canvas, one whose box leaves mouth_inner's \u2014 with the opening's size and the MouthOpen below which no slit shows). Every preview*.png is skipped. Use to re-check a layers dir without recomposing. Its nose check reads the composed file against its crop, which is what auto_rig_from_layers acts on. Compose's inline report does the same unless the composer found the source part's core a speck, which it reports instead \u2014 so a speck that resampling erased from the layer shows there and not here.",
12879
13003
  inputSchema: {
12880
13004
  layersDir: import_zod.z.string().describe(
12881
13005
  "Directory of role-named layer PNGs (resolved against cwd)."