@keystoneui/mcp 0.2.0-beta.5 → 0.2.0-beta.6

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/dist/index.js CHANGED
@@ -3,14 +3,26 @@ import {
3
3
  auditChecklistTool,
4
4
  detectProjectContext,
5
5
  displayUrl,
6
+ escapedError,
6
7
  getExamplesTool,
8
+ isCommandSafe,
7
9
  listComponentsTool,
8
10
  loadProjectConfig,
11
+ lookupManifest,
12
+ nameRefusal,
13
+ parseThemeCode,
14
+ parseThemeParts,
9
15
  readPackageVersion,
10
16
  redactUrlInError,
17
+ registryCatalogueUrl,
18
+ resolveDocs,
11
19
  searchComponentsTool,
20
+ shown,
21
+ themeBuilderUrl,
22
+ themeInstallCommand,
23
+ themeInstallUrl,
12
24
  viewComponentTool
13
- } from "./chunk-TAXPGE7O.js";
25
+ } from "./chunk-LC22ZWZH.js";
14
26
 
15
27
  // src/cli.ts
16
28
  import { existsSync as existsSync3, readFileSync as readFileSync3 } from "fs";
@@ -93,7 +105,7 @@ function collect() {
93
105
  installedPackages: detectInstalledPackages(cwd),
94
106
  links: {
95
107
  docs: displayUrl(docsUrl),
96
- registry: displayUrl(`${config.registry.url}/registry.json`),
108
+ registry: displayUrl(registryCatalogueUrl(config.registry)),
97
109
  llms: displayUrl(`${docsUrl}/llms.txt`)
98
110
  }
99
111
  };
@@ -104,6 +116,9 @@ function pad(label, width = 18) {
104
116
  }
105
117
  return label.padEnd(width, " ");
106
118
  }
119
+ function shownOr(value) {
120
+ return value === null || value === void 0 ? "(unknown)" : shown(value);
121
+ }
107
122
  function printText(data) {
108
123
  const lines = [];
109
124
  lines.push(`${data.package.name} v${data.package.version}`);
@@ -111,20 +126,20 @@ function printText(data) {
111
126
  const p = data.project;
112
127
  lines.push("Project");
113
128
  lines.push(` ${pad("Install mode")}${p.installMode}`);
114
- lines.push(` ${pad("UI alias")}${p.aliases?.ui ?? "(unknown)"}`);
115
- lines.push(` ${pad("Theme CSS")}${p.tailwindCssFile ?? "(unknown)"}`);
116
- lines.push(` ${pad("Icon library")}${p.iconLibrary ?? "(unknown)"}`);
129
+ lines.push(` ${pad("UI alias")}${shownOr(p.aliases?.ui)}`);
130
+ lines.push(` ${pad("Theme CSS")}${shownOr(p.tailwindCssFile)}`);
131
+ lines.push(` ${pad("Icon library")}${shownOr(p.iconLibrary)}`);
117
132
  lines.push(
118
133
  ` ${pad("RSC")}${p.isRSC === null ? "(unknown)" : String(p.isRSC)}`
119
134
  );
120
- lines.push(` ${pad("Package manager")}${p.packageManager ?? "(unknown)"}`);
135
+ lines.push(` ${pad("Package manager")}${shownOr(p.packageManager)}`);
121
136
  lines.push("");
122
137
  lines.push("Environment");
123
- lines.push(` ${pad("Node")}${data.environment.node}`);
124
- lines.push(` ${pad("Platform")}${data.environment.platform}`);
125
- lines.push(` ${pad("Project root")}${data.environment.cwd}`);
126
- lines.push(` ${pad("Registry URL")}${data.environment.registryUrl}`);
127
- lines.push(` ${pad("Docs URL")}${data.environment.docsUrl}`);
138
+ lines.push(` ${pad("Node")}${shown(data.environment.node)}`);
139
+ lines.push(` ${pad("Platform")}${shown(data.environment.platform)}`);
140
+ lines.push(` ${pad("Project root")}${shown(data.environment.cwd)}`);
141
+ lines.push(` ${pad("Registry URL")}${shown(data.environment.registryUrl)}`);
142
+ lines.push(` ${pad("Docs URL")}${shown(data.environment.docsUrl)}`);
128
143
  lines.push("");
129
144
  lines.push("MCP clients");
130
145
  const configured = data.mcpClients.filter((c) => c.configured);
@@ -132,7 +147,7 @@ function printText(data) {
132
147
  lines.push(" (none configured for keystoneui)");
133
148
  } else {
134
149
  for (const client of configured) {
135
- lines.push(` ${pad(client.name)}${client.configPath}`);
150
+ lines.push(` ${pad(client.name)}${shown(client.configPath)}`);
136
151
  }
137
152
  }
138
153
  lines.push("");
@@ -141,14 +156,14 @@ function printText(data) {
141
156
  lines.push(" (none detected in this project)");
142
157
  } else {
143
158
  for (const pkg of data.installedPackages) {
144
- lines.push(` ${pad(pkg.name, 28)}v${pkg.version}`);
159
+ lines.push(` ${pad(shown(pkg.name), 28)}v${shown(pkg.version)}`);
145
160
  }
146
161
  }
147
162
  lines.push("");
148
163
  lines.push("Links");
149
- lines.push(` ${pad("Docs")}${data.links.docs}`);
150
- lines.push(` ${pad("Registry")}${data.links.registry}`);
151
- lines.push(` ${pad("llms.txt")}${data.links.llms}`);
164
+ lines.push(` ${pad("Docs")}${shown(data.links.docs)}`);
165
+ lines.push(` ${pad("Registry")}${shown(data.links.registry)}`);
166
+ lines.push(` ${pad("llms.txt")}${shown(data.links.llms)}`);
152
167
  console.log(lines.join("\n"));
153
168
  }
154
169
  function runInfo(args) {
@@ -233,7 +248,11 @@ function mergeJsonConfig(existing, client) {
233
248
  function writeJsonClient(client) {
234
249
  const targetPath = resolve2(process.cwd(), client.configPath);
235
250
  const dir = dirname(targetPath);
236
- mkdirSync(dir, { recursive: true });
251
+ try {
252
+ mkdirSync(dir, { recursive: true });
253
+ } catch (error) {
254
+ throw escapedError(error);
255
+ }
237
256
  let existing = {};
238
257
  if (existsSync2(targetPath)) {
239
258
  try {
@@ -242,8 +261,12 @@ function writeJsonClient(client) {
242
261
  }
243
262
  }
244
263
  const merged = mergeJsonConfig(existing, client);
245
- writeFileSync(targetPath, `${JSON.stringify(merged, null, 2)}
264
+ try {
265
+ writeFileSync(targetPath, `${JSON.stringify(merged, null, 2)}
246
266
  `);
267
+ } catch (error) {
268
+ throw escapedError(error);
269
+ }
247
270
  console.log(`Created ${client.configPath}`);
248
271
  console.log(`Keystone UI MCP server configured for ${client.name}.`);
249
272
  console.log(TRUST_POINTER);
@@ -280,7 +303,7 @@ function init() {
280
303
  }
281
304
  const client = CLIENTS.find((c) => c.name === clientName);
282
305
  if (!client) {
283
- console.error(`Unknown client: "${clientName}"`);
306
+ console.error(`Unknown client: "${shown(clientName)}"`);
284
307
  console.error("");
285
308
  printUsage();
286
309
  process.exitCode = 1;
@@ -293,43 +316,6 @@ function init() {
293
316
  writeJsonClient(client);
294
317
  }
295
318
 
296
- // src/theme.ts
297
- var THEME_CODE_RE = /^k1_([a-z]+)_(\d+(?:\.\d+)?)_(\d+(?:\.\d+)?)_(\d+(?:\.\d+)?)_([a-z]+)_([a-z-]+)$/;
298
- function parseThemeCode(code) {
299
- const match = THEME_CODE_RE.exec(code);
300
- if (!match) {
301
- return null;
302
- }
303
- const [, base, l, c, h, radius, font] = match;
304
- return { base, font, primary: `oklch(${l} ${c} ${h})`, radius };
305
- }
306
- function themeInstallCommand(code, siteUrl, only = []) {
307
- const query = only.length > 0 ? `?only=${only.join(",")}` : "";
308
- return `npx shadcn@latest add ${siteUrl}/r/theme/${code}.json${query}`;
309
- }
310
- function themeBuilderUrl(code, siteUrl) {
311
- const match = THEME_CODE_RE.exec(code);
312
- if (!match) {
313
- return null;
314
- }
315
- const [, base, primaryL, primaryC, primaryH, radius, font] = match;
316
- const params = new URLSearchParams({
317
- base,
318
- primaryL,
319
- primaryC,
320
- primaryH,
321
- radius,
322
- font
323
- });
324
- return `${siteUrl}/theme-builder?${params}`;
325
- }
326
- function parseThemeParts(value) {
327
- if (!value) {
328
- return [];
329
- }
330
- return value.split(",").map((part) => part.trim()).filter((part) => part === "theme" || part === "font");
331
- }
332
-
333
319
  // src/theme-audit.ts
334
320
  var TEXT_PAIRS = [
335
321
  ["foreground", "background"],
@@ -475,7 +461,7 @@ function auditTheme(tokens) {
475
461
  }
476
462
  function formatAudit(file, results) {
477
463
  if (results.length === 0) {
478
- return `No keystone token pairs found in ${file}. Pass the CSS file that holds :root and .dark.`;
464
+ return `No keystone token pairs found in ${shown(file)}. Pass the CSS file that holds :root and .dark.`;
479
465
  }
480
466
  const lines = results.map((r) => {
481
467
  const mark = { fail: "\u2716", pass: "\u2714", skip: "\u2013" }[r.status];
@@ -484,7 +470,7 @@ function formatAudit(file, results) {
484
470
  });
485
471
  const failed = results.filter((r) => r.status === "fail").length;
486
472
  return [
487
- `Theme contrast \u2014 ${file} (WCAG AA for text: ${AA_TEXT}:1)`,
473
+ `Theme contrast \u2014 ${shown(file)} (WCAG AA for text: ${AA_TEXT}:1)`,
488
474
  "",
489
475
  ...lines,
490
476
  "",
@@ -529,24 +515,46 @@ function parseArgs2(args) {
529
515
  }
530
516
  return { flags, positional };
531
517
  }
518
+ var TYPES = [
519
+ "ui",
520
+ "block",
521
+ "example",
522
+ "kit",
523
+ "style",
524
+ "theme",
525
+ "item"
526
+ ];
532
527
  function parseType(value) {
533
528
  if (value === void 0) {
534
529
  return;
535
530
  }
536
- if (value === "ui" || value === "block" || value === "example") {
531
+ if (TYPES.includes(value)) {
537
532
  return value;
538
533
  }
539
534
  throw new Error(
540
- `Invalid --type value "${value}". Expected one of: ui, block, example.`
535
+ `Invalid --type value "${shown(value)}". Expected one of: ${TYPES.join(", ")}.`
541
536
  );
542
537
  }
538
+ function refuseInvalid(names) {
539
+ const valid = [];
540
+ for (const name of names) {
541
+ const refusal = nameRefusal(name);
542
+ if (refusal) {
543
+ console.error(refusal);
544
+ process.exitCode = 1;
545
+ } else {
546
+ valid.push(name);
547
+ }
548
+ }
549
+ return valid;
550
+ }
543
551
  function parseInt10(value, fallback) {
544
552
  if (value === void 0) {
545
553
  return fallback;
546
554
  }
547
555
  const n = Number.parseInt(value, 10);
548
556
  if (Number.isNaN(n)) {
549
- throw new Error(`Expected an integer, got "${value}".`);
557
+ throw new Error(`Expected an integer, got "${shown(value)}".`);
550
558
  }
551
559
  return n;
552
560
  }
@@ -560,24 +568,26 @@ function printUsage2() {
560
568
  );
561
569
  console.log(" search <query> [--type T] [--category C] [--limit N]");
562
570
  console.log(
563
- " Fuzzy search components, blocks, examples"
571
+ " Fuzzy search components, blocks, kits, examples"
564
572
  );
565
573
  console.log(" list [--type T] [--category C] [--limit N] [--offset N]");
566
574
  console.log(
567
- " List items (T = ui|block|example)"
575
+ " List items (T = ui|block|example|kit|style|theme|item)"
576
+ );
577
+ console.log(
578
+ " view <name> [<name>...] Show source of components, blocks, kits"
568
579
  );
569
- console.log(" view <name> [<name>...] Show component source");
570
580
  console.log(
571
581
  " examples <name> Show all demos for a component/block"
572
582
  );
573
583
  console.log(
574
- " docs <name> Fetch /llms.mdx/docs/components/<name>"
584
+ " docs <name> [--type component|block] Fetch /llms.mdx/docs/{components|blocks}/<name>"
575
585
  );
576
586
  console.log(
577
587
  " audit [--theme [css]] [--strict] Post-install checklist, or measure your theme's contrast"
578
588
  );
579
589
  console.log(
580
- " blocks [<filter>] [--category C] List or filter full-page blocks"
590
+ " blocks [<filter>] [--category C] List or filter full-page blocks; an exact block name views it (kits: list --type kit)"
581
591
  );
582
592
  console.log(
583
593
  " theme <code> [--only theme,font] Install a theme-builder code via shadcn"
@@ -589,7 +599,7 @@ async function runSearch(args) {
589
599
  const { flags, positional } = parseArgs2(args);
590
600
  if (positional.length === 0) {
591
601
  console.error(
592
- "Usage: keystoneui search <query> [--type ui|block|example] [--category C] [--limit N]"
602
+ "Usage: keystoneui search <query> [--type ui|block|example|kit|style|theme|item] [--category C] [--limit N]"
593
603
  );
594
604
  process.exitCode = 1;
595
605
  return;
@@ -629,8 +639,12 @@ async function runView(args) {
629
639
  process.exitCode = 1;
630
640
  return;
631
641
  }
642
+ const names = refuseInvalid(positional);
643
+ if (names.length === 0) {
644
+ return;
645
+ }
632
646
  const config = loadProjectConfig();
633
- const text = await viewComponentTool(config, { names: positional });
647
+ const text = await viewComponentTool(config, { names });
634
648
  console.log(text);
635
649
  }
636
650
  async function runExamples(args) {
@@ -640,36 +654,39 @@ async function runExamples(args) {
640
654
  process.exitCode = 1;
641
655
  return;
642
656
  }
657
+ if (refuseInvalid([positional[0]]).length === 0) {
658
+ return;
659
+ }
643
660
  const config = loadProjectConfig();
644
661
  const text = await getExamplesTool(config, { name: positional[0] });
645
662
  console.log(text);
646
663
  }
647
664
  async function runDocs(args) {
648
- const { positional } = parseArgs2(args);
665
+ const { flags, positional } = parseArgs2(args);
649
666
  if (positional.length === 0) {
650
- console.error("Usage: keystoneui docs <name>");
667
+ console.error("Usage: keystoneui docs <name> [--type component|block]");
651
668
  process.exitCode = 1;
652
669
  return;
653
670
  }
654
671
  const name = positional[0];
655
- const siteUrl = process.env.KEYSTONEUI_URL ?? "https://keystoneui.io";
656
- const url = `${siteUrl}/llms.mdx/docs/components/${name}`;
657
- let response;
658
- try {
659
- response = await fetch(url, {
660
- headers: { "User-Agent": "keystoneui-cli/0.1" }
661
- });
662
- } catch (error) {
663
- throw redactUrlInError(error, url);
672
+ if (refuseInvalid([name]).length === 0) {
673
+ return;
674
+ }
675
+ const section = flags.type === "block" ? "blocks" : "components";
676
+ const result = await resolveDocs(loadProjectConfig(), name, section, () => ({
677
+ headers: { "User-Agent": "keystoneui-cli/0.1" }
678
+ }));
679
+ if (result.kind === "unreachable") {
680
+ throw escapedError(redactUrlInError(result.error, result.url));
664
681
  }
665
- if (!response.ok) {
682
+ if (result.kind === "status") {
666
683
  console.error(
667
- `Failed to fetch ${displayUrl(url)}: ${response.status} ${response.statusText}`
684
+ `Failed to fetch ${shown(displayUrl(result.url))}: ${result.status} ${shown(result.statusText)}`
668
685
  );
669
686
  process.exitCode = 1;
670
687
  return;
671
688
  }
672
- console.log(await response.text());
689
+ console.log(result.text);
673
690
  }
674
691
  function runAudit(args) {
675
692
  const { flags } = parseArgs2(args);
@@ -685,7 +702,13 @@ function runAudit(args) {
685
702
  process.exitCode = 1;
686
703
  return;
687
704
  }
688
- const results = auditTheme(readThemeTokens(readFileSync3(file, "utf-8")));
705
+ let css;
706
+ try {
707
+ css = readFileSync3(file, "utf-8");
708
+ } catch (error) {
709
+ throw escapedError(error);
710
+ }
711
+ const results = auditTheme(readThemeTokens(css));
689
712
  console.log(formatAudit(file, results));
690
713
  if (flags.strict === "true" && results.some((r) => r.status === "fail")) {
691
714
  process.exitCode = 1;
@@ -711,6 +734,14 @@ async function runBlocks(args) {
711
734
  console.log(text2);
712
735
  return;
713
736
  }
737
+ if (positional.length === 1 && await isBlockName(config, filter)) {
738
+ if (refuseInvalid([filter]).length === 0) {
739
+ return;
740
+ }
741
+ const text2 = await viewComponentTool(config, { names: [filter] });
742
+ console.log(text2);
743
+ return;
744
+ }
714
745
  const text = await searchComponentsTool(config, {
715
746
  query: filter,
716
747
  limit: 20,
@@ -719,6 +750,16 @@ async function runBlocks(args) {
719
750
  });
720
751
  console.log(text);
721
752
  }
753
+ async function isBlockName(config, name) {
754
+ try {
755
+ const { items } = await lookupManifest(config.registry);
756
+ return items.some(
757
+ (item) => item.name === name && item.type === "registry:block"
758
+ );
759
+ } catch {
760
+ return false;
761
+ }
762
+ }
722
763
  function runTheme(args) {
723
764
  const { flags, positional } = parseArgs2(args);
724
765
  const code = positional[0];
@@ -738,9 +779,11 @@ function runTheme(args) {
738
779
  );
739
780
  console.log("");
740
781
  console.log("Install (writes the tokens into your global CSS):");
741
- console.log(` ${themeInstallCommand(code, siteUrl, only)}`);
782
+ console.log(
783
+ isCommandSafe(themeInstallUrl(code, siteUrl, only)) ? ` ${themeInstallCommand(code, siteUrl, only)}` : ` (no command: ${shown(displayUrl(siteUrl))} holds a line break or control character)`
784
+ );
742
785
  console.log("");
743
- console.log(`Edit: ${themeBuilderUrl(code, siteUrl)}`);
786
+ console.log(`Edit: ${shown(themeBuilderUrl(code, siteUrl))}`);
744
787
  }
745
788
  async function runCli(args) {
746
789
  const verb = args[0];
@@ -750,7 +793,7 @@ async function runCli(args) {
750
793
  return;
751
794
  }
752
795
  if (!isCliVerb(verb)) {
753
- console.error(`Unknown verb: "${verb}".`);
796
+ console.error(`Unknown verb: "${shown(verb)}".`);
754
797
  console.error("");
755
798
  printUsage2();
756
799
  process.exitCode = 1;
@@ -805,6 +848,6 @@ if (isCliVerb(verbCandidate)) {
805
848
  process.exit();
806
849
  }
807
850
  var { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
808
- var { server } = await import("./server-7ZU3YJ7K.js");
851
+ var { server } = await import("./server-HWF3HIOR.js");
809
852
  var transport = new StdioServerTransport();
810
853
  await server.connect(transport);
@@ -12,7 +12,7 @@ import {
12
12
  readPackageVersion,
13
13
  searchComponentsTool,
14
14
  viewComponentTool
15
- } from "./chunk-TAXPGE7O.js";
15
+ } from "./chunk-LC22ZWZH.js";
16
16
 
17
17
  // src/server.ts
18
18
  import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
@@ -26,7 +26,7 @@ var server = new McpServer(
26
26
  capabilities: {
27
27
  tools: {}
28
28
  },
29
- instructions: "Keystone UI MCP server. Use these tools to discover, search, view, and install Keystone UI components. Start with list_components or search_components to explore available components, then view_component to get full source code."
29
+ instructions: "Keystone UI MCP server. Use these tools to discover, search, view, and install Keystone UI components, blocks, and kits. Call get_project_context first: install mode decides imports and, for a package-mode project, the flavour to pass to get_add_command. Then use list_components or search_components to explore, and view_component to get full source code."
30
30
  }
31
31
  );
32
32
  function text(value) {
@@ -54,7 +54,7 @@ server.tool(
54
54
  "get_add_command",
55
55
  TOOL_SPECS.get_add_command.description,
56
56
  TOOL_SPECS.get_add_command.schema.shape,
57
- (input) => text(getAddCommandTool(config, input))
57
+ async (input) => text(await getAddCommandTool(config, input))
58
58
  );
59
59
  server.tool(
60
60
  "get_examples",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@keystoneui/mcp",
3
- "version": "0.2.0-beta.5",
3
+ "version": "0.2.0-beta.6",
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",