@ikijs/mcp 0.17.2 → 0.18.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/README.md CHANGED
@@ -22,11 +22,11 @@ The `model` input for `validate_iki` and `describe_iki` accepts either a plain J
22
22
 
23
23
  Turns a set of role-named, full-canvas transparent PNG layers into a renderable, validated `.iki` model with the textures atlased and embedded as a base64 `data:image/png` URI. Under `quantizeColors` a `nose` layer is the exception: the palette rims a soft-shaded nose's feather, so the nose is atlased alone on a second, lossless page. The written model declares the head motions Nod, Shake and Tilt and up to six default expressions (smile, laugh, angry, sad, surprised, shy; `shy` needs a blush, `angry` and `sad` need brows), each with a description a host picks by; with a `blush_L`/`blush_R` layer it also declares `ParamCheek`, which fades the blush from faint at rest to as drawn.
24
24
 
25
- - **`layers`** — array of `{ path, fileName? }`. `path` is a PNG file path (resolved against the server's working directory); the role is derived from `fileName ?? basename(path)`. Required roles: `face`, `eye_L`, `eye_R`, `mouth`. Optional roles include `iris_L`/`iris_R`, `brow_L`/`brow_R`, `hair_front`/`hair_back`, `lash_L`/`lash_R`, `lash_lower_L`/`lash_lower_R`, etc. All layers must share the same canvas size (taken from the first layer).
25
+ - **`layers`** — array of `{ path, fileName? }`. `path` is a PNG file path (resolved against the server's working directory); the role is derived from `fileName ?? basename(path)`. Required roles: `face`, `eye_L`, `eye_R`, `mouth`. Optional roles include `iris_L`/`iris_R`, `brow_L`/`brow_R`, `hair_front`/`hair_back`, `lash_L`/`lash_R`, `lash_lower_L`/`lash_lower_R`, `body`, `arm_L`/`arm_R`, etc. An arm — the whole arm drawn hanging, its shoulder at the top — needs the `body` (it hangs from the body's shoulder) and becomes an upper arm and a forearm sharing its crop, on `ParamArmL/R` (the shoulder) and `ParamElbowL/R`. All layers must share the same canvas size (taken from the first layer).
26
26
  - **`outputPath`** — optional `.iki` output path (resolved against the working directory; the parent directory must already exist, and the path must end in `.iki`). Defaults to `auto-rigged-model.iki`.
27
27
  - **`turnTargets`** — optional head-turn cues to fit the rig to, in the units `measure_turn_reference` reports off a front/turned reference pair: `eyeShift` (plus `noseShift` and `mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width — a **magnitude**, since the rig turns both ways and the sign is the turn's own business; `farEyeRatio` is the far/near eye width at full turn over that same ratio at rest; `silhouetteRatio` the head's half-width turned over at rest. An omitted field leaves that part of the turn at the profile the rig defaults to. An `eyeShift` you pass is fitted by the turn's amount and _clamped_ when it runs past the room the art leaves the far eye — the face plate's edge, or the bangs' side strand over the far iris — since that room is a fact about these layers, not about the reference. Any other target you **do** pass that it cannot reach is refused, because that number is a measurement rather than a preference. A layer set without a `nose` still turns its head, on the profile, but fits no target: `turnTargets` is then inert and the result carries no `turn`.
28
28
  - **`style`** — optional per-character tuning from the profile the rig defaults to: `turn` (the whole head turn, the eyes' foreshortening with it, 0..3, 1 = the profile; ignored when `turnTargets.eyeShift` is given), `featureLead` (how far the features lead the face plate, 0..3), `hairFollow` (the front hair's share of the face's turn, 0..2, profile 1), `outlineFollow` (its outer edge's share where it draws the head's outline, 0..2, profile 0: the outline holds), `blink` (how far the upper lid comes down over the eye's height, 0.1..1, profile 0.6) and `sway` (the hair sway amplitude, 0..5). A value out of range, or a knob not named here, is refused.
29
- - **Result** — on success the result text is the written file path and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn? }`. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `headHalfWidth` is the head measured here rather than asked for: the layers' own opaque union at the eye row, under the same `alpha >= 128` rule and ±10-row band `measure_turn_reference` spans a render with, so the rig's own rest render measures that span back; it is **absent** when that union has no span there at all (translucent art painted below alpha 128 — still a valid layer set, just with nothing to measure). `headHalfWidthApplied` is `false` when the measured value is absent, or no wider than the face plate (a hairless set, or one widest at the plate itself) — the generator will not take such a head, so the plate stands in for it and the rig is still produced either way. `headEdges` is a companion to a measured, applied `headHalfWidth` (absent otherwise): every role with an opaque pixel in that same eye-row band, per side, each with its own rest x there — passed straight to the generator's own `options.headEdges` so it can tell which part's own deformation actually carries the union's outermost pixel through the turn. `strandEdges` is each side's iris and the `hair_front` run it would slide under on the turn, measured whenever the layers include `hair_front`, `iris_L` and `iris_R`: the iris's opaque span and the run's outer and face-side ends as pixel edges on the row holding the iris's centre (a run that reaches the other iris's centre, a fringe spanning the face, has `runFace: null`; a run narrower than half the iris's painted width on that row is hair detail the iris may cross, and is skipped as if clear) — passed straight to the generator's own `options.strandEdges`, which keeps the far iris from sliding under the bangs any further than it is painted. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped, strandOverlap? }`, where `achieved` is what the rig does reach and `clamped` names every target the rig cut down: the turn (`eyeShift`, passed or the profile's own) where the face plate's edge or the strand cut it short, and a profile `noseShift` / `mouthShift` past its room. `strandOverlap` gives, per side whose far iris the bangs still cover at some far stop, the covered width — how much of the iris's painted row the run covers where that is largest (`deg`, `px`, and `hh` in head half-widths), how much it covers at rest (`restPx`), and whether the bound held (`held`: `true` means the iris is kept no deeper under the run than it is painted; `false` means the art left no room to — always so for a fringe spanning the face — and `px` is what stays covered); it is absent when nothing is covered. `noseCore` is the nose's dense core in canvas px — its pixels at alpha >= 128, not grown, the box handed to the generator as the nose layer's `denseCore` and its turn landmark — absent without a `nose` layer, when it has no pixel at that threshold (painted wholly translucent), or when that core is a speck of the nose's crop (under a quarter of its width or height, such as a lone nostril mark), and in both of the last two cases the crop stands in for it. `turn` is absent without a `nose` layer. The (potentially multi-MB) model is written to disk, not inlined. Invalid input (unknown/missing role, empty layer, mismatched sizes, bad path, oversized atlas, a `turnTargets` field that is unknown or that this layer set cannot reach — any passed field other than an `eyeShift` past the art's room; a `style` knob out of range or unknown; the message names the field and the attainable range) returns `{ ok: false, error }` with a `INVALID: …` text — not a protocol error. An argument the tool's input schema refuses — a `turnTargets` or `style` that is not an object, or one of their named fields that is not a number — never reaches the tool: the MCP SDK answers with an `isError` result whose text is `MCP error -32602: Input validation error: …`, and no `structuredContent`.
29
+ - **Result** — on success the result text is the written file path and `structuredContent` carries `{ ok: true, path, canvas, partCount, atlasBytes, headHalfWidth?, headHalfWidthApplied, headEdges?, strandEdges?, noseCore?, turn? }`. `atlasBytes` is the embedded atlas's data-URI length, summed over both pages when the nose has one of its own. `headHalfWidth` is the head measured here rather than asked for: the layers' own opaque union at the eye row, under the same `alpha >= 128` rule and ±10-row band `measure_turn_reference` spans a render with, so the rig's own rest render measures that span back; it is **absent** when that union has no span there at all (translucent art painted below alpha 128 — still a valid layer set, just with nothing to measure). `headHalfWidthApplied` is `false` when the measured value is absent, or no wider than the face plate (a hairless set, or one widest at the plate itself) — the generator will not take such a head, so the plate stands in for it and the rig is still produced either way. `headEdges` is a companion to a measured, applied `headHalfWidth` (absent otherwise): every role with an opaque pixel in that same eye-row band, per side, each with its own rest x there — passed straight to the generator's own `options.headEdges` so it can tell which part's own deformation actually carries the union's outermost pixel through the turn. `strandEdges` is each side's iris and the `hair_front` run it would slide under on the turn, measured whenever the layers include `hair_front`, `iris_L` and `iris_R`: the iris's opaque span and the run's outer and face-side ends as pixel edges on the row holding the iris's centre (a run that reaches the other iris's centre, a fringe spanning the face, has `runFace: null`; a run narrower than half the iris's painted width on that row is hair detail the iris may cross, and is skipped as if clear) — passed straight to the generator's own `options.strandEdges`, which keeps the far iris from sliding under the bangs any further than it is painted. `turn` is what the solve settled on — `{ radius, holdBase, depths, achieved: { eyeShift, farEyeRatio, silhouetteRatio }, clamped, strandOverlap? }`, where `achieved` is what the rig does reach and `clamped` names every target the rig cut down: the turn (`eyeShift`, passed or the profile's own) where the face plate's edge or the strand cut it short, and a profile `noseShift` / `mouthShift` past its room. `strandOverlap` gives, per side whose far iris the bangs still cover at some far stop, the covered width — how much of the iris's painted row the run covers where that is largest (`deg`, `px`, and `hh` in head half-widths), how much it covers at rest (`restPx`), and whether the bound held (`held`: `true` means the iris is kept no deeper under the run than it is painted; `false` means the art left no room to — always so for a fringe spanning the face — and `px` is what stays covered); it is absent when nothing is covered. `noseCore` is the nose's dense core in canvas px — its pixels at alpha >= 128, not grown, the box handed to the generator as the nose layer's `denseCore` and its turn landmark — absent without a `nose` layer, when it has no pixel at that threshold (painted wholly translucent), or when that core is a speck of the nose's crop (under a quarter of its width or height, such as a lone nostril mark), and in both of the last two cases the crop stands in for it. `turn` is absent without a `nose` layer. The (potentially multi-MB) model is written to disk, not inlined. Invalid input (unknown/missing role, an arm without a `body`, empty layer, mismatched sizes, bad path, oversized atlas; art the rig cannot build on, such as a body's hips with no room under its pivots for a row line or for the body's motion, or an arm too short to hang an elbow under its shoulder; a `turnTargets` field that is unknown or that this layer set cannot reach — any passed field other than an `eyeShift` past the art's room; a `style` knob out of range or unknown; the message names the field and the attainable range) returns `{ ok: false, error }` with a `INVALID: …` text — not a protocol error. An argument the tool's input schema refuses — a `turnTargets` or `style` that is not an object, or one of their named fields that is not a number — never reaches the tool: the MCP SDK answers with an `isError` result whose text is `MCP error -32602: Input validation error: …`, and no `structuredContent`.
30
30
 
31
31
  The decode/atlas pipeline runs in Node via `sharp` (a native dependency confined to this package); it mirrors the browser editor app's import flow and reuses the pure `@ikijs/editor` model + atlas math, so both paths produce the same rig.
32
32
 
@@ -13,6 +13,8 @@ import {
13
13
  createLayerSetMeasurer,
14
14
  generateIkiFromLayerSet,
15
15
  parseLayerRoles,
16
+ partIdsOfRole,
17
+ LayerGeometryError,
16
18
  TurnTargetError
17
19
  } from "@ikijs/editor";
18
20
 
@@ -330,6 +332,18 @@ var STANDARD_PARAMETER_INFO = [
330
332
  id: StandardParameter.AngleZ,
331
333
  description: "Head tilt / roll degrees; positive tilts the top of the head toward the viewer's right (clockwise), as in Live2D."
332
334
  },
335
+ {
336
+ id: StandardParameter.BodyAngleX,
337
+ description: "Body turn, degrees (-10 .. 10); positive turns the body toward the viewer's right, as AngleX does the head."
338
+ },
339
+ {
340
+ id: StandardParameter.BodyAngleY,
341
+ description: "Body lean, degrees (-10 .. 10); positive moves the upper body up, negative bows."
342
+ },
343
+ {
344
+ id: StandardParameter.BodyAngleZ,
345
+ description: "Body tilt, degrees (-10 .. 10); positive tilts the top toward the viewer's right (clockwise), as AngleZ does the head."
346
+ },
333
347
  {
334
348
  id: StandardParameter.Breath,
335
349
  description: "Idle breath (0 .. 1), cycled by the host."
@@ -361,6 +375,22 @@ var STANDARD_PARAMETER_INFO = [
361
375
  {
362
376
  id: StandardParameter.HairSwayZ,
363
377
  description: "Hair-sway driver behind a head tilt. Physics OUTPUT \u2014 driven by the spring, hosts should not set it directly."
378
+ },
379
+ {
380
+ id: StandardParameter.ArmLeft,
381
+ description: "Left shoulder, degrees; positive raises the arm outward (mirrored on the right)."
382
+ },
383
+ {
384
+ id: StandardParameter.ArmRight,
385
+ description: "Right shoulder, degrees; positive raises the arm outward (mirrored on the left)."
386
+ },
387
+ {
388
+ id: StandardParameter.ElbowLeft,
389
+ description: "Left elbow, degrees; positive bends the forearm the way positive ArmLeft raises the arm."
390
+ },
391
+ {
392
+ id: StandardParameter.ElbowRight,
393
+ description: "Right elbow, degrees; positive bends the forearm the way positive ArmRight raises the arm."
364
394
  }
365
395
  ];
366
396
  function listStandardParameters() {
@@ -501,7 +531,9 @@ async function autoRigFromLayers(input) {
501
531
  }
502
532
  );
503
533
  } catch (e) {
504
- if (!(e instanceof TurnTargetError)) throw e;
534
+ if (!(e instanceof TurnTargetError || e instanceof LayerGeometryError)) {
535
+ throw e;
536
+ }
505
537
  throw new AutoRigInputError(e.message);
506
538
  }
507
539
  const doc = new EditorDocument(model);
@@ -520,18 +552,16 @@ async function autoRigFromLayers(input) {
520
552
  );
521
553
  }
522
554
  const partTextureAssignments = pages.flatMap(
523
- ({ crops: pageCrops, layout }) => pageCrops.map((crop) => {
555
+ ({ crops: pageCrops, layout }) => pageCrops.flatMap((crop) => {
524
556
  const placement2 = layout.placements.find((p) => p.id === crop.id);
525
557
  if (placement2 === void 0) {
526
558
  throw new Error(`auto-rig: no atlas placement for "${crop.id}"`);
527
559
  }
528
- return {
529
- partId: crop.id,
530
- uv: uvRectFor(placement2, {
531
- width: layout.pageWidth,
532
- height: layout.pageHeight
533
- })
534
- };
560
+ const uv = uvRectFor(placement2, {
561
+ width: layout.pageWidth,
562
+ height: layout.pageHeight
563
+ });
564
+ return partIdsOfRole(crop.id).map((partId) => ({ partId, uv }));
535
565
  })
536
566
  );
537
567
  doc.applyAtlas({
@@ -542,7 +572,9 @@ async function autoRigFromLayers(input) {
542
572
  if (losslessCrop !== void 0) {
543
573
  patched = structuredClone(patched);
544
574
  patched.textures = pages.map((p) => ({ source: p.dataUri }));
545
- patched.parts.find((p) => p.id === losslessCrop.id).texture.index = 1;
575
+ for (const partId of partIdsOfRole(losslessCrop.id)) {
576
+ patched.parts.find((p) => p.id === partId).texture.index = 1;
577
+ }
546
578
  }
547
579
  const finalModel = parseIkiModel(patched);
548
580
  writeFileAtomic(outPath, JSON.stringify(finalModel));
@@ -1233,7 +1265,7 @@ var DEFAULT_LAYOUT = {
1233
1265
  // without them still composes (head-only character).
1234
1266
  hair_back: { src: "hair_back.png", cx: 550, cy: 523, w: 800, optional: true },
1235
1267
  // The torso, cut off by the canvas bottom, so the character is not a
1236
- // floating head. It rides its own `bodyDeformer`, which only breathes.
1268
+ // floating head. It rides the rig's `bodyWarp`, which the head hangs from.
1237
1269
  body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
1238
1270
  // The face is drawn without a neck, so its box is the skull and centres
1239
1271
  // above the eye row (bob's skull at 437 against his eyes' 475).
@@ -1846,7 +1878,7 @@ async function composeLayersFromParts(input) {
1846
1878
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
1847
1879
  import { z } from "zod";
1848
1880
  function createIkiMcpServer() {
1849
- const server = new McpServer({ name: "iki", version: "0.17.2" });
1881
+ const server = new McpServer({ name: "iki", version: "0.18.0" });
1850
1882
  server.registerTool(
1851
1883
  "validate_iki",
1852
1884
  {
@@ -1911,7 +1943,7 @@ function createIkiMcpServer() {
1911
1943
  server.registerTool(
1912
1944
  "auto_rig_from_layers",
1913
1945
  {
1914
- description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R, mouth required; iris_L/R, brow_L/R, hair_front, etc. optional) 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.",
1946
+ description: "Auto-rigs role-named PNG layers (face, eye_L/eye_R, mouth required; iris_L/R, brow_L/R, hair_front, body, arm_L/arm_R, etc. optional; an arm needs the body) 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.",
1915
1947
  inputSchema: {
1916
1948
  layers: z.array(
1917
1949
  z.object({
@@ -2088,4 +2120,4 @@ export {
2088
2120
  composeLayersFromParts,
2089
2121
  createIkiMcpServer
2090
2122
  };
2091
- //# sourceMappingURL=chunk-CUINYKRG.mjs.map
2123
+ //# sourceMappingURL=chunk-JKH44M2Z.mjs.map