@keystoneui/mcp 0.2.0-beta.2 → 0.2.0-beta.4

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/README.md CHANGED
@@ -41,6 +41,9 @@ npx shadcn@latest add https://keystoneui.io/r/table-with-pagination.json
41
41
 
42
42
  # Verify
43
43
  npx keystoneui audit
44
+
45
+ # Theme (a code from https://keystoneui.io/theme-builder)
46
+ npx keystoneui theme k1_slate_0.55_0.2_262.5_large_inter
44
47
  ```
45
48
 
46
49
  ## Verbs
@@ -53,8 +56,9 @@ npx keystoneui audit
53
56
  | `view <name> [<name>...]` | Show component source |
54
57
  | `examples <name>` | All demo files for a component or block |
55
58
  | `docs <name>` | Fetch the LLM-resolved MDX page (`/llms.mdx/docs/components/<name>`) |
56
- | `audit` | Print the post-install checklist |
59
+ | `audit [--theme [css]] [--strict]` | Print the post-install checklist, or measure every text/surface token pair in your theme against WCAG AA |
57
60
  | `blocks [<filter>]` | List or filter full-page blocks |
61
+ | `theme <code> [--only theme,font]` | Decode a theme-builder code and print its `shadcn add` command |
58
62
 
59
63
  Run `keystoneui help` for the full list. Without any verb the binary launches the MCP stdio server.
60
64
 
@@ -381,6 +381,7 @@ file rather than creating a new one, or the tokens will not reach the components
381
381
  | \`--destructive\` | \`oklch(0.577 0.245 27)\` | \`oklch(0.704 0.191 22)\` | Destructive actions, a metric that got worse |
382
382
  | \`--success\` | \`oklch(0.627 0.194 149)\` | \`oklch(0.723 0.19 150)\` | Positive status, a metric that improved |
383
383
  | \`--warning\` | \`oklch(0.769 0.188 70)\` | \`oklch(0.828 0.189 84)\` | Caution and threshold states only |
384
+ | \`--info\` | \`oklch(0.546 0.245 263)\` | \`oklch(0.707 0.165 255)\` | Neutral notices (info Alert, info Toast) |
384
385
  | \`--muted\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Subdued elements |
385
386
  | \`--accent\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Highlights |
386
387
  | \`--background\` | \`oklch(1 0 0)\` | \`oklch(0.141 0.005 286)\` | Page background |
@@ -416,7 +417,17 @@ Add the \`dark\` class to a parent element.
416
417
  Get the full style definition:
417
418
  \`\`\`bash
418
419
  npx shadcn@latest add ${registryUrl}/default.json
419
- \`\`\``;
420
+ \`\`\`
421
+
422
+ ## Custom themes
423
+
424
+ The theme builder (${config.docsUrl}/theme-builder) encodes a theme as a code,
425
+ \`k1_<base>_<L>_<C>_<H>_<radius>_<font>\`, served as a \`registry:theme\` item.
426
+ Install one, or only its colours (\`?only=theme\`) or font (\`?only=font\`):
427
+ \`\`\`bash
428
+ npx shadcn@latest add ${registryUrl}/theme/<code>.json
429
+ \`\`\`
430
+ \`keystoneui theme <code>\` prints the decoded settings and this command.`;
420
431
  }
421
432
  function auditChecklistTool() {
422
433
  const ctx = detectProjectContext();
@@ -512,7 +523,7 @@ var TOOL_SPECS = {
512
523
  schema: getExamplesSchema
513
524
  },
514
525
  get_docs: {
515
- description: "Fetch the full documentation page for a component or block, including its API Reference table. Props are documented ONLY here -- not in the registry -- so view_component alone will not give you a prop's type or default. Previews arrive resolved to inline TSX, so one call returns prose and working code.",
526
+ description: "Fetch the full documentation page for a component or block, including its Composition tree (the parts hierarchy, and nestings Base UI rejects) and its API Reference table. Read it before composing any compound component. Props are documented ONLY here -- not in the registry -- so view_component alone will not give you a prop's type or default. Previews arrive resolved to inline TSX, so one call returns prose and working code.",
516
527
  schema: getDocsSchema
517
528
  },
518
529
  get_project_context: {
package/dist/index.js CHANGED
@@ -8,7 +8,10 @@ import {
8
8
  readPackageVersion,
9
9
  searchComponentsTool,
10
10
  viewComponentTool
11
- } from "./chunk-VGA5HGCS.js";
11
+ } from "./chunk-JVJEQ7VV.js";
12
+
13
+ // src/cli.ts
14
+ import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
12
15
 
13
16
  // src/info.ts
14
17
  import { existsSync, readFileSync } from "fs";
@@ -285,6 +288,205 @@ function init() {
285
288
  writeJsonClient(client);
286
289
  }
287
290
 
291
+ // src/theme.ts
292
+ var THEME_CODE_RE = /^k1_([a-z]+)_(\d+(?:\.\d+)?)_(\d+(?:\.\d+)?)_(\d+(?:\.\d+)?)_([a-z]+)_([a-z-]+)$/;
293
+ function parseThemeCode(code) {
294
+ const match = THEME_CODE_RE.exec(code);
295
+ if (!match) {
296
+ return null;
297
+ }
298
+ const [, base, l, c, h, radius, font] = match;
299
+ return { base, font, primary: `oklch(${l} ${c} ${h})`, radius };
300
+ }
301
+ function themeInstallCommand(code, siteUrl, only = []) {
302
+ const query = only.length > 0 ? `?only=${only.join(",")}` : "";
303
+ return `npx shadcn@latest add ${siteUrl}/r/theme/${code}.json${query}`;
304
+ }
305
+ function themeBuilderUrl(code, siteUrl) {
306
+ const match = THEME_CODE_RE.exec(code);
307
+ if (!match) {
308
+ return null;
309
+ }
310
+ const [, base, primaryL, primaryC, primaryH, radius, font] = match;
311
+ const params = new URLSearchParams({
312
+ base,
313
+ primaryL,
314
+ primaryC,
315
+ primaryH,
316
+ radius,
317
+ font
318
+ });
319
+ return `${siteUrl}/theme-builder?${params}`;
320
+ }
321
+ function parseThemeParts(value) {
322
+ if (!value) {
323
+ return [];
324
+ }
325
+ return value.split(",").map((part) => part.trim()).filter((part) => part === "theme" || part === "font");
326
+ }
327
+
328
+ // src/theme-audit.ts
329
+ var TEXT_PAIRS = [
330
+ ["foreground", "background"],
331
+ ["card-foreground", "card"],
332
+ ["popover-foreground", "popover"],
333
+ ["primary-foreground", "primary"],
334
+ ["secondary-foreground", "secondary"],
335
+ ["muted-foreground", "background"],
336
+ ["accent-foreground", "accent"],
337
+ ["destructive-foreground", "destructive"],
338
+ ["success-foreground", "success"],
339
+ ["warning-foreground", "warning"],
340
+ ["info-foreground", "info"]
341
+ ];
342
+ var AA_TEXT = 4.5;
343
+ var DECLARATION_RE = /--([\w-]+)\s*:\s*([^;]+);/g;
344
+ var OKLCH_RE = /^oklch\(\s*([\d.]+)(%?)\s+([\d.]+)\s+([\d.]+)(?:deg)?\s*\)$/i;
345
+ var HEX_RE = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i;
346
+ var COMMENT_RE = /\/\*[\s\S]*?\*\//g;
347
+ function declarations(block) {
348
+ const out = {};
349
+ for (const [, name, value] of block.matchAll(DECLARATION_RE)) {
350
+ out[name] = value.trim();
351
+ }
352
+ return out;
353
+ }
354
+ function closingBrace(css, open) {
355
+ let depth = 0;
356
+ for (let i = open; i < css.length; i++) {
357
+ if (css[i] === "{") {
358
+ depth++;
359
+ } else if (css[i] === "}") {
360
+ depth--;
361
+ if (depth === 0) {
362
+ return i;
363
+ }
364
+ }
365
+ }
366
+ return css.length;
367
+ }
368
+ function themeBlocks(css) {
369
+ const blocks = [];
370
+ const preludes = [];
371
+ let start = 0;
372
+ for (let i = 0; i < css.length; i++) {
373
+ const ch = css[i];
374
+ if (ch === "{") {
375
+ const prelude = css.slice(start, i).trim();
376
+ const ancestorsOk = preludes.every((p) => p.startsWith("@layer"));
377
+ if (ancestorsOk && (prelude === ":root" || prelude === ".dark")) {
378
+ const j = closingBrace(css, i);
379
+ blocks.push({ body: css.slice(i + 1, j), selector: prelude });
380
+ i = j;
381
+ start = j + 1;
382
+ continue;
383
+ }
384
+ preludes.push(prelude);
385
+ start = i + 1;
386
+ } else if (ch === "}") {
387
+ preludes.pop();
388
+ start = i + 1;
389
+ } else if (ch === ";") {
390
+ start = i + 1;
391
+ }
392
+ }
393
+ return blocks;
394
+ }
395
+ function readThemeTokens(css) {
396
+ const stripped = css.replace(COMMENT_RE, "");
397
+ const light = {};
398
+ const dark = {};
399
+ for (const { body, selector } of themeBlocks(stripped)) {
400
+ Object.assign(selector === ":root" ? light : dark, declarations(body));
401
+ }
402
+ return { dark: { ...light, ...dark }, light };
403
+ }
404
+ function linearRgb(value) {
405
+ const oklch = OKLCH_RE.exec(value.trim());
406
+ if (oklch) {
407
+ const l = Number(oklch[1]) / (oklch[2] === "%" ? 100 : 1);
408
+ const c = Number(oklch[3]);
409
+ const h = Number(oklch[4]) * Math.PI / 180;
410
+ const a = c * Math.cos(h);
411
+ const b = c * Math.sin(h);
412
+ const l3 = (l + 0.3963377774 * a + 0.2158037573 * b) ** 3;
413
+ const m3 = (l - 0.1055613458 * a - 0.0638541728 * b) ** 3;
414
+ const s3 = (l - 0.0894841775 * a - 1.291485548 * b) ** 3;
415
+ const clamp = (x) => Math.min(Math.max(x, 0), 1);
416
+ return [
417
+ clamp(4.0767416621 * l3 - 3.3077115913 * m3 + 0.2309699292 * s3),
418
+ clamp(
419
+ -1.2684380046 * l3 + 2.6097574011 * m3 - 0.3413193965 * s3
420
+ ),
421
+ clamp(-0.0041960863 * l3 - 0.7034186147 * m3 + 1.707614701 * s3)
422
+ ];
423
+ }
424
+ const hex = HEX_RE.exec(value.trim());
425
+ if (hex) {
426
+ const digits = hex[1].length === 3 ? [...hex[1]].map((d) => d + d).join("") : hex[1];
427
+ const channel = (i) => {
428
+ const v = Number.parseInt(digits.slice(i, i + 2), 16) / 255;
429
+ return v <= 0.04045 ? v / 12.92 : ((v + 0.055) / 1.055) ** 2.4;
430
+ };
431
+ return [channel(0), channel(2), channel(4)];
432
+ }
433
+ return null;
434
+ }
435
+ function contrastRatio(fg, bg) {
436
+ const a = linearRgb(fg);
437
+ const b = linearRgb(bg);
438
+ if (!(a && b)) {
439
+ return null;
440
+ }
441
+ const y = ([r, g, bl]) => 0.2126 * r + 0.7152 * g + 0.0722 * bl;
442
+ const [hi, lo] = [y(a), y(b)].sort((p, q) => q - p);
443
+ return (hi + 0.05) / (lo + 0.05);
444
+ }
445
+ function statusOf(ratio) {
446
+ if (ratio === null) {
447
+ return "skip";
448
+ }
449
+ return ratio >= AA_TEXT ? "pass" : "fail";
450
+ }
451
+ function auditTheme(tokens) {
452
+ const results = [];
453
+ for (const mode of ["light", "dark"]) {
454
+ for (const [fg, bg] of TEXT_PAIRS) {
455
+ const fgValue = tokens[mode][fg];
456
+ const bgValue = tokens[mode][bg];
457
+ if (!(fgValue && bgValue)) {
458
+ continue;
459
+ }
460
+ const ratio = contrastRatio(fgValue, bgValue);
461
+ results.push({
462
+ mode,
463
+ pair: `${fg} on ${bg}`,
464
+ ratio,
465
+ status: statusOf(ratio)
466
+ });
467
+ }
468
+ }
469
+ return results;
470
+ }
471
+ function formatAudit(file, results) {
472
+ if (results.length === 0) {
473
+ return `No keystone token pairs found in ${file}. Pass the CSS file that holds :root and .dark.`;
474
+ }
475
+ const lines = results.map((r) => {
476
+ const mark = { fail: "\u2716", pass: "\u2714", skip: "\u2013" }[r.status];
477
+ const ratio = r.ratio === null ? "needs a browser" : `${r.ratio.toFixed(2)}:1`;
478
+ return `${mark} ${r.mode.padEnd(5)} ${r.pair.padEnd(42)} ${ratio}`;
479
+ });
480
+ const failed = results.filter((r) => r.status === "fail").length;
481
+ return [
482
+ `Theme contrast \u2014 ${file} (WCAG AA for text: ${AA_TEXT}:1)`,
483
+ "",
484
+ ...lines,
485
+ "",
486
+ failed === 0 ? "All measurable pairs pass." : `${failed} pair(s) under ${AA_TEXT}:1.`
487
+ ].join("\n");
488
+ }
489
+
288
490
  // src/cli.ts
289
491
  var VERBS = [
290
492
  "init",
@@ -295,7 +497,8 @@ var VERBS = [
295
497
  "examples",
296
498
  "docs",
297
499
  "audit",
298
- "blocks"
500
+ "blocks",
501
+ "theme"
299
502
  ];
300
503
  var BLOCK_NAME_PATTERN = /^[a-z0-9-]+$/;
301
504
  function isCliVerb(arg) {
@@ -366,11 +569,14 @@ function printUsage2() {
366
569
  " docs <name> Fetch /llms.mdx/docs/components/<name>"
367
570
  );
368
571
  console.log(
369
- " audit Print post-install checklist"
572
+ " audit [--theme [css]] [--strict] Post-install checklist, or measure your theme's contrast"
370
573
  );
371
574
  console.log(
372
575
  " blocks [<filter>] [--category C] List or filter full-page blocks"
373
576
  );
577
+ console.log(
578
+ " theme <code> [--only theme,font] Install a theme-builder code via shadcn"
579
+ );
374
580
  console.log("");
375
581
  console.log("Without a verb, launches the MCP stdio server.");
376
582
  }
@@ -455,8 +661,25 @@ async function runDocs(args) {
455
661
  }
456
662
  console.log(await response.text());
457
663
  }
458
- function runAudit() {
459
- console.log(auditChecklistTool());
664
+ function runAudit(args) {
665
+ const { flags } = parseArgs2(args);
666
+ if (!("theme" in flags)) {
667
+ console.log(auditChecklistTool());
668
+ return;
669
+ }
670
+ const file = flags.theme === "true" ? detectProjectContext().tailwindCssFile : flags.theme;
671
+ if (!(file && existsSync3(file))) {
672
+ console.error(
673
+ "Usage: keystoneui audit --theme [path/to/globals.css] [--strict]\nNo CSS file found \u2014 pass the one that holds your :root and .dark tokens."
674
+ );
675
+ process.exitCode = 1;
676
+ return;
677
+ }
678
+ const results = auditTheme(readThemeTokens(readFileSync3(file, "utf-8")));
679
+ console.log(formatAudit(file, results));
680
+ if (flags.strict === "true" && results.some((r) => r.status === "fail")) {
681
+ process.exitCode = 1;
682
+ }
460
683
  }
461
684
  async function runBlocks(args) {
462
685
  const { flags, positional } = parseArgs2(args);
@@ -486,6 +709,29 @@ async function runBlocks(args) {
486
709
  });
487
710
  console.log(text);
488
711
  }
712
+ function runTheme(args) {
713
+ const { flags, positional } = parseArgs2(args);
714
+ const code = positional[0];
715
+ const fields = code ? parseThemeCode(code) : null;
716
+ if (!(code && fields)) {
717
+ console.error(
718
+ "Usage: keystoneui theme <code> [--only theme,font]\nCopy a code from https://keystoneui.io/theme-builder (Code panel)."
719
+ );
720
+ process.exitCode = 1;
721
+ return;
722
+ }
723
+ const siteUrl = process.env.KEYSTONEUI_URL ?? "https://keystoneui.io";
724
+ const only = parseThemeParts(flags.only);
725
+ console.log(`Theme ${code}`);
726
+ console.log(
727
+ ` base ${fields.base} \xB7 primary ${fields.primary} \xB7 radius ${fields.radius} \xB7 font ${fields.font}`
728
+ );
729
+ console.log("");
730
+ console.log("Install (writes the tokens into your global CSS):");
731
+ console.log(` ${themeInstallCommand(code, siteUrl, only)}`);
732
+ console.log("");
733
+ console.log(`Edit: ${themeBuilderUrl(code, siteUrl)}`);
734
+ }
489
735
  async function runCli(args) {
490
736
  const verb = args[0];
491
737
  const rest = args.slice(1);
@@ -523,11 +769,14 @@ async function runCli(args) {
523
769
  await runDocs(rest);
524
770
  return;
525
771
  case "audit":
526
- runAudit();
772
+ runAudit(rest);
527
773
  return;
528
774
  case "blocks":
529
775
  await runBlocks(rest);
530
776
  return;
777
+ case "theme":
778
+ runTheme(rest);
779
+ return;
531
780
  default: {
532
781
  const exhaustive = verb;
533
782
  throw new Error(`Unhandled verb: ${exhaustive}`);
@@ -546,6 +795,6 @@ if (isCliVerb(verbCandidate)) {
546
795
  process.exit();
547
796
  }
548
797
  var { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
549
- var { server } = await import("./server-2OYYC4H7.js");
798
+ var { server } = await import("./server-TNVOIXZW.js");
550
799
  var transport = new StdioServerTransport();
551
800
  await server.connect(transport);
@@ -12,7 +12,7 @@ import {
12
12
  readPackageVersion,
13
13
  searchComponentsTool,
14
14
  viewComponentTool
15
- } from "./chunk-VGA5HGCS.js";
15
+ } from "./chunk-JVJEQ7VV.js";
16
16
 
17
17
  // src/server.ts
18
18
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keystoneui/mcp",
3
- "version": "0.2.0-beta.2",
3
+ "version": "0.2.0-beta.4",
4
4
  "description": "MCP server and CLI for Keystone UI — lets AI agents and shell users discover, search, view, and install components, blocks, and named examples.",
5
5
  "type": "module",
6
6
  "license": "MIT",
@@ -37,15 +37,15 @@
37
37
  "README.md"
38
38
  ],
39
39
  "dependencies": {
40
- "@modelcontextprotocol/sdk": "^1.30.0",
40
+ "@modelcontextprotocol/sdk": "^1.32.1",
41
41
  "fuzzysort": "^4.0.2",
42
- "zod": "^4.5.4"
42
+ "zod": "^4.6.5"
43
43
  },
44
44
  "devDependencies": {
45
- "@types/node": "^26.4.1",
45
+ "@types/node": "^26.6.5",
46
46
  "tsup": "^8.5.1",
47
- "typescript": "^6.0.3",
48
- "vitest": "^4.1.11",
47
+ "typescript": "^7.0.2",
48
+ "vitest": "^5.0.5",
49
49
  "@keystoneui/typescript-config": "0.0.0"
50
50
  },
51
51
  "publishConfig": {