@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
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zabuti
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,43 @@
1
- # Temporary Holding Version
1
+ # @zabuti/components-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ An MCP server for Claude Code that copies Zabuti UI components into your project as source code you own. There's no runtime dependency on Zabuti and no package to import. Once a component is in your repo, it's yours to change.
4
+
5
+ This release carries the free tier: 41 UI primitives (button, dialog, date picker, combobox, select, tabs, table, chart and more), built on Radix and Tailwind v4, plus the theme they share.
6
+
7
+ ## Connect it to Claude Code
8
+
9
+ ```bash
10
+ claude mcp add zabuti -- npx -y @zabuti/components-mcp
11
+ ```
12
+
13
+ Then ask Claude for what you need, for example "add a date picker and a dialog from Zabuti".
14
+
15
+ ## What it needs
16
+
17
+ - A React + TypeScript project (Vite or Next.js App Router)
18
+ - Node 20 or later
19
+
20
+ Tailwind v4, the `@/` import alias and the theme stylesheet are set up for you by `setup_project`.
21
+
22
+ ## Tools
23
+
24
+ | Tool | What it does |
25
+ | --- | --- |
26
+ | `list_components` | Everything you can add, with a one-line summary |
27
+ | `get_component(name)` | What a piece delivers: files, npm packages, how to use it |
28
+ | `setup_project(targetDir, name?, skipInstall?)` | Gets a project ready in one call: Tailwind v4, the `@/` alias, the three CSS imports, and the npm packages. Safe to run again. On a brand-new Vite app it replaces the starter demo CSS, which would otherwise override the theme. |
29
+ | `add_component(name, targetDir, dryRun?, force?, overwrite?)` | Copies the piece, the primitives it builds on, and the theme into `src/components/zabuti/`. If a file is already there and you've changed it, your version is kept unless you pass `overwrite: true`. |
30
+ | `verify_component(targetDir, name)` | Checks every file landed and the CSS imports are in place, then runs `tsc -b` |
31
+ | `list_themes()` / `add_theme(name, targetDir)` | Accent colour presets. `add_theme("default", …)` removes one. |
32
+
33
+ The usual order is `setup_project`, then `add_component`, then `verify_component`.
34
+
35
+ ## Theming
36
+
37
+ `zabuti-ui.css` defines neutral design tokens (`--primary`, `--border`, `--radius`, …). To reskin, redefine those custom properties in your own stylesheet, after the import. Every component follows them.
38
+
39
+ More at [zabuti.com](https://zabuti.com).
40
+
41
+ ## License
42
+
43
+ MIT. The components you add are yours to use, change and ship, in any project.
package/dist/index.js ADDED
@@ -0,0 +1,527 @@
1
+ #!/usr/bin/env node
2
+ /**
3
+ * Zabuti Components MCP server (stdio).
4
+ *
5
+ * What it is: the "registry + source delivery" seam for the Zabuti component
6
+ * library. A connected Claude Code session gets three tools — discover the
7
+ * catalogue, read a component's data contract, and copy its source (the
8
+ * component, its Zabuti UI primitives, and the theme CSS) into the consumer's
9
+ * repo — then Claude writes the thin data adapter itself. No shadcn: the
10
+ * primitives are Zabuti-owned files in the payload. A primitive can be added on
11
+ * its own too. No auth/licensing yet.
12
+ *
13
+ * Everything it reads comes from `payload/` (`source.ts`): only the items in
14
+ * the release allow-list, never the library repo's own `src/`.
15
+ */
16
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
17
+ import { dirname, join, posix, resolve } from "node:path";
18
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
19
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
20
+ import { z } from "zod";
21
+ import { findComponent, registry } from "./registry.js";
22
+ import { readSource } from "./source.js";
23
+ import { checkCssImports, ensureCssImports, ensureThemeImport, npmInstall, patchTsconfigPaths, patchViteConfig, typecheck, } from "./project-setup.js";
24
+ function text(body) {
25
+ return { content: [{ type: "text", text: body }] };
26
+ }
27
+ /** Point every `@/components/...` import at its delivered `@/components/zabuti/...`
28
+ * home (component dirs and `ui/` alike); leave `@/lib/utils` alone. */
29
+ function rewriteImports(src) {
30
+ return src.replace(/@\/components\/(?!zabuti\/)/g, "@/components/zabuti/");
31
+ }
32
+ /** Where a registry file lands in the consumer repo, and any import rewrite. */
33
+ function planFile(relPath) {
34
+ const componentsPrefix = "src/components/";
35
+ if (relPath.startsWith(componentsPrefix)) {
36
+ return {
37
+ dest: posix.join("src/components/zabuti", relPath.slice(componentsPrefix.length)),
38
+ rewrite: rewriteImports,
39
+ skipIfExists: false,
40
+ };
41
+ }
42
+ if (relPath === "src/zabuti-ui.css") {
43
+ return {
44
+ dest: "src/components/zabuti/zabuti-ui.css",
45
+ rewrite: (s) => s,
46
+ skipIfExists: false,
47
+ };
48
+ }
49
+ if (relPath === "src/lib/utils.ts") {
50
+ return { dest: "src/lib/utils.ts", rewrite: (s) => s, skipIfExists: true };
51
+ }
52
+ return { dest: relPath, rewrite: (s) => s, skipIfExists: false };
53
+ }
54
+ function packageJsonDeps(targetDir) {
55
+ const p = join(targetDir, "package.json");
56
+ if (!existsSync(p))
57
+ return new Set();
58
+ try {
59
+ const pkg = JSON.parse(readFileSync(p, "utf8"));
60
+ const out = new Set();
61
+ for (const key of ["dependencies", "devDependencies", "peerDependencies"]) {
62
+ const block = pkg[key];
63
+ if (block && typeof block === "object") {
64
+ for (const name of Object.keys(block))
65
+ out.add(name);
66
+ }
67
+ }
68
+ return out;
69
+ }
70
+ catch {
71
+ return new Set();
72
+ }
73
+ }
74
+ function describe(c) {
75
+ return {
76
+ name: c.name,
77
+ title: c.title,
78
+ kind: c.kind,
79
+ category: c.category,
80
+ status: c.status,
81
+ summary: c.summary,
82
+ };
83
+ }
84
+ function readIf(p) {
85
+ try {
86
+ return readFileSync(p, "utf8");
87
+ }
88
+ catch {
89
+ return null;
90
+ }
91
+ }
92
+ /**
93
+ * Structural readiness of a consumer project, checked in dependency order.
94
+ * These are the things `add_component`'s file copy silently assumes: a Vite +
95
+ * React + TS app, Tailwind v4, and the `@/` alias on both the Vite and tsconfig
96
+ * side. If any fail, the delivered files cannot compile, so we stop before
97
+ * writing them. No shadcn check — the Zabuti primitives + `zabuti-ui.css` are
98
+ * part of the payload. npm-package installs and the one `@import` line are
99
+ * "do after" steps reported by `add_component` itself.
100
+ */
101
+ function preflightProject(target) {
102
+ const issues = [];
103
+ const deps = packageJsonDeps(target);
104
+ if (!existsSync(join(target, "package.json")) || !deps.has("react")) {
105
+ return [
106
+ {
107
+ label: "This is not a React project (no `react` in package.json).",
108
+ fix: [
109
+ "Zabuti targets React + TypeScript (Vite or Next.js). For a new Vite app:",
110
+ " npm create vite@latest my-app -- --template react-ts",
111
+ ],
112
+ },
113
+ ];
114
+ }
115
+ const isVite = deps.has("vite") ||
116
+ existsSync(join(target, "vite.config.ts")) ||
117
+ existsSync(join(target, "vite.config.js"));
118
+ if (!deps.has("tailwindcss")) {
119
+ issues.push({
120
+ label: "Tailwind CSS v4 is not installed.",
121
+ fix: isVite
122
+ ? [" npm i tailwindcss @tailwindcss/vite"]
123
+ : [" npm i tailwindcss", " (plus the Tailwind v4 wiring for your bundler)"],
124
+ });
125
+ }
126
+ else if (isVite && !deps.has("@tailwindcss/vite")) {
127
+ issues.push({
128
+ label: "Tailwind is installed but the Vite plugin is missing.",
129
+ fix: [
130
+ " npm i @tailwindcss/vite",
131
+ " then in vite.config.ts: import tailwindcss from '@tailwindcss/vite' and add tailwindcss() to plugins",
132
+ ],
133
+ });
134
+ }
135
+ const viteCfg = readIf(join(target, "vite.config.ts")) ?? readIf(join(target, "vite.config.js"));
136
+ if (isVite && viteCfg && !/alias/.test(viteCfg)) {
137
+ issues.push({
138
+ label: "The `@/` import alias is not configured in vite.config.ts.",
139
+ fix: [
140
+ "In vite.config.ts add:",
141
+ " resolve: { alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) } }",
142
+ " (import { fileURLToPath } from 'node:url' at the top)",
143
+ ],
144
+ });
145
+ }
146
+ const tsconfigText = ["tsconfig.json", "tsconfig.app.json"]
147
+ .map((f) => readIf(join(target, f)) ?? "")
148
+ .join("\n");
149
+ if (!/["']@\/\*["']/.test(tsconfigText)) {
150
+ issues.push({
151
+ label: "The `@/*` path is not declared in tsconfig.",
152
+ fix: [
153
+ "In tsconfig.app.json (and tsconfig.json) compilerOptions add:",
154
+ ' "paths": { "@/*": ["./src/*"] }',
155
+ ],
156
+ });
157
+ }
158
+ const css = readIf(join(target, "src/index.css")) ??
159
+ readIf(join(target, "src/main.css")) ??
160
+ readIf(join(target, "src/app/globals.css")) ??
161
+ readIf(join(target, "app/globals.css")) ??
162
+ readIf(join(target, "src/styles/globals.css")) ??
163
+ "";
164
+ if (!/@import\s+["']tailwindcss["']/.test(css)) {
165
+ issues.push({
166
+ label: "Your CSS entry doesn't `@import \"tailwindcss\"`.",
167
+ fix: [
168
+ "In src/index.css / src/app/globals.css (wherever your app's CSS entry is), first line:",
169
+ ' @import "tailwindcss";',
170
+ ' @import "tw-animate-css";',
171
+ ],
172
+ });
173
+ }
174
+ return issues;
175
+ }
176
+ const server = new McpServer({ name: "zabuti-components", version: "0.1.0" });
177
+ server.registerTool("list_components", {
178
+ title: "List Zabuti components",
179
+ description: "List everything in the Zabuti registry that can be added: feature components (kind \"component\") and standalone UI primitives (kind \"primitive\": button, dialog, date-picker, …), each with its status and a one-line summary. Call this first to see what can be added.",
180
+ inputSchema: {},
181
+ }, async () => text(JSON.stringify(registry.map(describe), null, 2)));
182
+ server.registerTool("get_component", {
183
+ title: "Get a Zabuti component's contract",
184
+ description: "Return a component's data contract and integration doc: what it does, the npm prerequisites, the exact files that would be delivered (component + Zabuti UI primitives + theme CSS), an adapter sketch, and the full usage guide with a worked example. Read this before add_component.",
185
+ inputSchema: { name: z.string().describe("Component or primitive id, e.g. \"date-picker\"") },
186
+ }, async ({ name }) => {
187
+ const c = findComponent(name);
188
+ if (!c) {
189
+ return text(`No component named "${name}". Known: ${registry.map((r) => r.name).join(", ")}.`);
190
+ }
191
+ if (c.status === "planned" || c.files.length === 0) {
192
+ return text(`${c.title} (${c.name}) — status: planned.\n\n${c.summary}\n\nNot yet in the registry; nothing to deliver.`);
193
+ }
194
+ const lines = [];
195
+ lines.push(`# ${c.title} (${c.name}) — status: ${c.status}`);
196
+ lines.push("");
197
+ lines.push(c.summary);
198
+ lines.push("");
199
+ lines.push(`## npm prerequisites\n${c.npmDependencies.map((d) => `- ${d}`).join("\n")}`);
200
+ lines.push(`\n## files delivered (${c.files.length})`);
201
+ for (const f of c.files) {
202
+ const { dest } = planFile(f);
203
+ lines.push(`- ${f} → ${dest}`);
204
+ }
205
+ if (c.kind === "primitive") {
206
+ lines.push(`\n## use\nimport it from "@/components/zabuti/ui/${c.name}". It's a Radix-based primitive styled by zabuti-ui.css; read the delivered file's header comment for its parts and props.`);
207
+ }
208
+ else {
209
+ lines.push(`\n## adapter sketch\n${c.adapterSketch}`);
210
+ if (c.usageDoc)
211
+ lines.push(`\n---\n\n${readSource(c.usageDoc)}`);
212
+ }
213
+ return text(lines.join("\n"));
214
+ });
215
+ const STEP_ICON = {
216
+ ok: "✓",
217
+ already: "·",
218
+ patched: "✓",
219
+ created: "✓",
220
+ manual: "⚠",
221
+ error: "✗",
222
+ };
223
+ server.registerTool("setup_project", {
224
+ title: "Prepare a project for Zabuti components",
225
+ description: "One call to make a Vite + React + TS project ready for add_component: patches vite.config for the @/ alias and the Tailwind v4 plugin, adds \"@/*\" to tsconfig.json + tsconfig.app.json, prepends the three @import lines to your CSS entry, and npm-installs Tailwind + (if you pass a component name) that component's runtime deps. Idempotent — safe to re-run. Pass skipInstall to only patch the config/CSS files. Run this before add_component; it replaces the manual setup checklist.",
226
+ inputSchema: {
227
+ targetDir: z
228
+ .string()
229
+ .describe("Absolute path to the consumer project root (the folder with package.json)"),
230
+ name: z
231
+ .string()
232
+ .optional()
233
+ .describe("Component or primitive id whose npm deps to install too, e.g. \"date-picker\""),
234
+ skipInstall: z
235
+ .boolean()
236
+ .optional()
237
+ .describe("Only patch vite.config / tsconfig / CSS; skip npm install"),
238
+ },
239
+ }, async ({ targetDir, name, skipInstall }) => {
240
+ const target = resolve(targetDir);
241
+ if (!existsSync(target))
242
+ return text(`Target directory does not exist: ${target}`);
243
+ const c = name ? findComponent(name) : undefined;
244
+ if (name && !c) {
245
+ return text(`No component named "${name}". Known: ${registry.map((r) => r.name).join(", ")}.`);
246
+ }
247
+ const steps = [];
248
+ steps.push(patchViteConfig(target));
249
+ steps.push(...patchTsconfigPaths(target));
250
+ steps.push(ensureCssImports(target));
251
+ const baseDeps = ["tailwindcss", "@tailwindcss/vite", "tw-animate-css"];
252
+ const want = [...new Set([...baseDeps, ...(c ? c.npmDependencies : [])])];
253
+ const have = packageJsonDeps(target);
254
+ const missing = want.filter((d) => !have.has(d));
255
+ if (skipInstall) {
256
+ steps.push({
257
+ step: "npm install",
258
+ status: missing.length ? "manual" : "already",
259
+ detail: missing.length
260
+ ? `skipInstall set — ${missing.length} package(s) still needed`
261
+ : "all required packages already in package.json",
262
+ manual: missing.length ? [`npm install ${missing.join(" ")}`] : undefined,
263
+ });
264
+ }
265
+ else {
266
+ steps.push(npmInstall(target, missing));
267
+ }
268
+ const out = [`setup_project → ${target}`, ""];
269
+ for (const s of steps) {
270
+ out.push(`${STEP_ICON[s.status]} ${s.step}: ${s.detail}`);
271
+ for (const m of s.manual ?? [])
272
+ out.push(` ${m}`);
273
+ }
274
+ const target_c = name ?? "<name>";
275
+ const remaining = preflightProject(target);
276
+ out.push("");
277
+ if (remaining.length) {
278
+ out.push(`Preflight still reports ${remaining.length} issue(s):`, ...remaining.map((i) => ` - ${i.label}`), "", `Resolve those, then: add_component("${target_c}", "${target}").`);
279
+ }
280
+ else {
281
+ out.push(`Ready. Next: add_component("${target_c}", "${target}"), then write the adapter.`);
282
+ }
283
+ return text(out.join("\n"));
284
+ });
285
+ server.registerTool("add_component", {
286
+ title: "Add a Zabuti component to a project",
287
+ description: "Copy a component's or a primitive's source into a target project: the component, the Zabuti UI primitives it composes, and zabuti-ui.css (the theme layer — no shadcn). A primitive alone (e.g. \"dialog\") brings the primitives it builds on and the theme layer. Runs a project preflight first (Vite+React+TS, Tailwind v4, the @/ alias) and writes nothing if it fails — pass force:true to override. On success everything lands under src/components/zabuti/ with imports rewritten; src/lib/utils.ts is written only if absent; the response reports which npm packages are still missing and the one @import line to add, then hand off to writing an adapter (see get_component).",
288
+ inputSchema: {
289
+ name: z.string().describe("Component or primitive id, e.g. \"date-picker\""),
290
+ targetDir: z
291
+ .string()
292
+ .describe("Absolute path to the consumer project root (the folder with package.json)"),
293
+ dryRun: z
294
+ .boolean()
295
+ .optional()
296
+ .describe("If true, report what would be written without touching the filesystem"),
297
+ force: z
298
+ .boolean()
299
+ .optional()
300
+ .describe("Skip the project-readiness preflight and write the files anyway"),
301
+ overwrite: z
302
+ .boolean()
303
+ .optional()
304
+ .describe("Replace delivered files the project has changed. Off by default: an existing file that differs from Zabuti's is kept, since the project owns that code."),
305
+ },
306
+ }, async ({ name, targetDir, dryRun, force, overwrite }) => {
307
+ const c = findComponent(name);
308
+ if (!c) {
309
+ return text(`No component named "${name}". Known: ${registry.map((r) => r.name).join(", ")}.`);
310
+ }
311
+ if (c.status === "planned" || c.files.length === 0) {
312
+ return text(`${c.title} (${c.name}) is status:planned — not yet deliverable.`);
313
+ }
314
+ const target = resolve(targetDir);
315
+ if (!existsSync(target)) {
316
+ return text(`Target directory does not exist: ${target}`);
317
+ }
318
+ const issues = preflightProject(target);
319
+ if (issues.length && !force) {
320
+ const lines = [
321
+ `${c.title}: project preflight failed — nothing written to ${target}.`,
322
+ "",
323
+ "Fix these in order, then re-run add_component (or pass force:true to write anyway):",
324
+ "",
325
+ ];
326
+ issues.forEach((iss, i) => {
327
+ lines.push(`${i + 1}. ${iss.label}`);
328
+ for (const f of iss.fix)
329
+ lines.push(` ${f}`);
330
+ lines.push("");
331
+ });
332
+ lines.push("Once the project is set up, add_component also needs (it will report what's still missing):", ` npm i ${c.npmDependencies.join(" ")}`);
333
+ return text(lines.join("\n"));
334
+ }
335
+ const written = [];
336
+ const skipped = [];
337
+ const kept = [];
338
+ for (const rel of c.files) {
339
+ const { dest, rewrite, skipIfExists } = planFile(rel);
340
+ const destAbs = join(target, dest);
341
+ if (skipIfExists && existsSync(destAbs)) {
342
+ skipped.push(`${dest} (already present)`);
343
+ continue;
344
+ }
345
+ const content = rewrite(readSource(rel));
346
+ if (existsSync(destAbs)) {
347
+ // Delivered once already (another component brought it, or a re-run).
348
+ // The project owns that file: never silently replace its edits.
349
+ const current = readFileSync(destAbs, "utf8");
350
+ const lf = (t) => t.split("\r\n").join("\n");
351
+ if (lf(current) === lf(content)) {
352
+ skipped.push(`${dest} (unchanged)`);
353
+ continue;
354
+ }
355
+ if (!overwrite) {
356
+ kept.push(dest);
357
+ continue;
358
+ }
359
+ }
360
+ if (!dryRun) {
361
+ mkdirSync(dirname(destAbs), { recursive: true });
362
+ writeFileSync(destAbs, content);
363
+ }
364
+ written.push(dest);
365
+ }
366
+ const have = packageJsonDeps(target);
367
+ const missingNpm = c.npmDependencies.filter((d) => !have.has(d));
368
+ const out = [];
369
+ out.push(`${dryRun ? "[dry run] " : ""}${c.title} → ${target}`, "", `Files ${dryRun ? "that would be written" : "written"} (${written.length}):`, ...written.map((f) => ` + ${f}`));
370
+ if (skipped.length) {
371
+ out.push("", "Skipped:", ...skipped.map((f) => ` · ${f}`));
372
+ }
373
+ if (kept.length) {
374
+ out.push("", `Kept the project's own version of ${kept.length} file(s) that differ from Zabuti's (pass overwrite:true to replace them):`, ...kept.map((f) => ` ~ ${f}`));
375
+ }
376
+ if (force && issues.length) {
377
+ out.push("", `⚠ preflight was forced past ${issues.length} issue(s) — these files will not compile until:`, ...issues.map((iss) => ` · ${iss.label}`));
378
+ }
379
+ out.push("", missingNpm.length ? `Install npm packages:\n npm i ${missingNpm.join(" ")}` : "npm prerequisites: all present.");
380
+ if (dryRun) {
381
+ const css = checkCssImports(target);
382
+ out.push("", css.missing.length
383
+ ? `CSS entry (${css.file}) is missing imports for: ${css.missing.join(", ")} — run without dryRun (or setup_project) to add them.`
384
+ : "CSS entry: tailwindcss + tw-animate-css + zabuti-ui.css all imported.");
385
+ }
386
+ else {
387
+ const css = ensureCssImports(target);
388
+ out.push("", `CSS entry — ${css.detail}`, " (zabuti-ui.css carries the theme tokens + variants — override the CSS custom properties in your own sheet to reskin)");
389
+ }
390
+ if (c.kind === "primitive") {
391
+ out.push("", `Next: import it from "@/components/zabuti/ui/${c.name}" and use it.`);
392
+ }
393
+ else {
394
+ out.push("", "Next: write a thin adapter that supplies your data as props.", c.adapterSketch, "", `Call get_component("${c.name}") for the full data model and a worked example.`);
395
+ }
396
+ if (c.files.some((f) => f.endsWith("/tooltip.tsx")))
397
+ out.push("Wrap the app root in <TooltipProvider> if it isn't already.");
398
+ out.push(`Then verify_component("${c.name}", "${target}") to type-check the result.`, `Optional: add_theme("teal", "${target}") to apply a bundled accent theme (list_themes to see them).`);
399
+ return text(out.join("\n"));
400
+ });
401
+ server.registerTool("verify_component", {
402
+ title: "Verify a delivered Zabuti component",
403
+ description: "Post-delivery check: confirms every delivered file (component + Zabuti primitives + zabuti-ui.css + src/lib/utils.ts) landed, that your CSS entry actually @imports all three sheets — miss the theme import and the build compiles but renders unstyled — then runs `tsc -b` in the target and reports the first errors. Run after add_component and after writing the adapter.",
404
+ inputSchema: {
405
+ targetDir: z.string().describe("Absolute path to the consumer project root"),
406
+ name: z.string().describe("The component or primitive id that was added"),
407
+ skipTypecheck: z.boolean().optional().describe("Skip the tsc -b run (file/CSS checks only)"),
408
+ },
409
+ }, async ({ targetDir, name, skipTypecheck }) => {
410
+ const target = resolve(targetDir);
411
+ if (!existsSync(target))
412
+ return text(`Target directory does not exist: ${target}`);
413
+ const c = findComponent(name);
414
+ if (!c || c.files.length === 0) {
415
+ return text(`Nothing to verify for "${name}" — not a deliverable component or primitive.`);
416
+ }
417
+ const lines = [];
418
+ let failed = false;
419
+ const mark = (ok, msg) => {
420
+ lines.push(`${ok ? "✓" : "✗"} ${msg}`);
421
+ if (!ok)
422
+ failed = true;
423
+ };
424
+ const expectedDests = c.files.map((f) => planFile(f).dest);
425
+ const missingFiles = expectedDests.filter((d) => !existsSync(join(target, d)));
426
+ mark(missingFiles.length === 0, missingFiles.length === 0
427
+ ? `all ${expectedDests.length} delivered files present`
428
+ : `${missingFiles.length} delivered file(s) missing: ${missingFiles.slice(0, 6).join(", ")}${missingFiles.length > 6 ? " …" : ""}`);
429
+ const css = checkCssImports(target);
430
+ mark(css.missing.length === 0, css.missing.length === 0
431
+ ? `CSS entry @imports tailwindcss + tw-animate-css + zabuti-ui.css`
432
+ : `CSS entry (${css.file}) is missing imports for ${css.missing.join(", ")} — run setup_project or add_component again`);
433
+ if (skipTypecheck) {
434
+ lines.push("· tsc -b skipped (skipTypecheck)");
435
+ }
436
+ else {
437
+ const tc = typecheck(target);
438
+ if (!tc.ran) {
439
+ lines.push(`· tsc -b could not run (${tc.output.split("\n")[0]}) — run \`npx tsc -b\` in the project yourself`);
440
+ }
441
+ else if (tc.ok) {
442
+ lines.push("✓ tsc -b clean");
443
+ }
444
+ else {
445
+ failed = true;
446
+ const errs = tc.output.split("\n").filter((l) => /error TS/.test(l));
447
+ lines.push(`✗ tsc -b reported ${errs.length} error(s):`, ...errs.slice(0, 15).map((e) => ` ${e.trim()}`));
448
+ }
449
+ }
450
+ lines.push("", failed
451
+ ? "RESULT: issues found — fix the above before shipping."
452
+ : "RESULT: ok — component delivered and type-checks.");
453
+ return text([`verify_component(${c.name}) → ${target}`, "", ...lines].join("\n"));
454
+ });
455
+ function readThemeManifest() {
456
+ try {
457
+ return JSON.parse(readSource("src/themes/manifest.json"));
458
+ }
459
+ catch {
460
+ return [];
461
+ }
462
+ }
463
+ server.registerTool("list_themes", {
464
+ title: "List Zabuti theme presets",
465
+ description: "List the bundled accent-only theme presets (name, label, swatch colour). Each redefines only --primary / --primary-foreground / --ring for light and dark; apply one to a project with add_theme.",
466
+ inputSchema: {},
467
+ }, async () => {
468
+ const themes = readThemeManifest();
469
+ return text(themes.length
470
+ ? JSON.stringify(themes, null, 2)
471
+ : "No theme presets found — run `npm run themes:build` in the Zabuti library.");
472
+ });
473
+ server.registerTool("add_theme", {
474
+ title: "Apply a Zabuti theme preset",
475
+ description: "Deliver one accent-only theme overlay (zabuti-ui-<name>.css) into a project and wire it into the CSS entry right after zabuti-ui.css, replacing any preset already applied. Pass name \"default\" (or \"none\") to remove the preset and fall back to the neutral tokens. Run add_component first so src/components/zabuti/ exists.",
476
+ inputSchema: {
477
+ name: z
478
+ .string()
479
+ .describe('Theme id from list_themes, e.g. "teal" — or "default"/"none" to clear'),
480
+ targetDir: z.string().describe("Absolute path to the consumer project root"),
481
+ },
482
+ }, async ({ name, targetDir }) => {
483
+ const target = resolve(targetDir);
484
+ if (!existsSync(target))
485
+ return text(`Target directory does not exist: ${target}`);
486
+ const clearing = name === "default" || name === "none" || name === "";
487
+ const themes = readThemeManifest();
488
+ const entry = themes.find((t) => t.name === name);
489
+ if (!clearing && !entry) {
490
+ return text(`No theme preset "${name}". Known: ${themes.map((t) => t.name).join(", ") || "(none — run npm run themes:build)"}. Use "default" to clear.`);
491
+ }
492
+ const out = [];
493
+ if (!clearing) {
494
+ const relPath = `src/themes/zabuti-ui-${name}.css`;
495
+ let cssSource;
496
+ try {
497
+ cssSource = readSource(relPath);
498
+ }
499
+ catch {
500
+ return text(`Theme file missing in the library: ${relPath}`);
501
+ }
502
+ const zabutiDir = join(target, "src/components/zabuti");
503
+ if (!existsSync(zabutiDir)) {
504
+ return text(`No src/components/zabuti/ in ${target} — run add_component first, then add_theme.`);
505
+ }
506
+ writeFileSync(join(zabutiDir, `zabuti-ui-${name}.css`), cssSource);
507
+ out.push(`✓ wrote src/components/zabuti/zabuti-ui-${name}.css`);
508
+ }
509
+ const res = ensureThemeImport(target, clearing ? null : name);
510
+ out.push(`${res.status === "already" ? "·" : "✓"} ${res.detail}`);
511
+ for (const m of res.manual ?? [])
512
+ out.push(` ${m}`);
513
+ out.push("", clearing
514
+ ? "Theme preset cleared — the project falls back to the neutral zabuti-ui.css tokens."
515
+ : `Theme "${entry?.label}" applied. Restart the dev server if the @import change isn't picked up.`);
516
+ return text(out.join("\n"));
517
+ });
518
+ async function main() {
519
+ // A stray console.log would corrupt the stdio JSON-RPC stream — keep stdout clean.
520
+ const transport = new StdioServerTransport();
521
+ await server.connect(transport);
522
+ process.stderr.write("zabuti-components MCP server ready (stdio)\n");
523
+ }
524
+ main().catch((err) => {
525
+ process.stderr.write(`fatal: ${String(err)}\n`);
526
+ process.exit(1);
527
+ });