@genart-dev/mcp-server 0.4.6 → 0.4.8

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.js CHANGED
@@ -2743,6 +2743,7 @@ function isDirectComponent(name, components) {
2743
2743
  }
2744
2744
 
2745
2745
  // src/tools/capture.ts
2746
+ import { exec } from "child_process";
2746
2747
  import { mkdir, writeFile as writeFile6 } from "fs/promises";
2747
2748
  import { dirname as dirname6, join as join3 } from "path";
2748
2749
  import {
@@ -2828,6 +2829,12 @@ async function captureHtmlMulti(options) {
2828
2829
 
2829
2830
  // src/tools/capture.ts
2830
2831
  var registry2 = createDefaultRegistry2();
2832
+ function openPreview(filePath) {
2833
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
2834
+ exec(`${cmd} "${filePath}"`, (err) => {
2835
+ if (err) console.error(`[openPreview] failed: ${err.message}`);
2836
+ });
2837
+ }
2831
2838
  function applyOverrides(sketch, overrides) {
2832
2839
  if (overrides.seed === void 0 && overrides.params === void 0) {
2833
2840
  return sketch;
@@ -2893,9 +2900,7 @@ async function captureScreenshot(state, input) {
2893
2900
  previewPath
2894
2901
  });
2895
2902
  const previewJpegBase64 = Buffer.from(multi.inlineJpeg).toString("base64");
2896
- const previewDataUri = `data:image/jpeg;base64,${previewJpegBase64}`;
2897
- metadata.previewDataUri = previewDataUri;
2898
- return { metadata, previewJpegBase64, previewDataUri };
2903
+ return { metadata, previewJpegBase64 };
2899
2904
  } catch (e) {
2900
2905
  const msg = e instanceof Error ? e.message : String(e);
2901
2906
  throw new Error(`Renderer error for '${sketchId}': ${msg}`);
@@ -2916,6 +2921,9 @@ async function buildScreenshotMetadata(state, multi, info) {
2916
2921
  await writeFile6(info.previewPath, multi.previewPng);
2917
2922
  metadata.savedPreviewTo = info.previewPath;
2918
2923
  metadata.previewWritten = true;
2924
+ if (info.autoOpen !== false) {
2925
+ openPreview(info.previewPath);
2926
+ }
2919
2927
  }
2920
2928
  return metadata;
2921
2929
  }
@@ -2950,7 +2958,9 @@ async function captureBatch(state, input) {
2950
2958
  target: "sketch",
2951
2959
  sketchId: id,
2952
2960
  seed: effectiveSeed,
2953
- previewPath
2961
+ previewPath,
2962
+ autoOpen: false
2963
+ // Don't flood windows for batch captures
2954
2964
  });
2955
2965
  items.push({
2956
2966
  metadata: itemMetadata,
@@ -5506,7 +5516,7 @@ function registerSketchTools(server, state) {
5506
5516
  addToWorkspace: z2.string().optional().describe("Path to workspace to add sketch to after creation"),
5507
5517
  agent: z2.string().optional().describe("Your CLI agent name (e.g. 'claude-code', 'codex-cli', 'gemini-cli', 'opencode', 'kiro')"),
5508
5518
  model: z2.string().optional().describe("Your AI model identifier (e.g. 'claude-opus-4-6', 'gpt-4o', 'gemini-2.5-pro')"),
5509
- capture: z2.boolean().optional().describe("When true, automatically capture a screenshot after creation. The result includes previewDataUri for rendering. IMPORTANT: When capture is true, you MUST show the preview to the user by creating an HTML artifact with an <img> tag using the previewDataUri from the capture metadata. Include savedPreviewTo as caption for the full-res file.")
5519
+ capture: z2.boolean().optional().describe("When true, automatically capture a screenshot after creation and return it inline (avoids a separate capture_screenshot call)")
5510
5520
  },
5511
5521
  async (args) => {
5512
5522
  try {
@@ -5517,15 +5527,13 @@ function registerSketchTools(server, state) {
5517
5527
  target: "sketch",
5518
5528
  sketchId: args.id
5519
5529
  });
5520
- const captureMeta = captureResult.metadata;
5521
5530
  return {
5522
5531
  content: [
5532
+ { type: "image", data: captureResult.previewJpegBase64, mimeType: "image/jpeg" },
5523
5533
  { type: "text", text: JSON.stringify({
5524
5534
  ...result,
5525
- capture: captureMeta
5526
- }, null, 2) },
5527
- { type: "image", data: captureResult.previewJpegBase64, mimeType: "image/jpeg" },
5528
- ...captureMeta.savedPreviewTo ? [{ type: "text", text: `![Sketch Preview](file://${captureMeta.savedPreviewTo})` }] : []
5535
+ capture: captureResult.metadata
5536
+ }, null, 2) }
5529
5537
  ]
5530
5538
  };
5531
5539
  } catch (captureErr) {
@@ -6091,7 +6099,7 @@ function registerSnapshotTools(server, state) {
6091
6099
  function registerCaptureTools(server, state) {
6092
6100
  server.tool(
6093
6101
  "capture_screenshot",
6094
- "Capture a screenshot of a sketch. Returns metadata (including previewDataUri) as text + a small inline JPEG image. In local mode, writes a full-res PNG to snapshots/<sketchId>-<seed>-preview.png. IMPORTANT: After every capture, you MUST show the preview to the user by creating an HTML artifact containing an <img> tag using the previewDataUri from the metadata. Include the savedPreviewTo path as a caption so the user can find the full-res file.",
6102
+ "Capture a screenshot of a sketch. Returns an inline JPEG image + metadata as text. In local mode, also writes a full-res PNG to snapshots/<sketchId>-<seed>-preview.png (path in savedPreviewTo).",
6095
6103
  {
6096
6104
  target: z2.enum(["selected", "sketch"]).optional().describe("What to capture (default: selected)"),
6097
6105
  sketchId: z2.string().optional().describe("Required when target is 'sketch'"),
@@ -6104,13 +6112,11 @@ function registerCaptureTools(server, state) {
6104
6112
  async (args) => {
6105
6113
  try {
6106
6114
  const result = await captureScreenshot(state, args);
6107
- console.error(`[capture_screenshot] jpeg base64 length: ${result.previewJpegBase64.length}, metadata: ${JSON.stringify(result.metadata)}`);
6115
+ console.error(`[capture_screenshot] jpeg base64 length: ${result.previewJpegBase64.length}`);
6108
6116
  return {
6109
6117
  content: [
6110
- { type: "text", text: JSON.stringify(result.metadata, null, 2) },
6111
6118
  { type: "image", data: result.previewJpegBase64, mimeType: "image/jpeg" },
6112
- // Markdown image for hosts that render local file refs or data URIs
6113
- ...result.metadata.savedPreviewTo ? [{ type: "text", text: `![Sketch Preview](file://${result.metadata.savedPreviewTo})` }] : []
6119
+ { type: "text", text: JSON.stringify(result.metadata, null, 2) }
6114
6120
  ]
6115
6121
  };
6116
6122
  } catch (e) {
@@ -6121,7 +6127,7 @@ function registerCaptureTools(server, state) {
6121
6127
  );
6122
6128
  server.tool(
6123
6129
  "capture_batch",
6124
- "Capture screenshots of multiple sketches in parallel. Returns per-sketch metadata (including previewDataUri) + inline JPEG images. IMPORTANT: After batch capture, you MUST show all previews to the user by creating an HTML artifact with <img> tags using each item's previewDataUri. Include sketch titles and savedPreviewTo paths.",
6130
+ "Capture screenshots of multiple sketches in parallel. Returns inline JPEG images + per-sketch metadata. In local mode, writes full-res PNGs to snapshots/.",
6125
6131
  {
6126
6132
  sketchIds: z2.array(z2.string()).optional().describe("IDs of sketches to capture (default: all)"),
6127
6133
  width: z2.number().optional().describe("Override width for all captures"),
@@ -6136,21 +6142,15 @@ function registerCaptureTools(server, state) {
6136
6142
  { type: "text", text: JSON.stringify(result.metadata, null, 2) }
6137
6143
  ];
6138
6144
  for (const item of result.items) {
6139
- content.push({
6140
- type: "text",
6141
- text: JSON.stringify(item.metadata, null, 2)
6142
- });
6143
6145
  content.push({
6144
6146
  type: "image",
6145
6147
  data: item.inlineJpegBase64,
6146
6148
  mimeType: "image/jpeg"
6147
6149
  });
6148
- if (item.metadata.savedPreviewTo) {
6149
- content.push({
6150
- type: "text",
6151
- text: `![${item.metadata.sketchId} Preview](file://${item.metadata.savedPreviewTo})`
6152
- });
6153
- }
6150
+ content.push({
6151
+ type: "text",
6152
+ text: JSON.stringify(item.metadata, null, 2)
6153
+ });
6154
6154
  }
6155
6155
  return { content };
6156
6156
  } catch (e) {