@zabuti/components-mcp 0.0.0-stage → 0.1.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.
Files changed (54) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +42 -2
  3. package/dist/index.js +527 -0
  4. package/dist/project-setup.js +424 -0
  5. package/dist/registry.js +73 -0
  6. package/dist/source.js +19 -0
  7. package/package.json +41 -4
  8. package/payload/registry.json +801 -0
  9. package/payload/src/components/ui/accordion.tsx +75 -0
  10. package/payload/src/components/ui/alert-dialog.tsx +151 -0
  11. package/payload/src/components/ui/alert.tsx +69 -0
  12. package/payload/src/components/ui/avatar.tsx +59 -0
  13. package/payload/src/components/ui/badge.tsx +57 -0
  14. package/payload/src/components/ui/breadcrumb.tsx +109 -0
  15. package/payload/src/components/ui/button.tsx +76 -0
  16. package/payload/src/components/ui/calendar.tsx +117 -0
  17. package/payload/src/components/ui/card.tsx +120 -0
  18. package/payload/src/components/ui/chart.tsx +249 -0
  19. package/payload/src/components/ui/checkbox.tsx +38 -0
  20. package/payload/src/components/ui/collapsible.tsx +30 -0
  21. package/payload/src/components/ui/combobox.tsx +127 -0
  22. package/payload/src/components/ui/command.tsx +186 -0
  23. package/payload/src/components/ui/context-menu.tsx +261 -0
  24. package/payload/src/components/ui/date-picker.tsx +140 -0
  25. package/payload/src/components/ui/dialog.tsx +176 -0
  26. package/payload/src/components/ui/dropdown-menu.tsx +277 -0
  27. package/payload/src/components/ui/form.tsx +151 -0
  28. package/payload/src/components/ui/hover-card.tsx +46 -0
  29. package/payload/src/components/ui/input-group.tsx +127 -0
  30. package/payload/src/components/ui/input.tsx +25 -0
  31. package/payload/src/components/ui/label.tsx +28 -0
  32. package/payload/src/components/ui/pagination.tsx +130 -0
  33. package/payload/src/components/ui/popover.tsx +97 -0
  34. package/payload/src/components/ui/progress.tsx +35 -0
  35. package/payload/src/components/ui/radio-group.tsx +49 -0
  36. package/payload/src/components/ui/scroll-area.tsx +67 -0
  37. package/payload/src/components/ui/select.tsx +199 -0
  38. package/payload/src/components/ui/separator.tsx +32 -0
  39. package/payload/src/components/ui/sheet.tsx +155 -0
  40. package/payload/src/components/ui/skeleton.tsx +21 -0
  41. package/payload/src/components/ui/slider.tsx +61 -0
  42. package/payload/src/components/ui/sonner.tsx +31 -0
  43. package/payload/src/components/ui/switch.tsx +40 -0
  44. package/payload/src/components/ui/table.tsx +108 -0
  45. package/payload/src/components/ui/tabs.tsx +98 -0
  46. package/payload/src/components/ui/textarea.tsx +24 -0
  47. package/payload/src/components/ui/toggle-group.tsx +72 -0
  48. package/payload/src/components/ui/toggle.tsx +54 -0
  49. package/payload/src/components/ui/tooltip.tsx +65 -0
  50. package/payload/src/lib/utils.ts +1 -0
  51. package/payload/src/themes/manifest.json +12 -0
  52. package/payload/src/themes/zabuti-ui-sky.css +14 -0
  53. package/payload/src/themes/zabuti-ui-teal.css +14 -0
  54. package/payload/src/zabuti-ui.css +272 -0
@@ -0,0 +1,424 @@
1
+ /**
2
+ * Project-prep helpers shared by `setup_project` (does the work up front) and
3
+ * `add_component` / `verify_component` (the CSS-import half of it).
4
+ *
5
+ * Each patch is idempotent and honest about what it can't do: a helper returns
6
+ * `status: "manual"` with the exact snippet when a project's config doesn't match
7
+ * a shape it knows how to edit, rather than corrupting the file. The goal is to
8
+ * turn the ~7 hand-steps a cold agent used to follow (patch vite.config, patch
9
+ * both tsconfigs, add three @import lines, npm i the deps) into one tool call.
10
+ */
11
+ import { spawnSync } from "node:child_process";
12
+ import { existsSync, readFileSync, writeFileSync } from "node:fs";
13
+ import { dirname, join, relative } from "node:path";
14
+ /**
15
+ * The three sheets a consumer's CSS entry must pull in, in order. The first two
16
+ * are bare specifiers; the theme sheet is imported by a **relative** path (not
17
+ * the `@/` alias) — Vite's bundled `postcss-import` inlines `@import` before the
18
+ * alias resolver runs, so `@import "@/…"` fails with an unresolved-`@` ENOENT in
19
+ * some setups. `zabutiThemeImport()` computes the right relative path from the
20
+ * CSS entry's own location.
21
+ */
22
+ export const CSS_IMPORT_LABELS = ["tailwindcss", "tw-animate-css", "zabuti-ui.css"];
23
+ /** Matches any existing theme import regardless of prefix (`@/`, `./`, `../`). */
24
+ const THEME_IMPORT_RE = /@import\s+["'][^"']*zabuti[/\\]zabuti-ui\.css["'];?/;
25
+ /** The canonical `@import "…";` for the theme sheet, relative to `cssEntryFile`. */
26
+ function zabutiThemeImport(cssEntryFile, target) {
27
+ let r = relative(dirname(cssEntryFile), join(target, "src/components/zabuti/zabuti-ui.css")).replace(/\\/g, "/");
28
+ if (!r.startsWith("."))
29
+ r = `./${r}`;
30
+ return `@import "${r}";`;
31
+ }
32
+ function readIf(p) {
33
+ try {
34
+ return readFileSync(p, "utf8");
35
+ }
36
+ catch {
37
+ return null;
38
+ }
39
+ }
40
+ function rel(target, abs) {
41
+ return relative(target, abs).replace(/\\/g, "/");
42
+ }
43
+ // ---------------------------------------------------------------------------
44
+ // vite.config
45
+ // ---------------------------------------------------------------------------
46
+ /**
47
+ * Ensure vite.config has (a) the `@tailwindcss/vite` plugin and (b) a `@/` →
48
+ * `./src` resolve alias. Handles the stock `npm create vite` react-ts shape
49
+ * (`export default defineConfig({ plugins: [react()] })`) and is a no-op when
50
+ * both are already present. Anything it can't safely edit comes back "manual".
51
+ */
52
+ export function patchViteConfig(target) {
53
+ const step = "vite.config";
54
+ const file = (existsSync(join(target, "vite.config.ts")) && join(target, "vite.config.ts")) ||
55
+ (existsSync(join(target, "vite.config.js")) && join(target, "vite.config.js")) ||
56
+ "";
57
+ if (!file) {
58
+ return {
59
+ step,
60
+ status: "manual",
61
+ detail: "no vite.config.ts / vite.config.js found",
62
+ manual: [
63
+ "Create vite.config.ts:",
64
+ " import { fileURLToPath } from 'node:url'",
65
+ " import tailwindcss from '@tailwindcss/vite'",
66
+ " import react from '@vitejs/plugin-react'",
67
+ " import { defineConfig } from 'vite'",
68
+ " export default defineConfig({",
69
+ " plugins: [react(), tailwindcss()],",
70
+ " resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },",
71
+ " })",
72
+ ],
73
+ };
74
+ }
75
+ let src = readFileSync(file, "utf8");
76
+ const before = src;
77
+ const done = [];
78
+ const manual = [];
79
+ // (a) Tailwind v4 Vite plugin
80
+ const hasTwImport = /['"]@tailwindcss\/vite['"]/.test(src);
81
+ const hasTwInPlugins = /tailwindcss\(\)/.test(src);
82
+ if (!hasTwImport) {
83
+ src = addImport(src, "import tailwindcss from '@tailwindcss/vite'");
84
+ }
85
+ if (!hasTwInPlugins) {
86
+ const m = src.match(/plugins:\s*\[/);
87
+ if (m) {
88
+ src = src.replace(/plugins:\s*\[/, (hit) => `${hit}tailwindcss(), `);
89
+ done.push("added tailwindcss() to plugins");
90
+ }
91
+ else if (/defineConfig\(\{/.test(src)) {
92
+ src = src.replace(/defineConfig\(\{/, (hit) => `${hit}\n plugins: [tailwindcss()],`);
93
+ done.push("added a plugins: [tailwindcss()] block");
94
+ }
95
+ else {
96
+ manual.push("Add tailwindcss() to the Vite plugins array.");
97
+ }
98
+ }
99
+ // (b) @/ alias
100
+ const hasAlias = /alias\s*:/.test(src) && /['"]@['"]\s*:/.test(src);
101
+ if (!hasAlias) {
102
+ if (!/from ['"]node:url['"]/.test(src)) {
103
+ src = addImport(src, "import { fileURLToPath } from 'node:url'");
104
+ }
105
+ if (/defineConfig\(\{/.test(src)) {
106
+ src = src.replace(/defineConfig\(\{/, (hit) => `${hit}\n resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } },`);
107
+ done.push("added the @/ → ./src resolve alias");
108
+ }
109
+ else {
110
+ manual.push("Add to your Vite config: resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }");
111
+ }
112
+ }
113
+ if (src !== before)
114
+ writeFileSync(file, src);
115
+ if (manual.length) {
116
+ return { step, status: "manual", detail: `${rel(target, file)} — partly patched`, manual };
117
+ }
118
+ if (done.length === 0) {
119
+ return { step, status: "already", detail: `${rel(target, file)} — plugin + alias already set` };
120
+ }
121
+ return { step, status: "patched", detail: `${rel(target, file)} — ${done.join("; ")}` };
122
+ }
123
+ /** Insert an import after the last existing top-of-file import, else at line 0. */
124
+ function addImport(src, line) {
125
+ const lines = src.split("\n");
126
+ let last = -1;
127
+ for (let i = 0; i < lines.length; i++) {
128
+ if (/^\s*import\b/.test(lines[i] ?? ""))
129
+ last = i;
130
+ else if (last >= 0 && (lines[i] ?? "").trim() !== "")
131
+ break;
132
+ }
133
+ lines.splice(last + 1, 0, line);
134
+ return lines.join("\n");
135
+ }
136
+ // ---------------------------------------------------------------------------
137
+ // tsconfig paths
138
+ // ---------------------------------------------------------------------------
139
+ /**
140
+ * Ensure `compilerOptions.paths["@/*"] = ["./src/*"]` in tsconfig.json and
141
+ * tsconfig.app.json. These files carry `// comments` in the Vite template, so
142
+ * this is a targeted string insert, not a JSON round-trip. One StepResult per
143
+ * file that exists.
144
+ */
145
+ export function patchTsconfigPaths(target) {
146
+ const names = ["tsconfig.json", "tsconfig.app.json"];
147
+ const out = [];
148
+ let touchedAny = false;
149
+ for (const name of names) {
150
+ const file = join(target, name);
151
+ const src = readIf(file);
152
+ if (src == null)
153
+ continue;
154
+ touchedAny = true;
155
+ const step = name;
156
+ if (/["']@\/\*["']\s*:/.test(src)) {
157
+ out.push({ step, status: "already", detail: `${name} — "@/*" path already declared` });
158
+ continue;
159
+ }
160
+ const pathsSnippet = `"paths": { "@/*": ["./src/*"] }`;
161
+ let next = null;
162
+ if (/"compilerOptions"\s*:\s*\{/.test(src)) {
163
+ next = src.replace(/("compilerOptions"\s*:\s*\{)/, (hit) => `${hit}\n ${pathsSnippet},`);
164
+ }
165
+ else {
166
+ // e.g. a tsconfig.json that only has files/references
167
+ const firstBrace = src.indexOf("{");
168
+ if (firstBrace >= 0) {
169
+ next =
170
+ src.slice(0, firstBrace + 1) +
171
+ `\n "compilerOptions": { ${pathsSnippet} },` +
172
+ src.slice(firstBrace + 1);
173
+ }
174
+ }
175
+ if (next && next !== src) {
176
+ writeFileSync(file, next);
177
+ out.push({ step, status: "patched", detail: `${name} — added "@/*": ["./src/*"]` });
178
+ }
179
+ else {
180
+ out.push({
181
+ step,
182
+ status: "manual",
183
+ detail: `${name} — couldn't place the paths entry`,
184
+ manual: [`In ${name} compilerOptions add: ${pathsSnippet}`],
185
+ });
186
+ }
187
+ }
188
+ if (!touchedAny) {
189
+ out.push({
190
+ step: "tsconfig",
191
+ status: "manual",
192
+ detail: "no tsconfig.json / tsconfig.app.json found",
193
+ manual: ['In tsconfig compilerOptions add: "paths": { "@/*": ["./src/*"] }'],
194
+ });
195
+ }
196
+ return out;
197
+ }
198
+ // ---------------------------------------------------------------------------
199
+ // CSS entry @imports
200
+ // ---------------------------------------------------------------------------
201
+ /** Follow an entry module's own `import './x.css'`, else the first conventional
202
+ * entry. Covers Vite (`src/main.tsx` → `./index.css`) and Next App Router
203
+ * (`src/app/layout.tsx` → `./globals.css`); the CSS path resolves relative to
204
+ * the entry file, not a hardcoded `src/`. */
205
+ function findCssEntry(target) {
206
+ for (const main of [
207
+ "src/main.tsx",
208
+ "src/main.jsx",
209
+ "src/main.ts",
210
+ "src/index.tsx",
211
+ "src/index.jsx",
212
+ "src/app/layout.tsx",
213
+ "app/layout.tsx",
214
+ "src/app/layout.jsx",
215
+ "app/layout.jsx",
216
+ ]) {
217
+ const mainPath = join(target, main);
218
+ const txt = readIf(mainPath);
219
+ if (!txt)
220
+ continue;
221
+ const m = txt.match(/import\s+["'](\.\.?\/[^"']+\.css)["']/);
222
+ if (m?.[1])
223
+ return join(dirname(mainPath), m[1]);
224
+ }
225
+ for (const c of [
226
+ "src/index.css",
227
+ "src/main.css",
228
+ "src/styles.css",
229
+ "src/App.css",
230
+ "src/app/globals.css",
231
+ "app/globals.css",
232
+ "src/styles/globals.css",
233
+ ]) {
234
+ if (existsSync(join(target, c)))
235
+ return join(target, c);
236
+ }
237
+ return join(target, "src/index.css");
238
+ }
239
+ function analyzeCss(target) {
240
+ const file = findCssEntry(target);
241
+ const css = readIf(file) ?? "";
242
+ const themeImport = zabutiThemeImport(file, target);
243
+ const themeMatch = css.match(THEME_IMPORT_RE);
244
+ return {
245
+ file,
246
+ css,
247
+ hasTailwind: /@import\s+["']tailwindcss["']/.test(css),
248
+ hasAnimate: /@import\s+["']tw-animate-css["']/.test(css),
249
+ hasThemeAny: themeMatch != null,
250
+ hasThemeExact: themeMatch?.[0].replace(/;?$/, ";") === themeImport,
251
+ themeImport,
252
+ };
253
+ }
254
+ /** Read-only: which of the three imports the CSS entry has (labels, not specs). */
255
+ export function checkCssImports(target) {
256
+ const s = analyzeCss(target);
257
+ const present = [];
258
+ const missing = [];
259
+ (s.hasTailwind ? present : missing).push("tailwindcss");
260
+ (s.hasAnimate ? present : missing).push("tw-animate-css");
261
+ (s.hasThemeAny ? present : missing).push("zabuti-ui.css");
262
+ return { file: s.file, present, missing };
263
+ }
264
+ /**
265
+ * Make the CSS entry `@import` all three sheets, in canonical order —
266
+ * `tailwindcss` → `tw-animate-css` → `zabuti-ui.css`. Missing sheets are
267
+ * inserted right after the existing `@import "tailwindcss";` line if there is
268
+ * one (so a create-next-app entry that already leads with Tailwind stays
269
+ * first), otherwise prepended. Also rewrites a fragile `@import
270
+ * "@/…zabuti-ui.css"` to the relative form.
271
+ */
272
+ export function ensureCssImports(target) {
273
+ const step = "CSS @imports";
274
+ const s = analyzeCss(target);
275
+ const existed = existsSync(s.file);
276
+ let css = s.css;
277
+ const changes = [];
278
+ // A brand-new Vite app's index.css is demo styling: it centres everything in
279
+ // #root and redefines --border / --accent, the same tokens Zabuti uses, after
280
+ // the theme import, so the theme loses. Found by a cold install 2026-11-14.
281
+ // Matched on markers only the untouched templates carry, so a stylesheet the
282
+ // developer wrote is never dropped.
283
+ const wiped = isViteStarterCss(css);
284
+ if (wiped) {
285
+ css = "";
286
+ changes.push("replaced the Vite starter styles (demo CSS that overrode Zabuti's --border/--accent and centred the page)");
287
+ }
288
+ // After a wipe every import is gone, so all three get added back.
289
+ const has = {
290
+ tailwind: s.hasTailwind && !wiped,
291
+ animate: s.hasAnimate && !wiped,
292
+ themeAny: s.hasThemeAny && !wiped,
293
+ };
294
+ if (has.themeAny && !s.hasThemeExact) {
295
+ css = css.replace(THEME_IMPORT_RE, s.themeImport);
296
+ changes.push(`rewrote theme @import → ${s.themeImport.slice(9, -2)} (relative)`);
297
+ }
298
+ const toAdd = [];
299
+ if (!has.tailwind) {
300
+ toAdd.push('@import "tailwindcss";');
301
+ changes.push('added @import "tailwindcss"');
302
+ }
303
+ if (!has.animate) {
304
+ toAdd.push('@import "tw-animate-css";');
305
+ changes.push('added @import "tw-animate-css"');
306
+ }
307
+ if (!has.themeAny) {
308
+ toAdd.push(s.themeImport);
309
+ changes.push(`added ${s.themeImport.slice(9, -2)}`);
310
+ }
311
+ if (changes.length === 0) {
312
+ return {
313
+ step,
314
+ status: "already",
315
+ detail: `${rel(target, s.file)} — tailwindcss + tw-animate-css + zabuti-ui.css all imported (relative)`,
316
+ };
317
+ }
318
+ let next;
319
+ const tailwindLine = css.match(/^.*@import\s+["']tailwindcss["'];?.*$/m);
320
+ if (has.tailwind && tailwindLine && toAdd.length) {
321
+ // Insert the new sheets immediately after the existing Tailwind import so
322
+ // `@import "tailwindcss"` stays the first line.
323
+ const idx = tailwindLine.index + tailwindLine[0].length;
324
+ next = `${css.slice(0, idx)}\n${toAdd.join("\n")}${css.slice(idx)}`;
325
+ }
326
+ else {
327
+ const body = toAdd.length ? `${toAdd.join("\n")}\n` : "";
328
+ next = existed && css.trim() ? `${body}${css}` : body || "\n";
329
+ }
330
+ writeFileSync(s.file, next);
331
+ return {
332
+ step,
333
+ status: existed ? "patched" : "created",
334
+ detail: `${rel(target, s.file)} — ${changes.join("; ")}`,
335
+ };
336
+ }
337
+ /**
338
+ * Whether a CSS entry is still the untouched create-vite starter: current
339
+ * templates carry the `#social` / `--social-bg` demo block, older ones the
340
+ * `#646cff` link colour with `place-items: center` on body.
341
+ */
342
+ function isViteStarterCss(css) {
343
+ return ((css.includes("--social-bg") && css.includes("#social")) ||
344
+ (css.includes("#646cff") && /place-items:s*center/.test(css)));
345
+ }
346
+ /** Matches a delivered theme-preset import (`zabuti-ui-<name>.css`), any prefix. */
347
+ const THEME_PRESET_RE = /[ \t]*@import\s+["'][^"']*zabuti-ui-[a-z0-9-]+\.css["'];?\n?/g;
348
+ /**
349
+ * Point the CSS entry at exactly one theme-preset overlay (or none). Drops any
350
+ * existing `zabuti-ui-*.css` import and, for a non-null `themeName`, adds
351
+ * `@import "./…/zabuti-ui-<name>.css";` immediately after the base zabuti-ui.css
352
+ * line. Assumes `ensureCssImports` has already run (base import present).
353
+ */
354
+ export function ensureThemeImport(target, themeName) {
355
+ const step = "theme @import";
356
+ const s = analyzeCss(target);
357
+ if (!s.css) {
358
+ return { step, status: "manual", detail: "no CSS entry found", manual: ["Create src/index.css first."] };
359
+ }
360
+ const had = s.css.match(THEME_PRESET_RE) != null;
361
+ let css = s.css.replace(THEME_PRESET_RE, "");
362
+ if (!themeName) {
363
+ if (css === s.css)
364
+ return { step, status: "already", detail: "no theme preset in use" };
365
+ writeFileSync(s.file, css);
366
+ return { step, status: "patched", detail: `${rel(target, s.file)} — removed the theme preset import` };
367
+ }
368
+ const spec = s.themeImport.replace("zabuti-ui.css", `zabuti-ui-${themeName}.css`);
369
+ const base = css.match(THEME_IMPORT_RE);
370
+ if (base?.index != null) {
371
+ const at = base.index + base[0].length;
372
+ css = `${css.slice(0, at)}\n${spec}${css.slice(at)}`;
373
+ }
374
+ else {
375
+ css = `${spec}\n${css}`;
376
+ }
377
+ writeFileSync(s.file, css);
378
+ return {
379
+ step,
380
+ status: had ? "patched" : "created",
381
+ detail: `${rel(target, s.file)} — ${had ? "switched to" : "added"} ${spec.slice(9, -2)}`,
382
+ };
383
+ }
384
+ // ---------------------------------------------------------------------------
385
+ // subprocess: npm install, tsc
386
+ // ---------------------------------------------------------------------------
387
+ export function npmInstall(target, packages) {
388
+ const step = "npm install";
389
+ if (packages.length === 0) {
390
+ return { step, status: "already", detail: "all required packages already in package.json" };
391
+ }
392
+ const res = spawnSync("npm", ["install", ...packages], {
393
+ cwd: target,
394
+ encoding: "utf8",
395
+ shell: process.platform === "win32",
396
+ timeout: 300_000,
397
+ maxBuffer: 32 * 1024 * 1024,
398
+ });
399
+ const cmd = `npm install ${packages.join(" ")}`;
400
+ if (res.error) {
401
+ return { step, status: "error", detail: String(res.error), manual: [cmd] };
402
+ }
403
+ if ((res.status ?? 1) !== 0) {
404
+ const tail = (res.stderr || res.stdout || "").split("\n").filter(Boolean).slice(-10).join("\n");
405
+ return { step, status: "error", detail: `npm exited ${res.status}\n${tail}`, manual: [cmd] };
406
+ }
407
+ return { step, status: "ok", detail: `installed ${packages.length}: ${packages.join(" ")}` };
408
+ }
409
+ export function typecheck(target) {
410
+ const res = spawnSync("npx", ["--yes", "tsc", "-b", "--pretty", "false"], {
411
+ cwd: target,
412
+ encoding: "utf8",
413
+ shell: process.platform === "win32",
414
+ timeout: 240_000,
415
+ maxBuffer: 32 * 1024 * 1024,
416
+ });
417
+ if (res.error)
418
+ return { ok: false, ran: false, output: String(res.error) };
419
+ return {
420
+ ok: (res.status ?? 1) === 0,
421
+ ran: true,
422
+ output: (res.stdout || "") + (res.stderr || ""),
423
+ };
424
+ }
@@ -0,0 +1,73 @@
1
+ /**
2
+ * The Zabuti Components registry — MCP view.
3
+ *
4
+ * Reads `payload/registry.json`: only the released items (see `source.ts` and
5
+ * `scripts/build-payload.mjs`). Each deliverable item — a feature component or a
6
+ * standalone primitive — is flattened, resolving `registryDependencies`
7
+ * transitively, into the self-contained `RegistryComponent` shape the tools use:
8
+ * a flat `files` list and the full `npmDependencies`.
9
+ */
10
+ import { readSource } from "./source.js";
11
+ const allItems = JSON.parse(readSource("registry.json")).items;
12
+ const byName = new Map(allItems.map((i) => [i.name, i]));
13
+ /** Flatten an item + its registryDependencies into one file + npm set. */
14
+ function resolveFlat(name) {
15
+ const files = new Set();
16
+ const npm = new Set();
17
+ const seen = new Set();
18
+ const stack = [name];
19
+ while (stack.length) {
20
+ const n = stack.pop();
21
+ if (n === undefined || seen.has(n))
22
+ continue;
23
+ seen.add(n);
24
+ const item = byName.get(n);
25
+ if (!item)
26
+ continue;
27
+ for (const f of item.files)
28
+ files.add(f);
29
+ for (const p of item.npmDependencies)
30
+ npm.add(p);
31
+ for (const d of item.registryDependencies)
32
+ stack.push(d);
33
+ }
34
+ return { files: [...files].sort(), npm: [...npm].sort() };
35
+ }
36
+ function toComponent(i) {
37
+ const primitive = i.type === "registry:ui";
38
+ // A primitive arrives with the theme layer too, so it renders styled on its own.
39
+ const { files, npm } = resolveFlat(i.name);
40
+ if (primitive) {
41
+ for (const base of ["utils", "zabuti-ui"]) {
42
+ const extra = resolveFlat(base);
43
+ for (const f of extra.files)
44
+ if (!files.includes(f))
45
+ files.push(f);
46
+ for (const p of extra.npm)
47
+ if (!npm.includes(p))
48
+ npm.push(p);
49
+ }
50
+ files.sort();
51
+ npm.sort();
52
+ }
53
+ return {
54
+ name: i.name,
55
+ title: i.title,
56
+ category: primitive ? "primitive" : i.category,
57
+ kind: primitive ? "primitive" : "component",
58
+ status: i.status,
59
+ summary: i.description,
60
+ npmDependencies: npm,
61
+ files,
62
+ usageDoc: i.docs ?? "",
63
+ adapterSketch: i.adapterSketch ?? "",
64
+ };
65
+ }
66
+ /** Every deliverable item: feature components first, then primitives. */
67
+ export const registry = [
68
+ ...allItems.filter((i) => i.type === "registry:component"),
69
+ ...allItems.filter((i) => i.type === "registry:ui"),
70
+ ].map(toComponent);
71
+ export function findComponent(name) {
72
+ return registry.find((c) => c.name === name);
73
+ }
package/dist/source.js ADDED
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Where the server reads what it delivers: `payload/` inside this package, built
3
+ * by `scripts/build-payload.mjs` from the release allow-list. Never the sandbox's
4
+ * own `src/`, so only released files can be handed out, here or once published.
5
+ */
6
+ import { existsSync, readFileSync } from "node:fs";
7
+ import { dirname, join, resolve } from "node:path";
8
+ import { fileURLToPath } from "node:url";
9
+ /** The package root: `src/` (tsx dev) or `dist/` (built) → up one. */
10
+ export const MCP_ROOT = resolve(dirname(fileURLToPath(import.meta.url)), "..");
11
+ export const PAYLOAD_ROOT = join(MCP_ROOT, "payload");
12
+ if (!existsSync(join(PAYLOAD_ROOT, "registry.json"))) {
13
+ process.stderr.write(`zabuti-components: no payload at ${PAYLOAD_ROOT}. In the library repo run \`npm run build\` in mcp/ (it builds the payload).\n`);
14
+ process.exit(1);
15
+ }
16
+ /** A payload file, by its repo-relative POSIX path (as registry.json lists them). */
17
+ export function readSource(relPath) {
18
+ return readFileSync(join(PAYLOAD_ROOT, relPath), "utf8");
19
+ }
package/package.json CHANGED
@@ -1,6 +1,43 @@
1
1
  {
2
2
  "name": "@zabuti/components-mcp",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "MCP server for Claude Code that copies Zabuti component source into your project (shadcn-style: you own the code). Free tier: the UI primitives and the theme.",
5
+ "homepage": "https://zabuti.com",
6
+ "license": "MIT",
7
+ "type": "module",
8
+ "bin": {
9
+ "zabuti-components-mcp": "dist/index.js"
10
+ },
11
+ "files": [
12
+ "dist",
13
+ "payload",
14
+ "README.md"
15
+ ],
16
+ "engines": {
17
+ "node": ">=20"
18
+ },
19
+ "keywords": [
20
+ "mcp",
21
+ "claude-code",
22
+ "react",
23
+ "components",
24
+ "tailwind",
25
+ "radix"
26
+ ],
27
+ "scripts": {
28
+ "dev": "tsx src/index.ts",
29
+ "build": "node ../src/registry/build.ts && node scripts/build-payload.mjs && tsc -p tsconfig.json",
30
+ "start": "node dist/index.js",
31
+ "smoke": "node scripts/smoke.mjs",
32
+ "prepack": "npm run build"
33
+ },
34
+ "dependencies": {
35
+ "@modelcontextprotocol/sdk": "^1.12.0",
36
+ "zod": "^3.23.8"
37
+ },
38
+ "devDependencies": {
39
+ "@types/node": "^22.0.0",
40
+ "tsx": "^4.19.0",
41
+ "typescript": "^5.6.0"
42
+ }
43
+ }