@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/lib.js CHANGED
@@ -2424,6 +2424,7 @@ function isDirectComponent(name, components) {
2424
2424
  }
2425
2425
 
2426
2426
  // src/tools/capture.ts
2427
+ import { exec } from "child_process";
2427
2428
  import { mkdir, writeFile as writeFile5 } from "fs/promises";
2428
2429
  import { dirname as dirname5, join as join3 } from "path";
2429
2430
  import {
@@ -2509,6 +2510,12 @@ async function captureHtmlMulti(options) {
2509
2510
 
2510
2511
  // src/tools/capture.ts
2511
2512
  var registry2 = createDefaultRegistry2();
2513
+ function openPreview(filePath) {
2514
+ const cmd = process.platform === "darwin" ? "open" : process.platform === "win32" ? "start" : "xdg-open";
2515
+ exec(`${cmd} "${filePath}"`, (err) => {
2516
+ if (err) console.error(`[openPreview] failed: ${err.message}`);
2517
+ });
2518
+ }
2512
2519
  function applyOverrides(sketch, overrides) {
2513
2520
  if (overrides.seed === void 0 && overrides.params === void 0) {
2514
2521
  return sketch;
@@ -2574,9 +2581,7 @@ async function captureScreenshot(state, input) {
2574
2581
  previewPath
2575
2582
  });
2576
2583
  const previewJpegBase64 = Buffer.from(multi.inlineJpeg).toString("base64");
2577
- const previewDataUri = `data:image/jpeg;base64,${previewJpegBase64}`;
2578
- metadata.previewDataUri = previewDataUri;
2579
- return { metadata, previewJpegBase64, previewDataUri };
2584
+ return { metadata, previewJpegBase64 };
2580
2585
  } catch (e) {
2581
2586
  const msg = e instanceof Error ? e.message : String(e);
2582
2587
  throw new Error(`Renderer error for '${sketchId}': ${msg}`);
@@ -2597,6 +2602,9 @@ async function buildScreenshotMetadata(state, multi, info) {
2597
2602
  await writeFile5(info.previewPath, multi.previewPng);
2598
2603
  metadata.savedPreviewTo = info.previewPath;
2599
2604
  metadata.previewWritten = true;
2605
+ if (info.autoOpen !== false) {
2606
+ openPreview(info.previewPath);
2607
+ }
2600
2608
  }
2601
2609
  return metadata;
2602
2610
  }
@@ -2631,7 +2639,9 @@ async function captureBatch(state, input) {
2631
2639
  target: "sketch",
2632
2640
  sketchId: id,
2633
2641
  seed: effectiveSeed,
2634
- previewPath
2642
+ previewPath,
2643
+ autoOpen: false
2644
+ // Don't flood windows for batch captures
2635
2645
  });
2636
2646
  items.push({
2637
2647
  metadata: itemMetadata,
@@ -5187,7 +5197,7 @@ function registerSketchTools(server, state) {
5187
5197
  addToWorkspace: z2.string().optional().describe("Path to workspace to add sketch to after creation"),
5188
5198
  agent: z2.string().optional().describe("Your CLI agent name (e.g. 'claude-code', 'codex-cli', 'gemini-cli', 'opencode', 'kiro')"),
5189
5199
  model: z2.string().optional().describe("Your AI model identifier (e.g. 'claude-opus-4-6', 'gpt-4o', 'gemini-2.5-pro')"),
5190
- 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.")
5200
+ capture: z2.boolean().optional().describe("When true, automatically capture a screenshot after creation and return it inline (avoids a separate capture_screenshot call)")
5191
5201
  },
5192
5202
  async (args) => {
5193
5203
  try {
@@ -5198,15 +5208,13 @@ function registerSketchTools(server, state) {
5198
5208
  target: "sketch",
5199
5209
  sketchId: args.id
5200
5210
  });
5201
- const captureMeta = captureResult.metadata;
5202
5211
  return {
5203
5212
  content: [
5213
+ { type: "image", data: captureResult.previewJpegBase64, mimeType: "image/jpeg" },
5204
5214
  { type: "text", text: JSON.stringify({
5205
5215
  ...result,
5206
- capture: captureMeta
5207
- }, null, 2) },
5208
- { type: "image", data: captureResult.previewJpegBase64, mimeType: "image/jpeg" },
5209
- ...captureMeta.savedPreviewTo ? [{ type: "text", text: `![Sketch Preview](file://${captureMeta.savedPreviewTo})` }] : []
5216
+ capture: captureResult.metadata
5217
+ }, null, 2) }
5210
5218
  ]
5211
5219
  };
5212
5220
  } catch (captureErr) {
@@ -5772,7 +5780,7 @@ function registerSnapshotTools(server, state) {
5772
5780
  function registerCaptureTools(server, state) {
5773
5781
  server.tool(
5774
5782
  "capture_screenshot",
5775
- "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.",
5783
+ "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).",
5776
5784
  {
5777
5785
  target: z2.enum(["selected", "sketch"]).optional().describe("What to capture (default: selected)"),
5778
5786
  sketchId: z2.string().optional().describe("Required when target is 'sketch'"),
@@ -5785,13 +5793,11 @@ function registerCaptureTools(server, state) {
5785
5793
  async (args) => {
5786
5794
  try {
5787
5795
  const result = await captureScreenshot(state, args);
5788
- console.error(`[capture_screenshot] jpeg base64 length: ${result.previewJpegBase64.length}, metadata: ${JSON.stringify(result.metadata)}`);
5796
+ console.error(`[capture_screenshot] jpeg base64 length: ${result.previewJpegBase64.length}`);
5789
5797
  return {
5790
5798
  content: [
5791
- { type: "text", text: JSON.stringify(result.metadata, null, 2) },
5792
5799
  { type: "image", data: result.previewJpegBase64, mimeType: "image/jpeg" },
5793
- // Markdown image for hosts that render local file refs or data URIs
5794
- ...result.metadata.savedPreviewTo ? [{ type: "text", text: `![Sketch Preview](file://${result.metadata.savedPreviewTo})` }] : []
5800
+ { type: "text", text: JSON.stringify(result.metadata, null, 2) }
5795
5801
  ]
5796
5802
  };
5797
5803
  } catch (e) {
@@ -5802,7 +5808,7 @@ function registerCaptureTools(server, state) {
5802
5808
  );
5803
5809
  server.tool(
5804
5810
  "capture_batch",
5805
- "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.",
5811
+ "Capture screenshots of multiple sketches in parallel. Returns inline JPEG images + per-sketch metadata. In local mode, writes full-res PNGs to snapshots/.",
5806
5812
  {
5807
5813
  sketchIds: z2.array(z2.string()).optional().describe("IDs of sketches to capture (default: all)"),
5808
5814
  width: z2.number().optional().describe("Override width for all captures"),
@@ -5817,21 +5823,15 @@ function registerCaptureTools(server, state) {
5817
5823
  { type: "text", text: JSON.stringify(result.metadata, null, 2) }
5818
5824
  ];
5819
5825
  for (const item of result.items) {
5820
- content.push({
5821
- type: "text",
5822
- text: JSON.stringify(item.metadata, null, 2)
5823
- });
5824
5826
  content.push({
5825
5827
  type: "image",
5826
5828
  data: item.inlineJpegBase64,
5827
5829
  mimeType: "image/jpeg"
5828
5830
  });
5829
- if (item.metadata.savedPreviewTo) {
5830
- content.push({
5831
- type: "text",
5832
- text: `![${item.metadata.sketchId} Preview](file://${item.metadata.savedPreviewTo})`
5833
- });
5834
- }
5831
+ content.push({
5832
+ type: "text",
5833
+ text: JSON.stringify(item.metadata, null, 2)
5834
+ });
5835
5835
  }
5836
5836
  return { content };
5837
5837
  } catch (e) {