sbuilder-mcp 0.25.0 → 0.26.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 +8 -0
- package/CHANGELOG.vi.md +8 -0
- package/README.md +1 -1
- package/README.vi.md +7 -1
- package/dist/tools/live.js +73 -5
- package/dist/transport/stock.js +95 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -6,6 +6,14 @@ All notable changes to this project are documented in this file.
|
|
|
6
6
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
7
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
8
|
|
|
9
|
+
## [0.26.0] - 2026-09-10
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- sb_media_upload can now search for a real photograph: `query` returns real photographs with the description each photographer wrote, and `pick` uploads the chosen one into the site's own library instead of hotlinking it.
|
|
13
|
+
- sb_media_upload's search takes `orientation` (landscape, portrait, square) to ask the search itself for the right shape instead of cropping the result afterward.
|
|
14
|
+
- sb_media_upload's search results carry photographer credit (name, profile, photo page), and the uploaded asset's name defaults to the photograph's own description so the library stays searchable by what each image shows.
|
|
15
|
+
- An optional `PEXELS_API_KEY` calls Pexels directly for the image search; without one it falls back to a shared proxy, so an `npx` install with no configuration still finds real images.
|
|
16
|
+
|
|
9
17
|
## [0.25.0] - 2026-09-10
|
|
10
18
|
|
|
11
19
|
### Added
|
package/CHANGELOG.vi.md
CHANGED
|
@@ -6,6 +6,14 @@ Mọi thay đổi đáng chú ý của dự án được ghi lại trong file n
|
|
|
6
6
|
Định dạng dựa trên [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
|
7
7
|
và dự án tuân theo [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
8
8
|
|
|
9
|
+
## [0.26.0] - 2026-09-10
|
|
10
|
+
|
|
11
|
+
### Added
|
|
12
|
+
- sb_media_upload giờ có thể tìm ảnh chụp thật: `query` trả về ảnh chụp thật kèm mô tả do chính người chụp viết, và `pick` upload đúng tấm được chọn vào thư viện của site thay vì hotlink.
|
|
13
|
+
- Phần tìm ảnh của sb_media_upload nhận `orientation` (landscape, portrait, square) để hỏi thẳng bộ tìm kiếm về hình dạng phù hợp thay vì cắt ảnh lại sau đó.
|
|
14
|
+
- Kết quả tìm ảnh của sb_media_upload mang theo thông tin ghi công (tên người chụp, trang cá nhân, trang ảnh), và tên của asset sau khi upload mặc định lấy theo mô tả của bức ảnh để thư viện tìm được theo nội dung ảnh.
|
|
15
|
+
- `PEXELS_API_KEY` là tuỳ chọn, dùng để gọi thẳng Pexels cho phần tìm ảnh; không có key thì dùng một proxy chung, nên một bản cài `npx` không cấu hình gì vẫn tìm được ảnh thật.
|
|
16
|
+
|
|
9
17
|
## [0.25.0] - 2026-09-10
|
|
10
18
|
|
|
11
19
|
### Added
|
package/README.md
CHANGED
|
@@ -93,7 +93,7 @@ make, because those mean "this person's account".
|
|
|
93
93
|
| `sb_publish` | Compile the draft into the live page (cascades to shared globals) |
|
|
94
94
|
| `sb_review` | Every defect a visitor would see, each with its fix, plus the five gaps between this store and a paid order |
|
|
95
95
|
| `sb_media_list` | The site's media library |
|
|
96
|
-
| `sb_media_upload` | Add an image and get its URL —
|
|
96
|
+
| `sb_media_upload` | Add an image and get its URL — a local path, a URL the platform fetches, or a SEARCH for real photographs you read and pick from |
|
|
97
97
|
| `sb_live_join` | Join the editor's live-edit room as a visible peer — edits then appear live |
|
|
98
98
|
| `sb_look` | Save, render, and return screenshots plus measured node boxes and layout defects measured on the render |
|
|
99
99
|
| `sb_event` | Give a node a click action — open the cart, go to a page, open a pop-up |
|
package/README.vi.md
CHANGED
|
@@ -65,6 +65,12 @@ là "tài khoản của người này".
|
|
|
65
65
|
|
|
66
66
|
`SB_API` mặc định `http://localhost:8080`. Bí mật chỉ đọc từ biến môi trường.
|
|
67
67
|
|
|
68
|
+
`PEXELS_API_KEY` là **tuỳ chọn**, chỉ ảnh hưởng phần tìm ảnh của `sb_media_upload`: có key thì gọi
|
|
69
|
+
thẳng Pexels (key miễn phí ở <https://www.pexels.com/api/>), không có thì dùng proxy chung mà nhà
|
|
70
|
+
mình đang chạy (`PEXELS_PROXY_BASE`, mặc định `https://mcp.toolvn.io.vn`) — nên bản cài không cấu
|
|
71
|
+
hình gì vẫn tìm được ảnh. Proxy giữ key của chính nó và không bao giờ gửi key về client; đó là ưu
|
|
72
|
+
ái chứ không phải cam kết, và kết quả nói rõ cửa nào đã trả lời.
|
|
73
|
+
|
|
68
74
|
## Bộ tool
|
|
69
75
|
|
|
70
76
|
| Tool | Làm gì |
|
|
@@ -90,7 +96,7 @@ là "tài khoản của người này".
|
|
|
90
96
|
| `sb_publish` | Biên dịch bản nháp thành trang live (lan sang global dùng chung) |
|
|
91
97
|
| `sb_review` | Mọi khiếm khuyết người xem sẽ thấy, kèm lệnh sửa từng cái, và năm khoảng trống chắn giữa cửa hàng với một đơn đã thanh toán |
|
|
92
98
|
| `sb_media_list` | Thư viện ảnh của site |
|
|
93
|
-
| `sb_media_upload` | Thêm ảnh và lấy URL —
|
|
99
|
+
| `sb_media_upload` | Thêm ảnh và lấy URL — file trên máy, một URL để nền tảng tự tải, hoặc TÌM ảnh chụp thật để đọc mô tả rồi chọn |
|
|
94
100
|
| `sb_live_join` | Vào phòng live-edit của editor như một peer nhìn thấy được — sửa gì hiện ngay |
|
|
95
101
|
| `sb_look` | Lưu, render, trả về ảnh chụp kèm box đo được của node và lỗi bố cục đo trên bản render |
|
|
96
102
|
| `sb_event` | Gắn click action cho một node — mở giỏ, sang trang, mở pop-up |
|
package/dist/tools/live.js
CHANGED
|
@@ -27,6 +27,7 @@ import { LiveSession } from '../live/session.js';
|
|
|
27
27
|
import { refuseAppBlockInterior } from '../domains/site/builder.js';
|
|
28
28
|
import { childrenOf, isOverlay, overlayRoot, subtreeIds } from '../core/tree.js';
|
|
29
29
|
import { siteToken } from './credentialpick.js';
|
|
30
|
+
import { searchStock } from '../transport/stock.js';
|
|
30
31
|
import { siteFor } from './context.js';
|
|
31
32
|
import { projectList, MEDIA_FIELDS } from './project.js';
|
|
32
33
|
/**
|
|
@@ -403,21 +404,88 @@ export function registerLiveTools(server, ctx, session) {
|
|
|
403
404
|
}), 'assets', MEDIA_FIELDS)));
|
|
404
405
|
server.registerTool('sb_media_upload', {
|
|
405
406
|
description: 'Put an image into the media library and get its URL back, ready for sb_set. Takes a ' +
|
|
406
|
-
'local
|
|
407
|
-
'
|
|
407
|
+
'local path, a URL, or a SEARCH — `query` returns real photographs with their own ' +
|
|
408
|
+
'descriptions, and `pick` uploads the one you chose. The only way to add an image.',
|
|
408
409
|
inputSchema: {
|
|
409
410
|
site_id: z.string().optional(),
|
|
410
411
|
path: z.string().optional().describe('A file on this machine'),
|
|
411
412
|
url: z.string().optional().describe('Fetched, then uploaded'),
|
|
413
|
+
query: z.string().optional().describe('Search real photographs; read the descriptions, then pick'),
|
|
414
|
+
orientation: z.enum(['landscape', 'portrait', 'square']).optional(),
|
|
415
|
+
pick: z.number().int().optional().describe('The id of the search result to upload'),
|
|
412
416
|
name: z.string().optional(),
|
|
413
417
|
folder_id: z.string().optional(),
|
|
414
418
|
dry_run: z.boolean().optional(),
|
|
415
419
|
},
|
|
416
420
|
annotations: { readOnlyHint: false, destructiveHint: false },
|
|
417
|
-
}, async ({ site_id: given, path, url, name, folder_id, dry_run }) => {
|
|
421
|
+
}, async ({ site_id: given, path, url, name, folder_id, query, orientation, pick, dry_run }) => {
|
|
418
422
|
const site_id = siteFor(ctx, given);
|
|
419
|
-
|
|
420
|
-
|
|
423
|
+
// A SEARCH IS NOT A GUESS, and the difference is the whole reason this is
|
|
424
|
+
// two steps. Rule 7 records what a keyword glued into a URL returns —
|
|
425
|
+
// `loremflickr` answered "kids,clothing" with a cat statue — and the fault
|
|
426
|
+
// was never stock photography, it was that nobody looked. Every result
|
|
427
|
+
// here carries what it actually SHOWS, so the caller reads the
|
|
428
|
+
// descriptions and CHOOSES; uploading the first hit unread would rebuild
|
|
429
|
+
// the cat statue with better plumbing.
|
|
430
|
+
if (query) {
|
|
431
|
+
const found = await searchStock(ctx.fetchImpl ?? fetch, query, {
|
|
432
|
+
perPage: 8,
|
|
433
|
+
orientation,
|
|
434
|
+
});
|
|
435
|
+
const chosen = pick !== undefined ? found.photos.find((p) => p.id === pick) : undefined;
|
|
436
|
+
if (!chosen) {
|
|
437
|
+
return text({
|
|
438
|
+
...(pick !== undefined ? { no_such_pick: pick } : {}),
|
|
439
|
+
found: found.photos.map((p) => ({
|
|
440
|
+
pick: p.id,
|
|
441
|
+
shows: p.alt || '(the photographer left no description)',
|
|
442
|
+
size: `${p.width}x${p.height}`,
|
|
443
|
+
by: p.photographer,
|
|
444
|
+
})),
|
|
445
|
+
via: found.via,
|
|
446
|
+
next: 'Read what each one SHOWS, then re-call with pick:<id> and dry_run:false. The photo ' +
|
|
447
|
+
"is uploaded into this site's own library, never hotlinked.",
|
|
448
|
+
...(found.via === 'proxy'
|
|
449
|
+
? {
|
|
450
|
+
key: 'No PEXELS_API_KEY, so this used the shared proxy — a courtesy, not a ' +
|
|
451
|
+
'guarantee. A free key at https://www.pexels.com/api/ calls Pexels directly.',
|
|
452
|
+
}
|
|
453
|
+
: {}),
|
|
454
|
+
licence: ctx.notices.once('stock_licence', 'Pexels photographs are free for commercial use and attribution is appreciated ' +
|
|
455
|
+
'rather than required, so a storefront can carry one without printing a credit ' +
|
|
456
|
+
'line. The photographer and the photo page come back with each result if you ' +
|
|
457
|
+
'want to credit anyway.'),
|
|
458
|
+
});
|
|
459
|
+
}
|
|
460
|
+
if (dry_run !== false) {
|
|
461
|
+
return text({
|
|
462
|
+
dry_run: true,
|
|
463
|
+
would_upload: chosen.url,
|
|
464
|
+
shows: chosen.alt,
|
|
465
|
+
by: chosen.photographer,
|
|
466
|
+
into: site_id,
|
|
467
|
+
note: 'Nothing was sent. Re-call with dry_run:false to upload.',
|
|
468
|
+
});
|
|
469
|
+
}
|
|
470
|
+
const asset = await uploadMedia(ctx, site_id, {
|
|
471
|
+
url: chosen.url,
|
|
472
|
+
// THE DESCRIPTION BECOMES THE NAME, so the library is searchable by
|
|
473
|
+
// what the photographs show and the alt on the page means something.
|
|
474
|
+
name: name ?? chosen.alt ?? undefined,
|
|
475
|
+
folderId: folder_id,
|
|
476
|
+
});
|
|
477
|
+
return text({
|
|
478
|
+
asset,
|
|
479
|
+
shows: chosen.alt,
|
|
480
|
+
credit: { by: chosen.photographer, profile: chosen.photographer_url, photo: chosen.page_url },
|
|
481
|
+
next: asset.url
|
|
482
|
+
? `Use it: sb_set id "<node>", namespace specials, keys { "src": ${JSON.stringify(asset.url)} }`
|
|
483
|
+
: 'Uploaded, but the server returned no url — read it back with sb_media_list.',
|
|
484
|
+
});
|
|
485
|
+
}
|
|
486
|
+
if (!path && !url) {
|
|
487
|
+
throw new Error('sbuilder: give sb_media_upload a path, a url, or a query to search');
|
|
488
|
+
}
|
|
421
489
|
if (dry_run !== false) {
|
|
422
490
|
return text({
|
|
423
491
|
dry_run: true,
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* REAL PHOTOGRAPHS, WITH REAL DESCRIPTIONS.
|
|
3
|
+
*
|
|
4
|
+
* Rule 7 of the design skill is the reason this exists and the reason it is
|
|
5
|
+
* shaped the way it is: "keyword stock imagery is not a source — `loremflickr`
|
|
6
|
+
* answered 'kids,clothing' with a cat statue and a photo of an adult." That
|
|
7
|
+
* failure is not about stock photography, it is about GUESSING: a keyword glued
|
|
8
|
+
* into a URL returns something nobody looked at.
|
|
9
|
+
*
|
|
10
|
+
* A search API is a different thing entirely, because every result carries what
|
|
11
|
+
* it actually SHOWS. Pexels answers "coffee shop" with
|
|
12
|
+
* "Three young adults engage at a cafe counter, using mobile devices" — so the
|
|
13
|
+
* caller can read the descriptions and CHOOSE, which is what a person does and
|
|
14
|
+
* what the cat statue proves nobody was doing.
|
|
15
|
+
*
|
|
16
|
+
* PEXELS, because it is already this family's answer: `webcake-landing-mcp`
|
|
17
|
+
* ships the same client, down to the shared proxy below, and a second house
|
|
18
|
+
* standard for the same job is a second place for it to drift. Its licence is
|
|
19
|
+
* free for commercial use with attribution appreciated rather than required,
|
|
20
|
+
* which is what makes an image usable on a merchant's storefront without
|
|
21
|
+
* printing a credit line they did not ask for.
|
|
22
|
+
*
|
|
23
|
+
* THE KEY IS OPTIONAL, and that is deliberate: with `PEXELS_API_KEY` this calls
|
|
24
|
+
* Pexels directly, and without one it calls the shared proxy the sibling repo
|
|
25
|
+
* already runs (`https://mcp.toolvn.io.vn/api/images/search`), which holds a key
|
|
26
|
+
* and answers the same shape. An `npx` install with no configuration at all
|
|
27
|
+
* still finds images.
|
|
28
|
+
*/
|
|
29
|
+
const PEXELS_SEARCH = 'https://api.pexels.com/v1/search';
|
|
30
|
+
const PROXY_DEFAULT = 'https://mcp.toolvn.io.vn';
|
|
31
|
+
const PROXY_PATH = '/api/images/search';
|
|
32
|
+
const TIMEOUT_MS = 20_000;
|
|
33
|
+
/** The shape both doors answer, normalised here so the caller cannot tell them apart. */
|
|
34
|
+
function normalise(p) {
|
|
35
|
+
const src = (p.src ?? {});
|
|
36
|
+
// `large2x` is ~1880px wide, which is a hero at 1440 and still a few hundred
|
|
37
|
+
// KB; `original` is the native file and on a 3800px photograph that is tens of
|
|
38
|
+
// megabytes for a band nobody will view above 1440.
|
|
39
|
+
const url = src.large2x || src.large || src.original || '';
|
|
40
|
+
if (!url)
|
|
41
|
+
return null;
|
|
42
|
+
return {
|
|
43
|
+
id: Number(p.id ?? 0),
|
|
44
|
+
alt: typeof p.alt === 'string' ? p.alt : '',
|
|
45
|
+
width: Number(p.width ?? 0),
|
|
46
|
+
height: Number(p.height ?? 0),
|
|
47
|
+
photographer: typeof p.photographer === 'string' ? p.photographer : '',
|
|
48
|
+
photographer_url: typeof p.photographer_url === 'string' ? p.photographer_url : '',
|
|
49
|
+
page_url: typeof p.url === 'string' ? p.url : '',
|
|
50
|
+
url,
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Search for photographs.
|
|
55
|
+
*
|
|
56
|
+
* `orientation` is a SHAPE request, not a subject one — a hero panel filled with
|
|
57
|
+
* a portrait crop is the aspect-ratio mistake rule 6 is about, and it is far
|
|
58
|
+
* cheaper to ask the search than to crop afterwards.
|
|
59
|
+
*/
|
|
60
|
+
export async function searchStock(fetchImpl, query, opts = {}) {
|
|
61
|
+
const q = new URLSearchParams({
|
|
62
|
+
query,
|
|
63
|
+
per_page: String(Math.min(Math.max(opts.perPage ?? 8, 1), 30)),
|
|
64
|
+
});
|
|
65
|
+
if (opts.orientation)
|
|
66
|
+
q.set('orientation', opts.orientation);
|
|
67
|
+
const key = (process.env.PEXELS_API_KEY ?? '').trim();
|
|
68
|
+
const proxy = (process.env.PEXELS_PROXY_BASE ?? PROXY_DEFAULT).replace(/\/+$/, '');
|
|
69
|
+
const [url, headers, via] = key
|
|
70
|
+
? [`${PEXELS_SEARCH}?${q}`, { Authorization: key }, 'pexels']
|
|
71
|
+
: [`${proxy}${PROXY_PATH}?${q}`, {}, 'proxy'];
|
|
72
|
+
let res;
|
|
73
|
+
try {
|
|
74
|
+
res = await fetchImpl(url, {
|
|
75
|
+
headers: { Accept: 'application/json', ...headers },
|
|
76
|
+
signal: AbortSignal.timeout(TIMEOUT_MS),
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
catch (e) {
|
|
80
|
+
throw new Error(`sbuilder: could not reach the image search (${via}) — ${e.message}. ` +
|
|
81
|
+
'Set PEXELS_API_KEY for a direct connection, or PEXELS_PROXY_BASE to another host.');
|
|
82
|
+
}
|
|
83
|
+
if (!res.ok) {
|
|
84
|
+
throw new Error(`sbuilder: the image search (${via}) answered ${res.status}. ` +
|
|
85
|
+
(via === 'proxy'
|
|
86
|
+
? 'The shared proxy is a courtesy, not a guarantee — set PEXELS_API_KEY (free at ' +
|
|
87
|
+
'https://www.pexels.com/api/) to call Pexels directly.'
|
|
88
|
+
: 'Check PEXELS_API_KEY.'));
|
|
89
|
+
}
|
|
90
|
+
const body = (await res.json());
|
|
91
|
+
const photos = (body.photos ?? [])
|
|
92
|
+
.map(normalise)
|
|
93
|
+
.filter((p) => p !== null);
|
|
94
|
+
return { photos, via };
|
|
95
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "sbuilder-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.26.0",
|
|
4
4
|
"description": "MCP server that designs and operates a Store Builder site — pages, data, theme and publish — through the platform's own API and live-edit protocol.",
|
|
5
5
|
"mcpName": "io.github.vuluu2k/sbuilder-mcp",
|
|
6
6
|
"type": "module",
|