@snowcone-app/mcp 0.12.0 → 0.13.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.13.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#5271](https://github.com/snowcone-app/snowcone-monorepo/pull/5271) [`1475d52`](https://github.com/snowcone-app/snowcone-monorepo/commit/1475d528f13d5f88b8d4baae0d4434bf5c58a6b9) Thanks [@kevinsproles](https://github.com/kevinsproles)! - `snowcone_search_designs` now shows its fresh draft designs as a picture grid in MCP Apps hosts (ChatGPT, Claude, …): each draft on a product with its price, and a "Use this design" button that sends the pick back into the chat as the person's next message. The result also carries `grid`, `drafts_ms`, `drafts_cached` and `draft_budget`.
8
+
3
9
  ## 0.12.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.12.0",
252
+ version: "0.13.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: [
@@ -849,7 +849,7 @@ async function searchDesigns(query, limit, offset, filter, semanticRatio) {
849
849
  // src/drafts.ts
850
850
  var KNOWN = ["ok", "blocked", "limited", "budget-exhausted", "no-product", "unavailable"];
851
851
  async function searchDrafts(query, forwardedFor) {
852
- const none = (status, detail) => ({ status, detail, drafts: [], cached: false, subject: "", product_terms: "" });
852
+ const none = (status, detail) => ({ status, detail, drafts: [], cached: false, subject: "", product_terms: "", ms: 0, draft_budget: null });
853
853
  try {
854
854
  const r = await httpJson(`${API_BASE}/agent-drafts/search`, {
855
855
  method: "POST",
@@ -865,7 +865,9 @@ async function searchDrafts(query, forwardedFor) {
865
865
  drafts: Array.isArray(r.drafts) ? r.drafts.filter((d) => d && d.moderated === true && typeof d.mockup_url === "string") : [],
866
866
  cached: r.cached === true,
867
867
  subject: typeof r.subject === "string" ? r.subject : "",
868
- product_terms: typeof r.product_terms === "string" ? r.product_terms : ""
868
+ product_terms: typeof r.product_terms === "string" ? r.product_terms : "",
869
+ ms: typeof r.ms === "number" ? r.ms : 0,
870
+ draft_budget: typeof r.draft_budget?.max_ms === "number" && typeof r.draft_budget?.max_micro_usd === "number" ? { max_ms: r.draft_budget.max_ms, max_micro_usd: r.draft_budget.max_micro_usd } : null
869
871
  };
870
872
  } catch (err) {
871
873
  const why = err instanceof HttpError ? `HTTP ${err.status}` : err instanceof Error ? err.message : String(err);
@@ -886,6 +888,274 @@ ${a.detail}`;
886
888
  return a.detail ? `No fresh drafts: ${a.detail}` : "";
887
889
  }
888
890
 
891
+ // src/grid.ts
892
+ var GRID_URI = "ui://snowcone/drafts-grid.html";
893
+ var GRID_MIME = "text/html;profile=mcp-app";
894
+ var GRID_MAX_TILES = 6;
895
+ var GRID_TOOL_META = {
896
+ ui: { resourceUri: GRID_URI },
897
+ "ui/resourceUri": GRID_URI,
898
+ "openai/outputTemplate": GRID_URI,
899
+ "openai/toolInvocation/invoking": "Sketching ideas\u2026",
900
+ "openai/toolInvocation/invoked": "Ideas ready"
901
+ };
902
+ function gridResourceMeta(opts = {}) {
903
+ const domains = [new URL(IMG_BASE).origin];
904
+ if (opts.beaconUrl) domains.push(new URL(opts.beaconUrl).origin);
905
+ return {
906
+ ui: { csp: { resourceDomains: domains, connectDomains: [] }, prefersBorder: true },
907
+ "openai/widgetCSP": { resource_domains: domains, connect_domains: [] },
908
+ "openai/widgetPrefersBorder": true,
909
+ "openai/widgetDescription": "Draft designs made for the person's search, each shown on a product with its price. 'Use this design' sends their pick back into the chat."
910
+ };
911
+ }
912
+ var NOTES = {
913
+ ok: "",
914
+ "not-asked": "",
915
+ blocked: "We can't sketch this one: it asks for a brand, a real person or something we don't print. Try describing an original design.",
916
+ limited: "That's a lot of new ideas in a short time. Try again in a little while.",
917
+ "budget-exhausted": "Today's free sketches are used up. They come back tomorrow.",
918
+ "no-product": "We don't make that product yet. Try a t-shirt, hoodie, tote bag or phone case.",
919
+ unavailable: "Sketches aren't available right now. Try again in a moment.",
920
+ unreachable: "Sketches aren't available right now. Try again in a moment."
921
+ };
922
+ function buildGrid(query, drafted, catalogCount) {
923
+ if (!drafted) return { query, status: "not-asked", note: "", tiles: [], catalog_count: catalogCount };
924
+ const tiles = [];
925
+ const deepest = Math.max(0, ...drafted.drafts.map((d) => d.mockups.length));
926
+ for (let p = 0; p < deepest && tiles.length < GRID_MAX_TILES; p++) {
927
+ for (const d of drafted.drafts) {
928
+ const m = d.mockups[p];
929
+ if (!m || tiles.length >= GRID_MAX_TILES) continue;
930
+ tiles.push({ draft_id: d.draft_id, image_url: d.image_url, mockup_url: m.mockup_url, product_id: m.product_id, product_name: m.product_name, price_cents: m.price_cents });
931
+ }
932
+ }
933
+ const status = drafted.status === "ok" && tiles.length === 0 ? "unavailable" : drafted.status;
934
+ return { query, status, note: tiles.length > 0 ? "" : NOTES[status], tiles, catalog_count: catalogCount };
935
+ }
936
+ function gridHtml(opts = {}) {
937
+ return GRID_HTML.replace("__VERSION__", VERSION).replace("__BEACON__", opts.beaconUrl ? JSON.stringify(opts.beaconUrl).slice(1, -1) : "");
938
+ }
939
+ var GRID_HTML = `<!doctype html>
940
+ <html lang="en">
941
+ <head>
942
+ <meta charset="utf-8" />
943
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
944
+ <title>Snowcone draft designs</title>
945
+ <style>
946
+ :root { color-scheme: light dark; --bg:#fff; --fg:#14161a; --muted:#5d636e; --line:#e4e6ea; --well:#f4f5f7; --accent:#14161a; --accent-fg:#fff; }
947
+ :root[data-theme="dark"] { --bg:#16181c; --fg:#f2f3f5; --muted:#a2a8b3; --line:#2c3038; --well:#1f2228; --accent:#f2f3f5; --accent-fg:#14161a; }
948
+ @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) { --bg:#16181c; --fg:#f2f3f5; --muted:#a2a8b3; --line:#2c3038; --well:#1f2228; --accent:#f2f3f5; --accent-fg:#14161a; } }
949
+ * { box-sizing: border-box; }
950
+ html, body { margin: 0; background: var(--bg); color: var(--fg); font: 14px/1.4 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; }
951
+ .grid-card { max-width: 640px; margin: 0 auto; padding: 12px; }
952
+ .title { font-weight: 600; font-size: 15px; margin: 0 2px 10px; }
953
+ .tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
954
+ .tile { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; display: flex; flex-direction: column; }
955
+ .pic { position: relative; background: var(--well); aspect-ratio: 16 / 9; }
956
+ .pic img { width: 100%; height: 100%; object-fit: cover; display: block; }
957
+ .badge { position: absolute; top: 8px; left: 8px; background: var(--bg); color: var(--fg); border: 1px solid var(--line); border-radius: 999px; font-size: 11px; font-weight: 600; padding: 2px 8px; }
958
+ .meta { padding: 8px 10px 0; flex: 1; }
959
+ .pname { font-size: 13px; font-weight: 600; line-height: 1.3; }
960
+ .pprice { font-size: 13px; color: var(--muted); font-variant-numeric: tabular-nums; margin-top: 2px; }
961
+ .use { margin: 8px 10px 10px; border: 0; border-radius: 9px; padding: 9px 10px; font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-fg); cursor: pointer; }
962
+ .use:disabled { background: var(--well); color: var(--muted); cursor: default; }
963
+ .note { margin: 4px 2px; color: var(--muted); font-size: 13px; }
964
+ .foot { margin: 10px 2px 0; font-size: 12px; color: var(--muted); }
965
+ </style>
966
+ </head>
967
+ <body>
968
+ <div class="grid-card" id="grid" data-state="loading" data-status="" data-tiles="0" data-picked="">
969
+ <div class="title" id="title">Sketching ideas\u2026</div>
970
+ <div class="tiles" id="tiles"></div>
971
+ <div class="note" id="note" hidden></div>
972
+ <div class="foot" id="foot" hidden></div>
973
+ </div>
974
+ <script>
975
+ (() => {
976
+ "use strict";
977
+ const $ = (id) => document.getElementById(id);
978
+ const root = $("grid");
979
+ const BEACON = "__BEACON__";
980
+ let beaconSent = false;
981
+ let bridge = false;
982
+ let nextId = 1;
983
+ const pending = new Map();
984
+
985
+ function post(msg) { window.parent.postMessage(msg, "*"); }
986
+ function request(method, params) {
987
+ return new Promise((resolve, reject) => {
988
+ const id = nextId++;
989
+ pending.set(id, { resolve, reject });
990
+ post({ jsonrpc: "2.0", id, method, params });
991
+ setTimeout(() => { if (pending.has(id)) { pending.delete(id); reject(new Error(method + " timed out")); } }, 30000);
992
+ });
993
+ }
994
+ function notify(method, params) { post({ jsonrpc: "2.0", method, params: params || {} }); }
995
+ function applyTheme(ctx) {
996
+ const theme = ctx && ctx.theme;
997
+ if (theme === "dark" || theme === "light") document.documentElement.setAttribute("data-theme", theme);
998
+ }
999
+ function money(cents) { return typeof cents === "number" ? "$" + (cents / 100).toFixed(2) : ""; }
1000
+ function canSend() { return bridge || (window.openai && typeof window.openai.sendFollowUpMessage === "function"); }
1001
+
1002
+ let lastH = 0;
1003
+ function resize() {
1004
+ const h = Math.ceil(document.documentElement.getBoundingClientRect().height);
1005
+ if (bridge && h !== lastH) { lastH = h; notify("ui/notifications/size-changed", { height: h }); }
1006
+ }
1007
+ if (typeof ResizeObserver === "function") new ResizeObserver(resize).observe(document.body);
1008
+
1009
+ function message(t) {
1010
+ return "I like this draft. Show me this design on the " + t.product_name + " (product " + t.product_id + "), using the design image " + t.image_url + " (draft " + t.draft_id + ").";
1011
+ }
1012
+
1013
+ async function use(t, button) {
1014
+ const text = message(t);
1015
+ button.disabled = true;
1016
+ try {
1017
+ if (bridge) {
1018
+ const r = await request("ui/message", { role: "user", content: [{ type: "text", text }] });
1019
+ if (r && r.isError) throw new Error("the host did not take the message");
1020
+ } else if (window.openai && typeof window.openai.sendFollowUpMessage === "function") {
1021
+ await window.openai.sendFollowUpMessage({ prompt: text });
1022
+ } else {
1023
+ throw new Error("no way to send");
1024
+ }
1025
+ root.dataset.picked = t.draft_id + ":" + t.product_id;
1026
+ button.textContent = "Sent";
1027
+ } catch (_) {
1028
+ // Never a dead button: say what to ask for instead.
1029
+ button.disabled = true;
1030
+ button.textContent = "Ask for \u201Cdraft " + (t.n || "") + " on the " + t.product_name + "\u201D";
1031
+ }
1032
+ }
1033
+
1034
+ let grid = null;
1035
+ function render(next) {
1036
+ if (!next || typeof next !== "object") return;
1037
+ grid = next;
1038
+ const tiles = Array.isArray(grid.tiles) ? grid.tiles : [];
1039
+ root.dataset.state = "ready";
1040
+ root.dataset.status = String(grid.status || "");
1041
+ root.dataset.tiles = String(tiles.length);
1042
+ $("title").textContent = tiles.length ? "Ideas for \u201C" + grid.query + "\u201D" : (grid.query ? "\u201C" + grid.query + "\u201D" : "Designs");
1043
+ const list = $("tiles");
1044
+ list.textContent = "";
1045
+ const order = [];
1046
+ for (const t of tiles) {
1047
+ if (typeof t.mockup_url !== "string" || !/^https:\\/\\//.test(t.mockup_url)) continue;
1048
+ if (!order.includes(t.draft_id)) order.push(t.draft_id);
1049
+ const n = order.indexOf(t.draft_id) + 1;
1050
+ const tile = document.createElement("div");
1051
+ tile.className = "tile";
1052
+ tile.dataset.draft = t.draft_id;
1053
+ tile.dataset.product = t.product_id;
1054
+ const pic = document.createElement("div");
1055
+ pic.className = "pic";
1056
+ const img = document.createElement("img");
1057
+ img.alt = "Draft " + n + " on " + t.product_name;
1058
+ img.loading = "lazy";
1059
+ img.onload = () => { if (BEACON && !beaconSent) { beaconSent = true; new Image().src = BEACON; } resize(); };
1060
+ img.src = t.mockup_url;
1061
+ const badge = document.createElement("div");
1062
+ badge.className = "badge";
1063
+ badge.textContent = "Draft " + n;
1064
+ pic.appendChild(img);
1065
+ pic.appendChild(badge);
1066
+ const meta = document.createElement("div");
1067
+ meta.className = "meta";
1068
+ const name = document.createElement("div");
1069
+ name.className = "pname";
1070
+ name.textContent = t.product_name;
1071
+ const price = document.createElement("div");
1072
+ price.className = "pprice";
1073
+ price.textContent = money(t.price_cents);
1074
+ meta.appendChild(name);
1075
+ meta.appendChild(price);
1076
+ const b = document.createElement("button");
1077
+ b.type = "button";
1078
+ b.className = "use";
1079
+ b.textContent = "Use this design";
1080
+ b.addEventListener("click", () => use(Object.assign({ n }, t), b));
1081
+ tile.appendChild(pic);
1082
+ tile.appendChild(meta);
1083
+ tile.appendChild(b);
1084
+ list.appendChild(tile);
1085
+ }
1086
+ const note = $("note");
1087
+ const foot = $("foot");
1088
+ const count = Number(grid.catalog_count) || 0;
1089
+ const catalogLine = count > 0 ? count + " ready-made design" + (count === 1 ? "" : "s") + " for this search " + (count === 1 ? "is" : "are") + " listed in the chat." : "";
1090
+ if (tiles.length) {
1091
+ note.hidden = true;
1092
+ foot.textContent = "Drafts are quick sketches. Pick one to see it finished, or describe a change." + (catalogLine ? " " + catalogLine : "");
1093
+ foot.hidden = false;
1094
+ } else {
1095
+ note.textContent = [grid.note, catalogLine].filter(Boolean).join(" ") || "No designs to show for this search.";
1096
+ note.hidden = false;
1097
+ foot.hidden = true;
1098
+ }
1099
+ resize();
1100
+ }
1101
+
1102
+ function onToolResult(result) {
1103
+ if (!result) return;
1104
+ if (result.isError) {
1105
+ root.dataset.state = "error";
1106
+ $("title").textContent = "Designs";
1107
+ $("note").textContent = "The search didn't work this time.";
1108
+ $("note").hidden = false;
1109
+ return;
1110
+ }
1111
+ const sc = result.structuredContent;
1112
+ if (sc && sc.grid) render(sc.grid);
1113
+ }
1114
+
1115
+ window.addEventListener("message", (event) => {
1116
+ if (event.source !== window.parent) return;
1117
+ const m = event.data;
1118
+ if (!m || m.jsonrpc !== "2.0") return;
1119
+ if (m.method === undefined && m.id !== undefined && pending.has(m.id)) {
1120
+ const p = pending.get(m.id);
1121
+ pending.delete(m.id);
1122
+ if (m.error) p.reject(new Error(m.error.message || "host error"));
1123
+ else p.resolve(m.result);
1124
+ return;
1125
+ }
1126
+ switch (m.method) {
1127
+ case "ui/notifications/tool-result": onToolResult(m.params); break;
1128
+ case "ui/notifications/host-context-changed": applyTheme(m.params); break;
1129
+ default:
1130
+ if (m.id !== undefined && m.method) post({ jsonrpc: "2.0", id: m.id, result: {} });
1131
+ }
1132
+ });
1133
+
1134
+ function fromOpenAi() {
1135
+ const o = window.openai;
1136
+ if (!o) return;
1137
+ applyTheme({ theme: o.theme });
1138
+ if (o.toolOutput && o.toolOutput.grid) render(o.toolOutput.grid);
1139
+ }
1140
+ window.addEventListener("openai:set_globals", fromOpenAi);
1141
+ fromOpenAi();
1142
+
1143
+ request("ui/initialize", {
1144
+ appInfo: { name: "snowcone-drafts-grid", version: "__VERSION__" },
1145
+ appCapabilities: {},
1146
+ protocolVersion: "2026-01-26",
1147
+ }).then((r) => {
1148
+ bridge = true;
1149
+ applyTheme(r && r.hostContext);
1150
+ notify("ui/notifications/initialized", {});
1151
+ resize();
1152
+ }).catch(() => { /* no MCP Apps host: the openai globals (if any) drive the grid */ });
1153
+ })();
1154
+ </script>
1155
+ </body>
1156
+ </html>
1157
+ `;
1158
+
889
1159
  // src/launch.ts
890
1160
  var launchFetch = (url, init) => fetch(url, init);
891
1161
  var TTL_MS = 6e4;
@@ -1121,6 +1391,7 @@ var buyUrl = (input) => buildUrl(input, BUY_BASE);
1121
1391
  function createServer(ctx = {}) {
1122
1392
  const server2 = new McpServer({ name: "snowcone-mcp-server", version: VERSION });
1123
1393
  registerCard(server2, ctx);
1394
+ registerGrid(server2, ctx);
1124
1395
  registerTools(server2, ctx);
1125
1396
  return server2;
1126
1397
  }
@@ -1210,6 +1481,22 @@ function registerCard(server2, ctx) {
1210
1481
  })
1211
1482
  );
1212
1483
  }
1484
+ function registerGrid(server2, ctx) {
1485
+ const opts = ctx.cardBeaconUrl ? { beaconUrl: ctx.cardBeaconUrl } : {};
1486
+ server2.registerResource(
1487
+ "Snowcone draft designs",
1488
+ GRID_URI,
1489
+ {
1490
+ title: "Snowcone draft designs",
1491
+ description: "Draft designs made for a search, each on a product with its price; 'Use this design' sends the pick back into the chat.",
1492
+ mimeType: GRID_MIME,
1493
+ _meta: gridResourceMeta(opts)
1494
+ },
1495
+ async () => ({
1496
+ contents: [{ uri: GRID_URI, mimeType: GRID_MIME, text: gridHtml(opts), _meta: gridResourceMeta(opts) }]
1497
+ })
1498
+ );
1499
+ }
1213
1500
  function pickableOptions(p, chosen) {
1214
1501
  const attrs = p?.options?.attributes;
1215
1502
  const out = {};
@@ -1407,7 +1694,8 @@ Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right
1407
1694
  "snowcone_search_designs",
1408
1695
  {
1409
1696
  title: "Search the pre-made designs catalog",
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.",
1697
+ 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. In ChatGPT, Claude and other MCP Apps hosts the drafts show as a picture grid; when the person taps 'Use this design' their pick arrives as their next message, naming the product and the design image to render.",
1698
+ _meta: GRID_TOOL_META,
1411
1699
  inputSchema: {
1412
1700
  query: z.string().default("").describe("Search text, e.g. 'christmas card'. Empty string lists curated designs."),
1413
1701
  limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
@@ -1434,7 +1722,15 @@ Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right
1434
1722
  offset: args.offset,
1435
1723
  items,
1436
1724
  has_more: estimatedTotalHits > args.offset + items.length,
1437
- ...drafted ? { drafts: drafted.drafts, drafts_status: drafted.status, drafts_detail: drafted.detail } : {}
1725
+ ...drafted ? {
1726
+ drafts: drafted.drafts,
1727
+ drafts_status: drafted.status,
1728
+ drafts_detail: drafted.detail,
1729
+ drafts_cached: drafted.cached,
1730
+ drafts_ms: drafted.ms,
1731
+ ...drafted.draft_budget ? { draft_budget: drafted.draft_budget } : {}
1732
+ } : {},
1733
+ grid: buildGrid(args.query.trim(), drafted, estimatedTotalHits)
1438
1734
  };
1439
1735
  const catalog = { total: out.total, count: out.count, offset: out.offset, items, has_more: out.has_more };
1440
1736
  let text = JSON.stringify(catalog, null, 2);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@snowcone-app/mcp",
3
- "version": "0.12.0",
3
+ "version": "0.13.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": [