@ikijs/mcp 0.38.2 → 0.39.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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");
@@ -4493,6 +4494,7 @@ function describeIki(model) {
4493
4494
  motions,
4494
4495
  bustScale
4495
4496
  };
4497
+ if (m.generator !== void 0) summary.generator = m.generator;
4496
4498
  const face = m.parts.find((p) => p.id === "face");
4497
4499
  if (face !== void 0) summary.faceWidth = face.width;
4498
4500
  return { ok: true, summary };
@@ -4682,6 +4684,14 @@ async function renderAtlasPage(crops, quantizeColors) {
4682
4684
  }
4683
4685
  async function autoRigFromLayers(input) {
4684
4686
  try {
4687
+ if (input.generator !== void 0) {
4688
+ try {
4689
+ (0, import_format11.parseIkiGenerator)(input.generator);
4690
+ } catch (e) {
4691
+ if (e instanceof import_format11.IkiFormatError) throw new AutoRigInputError(e.message);
4692
+ throw e;
4693
+ }
4694
+ }
4685
4695
  const layers = input.layers;
4686
4696
  if (!Array.isArray(layers) || layers.length === 0) {
4687
4697
  throw new AutoRigInputError("layers must be a non-empty array");
@@ -4947,7 +4957,9 @@ async function autoRigFromLayers(input) {
4947
4957
  patched.parts.find((p) => p.id === crop.id).texture.index = pages.length;
4948
4958
  }
4949
4959
  }
4950
- const finalModel = (0, import_format11.parseIkiModel)(patched);
4960
+ const finalModel = (0, import_format11.parseIkiModel)(
4961
+ input.generator === void 0 ? patched : { ...patched, generator: input.generator }
4962
+ );
4951
4963
  const bakes = bakeReports === void 0 ? void 0 : checkBakes(finalModel, bakeReports);
4952
4964
  writeFileAtomic(outPath, JSON.stringify(finalModel));
4953
4965
  const folds = checkModelFolds(finalModel);
@@ -7900,6 +7912,27 @@ async function composeLayersFromParts(input) {
7900
7912
  }
7901
7913
  }
7902
7914
 
7915
+ // src/generator.ts
7916
+ var import_editor15 = require("@ikijs/editor");
7917
+ var import_format12 = require("@ikijs/format");
7918
+ var PLUGIN_ENV = "IKI_PLUGIN";
7919
+ function toolGenerator(env = process.env) {
7920
+ const generator = {
7921
+ tool: `@ikijs/mcp@${"0.39.0"}`,
7922
+ rigger: `@ikijs/editor@${import_editor15.EDITOR_VERSION}`
7923
+ };
7924
+ const plugin = env[PLUGIN_ENV];
7925
+ if (plugin === void 0 || plugin === "") return generator;
7926
+ try {
7927
+ return (0, import_format12.parseIkiGenerator)({ ...generator, plugin });
7928
+ } catch (e) {
7929
+ if (!(e instanceof import_format12.IkiFormatError)) throw e;
7930
+ throw new import_format12.IkiFormatError(
7931
+ `the ${PLUGIN_ENV} environment variable is no label for a model: ${e.message}`
7932
+ );
7933
+ }
7934
+ }
7935
+
7903
7936
  // src/hair-side-report.ts
7904
7937
  function signedPx(px2) {
7905
7938
  const s = px2.toFixed(1);
@@ -11025,7 +11058,7 @@ function cutFeatures(ctx, lipSet = false) {
11025
11058
  }
11026
11059
 
11027
11060
  // src/illustration-landmarks.ts
11028
- var import_editor15 = require("@ikijs/editor");
11061
+ var import_editor16 = require("@ikijs/editor");
11029
11062
  var DEFAULT_BROW_HALF_WIDTH = 8;
11030
11063
  var DEFAULT_BROW_TAIL_HALF_WIDTH = 5;
11031
11064
  var KEYS = {
@@ -11179,11 +11212,11 @@ function brow(path12, v, canvas) {
11179
11212
  tailHalfWidth: o.tailHalfWidth === void 0 ? DEFAULT_BROW_TAIL_HALF_WIDTH : positive(`${path12}.tailHalfWidth`, o.tailHalfWidth)
11180
11213
  };
11181
11214
  }
11182
- var YIELDED_PART_IDS = new Set(ARM_ROLES.flatMap((r) => (0, import_editor15.partIdsOfRole)(r)));
11215
+ var YIELDED_PART_IDS = new Set(ARM_ROLES.flatMap((r) => (0, import_editor16.partIdsOfRole)(r)));
11183
11216
  function isReservedId(id) {
11184
11217
  if (YIELDED_PART_IDS.has(id)) return true;
11185
11218
  try {
11186
- (0, import_editor15.partIdsOfRole)(id);
11219
+ (0, import_editor16.partIdsOfRole)(id);
11187
11220
  return true;
11188
11221
  } catch {
11189
11222
  return false;
@@ -12556,7 +12589,7 @@ function formatBakeChecks(bakes) {
12556
12589
  );
12557
12590
  }
12558
12591
  function createIkiMcpServer() {
12559
- const server = new import_mcp.McpServer({ name: "iki", version: "0.38.2" });
12592
+ const server = new import_mcp.McpServer({ name: "iki", version: "0.39.0" });
12560
12593
  server.registerTool(
12561
12594
  "validate_iki",
12562
12595
  {
@@ -12583,7 +12616,7 @@ function createIkiMcpServer() {
12583
12616
  server.registerTool(
12584
12617
  "describe_iki",
12585
12618
  {
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.",
12619
+ 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
12620
  inputSchema: {
12588
12621
  model: import_zod.z.unknown().optional().describe("Raw .iki model JSON (object or JSON string)"),
12589
12622
  modelPath: import_zod.z.string().optional().describe(
@@ -12648,7 +12681,7 @@ function createIkiMcpServer() {
12648
12681
  server.registerTool(
12649
12682
  "auto_rig_from_layers",
12650
12683
  {
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.",
12684
+ 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
12685
  inputSchema: {
12653
12686
  layers: import_zod.z.array(
12654
12687
  import_zod.z.object({
@@ -12792,8 +12825,19 @@ function createIkiMcpServer() {
12792
12825
  },
12793
12826
  async (args) => {
12794
12827
  try {
12828
+ let generator;
12829
+ try {
12830
+ generator = toolGenerator();
12831
+ } catch (e) {
12832
+ if (!(e instanceof import_format13.IkiFormatError)) throw e;
12833
+ return {
12834
+ content: [{ type: "text", text: `INVALID: ${e.message}` }],
12835
+ structuredContent: { ok: false, error: e.message }
12836
+ };
12837
+ }
12795
12838
  const r = await autoRigFromLayers({
12796
12839
  ...args,
12840
+ generator,
12797
12841
  // `.length(2)` makes each region span a pair, which its inferred
12798
12842
  // `number[]` cannot say.
12799
12843
  patches: args.patches,