@snowcone-app/mcp 0.10.0 → 0.11.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/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @snowcone-app/mcp
2
2
 
3
+ ## 0.11.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#5261](https://github.com/snowcone-app/snowcone-monorepo/pull/5261) [`0cda7e8`](https://github.com/snowcone-app/snowcone-monorepo/commit/0cda7e872d8d4d05a685e54544714897f1b50027) Thanks [@kevinsproles](https://github.com/kevinsproles)! - `snowcone_search_designs` now also returns `drafts`: a couple of fresh, low-res draft designs made for exactly the search (for example "corgi astronaut phone case"), each already shown on matching products as a ready `mockup_url`, with no shop needed. `drafts_status` and `drafts_detail` say why when there are none; pass `drafts: false` for catalog results alone.
8
+
3
9
  ## 0.10.0
4
10
 
5
11
  ### Minor Changes
package/dist/index.js CHANGED
@@ -249,7 +249,7 @@ function stripSlash(s) {
249
249
  // package.json
250
250
  var package_default = {
251
251
  name: "@snowcone-app/mcp",
252
- version: "0.10.0",
252
+ version: "0.11.0",
253
253
  mcpName: "io.github.snowcone-app/snowcone",
254
254
  description: "Snowcone MCP server \u2014 the agent-native quickstart. Mint a sandbox shop, browse the catalog, and turn any image into a buyable printed-merch mockup URL, all as callable tools.",
255
255
  keywords: [
@@ -328,17 +328,18 @@ var CARD_TOOL_META = {
328
328
  "openai/toolInvocation/invoking": "Rendering the mockup\u2026",
329
329
  "openai/toolInvocation/invoked": "Mockup ready"
330
330
  };
331
- function cardResourceMeta() {
332
- const img = new URL(IMG_BASE).origin;
331
+ function cardResourceMeta(opts = {}) {
332
+ const domains = [new URL(IMG_BASE).origin];
333
+ if (opts.beaconUrl) domains.push(new URL(opts.beaconUrl).origin);
333
334
  return {
334
- ui: { csp: { resourceDomains: [img], connectDomains: [] }, prefersBorder: true },
335
- "openai/widgetCSP": { resource_domains: [img], connect_domains: [] },
335
+ ui: { csp: { resourceDomains: domains, connectDomains: [] }, prefersBorder: true },
336
+ "openai/widgetCSP": { resource_domains: domains, connect_domains: [] },
336
337
  "openai/widgetPrefersBorder": true,
337
338
  "openai/widgetDescription": "A preview of the person's design printed on the product, with its price, option choices, and a Buy button (or 'Orders open soon' before launch)."
338
339
  };
339
340
  }
340
- function cardHtml() {
341
- return CARD_HTML.replace("__VERSION__", VERSION);
341
+ function cardHtml(opts = {}) {
342
+ return CARD_HTML.replace("__VERSION__", VERSION).replace("__BEACON__", opts.beaconUrl ? JSON.stringify(opts.beaconUrl).slice(1, -1) : "");
342
343
  }
343
344
  var CARD_HTML = `<!doctype html>
344
345
  <html lang="en">
@@ -389,6 +390,8 @@ var CARD_HTML = `<!doctype html>
389
390
  const $ = (id) => document.getElementById(id);
390
391
  const cardEl = $("card");
391
392
  let card = null;
393
+ const BEACON = "__BEACON__"; // hosted endpoint only: one 1\xD71 load per card, so we can tell where cards are viewed from
394
+ let beaconSent = false;
392
395
  let bridge = false; // MCP Apps bridge is up
393
396
  let nextId = 1;
394
397
  const pending = new Map();
@@ -433,7 +436,10 @@ var CARD_HTML = `<!doctype html>
433
436
 
434
437
  const img = $("img");
435
438
  if (typeof card.image_url === "string" && /^https:\\/\\//.test(card.image_url)) {
436
- img.onload = () => { $("placeholder").hidden = true; img.hidden = false; cardEl.dataset.busy = "false"; resize(); };
439
+ img.onload = () => {
440
+ $("placeholder").hidden = true; img.hidden = false; cardEl.dataset.busy = "false"; resize();
441
+ if (BEACON && !beaconSent) { beaconSent = true; new Image().src = BEACON; }
442
+ };
437
443
  img.onerror = () => { cardEl.dataset.busy = "false"; showError("The image host refused the picture."); };
438
444
  img.alt = card.product ? "Mockup of " + card.product.name : "Product mockup";
439
445
  if (img.src === card.image_url && img.complete) cardEl.dataset.busy = "false"; // same picture: no load event comes
@@ -840,7 +846,48 @@ async function searchDesigns(query, limit, offset, filter, semanticRatio) {
840
846
  return { hits: body.hits ?? [], estimatedTotalHits: body.estimatedTotalHits ?? body.hits?.length ?? 0 };
841
847
  }
842
848
 
849
+ // src/drafts.ts
850
+ var KNOWN = ["ok", "blocked", "limited", "budget-exhausted", "no-product", "unavailable"];
851
+ async function searchDrafts(query, forwardedFor) {
852
+ const none = (status, detail) => ({ status, detail, drafts: [], cached: false, subject: "", product_terms: "" });
853
+ try {
854
+ const r = await httpJson(`${API_BASE}/agent-drafts/search`, {
855
+ method: "POST",
856
+ body: { query },
857
+ ...forwardedFor ? { headers: { "X-Forwarded-For": forwardedFor } } : {}
858
+ });
859
+ const status = KNOWN.find((s) => s === r.status);
860
+ if (!status) return none("unreachable", `Draft designs answered with an unknown status (${String(r.status).slice(0, 40)}).`);
861
+ return {
862
+ status,
863
+ detail: typeof r.detail === "string" ? r.detail : "",
864
+ // Only what passed moderation is ever shown, whatever the wire says.
865
+ drafts: Array.isArray(r.drafts) ? r.drafts.filter((d) => d && d.moderated === true && typeof d.mockup_url === "string") : [],
866
+ cached: r.cached === true,
867
+ subject: typeof r.subject === "string" ? r.subject : "",
868
+ product_terms: typeof r.product_terms === "string" ? r.product_terms : ""
869
+ };
870
+ } catch (err) {
871
+ const why = err instanceof HttpError ? `HTTP ${err.status}` : err instanceof Error ? err.message : String(err);
872
+ return none("unreachable", `Draft designs could not be reached (${why.slice(0, 120)}). The catalog results are unaffected.`);
873
+ }
874
+ }
875
+ var money = (cents) => `$${(cents / 100).toFixed(2)}`;
876
+ function draftsText(query, a) {
877
+ if (a.status === "ok" && a.drafts.length > 0) {
878
+ const lines = a.drafts.flatMap(
879
+ (d, i) => d.mockups.map((m) => `- Draft ${i + 1} on ${m.product_name} (${money(m.price_cents)}): ${m.mockup_url}`).concat(` Draft ${i + 1} design: ${d.image_url}`)
880
+ );
881
+ return `Fresh draft designs for "${query}" (made just now, low-res, labelled drafts):
882
+ ${lines.join("\n")}
883
+ ${a.detail}`;
884
+ }
885
+ if (a.status === "unavailable" || a.status === "unreachable") return `No fresh drafts this time: ${a.detail}`;
886
+ return a.detail ? `No fresh drafts: ${a.detail}` : "";
887
+ }
888
+
843
889
  // src/launch.ts
890
+ var launchFetch = (url, init) => fetch(url, init);
844
891
  var TTL_MS = 6e4;
845
892
  var cached = null;
846
893
  async function readOrdersState(now = Date.now()) {
@@ -851,7 +898,7 @@ async function readOrdersState(now = Date.now()) {
851
898
  }
852
899
  async function fetchState() {
853
900
  try {
854
- const res = await fetch(LAUNCH_URL, { headers: { Accept: "application/json" }, signal: AbortSignal.timeout(3e3) });
901
+ const res = await launchFetch(LAUNCH_URL, { headers: { Accept: "application/json" }, signal: AbortSignal.timeout(3e3) });
855
902
  if (!res.ok) return unreadable(`HTTP ${res.status} from ${LAUNCH_URL}`);
856
903
  const body = await res.json();
857
904
  if (body.orders === "open") return { orders: "open" };
@@ -1073,7 +1120,7 @@ var buyUrl = (input) => buildUrl(input, BUY_BASE);
1073
1120
  // src/server.ts
1074
1121
  function createServer(ctx = {}) {
1075
1122
  const server2 = new McpServer({ name: "snowcone-mcp-server", version: VERSION });
1076
- registerCard(server2);
1123
+ registerCard(server2, ctx);
1077
1124
  registerTools(server2, ctx);
1078
1125
  return server2;
1079
1126
  }
@@ -1147,7 +1194,8 @@ async function summarizeDesign(d, shop, shopSecret) {
1147
1194
  const url = await renderUrl(input);
1148
1195
  return shop ? { ...base, mockup_url: url } : { ...base, mockup_url_template: url };
1149
1196
  }
1150
- function registerCard(server2) {
1197
+ function registerCard(server2, ctx) {
1198
+ const opts = ctx.cardBeaconUrl ? { beaconUrl: ctx.cardBeaconUrl } : {};
1151
1199
  server2.registerResource(
1152
1200
  "Snowcone mockup card",
1153
1201
  CARD_URI,
@@ -1155,10 +1203,10 @@ function registerCard(server2) {
1155
1203
  title: "Snowcone mockup card",
1156
1204
  description: "The person's design on the product, with price, option choices and Buy.",
1157
1205
  mimeType: CARD_MIME,
1158
- _meta: cardResourceMeta()
1206
+ _meta: cardResourceMeta(opts)
1159
1207
  },
1160
1208
  async () => ({
1161
- contents: [{ uri: CARD_URI, mimeType: CARD_MIME, text: cardHtml(), _meta: cardResourceMeta() }]
1209
+ contents: [{ uri: CARD_URI, mimeType: CARD_MIME, text: cardHtml(opts), _meta: cardResourceMeta(opts) }]
1162
1210
  })
1163
1211
  );
1164
1212
  }
@@ -1359,7 +1407,7 @@ Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right
1359
1407
  "snowcone_search_designs",
1360
1408
  {
1361
1409
  title: "Search the pre-made designs catalog",
1362
- description: "Search the public catalog of remixable published designs \u2014 hybrid semantic + keyword over each design's AI visual caption, so descriptive queries like 'pink cowgirl boots on the moon' work (e.g. holiday cards, tees, posters; filter curated = true for first-party-curated picks) so an integration never starts from a blank canvas. Filterable facets: tags, occasion, style, productId, minPriceCents, curated. Each result includes the design's product, license, and a ready-to-render mockup_url (a design=<pairingId> reference URL) when you pass your 'shop'. Catalog design renders are FREE \u2014 they don't count against the shop's usage budget. Without 'shop' you get a mockup_url_template containing YOUR_SHOP_ID to substitute.",
1410
+ description: "Search the public catalog of remixable published designs \u2014 hybrid semantic + keyword over each design's AI visual caption, so descriptive queries like 'pink cowgirl boots on the moon' work (e.g. holiday cards, tees, posters; filter curated = true for first-party-curated picks) so an integration never starts from a blank canvas. Filterable facets: tags, occasion, style, productId, minPriceCents, curated. Each result includes the design's product, license, and a ready-to-render mockup_url (a design=<pairingId> reference URL) when you pass your 'shop'. Catalog design renders are FREE \u2014 they don't count against the shop's usage budget. Without 'shop' you get a mockup_url_template containing YOUR_SHOP_ID to substitute. A search with words in it also returns 'drafts': a couple of fresh low-res draft designs made for exactly that search (e.g. 'corgi astronaut phone case'), each already shown on matching products as a ready mockup_url, no shop needed. Show the person those mockups. Drafts are labelled drafts, not finished designs; 'drafts_status' says why when there are none.",
1363
1411
  inputSchema: {
1364
1412
  query: z.string().default("").describe("Search text, e.g. 'christmas card'. Empty string lists curated designs."),
1365
1413
  limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
@@ -1367,25 +1415,37 @@ Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right
1367
1415
  filter: z.string().optional().describe(`Meilisearch filter expression, e.g. "occasion = 'christmas' AND style = 'watercolor'".`),
1368
1416
  semantic_ratio: z.number().min(0).max(1).default(0.5).describe("Semantic vs keyword blend (0 = keyword-only, 1 = fully semantic). Default 0.5."),
1369
1417
  shop: z.string().optional().describe("Your public Shop ID \u2014 when set, each result includes a ready-to-render mockup_url."),
1370
- shop_secret: z.string().optional().describe("Per-shop secret (scsec_\u2026). With 'shop', URLs are L3-signed (server-side only \u2014 never expose it).")
1418
+ shop_secret: z.string().optional().describe("Per-shop secret (scsec_\u2026). With 'shop', URLs are L3-signed (server-side only \u2014 never expose it)."),
1419
+ drafts: z.boolean().optional().describe("Also make fresh draft designs for this search (DEFAULT true; first page of a worded, unfiltered search only). Set false for catalog results alone.")
1371
1420
  },
1372
1421
  annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
1373
1422
  },
1374
1423
  async (args) => {
1375
1424
  try {
1376
- const { hits, estimatedTotalHits } = await searchDesigns(args.query, args.limit, args.offset, args.filter, args.semantic_ratio);
1425
+ const wantsDrafts = args.drafts !== false && args.query.trim().length > 0 && args.offset === 0 && !args.filter;
1426
+ const [{ hits, estimatedTotalHits }, drafted] = await Promise.all([
1427
+ searchDesigns(args.query, args.limit, args.offset, args.filter, args.semantic_ratio),
1428
+ wantsDrafts ? searchDrafts(args.query.trim(), ctx.forwardedFor) : Promise.resolve(null)
1429
+ ]);
1377
1430
  const items = await Promise.all(hits.map((h) => summarizeDesign(h, args.shop, args.shop_secret)));
1378
1431
  const out = {
1379
1432
  total: estimatedTotalHits,
1380
1433
  count: items.length,
1381
1434
  offset: args.offset,
1382
1435
  items,
1383
- has_more: estimatedTotalHits > args.offset + items.length
1436
+ has_more: estimatedTotalHits > args.offset + items.length,
1437
+ ...drafted ? { drafts: drafted.drafts, drafts_status: drafted.status, drafts_detail: drafted.detail } : {}
1384
1438
  };
1385
- let text = JSON.stringify(out, null, 2);
1439
+ const catalog = { total: out.total, count: out.count, offset: out.offset, items, has_more: out.has_more };
1440
+ let text = JSON.stringify(catalog, null, 2);
1386
1441
  if (text.length > CHARACTER_LIMIT) {
1387
- text = JSON.stringify({ ...out, items: items.slice(0, 5), truncated: true }, null, 2);
1442
+ text = JSON.stringify({ ...catalog, items: items.slice(0, 5), truncated: true }, null, 2);
1388
1443
  }
1444
+ const draftLines = drafted ? draftsText(args.query.trim(), drafted) : "";
1445
+ if (draftLines) text = `${draftLines}
1446
+
1447
+ Catalog designs for this search:
1448
+ ${text}`;
1389
1449
  return { content: [{ type: "text", text }], structuredContent: out };
1390
1450
  } catch (err) {
1391
1451
  return fail(formatError(err));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/mcp",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "mcpName": "io.github.snowcone-app/snowcone",
5
5
  "description": "Snowcone MCP server — the agent-native quickstart. Mint a sandbox shop, browse the catalog, and turn any image into a buyable printed-merch mockup URL, all as callable tools.",
6
6
  "keywords": [