@ikijs/mcp 0.11.3 → 0.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/README.md +4 -3
- package/dist/{chunk-CFP3KTDY.mjs → chunk-EY3AMMEG.mjs} +31 -15
- package/dist/chunk-EY3AMMEG.mjs.map +1 -0
- package/dist/cli.js +30 -14
- package/dist/cli.js.map +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.d.mts +4 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.js +30 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/package.json +2 -2
- package/dist/chunk-CFP3KTDY.mjs.map +0 -1
package/README.md
CHANGED
|
@@ -22,8 +22,9 @@ Turns a set of role-named, full-canvas transparent PNG layers into a renderable,
|
|
|
22
22
|
|
|
23
23
|
- **`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`, etc. All layers must share the same canvas size (taken from the first layer).
|
|
24
24
|
- **`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`.
|
|
25
|
-
- **`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
|
|
26
|
-
-
|
|
25
|
+
- **`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 Live2D 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`.
|
|
26
|
+
- **`style`** — optional per-character tuning from the Live2D profile, only where the Live2D samples themselves disagree: `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.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.58) and `sway` (the hair sway amplitude, 0..5). A value out of range, or a knob not named here, is refused.
|
|
27
|
+
- **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`.
|
|
27
28
|
|
|
28
29
|
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.
|
|
29
30
|
|
|
@@ -31,7 +32,7 @@ The decode/atlas pipeline runs in Node via `sharp` (a native dependency confined
|
|
|
31
32
|
|
|
32
33
|
Composes a directory of AI-generated part PNGs into canvas-aligned, role-named layer PNGs ready for `auto_rig_from_layers`, on a fixed 1100×1100 canvas with a built-in default layout tuned for the character-generation skill's standard front-facing framing. It ports the composer that shipped as a script (`compose.cjs`) in the Claude Code plugin.
|
|
33
34
|
|
|
34
|
-
- **`partsDir`** — directory of the source part PNGs (resolved against the server's working directory). Required sources: `face.png`, `eyewhite.png` (split into the sclera + lash layers), `iris.png`, `mouth.png`, `brow.png`, `hair_front.png`. Optional: `hair_back.png`, `body.png`, `mouth_open.png`, `nose.png` — a parts dir without them still composes, minus those roles. The nose is what the auto-rig leads the head turn with
|
|
35
|
+
- **`partsDir`** — directory of the source part PNGs (resolved against the server's working directory). Required sources: `face.png`, `eyewhite.png` (split into the sclera + lash layers), `iris.png`, `mouth.png`, `brow.png`, `hair_front.png`. Optional: `hair_back.png`, `body.png`, `mouth_open.png`, `nose.png` — a parts dir without them still composes, minus those roles. The nose is what the auto-rig leads the head turn with, and a face supplied alongside it must be drawn without one, or the painted nose stays on the face plate while the real one moves.
|
|
35
36
|
- **`outDir`** — an existing directory (resolved against the working directory, confined to it exactly like `auto_rig_from_layers`'s `outputPath`; the tool never creates directories) to write the role layer PNGs and a flattened `preview.png` into. Reusing a directory across runs is intentional — a role this run skips (e.g. composing a head-only set that omits `body`) has its stale `<role>.png` from an earlier run deleted, so the directory always holds exactly this run's roles.
|
|
36
37
|
- **`layout`** — optional per-role override merged over the built-in defaults, e.g. `{ "eye_L": { "cx": 660 } }`, so a character can be retuned by re-running compose rather than editing a script. Each of `cx`, `cy`, `w`, `h` is optional; `w` and `h` must be integers in 1..1100 (the canvas size). Omitting `h` keeps the part's own aspect ratio, which is what every role wants until one does not: a generated eyewhite often comes back flatter than its reference, and stretching a flat white lens costs nothing where regenerating it is billed and unreliable. The nose is sized and placed by its dense core — its pixels at alpha ≥ 128, the drawing a viewer reads inside a soft nose's feather — rather than its whole part, which for a shaded-bump nose is mostly feather: `w` (default 40) and `h` size the core, `cx` (default 550) centres it, and a set `cy` centres its rows. By default its `cy` is unset, and the core's bottom row (the tip) lands 0.86 of the way from the eye row down to the mouth's, so the nose follows a retuned eye or mouth row. A nose with no pixel at alpha ≥ 128 is sized and placed whole, and so is one whose core is a speck of its trimmed part — under a quarter of its width or height, such as a lone nostril mark or highlight, which sized to `w` would blow the whole nose up — and the report warns of the speck. Set `h` on a sclera and its lash together — they share one frame, and the blink fold tears if they diverge, so a pair set to land on different frames is rejected.
|
|
37
38
|
- **`mirrorParts`** — optional list of part files to flip left-right as they are read, e.g. `["eyewhite.png"]`. Which way a part faces is fixed by the layout, and "left eye" cannot pin it down — it reads as the viewer's left or the character's — so in image terms: `eyewhite.png` is read as the eye on the screen left, lash wing (outer corner) at the image's left end and lash-free tear duct at its right; `brow.png` as the brow on the screen right, thick head at the image's left end and tail at its right. A part drawn the other way round is fixed here for free instead of regenerated. It flips the source, so every role cut from it flips together and an eye's sclera and lash stay in one frame.
|
|
@@ -392,6 +392,17 @@ async function autoRigFromLayers(input) {
|
|
|
392
392
|
`quantizeColors must be an integer in 2..256, got ${String(quantizeColors)}`
|
|
393
393
|
);
|
|
394
394
|
}
|
|
395
|
+
const turnTargets = input.turnTargets;
|
|
396
|
+
if (turnTargets !== void 0) {
|
|
397
|
+
if (typeof turnTargets !== "object" || turnTargets === null || Array.isArray(turnTargets)) {
|
|
398
|
+
throw new AutoRigInputError("turnTargets must be a plain object");
|
|
399
|
+
}
|
|
400
|
+
if (turnTargets.headHalfWidth !== void 0) {
|
|
401
|
+
throw new AutoRigInputError(
|
|
402
|
+
"turnTargets.headHalfWidth is measured off the layers, not accepted as input"
|
|
403
|
+
);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
395
406
|
const resolvedLayers = layers.map((layer) => {
|
|
396
407
|
const resolved = resolveInputPath(layer.path);
|
|
397
408
|
return { resolved, fileName: layer.fileName ?? path2.basename(resolved) };
|
|
@@ -457,22 +468,18 @@ async function autoRigFromLayers(input) {
|
|
|
457
468
|
let turn;
|
|
458
469
|
let model;
|
|
459
470
|
try {
|
|
460
|
-
const { eyeShift, farEyeRatio, silhouetteRatio, noseShift, mouthShift } = input.turnTargets ?? {};
|
|
461
471
|
model = generateIkiFromLayerSet(
|
|
462
472
|
measurement.layers,
|
|
463
473
|
{ width: canvasW, height: canvasH },
|
|
464
474
|
{
|
|
465
475
|
turnTargets: {
|
|
466
|
-
|
|
467
|
-
farEyeRatio,
|
|
468
|
-
silhouetteRatio,
|
|
469
|
-
noseShift,
|
|
470
|
-
mouthShift,
|
|
476
|
+
...input.turnTargets,
|
|
471
477
|
...turnOptions.turnTargets
|
|
472
478
|
},
|
|
473
479
|
onTurnSolved: (report) => {
|
|
474
480
|
turn = report;
|
|
475
481
|
},
|
|
482
|
+
...input.style === void 0 ? {} : { style: input.style },
|
|
476
483
|
...headEdges === void 0 ? {} : { headEdges },
|
|
477
484
|
...strandEdges === void 0 ? {} : { strandEdges }
|
|
478
485
|
}
|
|
@@ -1143,7 +1150,7 @@ async function measureDir(absDir, noseSpeck) {
|
|
|
1143
1150
|
["hair_back", "without it the silhouette is flat behind the face"],
|
|
1144
1151
|
[
|
|
1145
1152
|
"nose",
|
|
1146
|
-
"without it
|
|
1153
|
+
"without it the head still turns on the Live2D profile, but there is no nose to lead it, and no turn fit to the art (`turnTargets` is inert, no `turn` report)"
|
|
1147
1154
|
]
|
|
1148
1155
|
]) {
|
|
1149
1156
|
if (layers[role] === void 0) warnings.push(`${role}: missing \u2014 ${why}.`);
|
|
@@ -1206,9 +1213,8 @@ var DEFAULT_LAYOUT = {
|
|
|
1206
1213
|
// Back hair and body sit behind the face. Both are OPTIONAL: a parts dir
|
|
1207
1214
|
// without them still composes (head-only character).
|
|
1208
1215
|
hair_back: { src: "hair_back.png", cx: 550, cy: 523, w: 800, optional: true },
|
|
1209
|
-
// The torso, cut off by the canvas bottom
|
|
1210
|
-
//
|
|
1211
|
-
// not a floating head.
|
|
1216
|
+
// The torso, cut off by the canvas bottom, so the character is not a
|
|
1217
|
+
// floating head. It rides its own `bodyDeformer`, which only breathes.
|
|
1212
1218
|
body: { src: "body.png", cx: 550, cy: 1017, w: 840, optional: true },
|
|
1213
1219
|
face: { src: "face.png", cx: 550, cy: 475, w: 400 },
|
|
1214
1220
|
// The nose, drawn on its own (the face is drawn without one): the auto-rig
|
|
@@ -1591,7 +1597,7 @@ async function composeLayersFromParts(input) {
|
|
|
1591
1597
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
1592
1598
|
import { z } from "zod";
|
|
1593
1599
|
function createIkiMcpServer() {
|
|
1594
|
-
const server = new McpServer({ name: "iki", version: "0.
|
|
1600
|
+
const server = new McpServer({ name: "iki", version: "0.12.1" });
|
|
1595
1601
|
server.registerTool(
|
|
1596
1602
|
"validate_iki",
|
|
1597
1603
|
{
|
|
@@ -1678,8 +1684,18 @@ function createIkiMcpServer() {
|
|
|
1678
1684
|
silhouetteRatio: z.number().optional(),
|
|
1679
1685
|
noseShift: z.number().optional(),
|
|
1680
1686
|
mouthShift: z.number().optional()
|
|
1681
|
-
}).optional().describe(
|
|
1682
|
-
"What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift
|
|
1687
|
+
}).passthrough().optional().describe(
|
|
1688
|
+
"What the head turn is fitted to, as `measure_turn_reference` reports it off a front/turned reference pair. `eyeShift` (and the optional `noseShift`/`mouthShift`) is how far that feature slides across the head at full turn, as a fraction of the head's half-width \u2014 a MAGNITUDE: the rig turns both ways, so the sign is ignored. `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. The half-width the shifts are fractions of is measured off the layers themselves, so it is not an input. An omitted field leaves that part of the turn at the Live2D profile the rig defaults to. A passed `eyeShift` is fitted by the turn's amount and clamped to the room the art leaves the far eye \u2014 the face plate's edge, or the bangs' side strand over the far iris (the result's `turn.clamped` lists every clamped field, `turn.achieved` what the rig reaches, and `turn.strandOverlap` how much of a far iris the bangs still cover). Any other passed target this layer set cannot reach comes back as `INVALID: \u2026` naming the field and the attainable range, since it is a measurement rather than a preference. A field not named here is refused the same way."
|
|
1689
|
+
),
|
|
1690
|
+
style: z.object({
|
|
1691
|
+
turn: z.number().optional(),
|
|
1692
|
+
featureLead: z.number().optional(),
|
|
1693
|
+
hairFollow: z.number().optional(),
|
|
1694
|
+
outlineFollow: z.number().optional(),
|
|
1695
|
+
blink: z.number().optional(),
|
|
1696
|
+
sway: z.number().optional()
|
|
1697
|
+
}).passthrough().optional().describe(
|
|
1698
|
+
"Per-character tuning from the Live2D profile the rig defaults to \u2014 only what the Live2D samples themselves disagree on: `turn` scales the whole head turn (plate, features, hair and the eyes' foreshortening; 0..3, 1 = the profile; ignored when `turnTargets.eyeShift` is given), `featureLead` how far the features lead the face plate (0..3, 1 = the profile), `hairFollow` the front hair's share of the face's turn (0..2, profile 1.1), `outlineFollow` its outer edge's share where the front hair 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.58), `sway` the hair sway amplitude (0..5, 1 = the profile). A value out of range, or a knob not named here, comes back as `INVALID: \u2026`."
|
|
1683
1699
|
)
|
|
1684
1700
|
}
|
|
1685
1701
|
},
|
|
@@ -1701,7 +1717,7 @@ function createIkiMcpServer() {
|
|
|
1701
1717
|
server.registerTool(
|
|
1702
1718
|
"compose_layers_from_parts",
|
|
1703
1719
|
{
|
|
1704
|
-
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, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open, nose are optional \u2014 without a nose layer the rig
|
|
1720
|
+
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, mouth, eyewhite, iris, brow, hair_front are required; hair_back, body, mouth_open, nose are optional \u2014 without a nose layer the head still turns on the rig's Live2D 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). 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.",
|
|
1705
1721
|
inputSchema: {
|
|
1706
1722
|
partsDir: z.string().describe(
|
|
1707
1723
|
"Directory of the source part PNGs (resolved against cwd)."
|
|
@@ -1823,4 +1839,4 @@ export {
|
|
|
1823
1839
|
composeLayersFromParts,
|
|
1824
1840
|
createIkiMcpServer
|
|
1825
1841
|
};
|
|
1826
|
-
//# sourceMappingURL=chunk-
|
|
1842
|
+
//# sourceMappingURL=chunk-EY3AMMEG.mjs.map
|