@genart-dev/mcp-server 0.2.0 → 0.3.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/index.cjs +670 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +672 -2
- package/dist/index.js.map +1 -1
- package/dist/lib.cjs +675 -6
- package/dist/lib.cjs.map +1 -1
- package/dist/lib.d.cts +26 -2
- package/dist/lib.d.ts +26 -2
- package/dist/lib.js +672 -2
- package/dist/lib.js.map +1 -1
- package/package.json +6 -2
package/dist/index.js
CHANGED
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
parseGenart,
|
|
26
26
|
parseWorkspace,
|
|
27
27
|
serializeGenart,
|
|
28
|
-
serializeWorkspace
|
|
28
|
+
serializeWorkspace,
|
|
29
|
+
createLayerStack
|
|
29
30
|
} from "@genart-dev/core";
|
|
30
31
|
import { writeFile } from "fs/promises";
|
|
31
32
|
var EditorState = class extends EventEmitter {
|
|
@@ -49,6 +50,10 @@ var EditorState = class extends EventEmitter {
|
|
|
49
50
|
* instead of writing to disk. Set by mcp-host for HTTP-based sessions.
|
|
50
51
|
*/
|
|
51
52
|
remoteMode = false;
|
|
53
|
+
/** Plugin registry for design mode. Set during server initialization. */
|
|
54
|
+
pluginRegistry = null;
|
|
55
|
+
/** Layer stacks keyed by sketch ID. Created lazily when design tools are used. */
|
|
56
|
+
layerStacks = /* @__PURE__ */ new Map();
|
|
52
57
|
constructor(options) {
|
|
53
58
|
super();
|
|
54
59
|
if (options?.basePath) {
|
|
@@ -113,6 +118,7 @@ var EditorState = class extends EventEmitter {
|
|
|
113
118
|
this.workspace = ws;
|
|
114
119
|
this.sketches.clear();
|
|
115
120
|
this.selection.clear();
|
|
121
|
+
this.layerStacks.clear();
|
|
116
122
|
for (const ref of ws.sketches) {
|
|
117
123
|
const sketchPath = this.resolveSketchPath(ref.file);
|
|
118
124
|
await this.loadSketch(sketchPath);
|
|
@@ -154,6 +160,7 @@ var EditorState = class extends EventEmitter {
|
|
|
154
160
|
removeSketch(id) {
|
|
155
161
|
this.sketches.delete(id);
|
|
156
162
|
this.selection.delete(id);
|
|
163
|
+
this.layerStacks.delete(id);
|
|
157
164
|
this.emitMutation("sketch:removed", { id });
|
|
158
165
|
}
|
|
159
166
|
/** Save the active workspace to disk. */
|
|
@@ -197,6 +204,81 @@ var EditorState = class extends EventEmitter {
|
|
|
197
204
|
selection: Array.from(this.selection)
|
|
198
205
|
};
|
|
199
206
|
}
|
|
207
|
+
/**
|
|
208
|
+
* Get or create a LayerStackAccessor for a sketch.
|
|
209
|
+
* Initializes from the sketch's persisted design layers.
|
|
210
|
+
*/
|
|
211
|
+
getLayerStack(sketchId) {
|
|
212
|
+
let stack = this.layerStacks.get(sketchId);
|
|
213
|
+
if (stack) return stack;
|
|
214
|
+
const loaded = this.requireSketch(sketchId);
|
|
215
|
+
const initialLayers = loaded.definition.layers ?? [];
|
|
216
|
+
stack = createLayerStack(initialLayers, (changeType) => {
|
|
217
|
+
this.syncLayersToDefinition(sketchId);
|
|
218
|
+
const mutationType = `design:${changeType}`;
|
|
219
|
+
this.emitMutation(mutationType, { sketchId, changeType });
|
|
220
|
+
});
|
|
221
|
+
this.layerStacks.set(sketchId, stack);
|
|
222
|
+
return stack;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Sync the layer stack's current state back to the sketch definition.
|
|
226
|
+
* Called automatically on every layer mutation.
|
|
227
|
+
*/
|
|
228
|
+
syncLayersToDefinition(sketchId) {
|
|
229
|
+
const loaded = this.sketches.get(sketchId);
|
|
230
|
+
const stack = this.layerStacks.get(sketchId);
|
|
231
|
+
if (!loaded || !stack) return;
|
|
232
|
+
const layers = stack.getAll();
|
|
233
|
+
loaded.definition = {
|
|
234
|
+
...loaded.definition,
|
|
235
|
+
layers: layers.length > 0 ? layers : void 0
|
|
236
|
+
};
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Create an McpToolContext for a plugin's MCP tool handler.
|
|
240
|
+
* Provides access to the layer stack, sketch state, and change notifications.
|
|
241
|
+
*/
|
|
242
|
+
createMcpToolContext(sketchId) {
|
|
243
|
+
const loaded = this.requireSketch(sketchId);
|
|
244
|
+
const layerStack = this.getLayerStack(sketchId);
|
|
245
|
+
const def = loaded.definition;
|
|
246
|
+
const sketchState = {
|
|
247
|
+
seed: def.state.seed,
|
|
248
|
+
params: def.state.params,
|
|
249
|
+
colorPalette: def.state.colorPalette,
|
|
250
|
+
canvasWidth: def.canvas.width,
|
|
251
|
+
canvasHeight: def.canvas.height,
|
|
252
|
+
rendererId: def.renderer.type
|
|
253
|
+
};
|
|
254
|
+
return {
|
|
255
|
+
layers: layerStack,
|
|
256
|
+
sketchState,
|
|
257
|
+
canvasWidth: def.canvas.width,
|
|
258
|
+
canvasHeight: def.canvas.height,
|
|
259
|
+
async resolveAsset(_assetId) {
|
|
260
|
+
return null;
|
|
261
|
+
},
|
|
262
|
+
async captureComposite(_format) {
|
|
263
|
+
throw new Error("captureComposite is not available in headless MCP mode");
|
|
264
|
+
},
|
|
265
|
+
emitChange(_changeType) {
|
|
266
|
+
}
|
|
267
|
+
};
|
|
268
|
+
}
|
|
269
|
+
/**
|
|
270
|
+
* Get the currently selected sketch ID for design operations.
|
|
271
|
+
* Returns the single selected sketch, or throws if none/multiple selected.
|
|
272
|
+
*/
|
|
273
|
+
requireSelectedSketchId() {
|
|
274
|
+
if (this.selection.size === 0) {
|
|
275
|
+
throw new Error("No sketch is selected. Use select_sketch or open_sketch first.");
|
|
276
|
+
}
|
|
277
|
+
if (this.selection.size > 1) {
|
|
278
|
+
throw new Error("Multiple sketches are selected. Design operations require a single sketch.");
|
|
279
|
+
}
|
|
280
|
+
return this.selection.values().next().value;
|
|
281
|
+
}
|
|
200
282
|
/** Emit a mutation event for external listeners (WebSocket broadcast, sidecar IPC). */
|
|
201
283
|
emitMutation(type, payload) {
|
|
202
284
|
this.emit("mutation", { type, payload });
|
|
@@ -207,6 +289,11 @@ var EditorState = class extends EventEmitter {
|
|
|
207
289
|
// src/server.ts
|
|
208
290
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
209
291
|
import { z as z2 } from "zod";
|
|
292
|
+
import { createPluginRegistry } from "@genart-dev/core";
|
|
293
|
+
import typographyPlugin from "@genart-dev/plugin-typography";
|
|
294
|
+
import filtersPlugin from "@genart-dev/plugin-filters";
|
|
295
|
+
import shapesPlugin from "@genart-dev/plugin-shapes";
|
|
296
|
+
import layoutGuidesPlugin from "@genart-dev/plugin-layout-guides";
|
|
210
297
|
|
|
211
298
|
// src/tools/workspace.ts
|
|
212
299
|
import { readFile as readFile2, writeFile as writeFile2, stat } from "fs/promises";
|
|
@@ -2881,6 +2968,330 @@ async function exportZip(sketch, input) {
|
|
|
2881
2968
|
};
|
|
2882
2969
|
}
|
|
2883
2970
|
|
|
2971
|
+
// src/tools/design.ts
|
|
2972
|
+
function requireSketchId(state, args) {
|
|
2973
|
+
return args.sketchId ?? state.requireSelectedSketchId();
|
|
2974
|
+
}
|
|
2975
|
+
var BLEND_MODES = [
|
|
2976
|
+
"normal",
|
|
2977
|
+
"multiply",
|
|
2978
|
+
"screen",
|
|
2979
|
+
"overlay",
|
|
2980
|
+
"darken",
|
|
2981
|
+
"lighten",
|
|
2982
|
+
"color-dodge",
|
|
2983
|
+
"color-burn",
|
|
2984
|
+
"hard-light",
|
|
2985
|
+
"soft-light",
|
|
2986
|
+
"difference",
|
|
2987
|
+
"exclusion",
|
|
2988
|
+
"hue",
|
|
2989
|
+
"saturation",
|
|
2990
|
+
"color",
|
|
2991
|
+
"luminosity"
|
|
2992
|
+
];
|
|
2993
|
+
function generateLayerId() {
|
|
2994
|
+
return `layer-${Date.now().toString(36)}-${Math.random().toString(36).slice(2, 8)}`;
|
|
2995
|
+
}
|
|
2996
|
+
async function designAddLayer(state, args) {
|
|
2997
|
+
const sketchId = requireSketchId(state, args);
|
|
2998
|
+
const loaded = state.requireSketch(sketchId);
|
|
2999
|
+
const stack = state.getLayerStack(sketchId);
|
|
3000
|
+
const registry4 = state.pluginRegistry;
|
|
3001
|
+
const layerTypeDef = registry4?.resolveLayerType(args.type);
|
|
3002
|
+
if (!layerTypeDef) {
|
|
3003
|
+
throw new Error(
|
|
3004
|
+
`Unknown layer type: '${args.type}'. Use design_list_layers types from registered plugins.`
|
|
3005
|
+
);
|
|
3006
|
+
}
|
|
3007
|
+
const defaults = layerTypeDef.createDefault();
|
|
3008
|
+
const id = generateLayerId();
|
|
3009
|
+
const { width, height } = loaded.definition.canvas;
|
|
3010
|
+
const layer = {
|
|
3011
|
+
id,
|
|
3012
|
+
type: args.type,
|
|
3013
|
+
name: args.name ?? layerTypeDef.displayName,
|
|
3014
|
+
visible: true,
|
|
3015
|
+
locked: false,
|
|
3016
|
+
opacity: args.opacity ?? 1,
|
|
3017
|
+
blendMode: args.blendMode ?? "normal",
|
|
3018
|
+
transform: {
|
|
3019
|
+
x: 0,
|
|
3020
|
+
y: 0,
|
|
3021
|
+
width,
|
|
3022
|
+
height,
|
|
3023
|
+
rotation: 0,
|
|
3024
|
+
scaleX: 1,
|
|
3025
|
+
scaleY: 1,
|
|
3026
|
+
anchorX: 0.5,
|
|
3027
|
+
anchorY: 0.5,
|
|
3028
|
+
...args.transform
|
|
3029
|
+
},
|
|
3030
|
+
properties: { ...defaults, ...args.properties }
|
|
3031
|
+
};
|
|
3032
|
+
stack.add(layer, args.index);
|
|
3033
|
+
await state.saveSketch(sketchId);
|
|
3034
|
+
return {
|
|
3035
|
+
layerId: id,
|
|
3036
|
+
type: args.type,
|
|
3037
|
+
name: layer.name,
|
|
3038
|
+
index: args.index ?? stack.count - 1,
|
|
3039
|
+
sketchId
|
|
3040
|
+
};
|
|
3041
|
+
}
|
|
3042
|
+
async function designRemoveLayer(state, args) {
|
|
3043
|
+
const sketchId = requireSketchId(state, args);
|
|
3044
|
+
const stack = state.getLayerStack(sketchId);
|
|
3045
|
+
const removed = stack.remove(args.layerId);
|
|
3046
|
+
if (!removed) {
|
|
3047
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3048
|
+
}
|
|
3049
|
+
await state.saveSketch(sketchId);
|
|
3050
|
+
return { removed: true, layerId: args.layerId, sketchId };
|
|
3051
|
+
}
|
|
3052
|
+
async function designListLayers(state, args) {
|
|
3053
|
+
const sketchId = requireSketchId(state, args);
|
|
3054
|
+
const stack = state.getLayerStack(sketchId);
|
|
3055
|
+
const layers = stack.getAll();
|
|
3056
|
+
return {
|
|
3057
|
+
sketchId,
|
|
3058
|
+
count: layers.length,
|
|
3059
|
+
layers: layers.map((l, i) => ({
|
|
3060
|
+
index: i,
|
|
3061
|
+
id: l.id,
|
|
3062
|
+
type: l.type,
|
|
3063
|
+
name: l.name,
|
|
3064
|
+
visible: l.visible,
|
|
3065
|
+
locked: l.locked,
|
|
3066
|
+
opacity: l.opacity,
|
|
3067
|
+
blendMode: l.blendMode
|
|
3068
|
+
}))
|
|
3069
|
+
};
|
|
3070
|
+
}
|
|
3071
|
+
async function designGetLayer(state, args) {
|
|
3072
|
+
const sketchId = requireSketchId(state, args);
|
|
3073
|
+
const stack = state.getLayerStack(sketchId);
|
|
3074
|
+
const layer = stack.get(args.layerId);
|
|
3075
|
+
if (!layer) {
|
|
3076
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3077
|
+
}
|
|
3078
|
+
return {
|
|
3079
|
+
sketchId,
|
|
3080
|
+
layer: {
|
|
3081
|
+
id: layer.id,
|
|
3082
|
+
type: layer.type,
|
|
3083
|
+
name: layer.name,
|
|
3084
|
+
visible: layer.visible,
|
|
3085
|
+
locked: layer.locked,
|
|
3086
|
+
opacity: layer.opacity,
|
|
3087
|
+
blendMode: layer.blendMode,
|
|
3088
|
+
transform: layer.transform,
|
|
3089
|
+
properties: layer.properties
|
|
3090
|
+
}
|
|
3091
|
+
};
|
|
3092
|
+
}
|
|
3093
|
+
async function designUpdateLayer(state, args) {
|
|
3094
|
+
const sketchId = requireSketchId(state, args);
|
|
3095
|
+
const stack = state.getLayerStack(sketchId);
|
|
3096
|
+
const layer = stack.get(args.layerId);
|
|
3097
|
+
if (!layer) {
|
|
3098
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3099
|
+
}
|
|
3100
|
+
const updates = {};
|
|
3101
|
+
if (args.properties) {
|
|
3102
|
+
Object.assign(updates, args.properties);
|
|
3103
|
+
}
|
|
3104
|
+
if (Object.keys(updates).length > 0) {
|
|
3105
|
+
stack.updateProperties(args.layerId, updates);
|
|
3106
|
+
}
|
|
3107
|
+
if (args.name !== void 0) {
|
|
3108
|
+
const current = stack.get(args.layerId);
|
|
3109
|
+
stack.updateProperties(args.layerId, { ...current.properties });
|
|
3110
|
+
const mutableLayer = stack.get(args.layerId);
|
|
3111
|
+
mutableLayer.name = args.name;
|
|
3112
|
+
}
|
|
3113
|
+
await state.saveSketch(sketchId);
|
|
3114
|
+
return { updated: true, layerId: args.layerId, sketchId };
|
|
3115
|
+
}
|
|
3116
|
+
async function designSetTransform(state, args) {
|
|
3117
|
+
const sketchId = requireSketchId(state, args);
|
|
3118
|
+
const stack = state.getLayerStack(sketchId);
|
|
3119
|
+
const layer = stack.get(args.layerId);
|
|
3120
|
+
if (!layer) {
|
|
3121
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3122
|
+
}
|
|
3123
|
+
const partial = {};
|
|
3124
|
+
if (args.x !== void 0) partial.x = args.x;
|
|
3125
|
+
if (args.y !== void 0) partial.y = args.y;
|
|
3126
|
+
if (args.width !== void 0) partial.width = args.width;
|
|
3127
|
+
if (args.height !== void 0) partial.height = args.height;
|
|
3128
|
+
if (args.rotation !== void 0) partial.rotation = args.rotation;
|
|
3129
|
+
if (args.scaleX !== void 0) partial.scaleX = args.scaleX;
|
|
3130
|
+
if (args.scaleY !== void 0) partial.scaleY = args.scaleY;
|
|
3131
|
+
if (args.anchorX !== void 0) partial.anchorX = args.anchorX;
|
|
3132
|
+
if (args.anchorY !== void 0) partial.anchorY = args.anchorY;
|
|
3133
|
+
stack.updateTransform(args.layerId, partial);
|
|
3134
|
+
await state.saveSketch(sketchId);
|
|
3135
|
+
return {
|
|
3136
|
+
updated: true,
|
|
3137
|
+
layerId: args.layerId,
|
|
3138
|
+
transform: stack.get(args.layerId).transform,
|
|
3139
|
+
sketchId
|
|
3140
|
+
};
|
|
3141
|
+
}
|
|
3142
|
+
async function designSetBlend(state, args) {
|
|
3143
|
+
const sketchId = requireSketchId(state, args);
|
|
3144
|
+
const stack = state.getLayerStack(sketchId);
|
|
3145
|
+
const layer = stack.get(args.layerId);
|
|
3146
|
+
if (!layer) {
|
|
3147
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3148
|
+
}
|
|
3149
|
+
if (args.blendMode && !BLEND_MODES.includes(args.blendMode)) {
|
|
3150
|
+
throw new Error(
|
|
3151
|
+
`Invalid blend mode '${args.blendMode}'. Must be one of: ${BLEND_MODES.join(", ")}`
|
|
3152
|
+
);
|
|
3153
|
+
}
|
|
3154
|
+
stack.updateBlend(
|
|
3155
|
+
args.layerId,
|
|
3156
|
+
args.blendMode,
|
|
3157
|
+
args.opacity
|
|
3158
|
+
);
|
|
3159
|
+
await state.saveSketch(sketchId);
|
|
3160
|
+
const updated = stack.get(args.layerId);
|
|
3161
|
+
return {
|
|
3162
|
+
updated: true,
|
|
3163
|
+
layerId: args.layerId,
|
|
3164
|
+
blendMode: updated.blendMode,
|
|
3165
|
+
opacity: updated.opacity,
|
|
3166
|
+
sketchId
|
|
3167
|
+
};
|
|
3168
|
+
}
|
|
3169
|
+
async function designReorderLayers(state, args) {
|
|
3170
|
+
const sketchId = requireSketchId(state, args);
|
|
3171
|
+
const stack = state.getLayerStack(sketchId);
|
|
3172
|
+
const layer = stack.get(args.layerId);
|
|
3173
|
+
if (!layer) {
|
|
3174
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3175
|
+
}
|
|
3176
|
+
stack.reorder(args.layerId, args.newIndex);
|
|
3177
|
+
await state.saveSketch(sketchId);
|
|
3178
|
+
return {
|
|
3179
|
+
reordered: true,
|
|
3180
|
+
layerId: args.layerId,
|
|
3181
|
+
newIndex: args.newIndex,
|
|
3182
|
+
sketchId
|
|
3183
|
+
};
|
|
3184
|
+
}
|
|
3185
|
+
async function designDuplicateLayer(state, args) {
|
|
3186
|
+
const sketchId = requireSketchId(state, args);
|
|
3187
|
+
const stack = state.getLayerStack(sketchId);
|
|
3188
|
+
const layer = stack.get(args.layerId);
|
|
3189
|
+
if (!layer) {
|
|
3190
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3191
|
+
}
|
|
3192
|
+
const newId = stack.duplicate(args.layerId);
|
|
3193
|
+
await state.saveSketch(sketchId);
|
|
3194
|
+
return {
|
|
3195
|
+
duplicated: true,
|
|
3196
|
+
sourceLayerId: args.layerId,
|
|
3197
|
+
newLayerId: newId,
|
|
3198
|
+
sketchId
|
|
3199
|
+
};
|
|
3200
|
+
}
|
|
3201
|
+
async function designToggleVisibility(state, args) {
|
|
3202
|
+
const sketchId = requireSketchId(state, args);
|
|
3203
|
+
const stack = state.getLayerStack(sketchId);
|
|
3204
|
+
const layer = stack.get(args.layerId);
|
|
3205
|
+
if (!layer) {
|
|
3206
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3207
|
+
}
|
|
3208
|
+
const newVisible = args.visible ?? !layer.visible;
|
|
3209
|
+
const mutableLayer = layer;
|
|
3210
|
+
mutableLayer.visible = newVisible;
|
|
3211
|
+
stack.updateProperties(args.layerId, { ...layer.properties });
|
|
3212
|
+
await state.saveSketch(sketchId);
|
|
3213
|
+
return {
|
|
3214
|
+
layerId: args.layerId,
|
|
3215
|
+
visible: newVisible,
|
|
3216
|
+
sketchId
|
|
3217
|
+
};
|
|
3218
|
+
}
|
|
3219
|
+
async function designLockLayer(state, args) {
|
|
3220
|
+
const sketchId = requireSketchId(state, args);
|
|
3221
|
+
const stack = state.getLayerStack(sketchId);
|
|
3222
|
+
const layer = stack.get(args.layerId);
|
|
3223
|
+
if (!layer) {
|
|
3224
|
+
throw new Error(`Layer '${args.layerId}' not found in sketch '${sketchId}'.`);
|
|
3225
|
+
}
|
|
3226
|
+
const newLocked = args.locked ?? !layer.locked;
|
|
3227
|
+
const mutableLayer = layer;
|
|
3228
|
+
mutableLayer.locked = newLocked;
|
|
3229
|
+
stack.updateProperties(args.layerId, { ...layer.properties });
|
|
3230
|
+
await state.saveSketch(sketchId);
|
|
3231
|
+
return {
|
|
3232
|
+
layerId: args.layerId,
|
|
3233
|
+
locked: newLocked,
|
|
3234
|
+
sketchId
|
|
3235
|
+
};
|
|
3236
|
+
}
|
|
3237
|
+
async function designCaptureComposite(state, args) {
|
|
3238
|
+
const sketchId = requireSketchId(state, args);
|
|
3239
|
+
const stack = state.getLayerStack(sketchId);
|
|
3240
|
+
const layers = stack.getAll();
|
|
3241
|
+
return {
|
|
3242
|
+
sketchId,
|
|
3243
|
+
layerCount: layers.length,
|
|
3244
|
+
visibleCount: layers.filter((l) => l.visible).length,
|
|
3245
|
+
message: "Composite capture requires a rendering surface. Use capture_screenshot to get a rasterized preview of the sketch, then use design_list_layers to see the design layer stack."
|
|
3246
|
+
};
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
// src/tools/design-plugins.ts
|
|
3250
|
+
function registerPluginMcpTools(server, registry4, state) {
|
|
3251
|
+
for (const tool of registry4.getMcpTools()) {
|
|
3252
|
+
const inputSchema = tool.definition.inputSchema;
|
|
3253
|
+
server.tool(
|
|
3254
|
+
tool.name,
|
|
3255
|
+
tool.definition.description,
|
|
3256
|
+
// Pass raw JSON schema — MCP SDK accepts this alongside Zod
|
|
3257
|
+
inputSchema,
|
|
3258
|
+
async (args) => {
|
|
3259
|
+
try {
|
|
3260
|
+
const sketchId = args.sketchId ?? state.requireSelectedSketchId();
|
|
3261
|
+
const context = state.createMcpToolContext(sketchId);
|
|
3262
|
+
const result = await tool.definition.handler(args, context);
|
|
3263
|
+
await state.saveSketch(sketchId);
|
|
3264
|
+
return {
|
|
3265
|
+
content: result.content.map((c) => {
|
|
3266
|
+
if (c.type === "text") {
|
|
3267
|
+
return { type: "text", text: c.text };
|
|
3268
|
+
}
|
|
3269
|
+
return {
|
|
3270
|
+
type: "image",
|
|
3271
|
+
data: c.data,
|
|
3272
|
+
mimeType: c.mimeType
|
|
3273
|
+
};
|
|
3274
|
+
}),
|
|
3275
|
+
isError: result.isError
|
|
3276
|
+
};
|
|
3277
|
+
} catch (e) {
|
|
3278
|
+
return {
|
|
3279
|
+
content: [
|
|
3280
|
+
{
|
|
3281
|
+
type: "text",
|
|
3282
|
+
text: JSON.stringify({
|
|
3283
|
+
error: e instanceof Error ? e.message : String(e)
|
|
3284
|
+
})
|
|
3285
|
+
}
|
|
3286
|
+
],
|
|
3287
|
+
isError: true
|
|
3288
|
+
};
|
|
3289
|
+
}
|
|
3290
|
+
}
|
|
3291
|
+
);
|
|
3292
|
+
}
|
|
3293
|
+
}
|
|
3294
|
+
|
|
2884
3295
|
// src/resources/index.ts
|
|
2885
3296
|
import {
|
|
2886
3297
|
CANVAS_PRESETS,
|
|
@@ -3368,11 +3779,23 @@ function toolError(message) {
|
|
|
3368
3779
|
isError: true
|
|
3369
3780
|
};
|
|
3370
3781
|
}
|
|
3782
|
+
async function initializePluginRegistry() {
|
|
3783
|
+
const registry4 = createPluginRegistry({
|
|
3784
|
+
surface: "mcp",
|
|
3785
|
+
supportsInteractiveTools: false,
|
|
3786
|
+
supportsRendering: false
|
|
3787
|
+
});
|
|
3788
|
+
await registry4.register(typographyPlugin);
|
|
3789
|
+
await registry4.register(filtersPlugin);
|
|
3790
|
+
await registry4.register(shapesPlugin);
|
|
3791
|
+
await registry4.register(layoutGuidesPlugin);
|
|
3792
|
+
return registry4;
|
|
3793
|
+
}
|
|
3371
3794
|
function createServer(state) {
|
|
3372
3795
|
const server = new McpServer(
|
|
3373
3796
|
{
|
|
3374
3797
|
name: "@genart/mcp-server",
|
|
3375
|
-
version: "0.0
|
|
3798
|
+
version: "0.3.0"
|
|
3376
3799
|
},
|
|
3377
3800
|
{
|
|
3378
3801
|
capabilities: {
|
|
@@ -3382,6 +3805,11 @@ function createServer(state) {
|
|
|
3382
3805
|
}
|
|
3383
3806
|
}
|
|
3384
3807
|
);
|
|
3808
|
+
const registryReady = initializePluginRegistry().then((registry4) => {
|
|
3809
|
+
state.pluginRegistry = registry4;
|
|
3810
|
+
registerPluginMcpTools(server, registry4, state);
|
|
3811
|
+
});
|
|
3812
|
+
server._pluginsReady = registryReady;
|
|
3385
3813
|
registerWorkspaceTools(server, state);
|
|
3386
3814
|
registerSketchTools(server, state);
|
|
3387
3815
|
registerComponentTools(server, state);
|
|
@@ -3392,6 +3820,7 @@ function createServer(state) {
|
|
|
3392
3820
|
registerMergeTools(server, state);
|
|
3393
3821
|
registerSnapshotTools(server, state);
|
|
3394
3822
|
registerKnowledgeTools(server, state);
|
|
3823
|
+
registerDesignTools(server, state);
|
|
3395
3824
|
registerCaptureTools(server, state);
|
|
3396
3825
|
registerExportTools(server, state);
|
|
3397
3826
|
registerResources(server, state);
|
|
@@ -4180,6 +4609,247 @@ function registerExportTools(server, state) {
|
|
|
4180
4609
|
}
|
|
4181
4610
|
);
|
|
4182
4611
|
}
|
|
4612
|
+
function registerDesignTools(server, state) {
|
|
4613
|
+
server.tool(
|
|
4614
|
+
"design_add_layer",
|
|
4615
|
+
"Add a new design layer of a given type to the active sketch. Layer types come from registered plugins (e.g. 'typography:text', 'filter:grain', 'shapes:rect', 'guides:thirds').",
|
|
4616
|
+
{
|
|
4617
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4618
|
+
type: z2.string().describe("Layer type ID (e.g. 'typography:text', 'filter:grain', 'shapes:rect')"),
|
|
4619
|
+
name: z2.string().optional().describe("Layer display name (default: type's display name)"),
|
|
4620
|
+
properties: z2.record(z2.unknown()).optional().describe("Initial layer properties (merged with type defaults)"),
|
|
4621
|
+
transform: z2.object({
|
|
4622
|
+
x: z2.number().optional(),
|
|
4623
|
+
y: z2.number().optional(),
|
|
4624
|
+
width: z2.number().optional(),
|
|
4625
|
+
height: z2.number().optional(),
|
|
4626
|
+
rotation: z2.number().optional(),
|
|
4627
|
+
scaleX: z2.number().optional(),
|
|
4628
|
+
scaleY: z2.number().optional(),
|
|
4629
|
+
anchorX: z2.number().optional(),
|
|
4630
|
+
anchorY: z2.number().optional()
|
|
4631
|
+
}).optional().describe("Layer transform (default: full canvas)"),
|
|
4632
|
+
opacity: z2.number().optional().describe("Layer opacity 0\u20131 (default: 1)"),
|
|
4633
|
+
blendMode: z2.string().optional().describe("Blend mode (default: 'normal')"),
|
|
4634
|
+
index: z2.number().optional().describe("Insert position in layer stack (default: top)")
|
|
4635
|
+
},
|
|
4636
|
+
async (args) => {
|
|
4637
|
+
try {
|
|
4638
|
+
const result = await designAddLayer(state, args);
|
|
4639
|
+
return jsonResult(result);
|
|
4640
|
+
} catch (e) {
|
|
4641
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4642
|
+
}
|
|
4643
|
+
}
|
|
4644
|
+
);
|
|
4645
|
+
server.tool(
|
|
4646
|
+
"design_remove_layer",
|
|
4647
|
+
"Remove a design layer from the active sketch",
|
|
4648
|
+
{
|
|
4649
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4650
|
+
layerId: z2.string().describe("ID of the layer to remove")
|
|
4651
|
+
},
|
|
4652
|
+
async (args) => {
|
|
4653
|
+
try {
|
|
4654
|
+
const result = await designRemoveLayer(state, args);
|
|
4655
|
+
return jsonResult(result);
|
|
4656
|
+
} catch (e) {
|
|
4657
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4658
|
+
}
|
|
4659
|
+
}
|
|
4660
|
+
);
|
|
4661
|
+
server.tool(
|
|
4662
|
+
"design_list_layers",
|
|
4663
|
+
"List all design layers in the active sketch with their types, visibility, and key properties",
|
|
4664
|
+
{
|
|
4665
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)")
|
|
4666
|
+
},
|
|
4667
|
+
async (args) => {
|
|
4668
|
+
try {
|
|
4669
|
+
const result = await designListLayers(state, args);
|
|
4670
|
+
return jsonResult(result);
|
|
4671
|
+
} catch (e) {
|
|
4672
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4673
|
+
}
|
|
4674
|
+
}
|
|
4675
|
+
);
|
|
4676
|
+
server.tool(
|
|
4677
|
+
"design_get_layer",
|
|
4678
|
+
"Get full details of a single design layer including all properties and transform",
|
|
4679
|
+
{
|
|
4680
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4681
|
+
layerId: z2.string().describe("ID of the layer to inspect")
|
|
4682
|
+
},
|
|
4683
|
+
async (args) => {
|
|
4684
|
+
try {
|
|
4685
|
+
const result = await designGetLayer(state, args);
|
|
4686
|
+
return jsonResult(result);
|
|
4687
|
+
} catch (e) {
|
|
4688
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4689
|
+
}
|
|
4690
|
+
}
|
|
4691
|
+
);
|
|
4692
|
+
server.tool(
|
|
4693
|
+
"design_update_layer",
|
|
4694
|
+
"Update properties on a design layer (e.g. text content, filter intensity, shape fill color)",
|
|
4695
|
+
{
|
|
4696
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4697
|
+
layerId: z2.string().describe("ID of the layer to update"),
|
|
4698
|
+
name: z2.string().optional().describe("New display name"),
|
|
4699
|
+
properties: z2.record(z2.unknown()).optional().describe("Property key-value pairs to set")
|
|
4700
|
+
},
|
|
4701
|
+
async (args) => {
|
|
4702
|
+
try {
|
|
4703
|
+
const result = await designUpdateLayer(state, args);
|
|
4704
|
+
return jsonResult(result);
|
|
4705
|
+
} catch (e) {
|
|
4706
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4707
|
+
}
|
|
4708
|
+
}
|
|
4709
|
+
);
|
|
4710
|
+
server.tool(
|
|
4711
|
+
"design_set_transform",
|
|
4712
|
+
"Set the position, size, rotation, and scale of a design layer",
|
|
4713
|
+
{
|
|
4714
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4715
|
+
layerId: z2.string().describe("ID of the layer to transform"),
|
|
4716
|
+
x: z2.number().optional().describe("X position"),
|
|
4717
|
+
y: z2.number().optional().describe("Y position"),
|
|
4718
|
+
width: z2.number().optional().describe("Width"),
|
|
4719
|
+
height: z2.number().optional().describe("Height"),
|
|
4720
|
+
rotation: z2.number().optional().describe("Rotation in degrees"),
|
|
4721
|
+
scaleX: z2.number().optional().describe("Horizontal scale"),
|
|
4722
|
+
scaleY: z2.number().optional().describe("Vertical scale"),
|
|
4723
|
+
anchorX: z2.number().optional().describe("Anchor X (0\u20131)"),
|
|
4724
|
+
anchorY: z2.number().optional().describe("Anchor Y (0\u20131)")
|
|
4725
|
+
},
|
|
4726
|
+
async (args) => {
|
|
4727
|
+
try {
|
|
4728
|
+
const result = await designSetTransform(state, args);
|
|
4729
|
+
return jsonResult(result);
|
|
4730
|
+
} catch (e) {
|
|
4731
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4732
|
+
}
|
|
4733
|
+
}
|
|
4734
|
+
);
|
|
4735
|
+
server.tool(
|
|
4736
|
+
"design_set_blend",
|
|
4737
|
+
"Set blend mode and/or opacity on a design layer",
|
|
4738
|
+
{
|
|
4739
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4740
|
+
layerId: z2.string().describe("ID of the layer"),
|
|
4741
|
+
blendMode: z2.enum([
|
|
4742
|
+
"normal",
|
|
4743
|
+
"multiply",
|
|
4744
|
+
"screen",
|
|
4745
|
+
"overlay",
|
|
4746
|
+
"darken",
|
|
4747
|
+
"lighten",
|
|
4748
|
+
"color-dodge",
|
|
4749
|
+
"color-burn",
|
|
4750
|
+
"hard-light",
|
|
4751
|
+
"soft-light",
|
|
4752
|
+
"difference",
|
|
4753
|
+
"exclusion",
|
|
4754
|
+
"hue",
|
|
4755
|
+
"saturation",
|
|
4756
|
+
"color",
|
|
4757
|
+
"luminosity"
|
|
4758
|
+
]).optional().describe("CSS blend mode"),
|
|
4759
|
+
opacity: z2.number().optional().describe("Layer opacity 0\u20131")
|
|
4760
|
+
},
|
|
4761
|
+
async (args) => {
|
|
4762
|
+
try {
|
|
4763
|
+
const result = await designSetBlend(state, args);
|
|
4764
|
+
return jsonResult(result);
|
|
4765
|
+
} catch (e) {
|
|
4766
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4767
|
+
}
|
|
4768
|
+
}
|
|
4769
|
+
);
|
|
4770
|
+
server.tool(
|
|
4771
|
+
"design_reorder_layers",
|
|
4772
|
+
"Move a design layer to a new position in the z-order stack",
|
|
4773
|
+
{
|
|
4774
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4775
|
+
layerId: z2.string().describe("ID of the layer to move"),
|
|
4776
|
+
newIndex: z2.number().describe("New position (0 = bottom, n-1 = top)")
|
|
4777
|
+
},
|
|
4778
|
+
async (args) => {
|
|
4779
|
+
try {
|
|
4780
|
+
const result = await designReorderLayers(state, args);
|
|
4781
|
+
return jsonResult(result);
|
|
4782
|
+
} catch (e) {
|
|
4783
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4784
|
+
}
|
|
4785
|
+
}
|
|
4786
|
+
);
|
|
4787
|
+
server.tool(
|
|
4788
|
+
"design_duplicate_layer",
|
|
4789
|
+
"Clone a design layer with a new ID, inserted directly above the source",
|
|
4790
|
+
{
|
|
4791
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4792
|
+
layerId: z2.string().describe("ID of the layer to duplicate")
|
|
4793
|
+
},
|
|
4794
|
+
async (args) => {
|
|
4795
|
+
try {
|
|
4796
|
+
const result = await designDuplicateLayer(state, args);
|
|
4797
|
+
return jsonResult(result);
|
|
4798
|
+
} catch (e) {
|
|
4799
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4800
|
+
}
|
|
4801
|
+
}
|
|
4802
|
+
);
|
|
4803
|
+
server.tool(
|
|
4804
|
+
"design_toggle_visibility",
|
|
4805
|
+
"Show or hide a design layer",
|
|
4806
|
+
{
|
|
4807
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4808
|
+
layerId: z2.string().describe("ID of the layer"),
|
|
4809
|
+
visible: z2.boolean().optional().describe("Set visibility (default: toggle)")
|
|
4810
|
+
},
|
|
4811
|
+
async (args) => {
|
|
4812
|
+
try {
|
|
4813
|
+
const result = await designToggleVisibility(state, args);
|
|
4814
|
+
return jsonResult(result);
|
|
4815
|
+
} catch (e) {
|
|
4816
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4817
|
+
}
|
|
4818
|
+
}
|
|
4819
|
+
);
|
|
4820
|
+
server.tool(
|
|
4821
|
+
"design_lock_layer",
|
|
4822
|
+
"Lock or unlock a design layer to prevent accidental edits",
|
|
4823
|
+
{
|
|
4824
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)"),
|
|
4825
|
+
layerId: z2.string().describe("ID of the layer"),
|
|
4826
|
+
locked: z2.boolean().optional().describe("Set lock state (default: toggle)")
|
|
4827
|
+
},
|
|
4828
|
+
async (args) => {
|
|
4829
|
+
try {
|
|
4830
|
+
const result = await designLockLayer(state, args);
|
|
4831
|
+
return jsonResult(result);
|
|
4832
|
+
} catch (e) {
|
|
4833
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4834
|
+
}
|
|
4835
|
+
}
|
|
4836
|
+
);
|
|
4837
|
+
server.tool(
|
|
4838
|
+
"design_capture_composite",
|
|
4839
|
+
"Get info about the design layer composite for a sketch. For full visual capture use capture_screenshot.",
|
|
4840
|
+
{
|
|
4841
|
+
sketchId: z2.string().optional().describe("Target sketch ID (default: selected sketch)")
|
|
4842
|
+
},
|
|
4843
|
+
async (args) => {
|
|
4844
|
+
try {
|
|
4845
|
+
const result = await designCaptureComposite(state, args);
|
|
4846
|
+
return jsonResult(result);
|
|
4847
|
+
} catch (e) {
|
|
4848
|
+
return toolError(e instanceof Error ? e.message : String(e));
|
|
4849
|
+
}
|
|
4850
|
+
}
|
|
4851
|
+
);
|
|
4852
|
+
}
|
|
4183
4853
|
function registerKnowledgeTools(server, _state) {
|
|
4184
4854
|
server.tool(
|
|
4185
4855
|
"list_skills",
|