@snowcone-app/mcp 0.9.2 → 0.10.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 +6 -0
- package/dist/index.js +853 -402
- package/package.json +4 -1
package/dist/index.js
CHANGED
|
@@ -24,7 +24,9 @@ var SNOWCONE_HOSTS = {
|
|
|
24
24
|
/** Content-addressed artwork store (ingest handles). */
|
|
25
25
|
raws: "https://raws.snowcone.app",
|
|
26
26
|
/** Developer docs. */
|
|
27
|
-
docs: "https://developers.snowcone.app"
|
|
27
|
+
docs: "https://developers.snowcone.app",
|
|
28
|
+
/** The storefront site; `/api/launch` says whether orders are open yet. */
|
|
29
|
+
site: "https://snowcone.app"
|
|
28
30
|
};
|
|
29
31
|
var SNOWCONE_REALTIME_WS_URL = `${SNOWCONE_HOSTS.cdn.replace(/^http/, "ws")}/realtime`;
|
|
30
32
|
var PARAMS = {
|
|
@@ -232,6 +234,7 @@ async function signDevSig(canonical, secret) {
|
|
|
232
234
|
var API_BASE = stripSlash(process.env.SNOWCONE_API_BASE ?? SNOWCONE_HOSTS.api);
|
|
233
235
|
var IMG_BASE = stripSlash(process.env.SNOWCONE_IMG_BASE ?? SNOWCONE_HOSTS.img);
|
|
234
236
|
var BUY_BASE = stripSlash(process.env.SNOWCONE_BUY_BASE ?? SNOWCONE_HOSTS.buy);
|
|
237
|
+
var LAUNCH_URL = process.env.SNOWCONE_LAUNCH_URL ?? `${stripSlash(SNOWCONE_HOSTS.site)}/api/launch`;
|
|
235
238
|
var MEILI_HOST = stripSlash(process.env.SNOWCONE_MEILI_HOST ?? SNOWCONE_HOSTS.search);
|
|
236
239
|
var MEILI_KEY = process.env.SNOWCONE_MEILI_KEY ?? "73f573ead9be75531c56ee89d104caa49d79154db387f119a013d33eccfe654b";
|
|
237
240
|
var MEILI_INDEX = process.env.SNOWCONE_MEILI_INDEX ?? "snowcone";
|
|
@@ -243,6 +246,362 @@ function stripSlash(s) {
|
|
|
243
246
|
return s.replace(/\/+$/, "");
|
|
244
247
|
}
|
|
245
248
|
|
|
249
|
+
// package.json
|
|
250
|
+
var package_default = {
|
|
251
|
+
name: "@snowcone-app/mcp",
|
|
252
|
+
version: "0.10.0",
|
|
253
|
+
mcpName: "io.github.snowcone-app/snowcone",
|
|
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
|
+
keywords: [
|
|
256
|
+
"mcp",
|
|
257
|
+
"model-context-protocol",
|
|
258
|
+
"snowcone",
|
|
259
|
+
"print-on-demand",
|
|
260
|
+
"mockup",
|
|
261
|
+
"merch",
|
|
262
|
+
"agent"
|
|
263
|
+
],
|
|
264
|
+
author: "Snowcone <dev@snowcone.app>",
|
|
265
|
+
license: "MIT",
|
|
266
|
+
repository: {
|
|
267
|
+
type: "git",
|
|
268
|
+
url: "https://github.com/snowcone-app/snowcone-monorepo.git",
|
|
269
|
+
directory: "packages/mcp"
|
|
270
|
+
},
|
|
271
|
+
bugs: {
|
|
272
|
+
url: "https://github.com/snowcone-app/snowcone-monorepo/issues"
|
|
273
|
+
},
|
|
274
|
+
homepage: "https://developers.snowcone.app",
|
|
275
|
+
private: false,
|
|
276
|
+
type: "module",
|
|
277
|
+
bin: {
|
|
278
|
+
"snowcone-mcp": "./dist/index.js"
|
|
279
|
+
},
|
|
280
|
+
main: "dist/index.js",
|
|
281
|
+
files: [
|
|
282
|
+
"dist",
|
|
283
|
+
"README.md",
|
|
284
|
+
"CHANGELOG.md"
|
|
285
|
+
],
|
|
286
|
+
scripts: {
|
|
287
|
+
build: "tsup",
|
|
288
|
+
dev: "tsup --watch",
|
|
289
|
+
start: "node dist/index.js",
|
|
290
|
+
"worker:dev": "wrangler dev",
|
|
291
|
+
deploy: "wrangler deploy --env production",
|
|
292
|
+
clean: "rm -rf dist",
|
|
293
|
+
typecheck: "tsc --noEmit",
|
|
294
|
+
test: "vitest run",
|
|
295
|
+
prepack: "pnpm run build"
|
|
296
|
+
},
|
|
297
|
+
dependencies: {
|
|
298
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
299
|
+
zod: "^3.23.8"
|
|
300
|
+
},
|
|
301
|
+
devDependencies: {
|
|
302
|
+
"@snowcone-app/mockup-url": "workspace:*",
|
|
303
|
+
"@types/node": "^20.11.0",
|
|
304
|
+
tsup: "^8.1.0",
|
|
305
|
+
typescript: "^5.5.4",
|
|
306
|
+
vitest: "^2.1.9",
|
|
307
|
+
wrangler: "^3.91.0"
|
|
308
|
+
},
|
|
309
|
+
publishConfig: {
|
|
310
|
+
access: "public"
|
|
311
|
+
},
|
|
312
|
+
engines: {
|
|
313
|
+
node: ">=18"
|
|
314
|
+
}
|
|
315
|
+
};
|
|
316
|
+
|
|
317
|
+
// src/version.ts
|
|
318
|
+
var VERSION = package_default.version ?? "0.0.0";
|
|
319
|
+
|
|
320
|
+
// src/card.ts
|
|
321
|
+
var CARD_URI = "ui://snowcone/mockup-card.html";
|
|
322
|
+
var CARD_MIME = "text/html;profile=mcp-app";
|
|
323
|
+
var CARD_TOOL_META = {
|
|
324
|
+
ui: { resourceUri: CARD_URI },
|
|
325
|
+
"ui/resourceUri": CARD_URI,
|
|
326
|
+
"openai/outputTemplate": CARD_URI,
|
|
327
|
+
"openai/widgetAccessible": true,
|
|
328
|
+
"openai/toolInvocation/invoking": "Rendering the mockup\u2026",
|
|
329
|
+
"openai/toolInvocation/invoked": "Mockup ready"
|
|
330
|
+
};
|
|
331
|
+
function cardResourceMeta() {
|
|
332
|
+
const img = new URL(IMG_BASE).origin;
|
|
333
|
+
return {
|
|
334
|
+
ui: { csp: { resourceDomains: [img], connectDomains: [] }, prefersBorder: true },
|
|
335
|
+
"openai/widgetCSP": { resource_domains: [img], connect_domains: [] },
|
|
336
|
+
"openai/widgetPrefersBorder": true,
|
|
337
|
+
"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
|
+
}
|
|
340
|
+
function cardHtml() {
|
|
341
|
+
return CARD_HTML.replace("__VERSION__", VERSION);
|
|
342
|
+
}
|
|
343
|
+
var CARD_HTML = `<!doctype html>
|
|
344
|
+
<html lang="en">
|
|
345
|
+
<head>
|
|
346
|
+
<meta charset="utf-8" />
|
|
347
|
+
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
|
348
|
+
<title>Snowcone mockup</title>
|
|
349
|
+
<style>
|
|
350
|
+
:root { color-scheme: light dark; --bg:#fff; --fg:#14161a; --muted:#5d636e; --line:#e4e6ea; --well:#f4f5f7; --accent:#14161a; --accent-fg:#fff; }
|
|
351
|
+
:root[data-theme="dark"] { --bg:#16181c; --fg:#f2f3f5; --muted:#a2a8b3; --line:#2c3038; --well:#1f2228; --accent:#f2f3f5; --accent-fg:#14161a; }
|
|
352
|
+
@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; } }
|
|
353
|
+
* { box-sizing: border-box; }
|
|
354
|
+
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; }
|
|
355
|
+
.card { max-width: 560px; margin: 0 auto; padding: 12px; }
|
|
356
|
+
.well { position: relative; background: var(--well); border-radius: 12px; overflow: hidden; aspect-ratio: 16 / 9; display: grid; place-items: center; }
|
|
357
|
+
.well img { width: 100%; height: 100%; object-fit: contain; display: block; transition: opacity .2s; }
|
|
358
|
+
.card[data-state="loading"] .well img, .card[data-busy="true"] .well img { opacity: .45; }
|
|
359
|
+
.placeholder { color: var(--muted); font-size: 13px; padding: 16px; text-align: center; }
|
|
360
|
+
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 12px 2px 0; }
|
|
361
|
+
.name { font-weight: 600; font-size: 15px; }
|
|
362
|
+
.price { font-variant-numeric: tabular-nums; color: var(--muted); white-space: nowrap; }
|
|
363
|
+
.opts { margin: 10px 2px 0; display: grid; gap: 8px; }
|
|
364
|
+
.opt-label { font-size: 12px; color: var(--muted); margin-bottom: 4px; text-transform: capitalize; }
|
|
365
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
|
|
366
|
+
.chip { border: 1px solid var(--line); background: transparent; color: var(--fg); border-radius: 999px; padding: 4px 10px; font: inherit; font-size: 13px; cursor: pointer; }
|
|
367
|
+
.chip[aria-pressed="true"] { border-color: var(--fg); font-weight: 600; }
|
|
368
|
+
.chip:disabled { cursor: default; opacity: .6; }
|
|
369
|
+
.buy { margin: 12px 2px 0; }
|
|
370
|
+
.btn { width: 100%; border: 0; border-radius: 10px; padding: 11px 14px; font: inherit; font-weight: 600; background: var(--accent); color: var(--accent-fg); cursor: pointer; }
|
|
371
|
+
.btn:disabled { background: var(--well); color: var(--muted); cursor: default; }
|
|
372
|
+
.note { margin: 6px 2px 0; font-size: 12px; color: var(--muted); }
|
|
373
|
+
.error { margin: 12px 2px 0; font-size: 13px; color: #c0392b; white-space: pre-wrap; }
|
|
374
|
+
.foot { margin: 10px 2px 0; font-size: 11px; color: var(--muted); }
|
|
375
|
+
</style>
|
|
376
|
+
</head>
|
|
377
|
+
<body>
|
|
378
|
+
<div class="card" id="card" data-state="loading" data-orders="" data-busy="false" data-missing-option="">
|
|
379
|
+
<div class="well"><div class="placeholder" id="placeholder">Rendering your mockup\u2026</div><img id="img" alt="" hidden /></div>
|
|
380
|
+
<div class="head" id="head" hidden><div class="name" id="name"></div><div class="price" id="price"></div></div>
|
|
381
|
+
<div class="opts" id="opts"></div>
|
|
382
|
+
<div class="buy" id="buy" hidden><button class="btn" id="buyBtn" type="button"></button><div class="note" id="note"></div></div>
|
|
383
|
+
<div class="error" id="error" hidden></div>
|
|
384
|
+
<div class="foot">Printed and shipped by Snowcone</div>
|
|
385
|
+
</div>
|
|
386
|
+
<script>
|
|
387
|
+
(() => {
|
|
388
|
+
"use strict";
|
|
389
|
+
const $ = (id) => document.getElementById(id);
|
|
390
|
+
const cardEl = $("card");
|
|
391
|
+
let card = null;
|
|
392
|
+
let bridge = false; // MCP Apps bridge is up
|
|
393
|
+
let nextId = 1;
|
|
394
|
+
const pending = new Map();
|
|
395
|
+
|
|
396
|
+
function post(msg) { window.parent.postMessage(msg, "*"); }
|
|
397
|
+
function request(method, params) {
|
|
398
|
+
return new Promise((resolve, reject) => {
|
|
399
|
+
const id = nextId++;
|
|
400
|
+
pending.set(id, { resolve, reject });
|
|
401
|
+
post({ jsonrpc: "2.0", id, method, params });
|
|
402
|
+
setTimeout(() => { if (pending.has(id)) { pending.delete(id); reject(new Error(method + " timed out")); } }, 30000);
|
|
403
|
+
});
|
|
404
|
+
}
|
|
405
|
+
function notify(method, params) { post({ jsonrpc: "2.0", method, params: params || {} }); }
|
|
406
|
+
|
|
407
|
+
function applyTheme(ctx) {
|
|
408
|
+
const theme = ctx && ctx.theme;
|
|
409
|
+
if (theme === "dark" || theme === "light") document.documentElement.setAttribute("data-theme", theme);
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
function money(cents) {
|
|
413
|
+
if (typeof cents !== "number") return "";
|
|
414
|
+
return "$" + (cents / 100).toFixed(2);
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
function showError(text) {
|
|
418
|
+
cardEl.dataset.state = "error";
|
|
419
|
+
$("placeholder").textContent = "This mockup didn't render.";
|
|
420
|
+
$("img").hidden = true;
|
|
421
|
+
$("placeholder").hidden = false;
|
|
422
|
+
const e = $("error");
|
|
423
|
+
e.textContent = text || "";
|
|
424
|
+
e.hidden = !text;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
function render(next) {
|
|
428
|
+
if (!next || typeof next !== "object") return;
|
|
429
|
+
card = next;
|
|
430
|
+
cardEl.dataset.state = "ready";
|
|
431
|
+
cardEl.dataset.orders = card.orders && card.orders.orders === "open" ? "open" : "not-open";
|
|
432
|
+
$("error").hidden = true;
|
|
433
|
+
|
|
434
|
+
const img = $("img");
|
|
435
|
+
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(); };
|
|
437
|
+
img.onerror = () => { cardEl.dataset.busy = "false"; showError("The image host refused the picture."); };
|
|
438
|
+
img.alt = card.product ? "Mockup of " + card.product.name : "Product mockup";
|
|
439
|
+
if (img.src === card.image_url && img.complete) cardEl.dataset.busy = "false"; // same picture: no load event comes
|
|
440
|
+
else img.src = card.image_url;
|
|
441
|
+
} else {
|
|
442
|
+
cardEl.dataset.busy = "false";
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (card.product) {
|
|
446
|
+
$("name").textContent = card.product.name;
|
|
447
|
+
$("price").textContent = money(card.product.price_cents);
|
|
448
|
+
$("head").hidden = false;
|
|
449
|
+
} else {
|
|
450
|
+
$("head").hidden = true;
|
|
451
|
+
}
|
|
452
|
+
|
|
453
|
+
const opts = $("opts");
|
|
454
|
+
opts.textContent = "";
|
|
455
|
+
const canPick = !!card.render_args && (bridge || (window.openai && typeof window.openai.callTool === "function"));
|
|
456
|
+
for (const [attr, o] of Object.entries(card.options || {})) {
|
|
457
|
+
const row = document.createElement("div");
|
|
458
|
+
const label = document.createElement("div");
|
|
459
|
+
label.className = "opt-label";
|
|
460
|
+
label.textContent = attr;
|
|
461
|
+
const chips = document.createElement("div");
|
|
462
|
+
chips.className = "chips";
|
|
463
|
+
for (const choice of o.choices || []) {
|
|
464
|
+
const b = document.createElement("button");
|
|
465
|
+
b.type = "button";
|
|
466
|
+
b.className = "chip";
|
|
467
|
+
b.textContent = choice;
|
|
468
|
+
b.dataset.attr = attr;
|
|
469
|
+
b.dataset.choice = choice;
|
|
470
|
+
b.setAttribute("aria-pressed", String(o.selected === choice));
|
|
471
|
+
b.disabled = !canPick;
|
|
472
|
+
b.addEventListener("click", () => pick(attr, choice));
|
|
473
|
+
chips.appendChild(b);
|
|
474
|
+
}
|
|
475
|
+
row.appendChild(label);
|
|
476
|
+
row.appendChild(chips);
|
|
477
|
+
opts.appendChild(row);
|
|
478
|
+
}
|
|
479
|
+
|
|
480
|
+
const btn = $("buyBtn");
|
|
481
|
+
const note = $("note");
|
|
482
|
+
const missing = Object.entries(card.options || {}).find(([, o]) => !o.selected);
|
|
483
|
+
cardEl.dataset.missingOption = missing ? missing[0] : "";
|
|
484
|
+
if (card.orders && card.orders.orders === "open" && missing) {
|
|
485
|
+
// Never let a shopper buy a size (or colour) nobody chose.
|
|
486
|
+
btn.disabled = true;
|
|
487
|
+
btn.textContent = "Choose a " + missing[0];
|
|
488
|
+
note.textContent = canPick ? "Pick one above, then buy." : "Ask for the " + missing[0] + " you want.";
|
|
489
|
+
} else if (card.orders && card.orders.orders === "open") {
|
|
490
|
+
btn.disabled = false;
|
|
491
|
+
btn.textContent = card.product && card.product.price_cents != null ? "Buy \xB7 " + money(card.product.price_cents) : "Buy";
|
|
492
|
+
note.textContent = "Opens checkout in your browser.";
|
|
493
|
+
} else {
|
|
494
|
+
btn.disabled = true;
|
|
495
|
+
btn.textContent = "Orders open soon";
|
|
496
|
+
note.textContent = card.orders && card.orders.reason === "prelaunch"
|
|
497
|
+
? "Snowcone hasn't launched yet. This is exactly what you'd get."
|
|
498
|
+
: "We couldn't confirm ordering is available right now.";
|
|
499
|
+
}
|
|
500
|
+
$("buy").hidden = false;
|
|
501
|
+
resize();
|
|
502
|
+
}
|
|
503
|
+
|
|
504
|
+
async function pick(attr, choice) {
|
|
505
|
+
if (!card || !card.render_args) return;
|
|
506
|
+
const current = {};
|
|
507
|
+
for (const [a, o] of Object.entries(card.options || {})) if (o.selected) current[a] = o.selected;
|
|
508
|
+
const args = Object.assign({}, card.render_args, { options: Object.assign(current, { [attr]: choice }) });
|
|
509
|
+
cardEl.dataset.busy = "true";
|
|
510
|
+
try {
|
|
511
|
+
let result;
|
|
512
|
+
if (bridge) result = await request("tools/call", { name: "snowcone_render_mockup", arguments: args });
|
|
513
|
+
else result = await window.openai.callTool("snowcone_render_mockup", args);
|
|
514
|
+
const sc = result && (result.structuredContent || (result.result && result.result.structuredContent));
|
|
515
|
+
if (result && result.isError) {
|
|
516
|
+
cardEl.dataset.busy = "false";
|
|
517
|
+
showError(textOf(result));
|
|
518
|
+
} else if (sc && sc.card) render(sc.card);
|
|
519
|
+
else cardEl.dataset.busy = "false";
|
|
520
|
+
} catch (err) {
|
|
521
|
+
cardEl.dataset.busy = "false";
|
|
522
|
+
showError(String(err && err.message || err));
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
function textOf(result) {
|
|
527
|
+
const c = (result && result.content) || [];
|
|
528
|
+
return c.filter((x) => x && x.type === "text").map((x) => x.text).join("\\n");
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
$("buyBtn").addEventListener("click", async () => {
|
|
532
|
+
if (!card || !card.orders || card.orders.orders !== "open" || cardEl.dataset.missingOption) return;
|
|
533
|
+
const url = card.buy_url;
|
|
534
|
+
if (!/^https:\\/\\//.test(url)) return;
|
|
535
|
+
try {
|
|
536
|
+
if (bridge) { await request("ui/open-link", { url }); return; }
|
|
537
|
+
if (window.openai && typeof window.openai.openExternal === "function") { window.openai.openExternal({ href: url }); return; }
|
|
538
|
+
} catch (_) { /* fall through to a plain new tab */ }
|
|
539
|
+
window.open(url, "_blank", "noopener");
|
|
540
|
+
});
|
|
541
|
+
|
|
542
|
+
let lastH = 0;
|
|
543
|
+
function resize() {
|
|
544
|
+
const h = Math.ceil(document.documentElement.getBoundingClientRect().height);
|
|
545
|
+
if (bridge && h !== lastH) { lastH = h; notify("ui/notifications/size-changed", { height: h }); }
|
|
546
|
+
}
|
|
547
|
+
if (typeof ResizeObserver === "function") new ResizeObserver(resize).observe(document.body);
|
|
548
|
+
|
|
549
|
+
function onToolResult(result) {
|
|
550
|
+
if (!result) return;
|
|
551
|
+
if (result.isError) { showError(textOf(result)); return; }
|
|
552
|
+
const sc = result.structuredContent;
|
|
553
|
+
if (sc && sc.card) render(sc.card);
|
|
554
|
+
}
|
|
555
|
+
|
|
556
|
+
window.addEventListener("message", (event) => {
|
|
557
|
+
if (event.source !== window.parent) return;
|
|
558
|
+
const m = event.data;
|
|
559
|
+
if (!m || m.jsonrpc !== "2.0") return;
|
|
560
|
+
if (m.method === undefined && m.id !== undefined && pending.has(m.id)) {
|
|
561
|
+
const p = pending.get(m.id);
|
|
562
|
+
pending.delete(m.id);
|
|
563
|
+
if (m.error) p.reject(new Error(m.error.message || "host error"));
|
|
564
|
+
else p.resolve(m.result);
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
switch (m.method) {
|
|
568
|
+
case "ui/notifications/tool-result": onToolResult(m.params); break;
|
|
569
|
+
case "ui/notifications/tool-cancelled": showError("The render was cancelled."); break;
|
|
570
|
+
case "ui/notifications/host-context-changed": applyTheme(m.params); break;
|
|
571
|
+
default:
|
|
572
|
+
// Answer any host request we don't handle (e.g. ui/resource-teardown) so the host never hangs.
|
|
573
|
+
if (m.id !== undefined && m.method) post({ jsonrpc: "2.0", id: m.id, result: {} });
|
|
574
|
+
}
|
|
575
|
+
});
|
|
576
|
+
|
|
577
|
+
// OpenAI Apps SDK globals, where a host injects them.
|
|
578
|
+
function fromOpenAi() {
|
|
579
|
+
const o = window.openai;
|
|
580
|
+
if (!o) return;
|
|
581
|
+
applyTheme({ theme: o.theme });
|
|
582
|
+
if (o.toolOutput && o.toolOutput.card) render(o.toolOutput.card);
|
|
583
|
+
}
|
|
584
|
+
window.addEventListener("openai:set_globals", fromOpenAi);
|
|
585
|
+
fromOpenAi();
|
|
586
|
+
|
|
587
|
+
// MCP Apps handshake.
|
|
588
|
+
request("ui/initialize", {
|
|
589
|
+
appInfo: { name: "snowcone-mockup-card", version: "__VERSION__" },
|
|
590
|
+
appCapabilities: {},
|
|
591
|
+
protocolVersion: "2026-01-26",
|
|
592
|
+
}).then((r) => {
|
|
593
|
+
bridge = true;
|
|
594
|
+
applyTheme(r && r.hostContext);
|
|
595
|
+
notify("ui/notifications/initialized", {});
|
|
596
|
+
if (card) render(card); // re-enable the picker now that tools/call is available
|
|
597
|
+
resize();
|
|
598
|
+
}).catch(() => { /* no MCP Apps host: the openai globals (if any) drive the card */ });
|
|
599
|
+
})();
|
|
600
|
+
</script>
|
|
601
|
+
</body>
|
|
602
|
+
</html>
|
|
603
|
+
`;
|
|
604
|
+
|
|
246
605
|
// src/http.ts
|
|
247
606
|
function ok(structured, text) {
|
|
248
607
|
return {
|
|
@@ -481,6 +840,37 @@ async function searchDesigns(query, limit, offset, filter, semanticRatio) {
|
|
|
481
840
|
return { hits: body.hits ?? [], estimatedTotalHits: body.estimatedTotalHits ?? body.hits?.length ?? 0 };
|
|
482
841
|
}
|
|
483
842
|
|
|
843
|
+
// src/launch.ts
|
|
844
|
+
var TTL_MS = 6e4;
|
|
845
|
+
var cached = null;
|
|
846
|
+
async function readOrdersState(now = Date.now()) {
|
|
847
|
+
if (cached && now - cached.at < TTL_MS) return cached.state;
|
|
848
|
+
const state = await fetchState();
|
|
849
|
+
if (!(state.orders === "not-open" && state.reason === "unreadable")) cached = { at: now, state };
|
|
850
|
+
return state;
|
|
851
|
+
}
|
|
852
|
+
async function fetchState() {
|
|
853
|
+
try {
|
|
854
|
+
const res = await fetch(LAUNCH_URL, { headers: { Accept: "application/json" }, signal: AbortSignal.timeout(3e3) });
|
|
855
|
+
if (!res.ok) return unreadable(`HTTP ${res.status} from ${LAUNCH_URL}`);
|
|
856
|
+
const body = await res.json();
|
|
857
|
+
if (body.orders === "open") return { orders: "open" };
|
|
858
|
+
if (body.orders === "not-open" && body.reason === "prelaunch") return { orders: "not-open", reason: "prelaunch" };
|
|
859
|
+
return unreadable(`unexpected answer from ${LAUNCH_URL}: ${JSON.stringify(body).slice(0, 200)}`);
|
|
860
|
+
} catch (err) {
|
|
861
|
+
return unreadable(`${LAUNCH_URL}: ${err instanceof Error ? err.message : String(err)}`);
|
|
862
|
+
}
|
|
863
|
+
}
|
|
864
|
+
function unreadable(detail) {
|
|
865
|
+
return { orders: "not-open", reason: "unreadable", detail };
|
|
866
|
+
}
|
|
867
|
+
function ordersLine(s) {
|
|
868
|
+
if (s.orders === "open") return "Orders are open: the buy link takes the person to checkout.";
|
|
869
|
+
if (s.reason === "prelaunch")
|
|
870
|
+
return "Orders open soon: Snowcone hasn't launched yet. Show the person the mockup, but don't offer the buy link as a way to order today.";
|
|
871
|
+
return "Couldn't confirm that orders are open right now, so don't offer the buy link yet; the mockup is fine to show.";
|
|
872
|
+
}
|
|
873
|
+
|
|
484
874
|
// src/orders.ts
|
|
485
875
|
async function getQuote(input) {
|
|
486
876
|
const q = new URLSearchParams({ quote: "1" });
|
|
@@ -519,17 +909,6 @@ function orderStatusText(r) {
|
|
|
519
909
|
].join("\n");
|
|
520
910
|
}
|
|
521
911
|
|
|
522
|
-
// src/version.ts
|
|
523
|
-
import { createRequire } from "module";
|
|
524
|
-
var VERSION = (() => {
|
|
525
|
-
try {
|
|
526
|
-
const pkg = createRequire(import.meta.url)("../package.json");
|
|
527
|
-
return pkg.version ?? "0.0.0";
|
|
528
|
-
} catch {
|
|
529
|
-
return "0.0.0";
|
|
530
|
-
}
|
|
531
|
-
})();
|
|
532
|
-
|
|
533
912
|
// src/quickstart.ts
|
|
534
913
|
var QUICKSTART = `# Snowcone in one screen (for agents)
|
|
535
914
|
|
|
@@ -633,6 +1012,7 @@ Until you lock the shop, treat any artwork you render on it as effectively publi
|
|
|
633
1012
|
function mintShop(input) {
|
|
634
1013
|
return httpJson(`${API_BASE}/shops/sandbox`, {
|
|
635
1014
|
method: "POST",
|
|
1015
|
+
...input.forwardedFor ? { headers: { "X-Forwarded-For": input.forwardedFor } } : {},
|
|
636
1016
|
body: {
|
|
637
1017
|
...input.name ? { name: input.name } : {},
|
|
638
1018
|
...input.claim_pin ? { claim_pin: input.claim_pin } : {},
|
|
@@ -691,7 +1071,12 @@ var renderUrl = (input) => buildUrl(input, IMG_BASE);
|
|
|
691
1071
|
var buyUrl = (input) => buildUrl(input, BUY_BASE);
|
|
692
1072
|
|
|
693
1073
|
// src/server.ts
|
|
694
|
-
|
|
1074
|
+
function createServer(ctx = {}) {
|
|
1075
|
+
const server2 = new McpServer({ name: "snowcone-mcp-server", version: VERSION });
|
|
1076
|
+
registerCard(server2);
|
|
1077
|
+
registerTools(server2, ctx);
|
|
1078
|
+
return server2;
|
|
1079
|
+
}
|
|
695
1080
|
var fillSchema = z.union([
|
|
696
1081
|
z.string().describe("A public image URL for this placement."),
|
|
697
1082
|
z.object({
|
|
@@ -739,170 +1124,6 @@ function toUrlInput(a) {
|
|
|
739
1124
|
...a.shop_secret !== void 0 ? { shopSecret: a.shop_secret } : {}
|
|
740
1125
|
};
|
|
741
1126
|
}
|
|
742
|
-
server.registerTool(
|
|
743
|
-
"snowcone_quickstart",
|
|
744
|
-
{
|
|
745
|
-
title: "Snowcone Quickstart",
|
|
746
|
-
description: "Make custom printed products from any photo, design or text \u2014 t-shirts, mugs, hoodies, totes, posters \u2014 with a photoreal preview and a link to buy, printed and shipped for the user. Return the entire Snowcone model and the recommended tool order in one screen. Call this FIRST when you're new to Snowcone \u2014 it explains how to mint a shop, render a mockup, and sell it, plus the silent-failure gotchas.",
|
|
747
|
-
inputSchema: {},
|
|
748
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
749
|
-
},
|
|
750
|
-
async () => ({ content: [{ type: "text", text: QUICKSTART }] })
|
|
751
|
-
);
|
|
752
|
-
server.registerTool(
|
|
753
|
-
"snowcone_mint_shop",
|
|
754
|
-
{
|
|
755
|
-
title: "Mint a sandbox Shop",
|
|
756
|
-
description: "Start a print-on-demand merch store for a creator, podcast or brand in one call \u2014 no account, no inventory; every order is printed and shipped. Mint your OWN sandbox Shop ID \u2014 no account or human needed. Returns { shop_id, shop_secret, api_key, api_key_scopes, store_url, lineup, claim }. When store_url is set, the shop is already a live store at that link \u2014 show it to the person you're helping. Pass image_url (the person's art, logo or photo) and the store opens stocked with best-sellers wearing that image \u2014 real listings at catalog prices, with mockups and checkout \u2014 listed in lineup. IMPORTANT: mint ONCE and reuse the shop_id for all render/buy calls \u2014 minting is rate-limited (60/hour, 200 unclaimed per IP \u2192 HTTP 429). shop_id is public (use it as 'shop'); shop_secret and api_key are secret (server-side only). To get paid, hand claim.verification_uri_complete to your human and poll snowcone_claim_status.",
|
|
757
|
-
inputSchema: {
|
|
758
|
-
name: z.string().optional().describe("Optional shop name (e.g. 'Jess Prints'); it also names the store's web address. Defaults to 'Sandbox <id>'."),
|
|
759
|
-
claim_pin: z.string().optional().describe("Optional out-of-band PIN your human must enter to claim (deliver it separately from the link)."),
|
|
760
|
-
require_signature: z.boolean().optional().describe(
|
|
761
|
-
"Lock the shop down: require SIGNED mockup URLs (L3). Default false \u2014 the shop is open and any unsigned URL renders (simplest to start). Set true to harden against Shop-ID theft: then every render/buy URL must be signed with the returned shop_secret (pass it as shop_secret to snowcone_render_mockup / buy URLs). Unsigned URLs will 403."
|
|
762
|
-
),
|
|
763
|
-
mockup_bg_color: z.string().optional().describe(
|
|
764
|
-
"Default background painted behind every mockup render (6-hex, '#' optional, e.g. 'f5f0ea'). Visible only where the mockup scene is transparent (studio-cutout shots). Omit for transparent (the default). Change it later with snowcone_set_mockup_background; a per-render bg overrides it."
|
|
765
|
-
),
|
|
766
|
-
image_url: z.string().url().optional().describe(
|
|
767
|
-
"Optional art for the store to open with: an https URL of a public PNG, JPEG, WebP or AVIF image (at most 10 MB). The store then opens stocked with best-sellers wearing that image, ready to sell. A bad image fails the mint with a typed E_MINT_IMAGE_* error and creates nothing. Omit for an empty store that shows what it will sell once art is added."
|
|
768
|
-
)
|
|
769
|
-
},
|
|
770
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
|
|
771
|
-
},
|
|
772
|
-
async (args) => {
|
|
773
|
-
try {
|
|
774
|
-
const r = await mintShop({
|
|
775
|
-
...args.name !== void 0 ? { name: args.name } : {},
|
|
776
|
-
...args.claim_pin !== void 0 ? { claim_pin: args.claim_pin } : {},
|
|
777
|
-
...args.require_signature ? { require_signed_urls: true } : {},
|
|
778
|
-
...args.mockup_bg_color !== void 0 ? { mockup_bg_color: args.mockup_bg_color } : {},
|
|
779
|
-
...args.image_url !== void 0 ? { image_url: args.image_url } : {}
|
|
780
|
-
});
|
|
781
|
-
const sigLine = r.require_signed_urls ? `This shop REQUIRES signed URLs: pass shop_secret=${r.shop_secret} as shop_secret on every render/buy call, or the edge 403s.
|
|
782
|
-
` : `This shop is OPEN (unsigned URLs render). To lock it later, your human can toggle "Require signed URLs" on /studio/api-keys.
|
|
783
|
-
`;
|
|
784
|
-
const storeLine = r.store_url ? `Your store is live at ${r.store_url} \u2014 show this link to the person you're helping.
|
|
785
|
-
` : "";
|
|
786
|
-
const lineupLine = r.lineup?.listings.length ? `It opened stocked with ${r.lineup.listings.length} best-sellers wearing your image:
|
|
787
|
-
` + r.lineup.listings.map((l) => `- ${l.product_name} \u2014 $${(l.price_cents / 100).toFixed(2)}${l.url ? ` \u2014 ${l.url}` : ""} (mockup: ${l.mockup_url})`).join("\n") + "\n" : "";
|
|
788
|
-
const text = storeLine + lineupLine + `Minted shop_id=${r.shop_id} (REUSE this \u2014 don't mint again).
|
|
789
|
-
shop_secret=${r.shop_secret} (secret)
|
|
790
|
-
api_key=${r.api_key} (secret; scopes: ${r.api_key_scopes.join(", ")})
|
|
791
|
-
` + sigLine + `To get paid, send your human: ${r.claim.verification_uri_complete}
|
|
792
|
-
claim_token=${r.claim.claim_token} (secret)
|
|
793
|
-
Poll claim with that claim_token via snowcone_claim_status. Expires in ${r.claim.expires_in}s.
|
|
794
|
-
Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right after minting can 404 "Unknown shop"; wait a second and retry.`;
|
|
795
|
-
return ok(r, text);
|
|
796
|
-
} catch (err) {
|
|
797
|
-
return fail(formatError(err));
|
|
798
|
-
}
|
|
799
|
-
}
|
|
800
|
-
);
|
|
801
|
-
server.registerTool(
|
|
802
|
-
"snowcone_claim_status",
|
|
803
|
-
{
|
|
804
|
-
title: "Poll Shop claim status",
|
|
805
|
-
description: "Check whether your human has claimed the shop yet. Pass the claim_token from snowcone_mint_shop. Returns status: 'pending' | 'claimed' | 'expired'. Once 'claimed', sales route to your human's account.",
|
|
806
|
-
inputSchema: {
|
|
807
|
-
claim_token: z.string().min(1).describe("The claim_token returned by snowcone_mint_shop (ct_\u2026).")
|
|
808
|
-
},
|
|
809
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
810
|
-
},
|
|
811
|
-
async (args) => {
|
|
812
|
-
try {
|
|
813
|
-
return ok(await claimStatus(args.claim_token));
|
|
814
|
-
} catch (err) {
|
|
815
|
-
return fail(formatError(err));
|
|
816
|
-
}
|
|
817
|
-
}
|
|
818
|
-
);
|
|
819
|
-
server.registerTool(
|
|
820
|
-
"snowcone_release_shop",
|
|
821
|
-
{
|
|
822
|
-
title: "Release a sandbox Shop",
|
|
823
|
-
description: "Delete an UNCLAIMED sandbox shop you minted, freeing your per-IP mint budget. Authenticated by the shop_secret. Refused if the shop has already been claimed. Use this when you're done iterating. What survives: already-produced mockup IMAGE URLs keep rendering (they're public marketing imagery). What dies: buy/checkout URLs, the shop's credentials (shop_secret, api_key), and the claim link. Irreversible.",
|
|
824
|
-
inputSchema: {
|
|
825
|
-
shop_id: z.string().min(1).describe("The sandbox shop_id to release."),
|
|
826
|
-
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026).")
|
|
827
|
-
},
|
|
828
|
-
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
|
|
829
|
-
},
|
|
830
|
-
async (args) => {
|
|
831
|
-
try {
|
|
832
|
-
const r = await releaseShop(args.shop_id, args.shop_secret);
|
|
833
|
-
return ok(
|
|
834
|
-
r,
|
|
835
|
-
`Released shop_id=${r.shop_id}. Already-produced mockup IMAGE URLs keep rendering (public marketing imagery survives release). Buy/checkout URLs, the shop_secret, the api_key, and the claim link are now dead. Your per-IP mint budget is freed.`
|
|
836
|
-
);
|
|
837
|
-
} catch (err) {
|
|
838
|
-
return fail(formatError(err));
|
|
839
|
-
}
|
|
840
|
-
}
|
|
841
|
-
);
|
|
842
|
-
server.registerTool(
|
|
843
|
-
"snowcone_set_mockup_background",
|
|
844
|
-
{
|
|
845
|
-
title: "Set the shop's default mockup background",
|
|
846
|
-
description: "Set (or clear) the shop's DEFAULT background color for mockup renders \u2014 painted behind every render where the mockup scene is transparent (studio-cutout shots). Applies to all renders for the shop that don't pass an explicit bg; a per-render bg on snowcone_render_mockup overrides it. Sandbox shops only (authenticated by shop_secret); once claimed, your human manages this in shop settings \u2192 Branding. Takes effect on new renders within a few seconds (already-cached mockup URLs keep their old background).",
|
|
847
|
-
inputSchema: {
|
|
848
|
-
shop_id: z.string().min(1).describe("The sandbox shop_id to update."),
|
|
849
|
-
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026)."),
|
|
850
|
-
color: z.string().nullable().describe("6-hex color ('#' optional, e.g. 'f5f0ea' or '#F5F0EA'), or null to clear back to transparent.")
|
|
851
|
-
},
|
|
852
|
-
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
853
|
-
},
|
|
854
|
-
async (args) => {
|
|
855
|
-
try {
|
|
856
|
-
const r = await setMockupBackground(args.shop_id, args.shop_secret, args.color);
|
|
857
|
-
const stated = r.mockup_bg_color === null ? "transparent (cleared)" : `#${r.mockup_bg_color}`;
|
|
858
|
-
return ok(
|
|
859
|
-
r,
|
|
860
|
-
`Default mockup background for shop_id=${r.shop_id} is now ${stated}. New renders pick it up within a few seconds; pass bg on snowcone_render_mockup to override per render.`
|
|
861
|
-
);
|
|
862
|
-
} catch (err) {
|
|
863
|
-
return fail(formatError(err));
|
|
864
|
-
}
|
|
865
|
-
}
|
|
866
|
-
);
|
|
867
|
-
server.registerTool(
|
|
868
|
-
"snowcone_search_catalog",
|
|
869
|
-
{
|
|
870
|
-
title: "Search the product catalog",
|
|
871
|
-
description: "Find products to put a photo or design on \u2014 t-shirts, hoodies, mugs, totes, posters and more \u2014 with their suggested retail prices. Full-text search the public Snowcone catalog (t-shirts, hoodies, mugs, \u2026). Returns matching products with their code (id), name, price_cents (suggested retail, USD cents), and placement/mockup counts. Use snowcone_get_product for the full placement/mockup/option detail needed to render.",
|
|
872
|
-
inputSchema: {
|
|
873
|
-
query: z.string().default("").describe("Search text. Empty string lists popular products."),
|
|
874
|
-
limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
|
|
875
|
-
offset: z.number().int().min(0).default(0).describe("Pagination offset.")
|
|
876
|
-
},
|
|
877
|
-
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
878
|
-
},
|
|
879
|
-
async (args) => {
|
|
880
|
-
try {
|
|
881
|
-
const { hits, estimatedTotalHits } = await searchCatalog(args.query, args.limit, args.offset);
|
|
882
|
-
const items = hits.map((h) => ({
|
|
883
|
-
id: h.id,
|
|
884
|
-
name: h.name,
|
|
885
|
-
price_cents: h.basePrice ?? h.price,
|
|
886
|
-
placements: h.placements?.length ?? 0,
|
|
887
|
-
mockups: h.mockups?.length ?? 0
|
|
888
|
-
}));
|
|
889
|
-
const out = {
|
|
890
|
-
total: estimatedTotalHits,
|
|
891
|
-
count: items.length,
|
|
892
|
-
offset: args.offset,
|
|
893
|
-
items,
|
|
894
|
-
has_more: estimatedTotalHits > args.offset + items.length
|
|
895
|
-
};
|
|
896
|
-
let text = JSON.stringify(out, null, 2);
|
|
897
|
-
if (text.length > CHARACTER_LIMIT) {
|
|
898
|
-
text = JSON.stringify({ ...out, items: items.slice(0, 5), truncated: true }, null, 2);
|
|
899
|
-
}
|
|
900
|
-
return { content: [{ type: "text", text }], structuredContent: out };
|
|
901
|
-
} catch (err) {
|
|
902
|
-
return fail(formatError(err));
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
);
|
|
906
1127
|
async function summarizeDesign(d, shop, shopSecret) {
|
|
907
1128
|
const base = {
|
|
908
1129
|
pairing_id: d.pairingId ?? d.id,
|
|
@@ -926,256 +1147,486 @@ async function summarizeDesign(d, shop, shopSecret) {
|
|
|
926
1147
|
const url = await renderUrl(input);
|
|
927
1148
|
return shop ? { ...base, mockup_url: url } : { ...base, mockup_url_template: url };
|
|
928
1149
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
filter: z.string().optional().describe(`Meilisearch filter expression, e.g. "occasion = 'christmas' AND style = 'watercolor'".`),
|
|
939
|
-
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."),
|
|
940
|
-
shop: z.string().optional().describe("Your public Shop ID \u2014 when set, each result includes a ready-to-render mockup_url."),
|
|
941
|
-
shop_secret: z.string().optional().describe("Per-shop secret (scsec_\u2026). With 'shop', URLs are L3-signed (server-side only \u2014 never expose it).")
|
|
1150
|
+
function registerCard(server2) {
|
|
1151
|
+
server2.registerResource(
|
|
1152
|
+
"Snowcone mockup card",
|
|
1153
|
+
CARD_URI,
|
|
1154
|
+
{
|
|
1155
|
+
title: "Snowcone mockup card",
|
|
1156
|
+
description: "The person's design on the product, with price, option choices and Buy.",
|
|
1157
|
+
mimeType: CARD_MIME,
|
|
1158
|
+
_meta: cardResourceMeta()
|
|
942
1159
|
},
|
|
943
|
-
|
|
944
|
-
|
|
945
|
-
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
1160
|
+
async () => ({
|
|
1161
|
+
contents: [{ uri: CARD_URI, mimeType: CARD_MIME, text: cardHtml(), _meta: cardResourceMeta() }]
|
|
1162
|
+
})
|
|
1163
|
+
);
|
|
1164
|
+
}
|
|
1165
|
+
function pickableOptions(p, chosen) {
|
|
1166
|
+
const attrs = p?.options?.attributes;
|
|
1167
|
+
const out = {};
|
|
1168
|
+
for (const [attr, meta] of Object.entries(attrs ?? {})) {
|
|
1169
|
+
const choices = (meta.choices ?? []).map((c) => c.label).filter((l) => typeof l === "string" && l.length > 0);
|
|
1170
|
+
if (choices.length < 2) continue;
|
|
1171
|
+
const picked = chosen?.[attr];
|
|
1172
|
+
out[attr] = { choices, selected: picked !== void 0 && choices.includes(picked) ? picked : null };
|
|
1173
|
+
}
|
|
1174
|
+
return out;
|
|
1175
|
+
}
|
|
1176
|
+
async function buildCard(args, imageUrl, orders, product) {
|
|
1177
|
+
const { shop_secret, verify: _verify, ...rest } = args;
|
|
1178
|
+
return {
|
|
1179
|
+
image_url: imageUrl,
|
|
1180
|
+
product: product ? {
|
|
1181
|
+
id: product.id,
|
|
1182
|
+
name: product.name ?? product.id,
|
|
1183
|
+
price_cents: typeof (product.basePrice ?? product.price) === "number" ? product.basePrice ?? product.price : null
|
|
1184
|
+
} : null,
|
|
1185
|
+
options: pickableOptions(product, args.options),
|
|
1186
|
+
buy_url: await buyUrl(toUrlInput(args)),
|
|
1187
|
+
orders,
|
|
1188
|
+
// A signed shop's secret never goes into the card, so its picker can't re-sign: no picker there.
|
|
1189
|
+
render_args: shop_secret ? null : rest
|
|
1190
|
+
};
|
|
1191
|
+
}
|
|
1192
|
+
function registerTools(server2, ctx) {
|
|
1193
|
+
server2.registerTool(
|
|
1194
|
+
"snowcone_quickstart",
|
|
1195
|
+
{
|
|
1196
|
+
title: "Snowcone Quickstart",
|
|
1197
|
+
description: "Make custom printed products from any photo, design or text \u2014 t-shirts, mugs, hoodies, totes, posters \u2014 with a photoreal preview and a link to buy, printed and shipped for the user. Return the entire Snowcone model and the recommended tool order in one screen. Call this FIRST when you're new to Snowcone \u2014 it explains how to mint a shop, render a mockup, and sell it, plus the silent-failure gotchas.",
|
|
1198
|
+
inputSchema: {},
|
|
1199
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false }
|
|
1200
|
+
},
|
|
1201
|
+
async () => ({ content: [{ type: "text", text: QUICKSTART }] })
|
|
1202
|
+
);
|
|
1203
|
+
server2.registerTool(
|
|
1204
|
+
"snowcone_mint_shop",
|
|
1205
|
+
{
|
|
1206
|
+
title: "Mint a sandbox Shop",
|
|
1207
|
+
description: "Start a print-on-demand merch store for a creator, podcast or brand in one call \u2014 no account, no inventory; every order is printed and shipped. Mint your OWN sandbox Shop ID \u2014 no account or human needed. Returns { shop_id, shop_secret, api_key, api_key_scopes, store_url, lineup, claim }. When store_url is set, the shop is already a live store at that link \u2014 show it to the person you're helping. Pass image_url (the person's art, logo or photo) and the store opens stocked with best-sellers wearing that image \u2014 real listings at catalog prices, with mockups and checkout \u2014 listed in lineup. IMPORTANT: mint ONCE and reuse the shop_id for all render/buy calls \u2014 minting is rate-limited (60/hour, 200 unclaimed per IP \u2192 HTTP 429). shop_id is public (use it as 'shop'); shop_secret and api_key are secret (server-side only). To get paid, hand claim.verification_uri_complete to your human and poll snowcone_claim_status.",
|
|
1208
|
+
inputSchema: {
|
|
1209
|
+
name: z.string().optional().describe("Optional shop name (e.g. 'Jess Prints'); it also names the store's web address. Defaults to 'Sandbox <id>'."),
|
|
1210
|
+
claim_pin: z.string().optional().describe("Optional out-of-band PIN your human must enter to claim (deliver it separately from the link)."),
|
|
1211
|
+
require_signature: z.boolean().optional().describe(
|
|
1212
|
+
"Lock the shop down: require SIGNED mockup URLs (L3). Default false \u2014 the shop is open and any unsigned URL renders (simplest to start). Set true to harden against Shop-ID theft: then every render/buy URL must be signed with the returned shop_secret (pass it as shop_secret to snowcone_render_mockup / buy URLs). Unsigned URLs will 403."
|
|
1213
|
+
),
|
|
1214
|
+
mockup_bg_color: z.string().optional().describe(
|
|
1215
|
+
"Default background painted behind every mockup render (6-hex, '#' optional, e.g. 'f5f0ea'). Visible only where the mockup scene is transparent (studio-cutout shots). Omit for transparent (the default). Change it later with snowcone_set_mockup_background; a per-render bg overrides it."
|
|
1216
|
+
),
|
|
1217
|
+
image_url: z.string().url().optional().describe(
|
|
1218
|
+
"Optional art for the store to open with: an https URL of a public PNG, JPEG, WebP or AVIF image (at most 10 MB). The store then opens stocked with best-sellers wearing that image, ready to sell. A bad image fails the mint with a typed E_MINT_IMAGE_* error and creates nothing. Omit for an empty store that shows what it will sell once art is added."
|
|
1219
|
+
)
|
|
1220
|
+
},
|
|
1221
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: false, openWorldHint: true }
|
|
1222
|
+
},
|
|
1223
|
+
async (args) => {
|
|
1224
|
+
try {
|
|
1225
|
+
const r = await mintShop({
|
|
1226
|
+
...ctx.forwardedFor ? { forwardedFor: ctx.forwardedFor } : {},
|
|
1227
|
+
...args.name !== void 0 ? { name: args.name } : {},
|
|
1228
|
+
...args.claim_pin !== void 0 ? { claim_pin: args.claim_pin } : {},
|
|
1229
|
+
...args.require_signature ? { require_signed_urls: true } : {},
|
|
1230
|
+
...args.mockup_bg_color !== void 0 ? { mockup_bg_color: args.mockup_bg_color } : {},
|
|
1231
|
+
...args.image_url !== void 0 ? { image_url: args.image_url } : {}
|
|
1232
|
+
});
|
|
1233
|
+
const sigLine = r.require_signed_urls ? `This shop REQUIRES signed URLs: pass shop_secret=${r.shop_secret} as shop_secret on every render/buy call, or the edge 403s.
|
|
1234
|
+
` : `This shop is OPEN (unsigned URLs render). To lock it later, your human can toggle "Require signed URLs" on /studio/api-keys.
|
|
1235
|
+
`;
|
|
1236
|
+
const storeLine = r.store_url ? `Your store is live at ${r.store_url} \u2014 show this link to the person you're helping.
|
|
1237
|
+
` : "";
|
|
1238
|
+
const lineupLine = r.lineup?.listings.length ? `It opened stocked with ${r.lineup.listings.length} best-sellers wearing your image:
|
|
1239
|
+
` + r.lineup.listings.map((l) => `- ${l.product_name} \u2014 $${(l.price_cents / 100).toFixed(2)}${l.url ? ` \u2014 ${l.url}` : ""} (mockup: ${l.mockup_url})`).join("\n") + "\n" : "";
|
|
1240
|
+
const text = storeLine + lineupLine + `Minted shop_id=${r.shop_id} (REUSE this \u2014 don't mint again).
|
|
1241
|
+
shop_secret=${r.shop_secret} (secret)
|
|
1242
|
+
api_key=${r.api_key} (secret; scopes: ${r.api_key_scopes.join(", ")})
|
|
1243
|
+
` + sigLine + `To get paid, send your human: ${r.claim.verification_uri_complete}
|
|
1244
|
+
claim_token=${r.claim.claim_token} (secret)
|
|
1245
|
+
Poll claim with that claim_token via snowcone_claim_status. Expires in ${r.claim.expires_in}s.
|
|
1246
|
+
Note: the shop takes ~1-3s to propagate to the render edge \u2014 a render right after minting can 404 "Unknown shop"; wait a second and retry.`;
|
|
1247
|
+
return ok(r, text);
|
|
1248
|
+
} catch (err) {
|
|
1249
|
+
return fail(formatError(err));
|
|
959
1250
|
}
|
|
960
|
-
return { content: [{ type: "text", text }], structuredContent: out };
|
|
961
|
-
} catch (err) {
|
|
962
|
-
return fail(formatError(err));
|
|
963
1251
|
}
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
// spelled it `id_or_slug` cost every cold agent a guaranteed failed
|
|
975
|
-
// round-trip. `product` is the canonical name; `id_or_slug` stays as a
|
|
976
|
-
// silent alias so agents that learned the old name keep working.
|
|
977
|
-
product: z.string().min(1).optional().describe("Product code (the catalog document id) or slug, e.g. 'BC43BE'. Same name as every other tool."),
|
|
978
|
-
id_or_slug: z.string().min(1).optional().describe("Deprecated alias of 'product' \u2014 accepted for back-compat; prefer 'product'.")
|
|
1252
|
+
);
|
|
1253
|
+
server2.registerTool(
|
|
1254
|
+
"snowcone_claim_status",
|
|
1255
|
+
{
|
|
1256
|
+
title: "Poll Shop claim status",
|
|
1257
|
+
description: "Check whether your human has claimed the shop yet. Pass the claim_token from snowcone_mint_shop. Returns status: 'pending' | 'claimed' | 'expired'. Once 'claimed', sales route to your human's account.",
|
|
1258
|
+
inputSchema: {
|
|
1259
|
+
claim_token: z.string().min(1).describe("The claim_token returned by snowcone_mint_shop (ct_\u2026).")
|
|
1260
|
+
},
|
|
1261
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
979
1262
|
},
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
1263
|
+
async (args) => {
|
|
1264
|
+
try {
|
|
1265
|
+
return ok(await claimStatus(args.claim_token));
|
|
1266
|
+
} catch (err) {
|
|
1267
|
+
return fail(formatError(err));
|
|
1268
|
+
}
|
|
1269
|
+
}
|
|
1270
|
+
);
|
|
1271
|
+
server2.registerTool(
|
|
1272
|
+
"snowcone_release_shop",
|
|
1273
|
+
{
|
|
1274
|
+
title: "Release a sandbox Shop",
|
|
1275
|
+
description: "Delete an UNCLAIMED sandbox shop you minted, freeing your per-IP mint budget. Authenticated by the shop_secret. Refused if the shop has already been claimed. Use this when you're done iterating. What survives: already-produced mockup IMAGE URLs keep rendering (they're public marketing imagery). What dies: buy/checkout URLs, the shop's credentials (shop_secret, api_key), and the claim link. Irreversible.",
|
|
1276
|
+
inputSchema: {
|
|
1277
|
+
shop_id: z.string().min(1).describe("The sandbox shop_id to release."),
|
|
1278
|
+
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026).")
|
|
1279
|
+
},
|
|
1280
|
+
annotations: { readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: true }
|
|
1281
|
+
},
|
|
1282
|
+
async (args) => {
|
|
1283
|
+
try {
|
|
1284
|
+
const r = await releaseShop(args.shop_id, args.shop_secret);
|
|
1285
|
+
return ok(
|
|
1286
|
+
r,
|
|
1287
|
+
`Released shop_id=${r.shop_id}. Already-produced mockup IMAGE URLs keep rendering (public marketing imagery survives release). Buy/checkout URLs, the shop_secret, the api_key, and the claim link are now dead. Your per-IP mint budget is freed.`
|
|
988
1288
|
);
|
|
1289
|
+
} catch (err) {
|
|
1290
|
+
return fail(formatError(err));
|
|
989
1291
|
}
|
|
990
|
-
const p = await getProduct(code);
|
|
991
|
-
if (!p) return fail(`Error: no product found for '${code}'. It would render blank \u2014 pick one from snowcone_search_catalog.`);
|
|
992
|
-
return ok(summarizeProduct(p));
|
|
993
|
-
} catch (err) {
|
|
994
|
-
return fail(formatError(err));
|
|
995
1292
|
}
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1293
|
+
);
|
|
1294
|
+
server2.registerTool(
|
|
1295
|
+
"snowcone_set_mockup_background",
|
|
1296
|
+
{
|
|
1297
|
+
title: "Set the shop's default mockup background",
|
|
1298
|
+
description: "Set (or clear) the shop's DEFAULT background color for mockup renders \u2014 painted behind every render where the mockup scene is transparent (studio-cutout shots). Applies to all renders for the shop that don't pass an explicit bg; a per-render bg on snowcone_render_mockup overrides it. Sandbox shops only (authenticated by shop_secret); once claimed, your human manages this in shop settings \u2192 Branding. Takes effect on new renders within a few seconds (already-cached mockup URLs keep their old background).",
|
|
1299
|
+
inputSchema: {
|
|
1300
|
+
shop_id: z.string().min(1).describe("The sandbox shop_id to update."),
|
|
1301
|
+
shop_secret: z.string().min(1).describe("The shop_secret from snowcone_mint_shop (scsec_\u2026)."),
|
|
1302
|
+
color: z.string().nullable().describe("6-hex color ('#' optional, e.g. 'f5f0ea' or '#F5F0EA'), or null to clear back to transparent.")
|
|
1303
|
+
},
|
|
1304
|
+
annotations: { readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1008
1305
|
},
|
|
1009
|
-
|
|
1010
|
-
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
const url = await renderUrl(toUrlInput(args));
|
|
1014
|
-
const img_html = `<img src="${url}" style="object-fit:cover" alt="mockup" />`;
|
|
1015
|
-
if (args.verify === false) {
|
|
1306
|
+
async (args) => {
|
|
1307
|
+
try {
|
|
1308
|
+
const r = await setMockupBackground(args.shop_id, args.shop_secret, args.color);
|
|
1309
|
+
const stated = r.mockup_bg_color === null ? "transparent (cleared)" : `#${r.mockup_bg_color}`;
|
|
1016
1310
|
return ok(
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
img_html,
|
|
1020
|
-
notes: "Unverified (verify=false). Display with object-fit:cover and request ~2\xD7 the displayed size. The asset URL must be a publicly-fetchable raster image."
|
|
1021
|
-
},
|
|
1022
|
-
url
|
|
1311
|
+
r,
|
|
1312
|
+
`Default mockup background for shop_id=${r.shop_id} is now ${stated}. New renders pick it up within a few seconds; pass bg on snowcone_render_mockup to override per render.`
|
|
1023
1313
|
);
|
|
1314
|
+
} catch (err) {
|
|
1315
|
+
return fail(formatError(err));
|
|
1024
1316
|
}
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1317
|
+
}
|
|
1318
|
+
);
|
|
1319
|
+
server2.registerTool(
|
|
1320
|
+
"snowcone_search_catalog",
|
|
1321
|
+
{
|
|
1322
|
+
title: "Search the product catalog",
|
|
1323
|
+
description: "Find products to put a photo or design on \u2014 t-shirts, hoodies, mugs, totes, posters and more \u2014 with their suggested retail prices. Full-text search the public Snowcone catalog (t-shirts, hoodies, mugs, \u2026). Returns matching products with their code (id), name, price_cents (suggested retail, USD cents), and placement/mockup counts. Use snowcone_get_product for the full placement/mockup/option detail needed to render.",
|
|
1324
|
+
inputSchema: {
|
|
1325
|
+
query: z.string().default("").describe("Search text. Empty string lists popular products."),
|
|
1326
|
+
limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
|
|
1327
|
+
offset: z.number().int().min(0).default(0).describe("Pagination offset.")
|
|
1328
|
+
},
|
|
1329
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1330
|
+
},
|
|
1331
|
+
async (args) => {
|
|
1332
|
+
try {
|
|
1333
|
+
const { hits, estimatedTotalHits } = await searchCatalog(args.query, args.limit, args.offset);
|
|
1334
|
+
const items = hits.map((h) => ({
|
|
1335
|
+
id: h.id,
|
|
1336
|
+
name: h.name,
|
|
1337
|
+
price_cents: h.basePrice ?? h.price,
|
|
1338
|
+
placements: h.placements?.length ?? 0,
|
|
1339
|
+
mockups: h.mockups?.length ?? 0
|
|
1340
|
+
}));
|
|
1341
|
+
const out = {
|
|
1342
|
+
total: estimatedTotalHits,
|
|
1343
|
+
count: items.length,
|
|
1344
|
+
offset: args.offset,
|
|
1345
|
+
items,
|
|
1346
|
+
has_more: estimatedTotalHits > args.offset + items.length
|
|
1347
|
+
};
|
|
1348
|
+
let text = JSON.stringify(out, null, 2);
|
|
1349
|
+
if (text.length > CHARACTER_LIMIT) {
|
|
1350
|
+
text = JSON.stringify({ ...out, items: items.slice(0, 5), truncated: true }, null, 2);
|
|
1351
|
+
}
|
|
1352
|
+
return { content: [{ type: "text", text }], structuredContent: out };
|
|
1353
|
+
} catch (err) {
|
|
1354
|
+
return fail(formatError(err));
|
|
1029
1355
|
}
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1356
|
+
}
|
|
1357
|
+
);
|
|
1358
|
+
server2.registerTool(
|
|
1359
|
+
"snowcone_search_designs",
|
|
1360
|
+
{
|
|
1361
|
+
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.",
|
|
1363
|
+
inputSchema: {
|
|
1364
|
+
query: z.string().default("").describe("Search text, e.g. 'christmas card'. Empty string lists curated designs."),
|
|
1365
|
+
limit: z.number().int().min(1).max(50).default(10).describe("Max results (1-50)."),
|
|
1366
|
+
offset: z.number().int().min(0).default(0).describe("Pagination offset."),
|
|
1367
|
+
filter: z.string().optional().describe(`Meilisearch filter expression, e.g. "occasion = 'christmas' AND style = 'watercolor'".`),
|
|
1368
|
+
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
|
+
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).")
|
|
1371
|
+
},
|
|
1372
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1373
|
+
},
|
|
1374
|
+
async (args) => {
|
|
1375
|
+
try {
|
|
1376
|
+
const { hits, estimatedTotalHits } = await searchDesigns(args.query, args.limit, args.offset, args.filter, args.semantic_ratio);
|
|
1377
|
+
const items = await Promise.all(hits.map((h) => summarizeDesign(h, args.shop, args.shop_secret)));
|
|
1378
|
+
const out = {
|
|
1379
|
+
total: estimatedTotalHits,
|
|
1380
|
+
count: items.length,
|
|
1381
|
+
offset: args.offset,
|
|
1382
|
+
items,
|
|
1383
|
+
has_more: estimatedTotalHits > args.offset + items.length
|
|
1384
|
+
};
|
|
1385
|
+
let text = JSON.stringify(out, null, 2);
|
|
1386
|
+
if (text.length > CHARACTER_LIMIT) {
|
|
1387
|
+
text = JSON.stringify({ ...out, items: items.slice(0, 5), truncated: true }, null, 2);
|
|
1388
|
+
}
|
|
1389
|
+
return { content: [{ type: "text", text }], structuredContent: out };
|
|
1390
|
+
} catch (err) {
|
|
1391
|
+
return fail(formatError(err));
|
|
1034
1392
|
}
|
|
1035
|
-
const designKeys = args.design ? Object.keys(args.design) : [];
|
|
1036
|
-
const verifiedView = args.view ? `view '${args.view}'` : "the default view";
|
|
1037
|
-
const scopeNote = designKeys.length > 1 ? `verify confirmed ${verifiedView} only \u2014 placements not visible in it (design keys: ${designKeys.join(", ")}) are built into the URL but NOT independently confirmed. Render each placement's own view to confirm it.` : void 0;
|
|
1038
|
-
return ok(
|
|
1039
|
-
{
|
|
1040
|
-
url,
|
|
1041
|
-
img_html,
|
|
1042
|
-
verified: true,
|
|
1043
|
-
kind: v.kind,
|
|
1044
|
-
bytes: v.bytes,
|
|
1045
|
-
...scopeNote ? { verified_scope: scopeNote } : {}
|
|
1046
|
-
},
|
|
1047
|
-
`\u2713 verified \u2014 renders ${v.kind} (${v.bytes} bytes): ${url}${scopeNote ? `
|
|
1048
|
-
\u26A0\uFE0F ${scopeNote}` : ""}`
|
|
1049
|
-
);
|
|
1050
|
-
} catch (err) {
|
|
1051
|
-
return fail(formatError(err));
|
|
1052
1393
|
}
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1394
|
+
);
|
|
1395
|
+
server2.registerTool(
|
|
1396
|
+
"snowcone_get_product",
|
|
1397
|
+
{
|
|
1398
|
+
title: "Get a product",
|
|
1399
|
+
description: "Fetch one product by its code (id) or slug. Returns placements (where art goes), mockups (scene ids for the 'view' param), and variant options \u2014 everything you need to build a render URL. Returns an error if the code doesn't exist (it would render blank).",
|
|
1400
|
+
inputSchema: {
|
|
1401
|
+
// eng/0049 F1 (growth/0013 cold-agent run): every sibling tool takes
|
|
1402
|
+
// `product`, and the prose says "product code" — the one tool that
|
|
1403
|
+
// spelled it `id_or_slug` cost every cold agent a guaranteed failed
|
|
1404
|
+
// round-trip. `product` is the canonical name; `id_or_slug` stays as a
|
|
1405
|
+
// silent alias so agents that learned the old name keep working.
|
|
1406
|
+
product: z.string().min(1).optional().describe("Product code (the catalog document id) or slug, e.g. 'BC43BE'. Same name as every other tool."),
|
|
1407
|
+
id_or_slug: z.string().min(1).optional().describe("Deprecated alias of 'product' \u2014 accepted for back-compat; prefer 'product'.")
|
|
1408
|
+
},
|
|
1409
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1065
1410
|
},
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1411
|
+
async (args) => {
|
|
1412
|
+
try {
|
|
1413
|
+
const code = args.product ?? args.id_or_slug;
|
|
1414
|
+
if (!code) {
|
|
1415
|
+
return fail(
|
|
1416
|
+
"E_MISSING_PRODUCT: pass product (the product code or slug, e.g. { product: 'BC43BE' }) \u2014 the same 'product' argument snowcone_render_mockup and snowcone_buy_url take."
|
|
1417
|
+
);
|
|
1418
|
+
}
|
|
1419
|
+
const p = await getProduct(code);
|
|
1420
|
+
if (!p) return fail(`Error: no product found for '${code}'. It would render blank \u2014 pick one from snowcone_search_catalog.`);
|
|
1421
|
+
return ok(summarizeProduct(p));
|
|
1422
|
+
} catch (err) {
|
|
1423
|
+
return fail(formatError(err));
|
|
1424
|
+
}
|
|
1425
|
+
}
|
|
1426
|
+
);
|
|
1427
|
+
server2.registerTool(
|
|
1428
|
+
"snowcone_render_mockup",
|
|
1429
|
+
{
|
|
1430
|
+
title: "Render a mockup URL",
|
|
1431
|
+
description: "Show the user their photo, design or text on a real product (t-shirt, mug, hoodie, tote, poster\u2026) as a photoreal preview image. Build a public mockup IMAGE url for a product + your artwork + your shop. The result is an <img>-ready URL \u2014 no API call, no upload. Provide 'asset' (one image) OR 'design' (per-placement map). The asset must be a publicly-fetchable raster image (PNG/JPEG/WebP/AVIF; not SVG), and the product code must exist in the catalog. Pass shop_secret to get an L3-signed URL. By DEFAULT the server fetches the built URL and confirms it actually renders, so a bad product code, wrong placement key, or unusable asset comes back as a clear error instead of a confident-but-broken URL. Pass verify=false to skip that check and just get the URL string instantly. In ChatGPT, Claude and other MCP Apps hosts the result shows as a card: the mockup, name, price, option choices and Buy. The result's 'orders' says whether Snowcone is taking orders yet; when it is 'not-open', show the mockup but don't offer the buy link as a way to order.",
|
|
1432
|
+
_meta: CARD_TOOL_META,
|
|
1433
|
+
inputSchema: {
|
|
1434
|
+
...urlShape,
|
|
1435
|
+
verify: z.boolean().optional().describe(
|
|
1436
|
+
"Fetch the built URL and confirm it returns a real image before reporting success (DEFAULT true). Turns silent failures into a clear, actionable error and retries once on a not-yet-propagated shop. Set false to skip the network round-trip and return the URL string unchecked."
|
|
1437
|
+
)
|
|
1438
|
+
},
|
|
1439
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1440
|
+
},
|
|
1441
|
+
async (args) => {
|
|
1442
|
+
try {
|
|
1443
|
+
const url = await renderUrl(toUrlInput(args));
|
|
1444
|
+
const img_html = `<img src="${url}" style="object-fit:cover" alt="mockup" />`;
|
|
1445
|
+
if (args.verify === false) {
|
|
1446
|
+
const orders2 = await readOrdersState();
|
|
1447
|
+
const card2 = await buildCard(args, url, orders2, null);
|
|
1448
|
+
return ok(
|
|
1449
|
+
{
|
|
1450
|
+
url,
|
|
1451
|
+
img_html,
|
|
1452
|
+
buy_url: card2.buy_url,
|
|
1453
|
+
orders: orders2,
|
|
1454
|
+
card: card2,
|
|
1455
|
+
notes: "Unverified (verify=false). Display with object-fit:cover and request ~2\xD7 the displayed size. The asset URL must be a publicly-fetchable raster image."
|
|
1456
|
+
},
|
|
1457
|
+
`${url}
|
|
1458
|
+
${ordersLine(orders2)}`
|
|
1459
|
+
);
|
|
1460
|
+
}
|
|
1461
|
+
const productP = getProduct(args.product).catch(() => null);
|
|
1462
|
+
const ordersP = readOrdersState();
|
|
1463
|
+
let v = await verifyImageUrl(url);
|
|
1464
|
+
if (!v.ok && /unknown shop/i.test(v.error ?? "")) {
|
|
1465
|
+
await new Promise((r) => setTimeout(r, 2e3));
|
|
1466
|
+
v = await verifyImageUrl(url);
|
|
1467
|
+
}
|
|
1468
|
+
if (!v.ok) {
|
|
1469
|
+
const hint = renderFixHint(v.error);
|
|
1470
|
+
const reason = (v.error ?? "render failed").replace(/\.*$/, "");
|
|
1471
|
+
return fail(`Built ${url} but it does NOT render: ${reason}.${hint ? " " + hint : ""}`);
|
|
1472
|
+
}
|
|
1473
|
+
const designKeys = args.design ? Object.keys(args.design) : [];
|
|
1474
|
+
const verifiedView = args.view ? `view '${args.view}'` : "the default view";
|
|
1475
|
+
const scopeNote = designKeys.length > 1 ? `verify confirmed ${verifiedView} only \u2014 placements not visible in it (design keys: ${designKeys.join(", ")}) are built into the URL but NOT independently confirmed. Render each placement's own view to confirm it.` : void 0;
|
|
1476
|
+
const [product, orders] = await Promise.all([productP, ordersP]);
|
|
1477
|
+
const card = await buildCard(args, url, orders, product);
|
|
1072
1478
|
return ok(
|
|
1073
|
-
{
|
|
1074
|
-
|
|
1479
|
+
{
|
|
1480
|
+
url,
|
|
1481
|
+
img_html,
|
|
1482
|
+
verified: true,
|
|
1483
|
+
kind: v.kind,
|
|
1484
|
+
bytes: v.bytes,
|
|
1485
|
+
...scopeNote ? { verified_scope: scopeNote } : {},
|
|
1486
|
+
buy_url: card.buy_url,
|
|
1487
|
+
orders,
|
|
1488
|
+
card
|
|
1489
|
+
},
|
|
1490
|
+
`\u2713 verified \u2014 renders ${v.kind} (${v.bytes} bytes): ${url}${scopeNote ? `
|
|
1491
|
+
\u26A0\uFE0F ${scopeNote}` : ""}
|
|
1492
|
+
${ordersLine(orders)}`
|
|
1075
1493
|
);
|
|
1494
|
+
} catch (err) {
|
|
1495
|
+
return fail(formatError(err));
|
|
1076
1496
|
}
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1497
|
+
}
|
|
1498
|
+
);
|
|
1499
|
+
server2.registerTool(
|
|
1500
|
+
"snowcone_buy_url",
|
|
1501
|
+
{
|
|
1502
|
+
title: "Build a checkout URL",
|
|
1503
|
+
description: "Give the user a link to buy the printed product they just previewed \u2014 it's printed and shipped to them. Build the buyable checkout url for the same product + artwork + shop you'd render. Same inputs as snowcone_render_mockup. Send a customer here to purchase the printed item. Sales route to Snowcone until your human claims the shop. By DEFAULT the server follows the URL and confirms it resolves to a live checkout (the Stripe session actually builds) AND that the matching mockup image renders \u2014 so a bad product code, shop, option combo, or unusable asset comes back as a clear error instead of a confident-but-broken link. 'verified' means the same thing here as in snowcone_render_mockup. This does NOT charge anything; it only builds the session. Pass verify=false to skip the check and get the URL string instantly. The result's 'orders' says whether Snowcone is taking orders yet: while it is 'not-open', don't offer this link to the person as a way to order.",
|
|
1504
|
+
inputSchema: {
|
|
1505
|
+
...urlShape,
|
|
1506
|
+
verify: z.boolean().optional().describe(
|
|
1507
|
+
"Follow the built URL and confirm it resolves to a live checkout, and fetch the matching mockup to confirm the product image renders, before reporting success (DEFAULT true). Set false to skip the network round-trip and return the URL string unchecked."
|
|
1508
|
+
)
|
|
1509
|
+
},
|
|
1510
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1511
|
+
},
|
|
1512
|
+
async (args) => {
|
|
1513
|
+
try {
|
|
1514
|
+
const url = await buyUrl(toUrlInput(args));
|
|
1515
|
+
const ordersP = readOrdersState();
|
|
1516
|
+
if (args.verify === false) {
|
|
1517
|
+
const orders2 = await ordersP;
|
|
1518
|
+
return ok(
|
|
1519
|
+
{ url, orders: orders2, notes: "Unverified (verify=false). Send a customer here to purchase the printed item." },
|
|
1520
|
+
`${url}
|
|
1521
|
+
${ordersLine(orders2)}`
|
|
1522
|
+
);
|
|
1523
|
+
}
|
|
1524
|
+
const [v, img] = await Promise.all([verifyCheckoutUrl(url), verifyImageUrl(await renderUrl(toUrlInput(args)))]);
|
|
1525
|
+
if (!v.ok) {
|
|
1526
|
+
const reason = (v.error ?? "checkout failed").replace(/\.*$/, "");
|
|
1527
|
+
return fail(`Built ${url} but it does NOT resolve to a live checkout: ${reason}.`);
|
|
1528
|
+
}
|
|
1529
|
+
if (!img.ok) {
|
|
1530
|
+
const hint = renderFixHint(img.error);
|
|
1531
|
+
const reason = (img.error ?? "render failed").replace(/\.*$/, "");
|
|
1532
|
+
return fail(
|
|
1533
|
+
`Built ${url} \u2014 the checkout is live, but the product image for these inputs does NOT render, so a customer would buy a broken mockup: ${reason}.${hint ? " " + hint : ""} Fix the inputs (same as snowcone_render_mockup) and call again.`
|
|
1534
|
+
);
|
|
1535
|
+
}
|
|
1536
|
+
const orders = await ordersP;
|
|
1537
|
+
return ok(
|
|
1538
|
+
{ url, verified: true, checkout_url: v.checkout_url, render_verified: true, render_kind: img.kind, orders },
|
|
1539
|
+
`\u2713 verified \u2014 resolves to a live checkout AND the product image renders (${img.kind}): ${url}
|
|
1540
|
+
${ordersLine(orders)}`
|
|
1087
1541
|
);
|
|
1542
|
+
} catch (err) {
|
|
1543
|
+
return fail(formatError(err));
|
|
1088
1544
|
}
|
|
1089
|
-
return ok(
|
|
1090
|
-
{ url, verified: true, checkout_url: v.checkout_url, render_verified: true, render_kind: img.kind },
|
|
1091
|
-
`\u2713 verified \u2014 resolves to a live checkout AND the product image renders (${img.kind}): ${url}`
|
|
1092
|
-
);
|
|
1093
|
-
} catch (err) {
|
|
1094
|
-
return fail(formatError(err));
|
|
1095
1545
|
}
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1546
|
+
);
|
|
1547
|
+
server2.registerTool(
|
|
1548
|
+
"snowcone_get_quote",
|
|
1549
|
+
{
|
|
1550
|
+
title: "Get the price, shipping and delivery",
|
|
1551
|
+
description: "Tell the user what a printed product costs and when it would arrive, before they buy. Returns the price the buy link will charge (before tax), and each shipping option with its cost and delivery estimate for where it's going. Takes the same product and options as snowcone_buy_url; no artwork or shop needed. Nothing is created or charged. Only promise what comes back: an option with no estimated_delivery means we have no date for it yet.",
|
|
1552
|
+
inputSchema: {
|
|
1553
|
+
product: z.string().min(1).describe("Product code (the catalog document id), e.g. 'BC43BE'."),
|
|
1554
|
+
options: z.record(z.string()).optional().describe("Variant option picks: attribute \u2192 choice, e.g. { size: 'M', color: 'black' }. The price depends on these."),
|
|
1555
|
+
quantity: z.number().int().min(1).max(100).optional().describe("How many (1 to 100). Default 1."),
|
|
1556
|
+
ship_to: z.string().length(2).optional().describe("2-letter destination country, e.g. 'US'. Default US. A country we can't ship to returns an error listing the ones we can.")
|
|
1557
|
+
},
|
|
1558
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1108
1559
|
},
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
|
|
1127
|
-
|
|
1128
|
-
|
|
1129
|
-
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
}
|
|
1137
|
-
|
|
1138
|
-
|
|
1139
|
-
|
|
1140
|
-
|
|
1141
|
-
|
|
1142
|
-
return fail(formatError(err));
|
|
1560
|
+
async (args) => {
|
|
1561
|
+
try {
|
|
1562
|
+
const q = await getQuote({
|
|
1563
|
+
product: args.product,
|
|
1564
|
+
...args.options ? { options: args.options } : {},
|
|
1565
|
+
...args.quantity !== void 0 ? { quantity: args.quantity } : {},
|
|
1566
|
+
...args.ship_to !== void 0 ? { shipTo: args.ship_to } : {}
|
|
1567
|
+
});
|
|
1568
|
+
return ok(
|
|
1569
|
+
{
|
|
1570
|
+
product: q.product,
|
|
1571
|
+
variant_id: q.variantId,
|
|
1572
|
+
variant_label: q.variantLabel,
|
|
1573
|
+
quantity: q.quantity,
|
|
1574
|
+
currency: q.currency,
|
|
1575
|
+
unit_price_cents: q.unitPriceCents,
|
|
1576
|
+
items_total_cents: q.itemsTotalCents,
|
|
1577
|
+
tax_included: q.taxIncluded,
|
|
1578
|
+
ship_to: q.shipTo,
|
|
1579
|
+
shipping: q.shipping.map((s) => ({
|
|
1580
|
+
speed: s.speed,
|
|
1581
|
+
price_cents: s.priceCents,
|
|
1582
|
+
...s.minTransitDays !== void 0 ? { min_transit_days: s.minTransitDays } : {},
|
|
1583
|
+
...s.maxTransitDays !== void 0 ? { max_transit_days: s.maxTransitDays } : {},
|
|
1584
|
+
...s.estimatedDelivery ? { estimated_delivery: s.estimatedDelivery } : {}
|
|
1585
|
+
})),
|
|
1586
|
+
quoted_at: q.quotedAt
|
|
1587
|
+
},
|
|
1588
|
+
quoteText(q)
|
|
1589
|
+
);
|
|
1590
|
+
} catch (err) {
|
|
1591
|
+
return fail(formatError(err));
|
|
1592
|
+
}
|
|
1143
1593
|
}
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
|
|
1147
|
-
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1152
|
-
|
|
1153
|
-
|
|
1594
|
+
);
|
|
1595
|
+
server2.registerTool(
|
|
1596
|
+
"snowcone_get_order_status",
|
|
1597
|
+
{
|
|
1598
|
+
title: "Find out where an order is",
|
|
1599
|
+
description: "Tell the user where their order is: whether it's being made or on its way, the carrier and tracking number, and the latest scan. Ask them for the order number and the email from their order confirmation. Read-only. If nothing matches, the error doesn't say which of the two was wrong, and repeated tries are limited, so check both with the person before retrying.",
|
|
1600
|
+
inputSchema: {
|
|
1601
|
+
order_number: z.string().min(1).describe("The order number from the confirmation email, e.g. '8532-5134'."),
|
|
1602
|
+
email: z.string().min(3).describe("The email the order was placed with.")
|
|
1603
|
+
},
|
|
1604
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true }
|
|
1154
1605
|
},
|
|
1155
|
-
|
|
1156
|
-
|
|
1157
|
-
|
|
1158
|
-
|
|
1159
|
-
|
|
1160
|
-
|
|
1161
|
-
|
|
1162
|
-
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
return fail(formatError(err));
|
|
1606
|
+
async (args) => {
|
|
1607
|
+
try {
|
|
1608
|
+
const r = await getOrderStatus({ orderNumber: args.order_number, email: args.email });
|
|
1609
|
+
return ok(
|
|
1610
|
+
{
|
|
1611
|
+
order_number: r.order.order.number,
|
|
1612
|
+
placed_at: r.order.order.placedAt,
|
|
1613
|
+
status: r.order.status,
|
|
1614
|
+
headline: r.order.headline,
|
|
1615
|
+
stages: r.order.stages,
|
|
1616
|
+
packages: r.order.packages,
|
|
1617
|
+
events: r.order.events,
|
|
1618
|
+
items: r.order.items,
|
|
1619
|
+
status_url: r.statusUrl
|
|
1620
|
+
},
|
|
1621
|
+
orderStatusText(r)
|
|
1622
|
+
);
|
|
1623
|
+
} catch (err) {
|
|
1624
|
+
return fail(formatError(err));
|
|
1625
|
+
}
|
|
1176
1626
|
}
|
|
1177
|
-
|
|
1178
|
-
|
|
1627
|
+
);
|
|
1628
|
+
}
|
|
1629
|
+
var server = createServer();
|
|
1179
1630
|
|
|
1180
1631
|
// src/index.ts
|
|
1181
1632
|
async function main() {
|