@keystoneui/mcp 0.2.0-beta.1 → 0.2.0-beta.10

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.
@@ -0,0 +1,88 @@
1
+ #!/usr/bin/env node
2
+ import {
3
+ TOOL_SPECS,
4
+ auditChecklistTool,
5
+ getAddCommandTool,
6
+ getDocsTool,
7
+ getExamplesTool,
8
+ getProjectContextTool,
9
+ getThemeInfoTool,
10
+ listComponentsTool,
11
+ loadProjectConfig,
12
+ readPackageVersion,
13
+ searchComponentsTool,
14
+ viewComponentTool
15
+ } from "./chunk-5RKRKR2Z.js";
16
+
17
+ // src/server.ts
18
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
19
+ var config = loadProjectConfig();
20
+ var server = new McpServer(
21
+ {
22
+ name: "keystoneui",
23
+ version: readPackageVersion()
24
+ },
25
+ {
26
+ capabilities: {
27
+ tools: {}
28
+ },
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
+ }
31
+ );
32
+ function text(value) {
33
+ return { content: [{ type: "text", text: value }] };
34
+ }
35
+ server.tool(
36
+ "list_components",
37
+ TOOL_SPECS.list_components.description,
38
+ TOOL_SPECS.list_components.schema.shape,
39
+ async (input) => text(await listComponentsTool(config, input))
40
+ );
41
+ server.tool(
42
+ "search_components",
43
+ TOOL_SPECS.search_components.description,
44
+ TOOL_SPECS.search_components.schema.shape,
45
+ async (input) => text(await searchComponentsTool(config, input))
46
+ );
47
+ server.tool(
48
+ "view_component",
49
+ TOOL_SPECS.view_component.description,
50
+ TOOL_SPECS.view_component.schema.shape,
51
+ async (input) => text(await viewComponentTool(config, input))
52
+ );
53
+ server.tool(
54
+ "get_add_command",
55
+ TOOL_SPECS.get_add_command.description,
56
+ TOOL_SPECS.get_add_command.schema.shape,
57
+ async (input) => text(await getAddCommandTool(config, input))
58
+ );
59
+ server.tool(
60
+ "get_examples",
61
+ TOOL_SPECS.get_examples.description,
62
+ TOOL_SPECS.get_examples.schema.shape,
63
+ async (input) => text(await getExamplesTool(config, input))
64
+ );
65
+ server.tool(
66
+ "get_docs",
67
+ TOOL_SPECS.get_docs.description,
68
+ TOOL_SPECS.get_docs.schema.shape,
69
+ async (input) => text(await getDocsTool(config, input))
70
+ );
71
+ server.tool(
72
+ "get_project_context",
73
+ TOOL_SPECS.get_project_context.description,
74
+ () => text(getProjectContextTool())
75
+ );
76
+ server.tool(
77
+ "get_theme_info",
78
+ TOOL_SPECS.get_theme_info.description,
79
+ async () => text(await getThemeInfoTool(config))
80
+ );
81
+ server.tool(
82
+ "audit_checklist",
83
+ TOOL_SPECS.audit_checklist.description,
84
+ async () => text(await auditChecklistTool())
85
+ );
86
+ export {
87
+ server
88
+ };
package/package.json CHANGED
@@ -1,9 +1,21 @@
1
1
  {
2
2
  "name": "@keystoneui/mcp",
3
- "version": "0.2.0-beta.1",
3
+ "version": "0.2.0-beta.10",
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",
7
+ "homepage": "https://keystoneui.io/docs/agents/mcp-server",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/keystone-ui/react.git",
11
+ "directory": "packages/keystoneui-mcp"
12
+ },
13
+ "bugs": {
14
+ "url": "https://github.com/keystone-ui/react/issues"
15
+ },
16
+ "engines": {
17
+ "node": ">=22"
18
+ },
7
19
  "keywords": [
8
20
  "keystoneui",
9
21
  "mcp",
@@ -25,14 +37,15 @@
25
37
  "README.md"
26
38
  ],
27
39
  "dependencies": {
28
- "@modelcontextprotocol/sdk": "^1.29.0",
29
- "fuzzysort": "^3.1.0",
30
- "zod": "^4.3.6"
40
+ "@modelcontextprotocol/sdk": "^1.32.1",
41
+ "fuzzysort": "^4.0.2",
42
+ "zod": "^4.6.5"
31
43
  },
32
44
  "devDependencies": {
33
- "@types/node": "^25.6.0",
34
- "tsup": "^8.5.0",
35
- "typescript": "^6.0.3",
45
+ "@types/node": "^26.6.5",
46
+ "tsup": "^8.5.1",
47
+ "typescript": "^7.0.2",
48
+ "vitest": "^5.0.5",
36
49
  "@keystoneui/typescript-config": "0.0.0"
37
50
  },
38
51
  "publishConfig": {
@@ -41,6 +54,8 @@
41
54
  "scripts": {
42
55
  "build": "tsup",
43
56
  "dev": "tsup --watch",
44
- "clean": "rm -rf dist node_modules"
57
+ "clean": "rm -rf dist node_modules",
58
+ "test": "vitest run",
59
+ "test:watch": "vitest"
45
60
  }
46
61
  }
@@ -1,331 +0,0 @@
1
- #!/usr/bin/env node
2
-
3
- // src/config.ts
4
- import { existsSync, readFileSync } from "fs";
5
- import { resolve } from "path";
6
- var DEFAULT_REGISTRY_URL = "https://keystoneui.io/r";
7
- function loadProjectConfig() {
8
- const registryUrlEnv = process.env.KEYSTONEUI_REGISTRY_URL;
9
- if (registryUrlEnv) {
10
- return { registry: { url: registryUrlEnv } };
11
- }
12
- const cwd = process.cwd();
13
- const configPath = resolve(cwd, "components.json");
14
- if (existsSync(configPath)) {
15
- try {
16
- const raw = JSON.parse(readFileSync(configPath, "utf-8"));
17
- const registryUrl = raw?.registries?.["@keystoneui"]?.url ?? DEFAULT_REGISTRY_URL;
18
- return { registry: { url: registryUrl } };
19
- } catch {
20
- }
21
- }
22
- return { registry: { url: DEFAULT_REGISTRY_URL } };
23
- }
24
-
25
- // src/tools.ts
26
- import { z } from "zod";
27
-
28
- // src/fetcher.ts
29
- var cache = /* @__PURE__ */ new Map();
30
- var CACHE_TTL_MS = 5 * 60 * 1e3;
31
- async function fetchJson(url) {
32
- const cached = cache.get(url);
33
- if (cached && Date.now() - cached.timestamp < CACHE_TTL_MS) {
34
- return cached.data;
35
- }
36
- const response = await fetch(url);
37
- if (!response.ok) {
38
- throw new Error(`Failed to fetch ${url}: ${response.status}`);
39
- }
40
- const data = await response.json();
41
- cache.set(url, { data, timestamp: Date.now() });
42
- return data;
43
- }
44
- function fetchManifest(registryUrl) {
45
- return fetchJson(`${registryUrl}/registry.json`);
46
- }
47
- function fetchItem(registryUrl, name) {
48
- return fetchJson(`${registryUrl}/${name}.json`);
49
- }
50
- function fetchExamples(registryUrl, name) {
51
- return fetchJson(`${registryUrl}/demos/${name}`);
52
- }
53
-
54
- // src/search.ts
55
- import fuzzysort from "fuzzysort";
56
- function applyFilters(items, type, category) {
57
- let filtered = items;
58
- if (type) {
59
- filtered = filtered.filter((i) => i.type === `registry:${type}`);
60
- }
61
- if (category) {
62
- filtered = filtered.filter((i) => i.categories?.includes(category));
63
- }
64
- return filtered;
65
- }
66
- function searchItems(manifest, query, opts = {}) {
67
- const { limit = 20, offset = 0, type, category } = opts;
68
- const items = applyFilters(manifest.items, type, category);
69
- const targets = items.map((item) => ({
70
- item,
71
- searchable: `${item.name} ${item.title ?? ""} ${item.description ?? ""} ${(item.categories ?? []).join(" ")}`
72
- }));
73
- const results = fuzzysort.go(query, targets, {
74
- key: "searchable",
75
- threshold: -1e4
76
- }).map((r) => ({ item: r.obj.item, score: r.score }));
77
- return {
78
- results: results.slice(offset, offset + limit),
79
- total: results.length
80
- };
81
- }
82
- function listItems(manifest, opts = {}) {
83
- const { limit = 20, offset = 0, type, category } = opts;
84
- const items = applyFilters(manifest.items, type, category);
85
- return {
86
- items: items.slice(offset, offset + limit),
87
- total: items.length
88
- };
89
- }
90
-
91
- // src/tools.ts
92
- function formatItemSummary(item) {
93
- const parts = [`**${item.title ?? item.name}** (\`${item.name}\`)`];
94
- if (item.description) {
95
- parts.push(item.description);
96
- }
97
- if (item.categories?.length) {
98
- parts.push(`Categories: ${item.categories.join(", ")}`);
99
- }
100
- if (item.dependencies?.length) {
101
- parts.push(`Dependencies: ${item.dependencies.join(", ")}`);
102
- }
103
- if (item.registryDependencies?.length) {
104
- parts.push(
105
- `Registry dependencies: ${item.registryDependencies.join(", ")}`
106
- );
107
- }
108
- return parts.join("\n");
109
- }
110
- function formatItemDetail(item) {
111
- const sections = [formatItemSummary(item)];
112
- if (item.files?.length) {
113
- for (const file of item.files) {
114
- if (file.content) {
115
- sections.push(`### ${file.path}
116
- \`\`\`tsx
117
- ${file.content}\`\`\``);
118
- }
119
- }
120
- }
121
- return sections.join("\n\n");
122
- }
123
- var listComponentsSchema = z.object({
124
- limit: z.number().min(1).max(100).default(20).describe("Maximum number of items to return"),
125
- offset: z.number().min(0).default(0).describe("Number of items to skip"),
126
- type: z.enum(["ui", "block", "example"]).optional().describe(
127
- "Filter by item type: 'ui' for components, 'block' for full-page blocks, 'example' for named demo variants like 'table-with-pagination'"
128
- ),
129
- category: z.string().optional().describe(
130
- "Filter by category (e.g. 'authentication', 'login', 'signup', 'navigation', 'data', 'betting'). Currently only block items carry categories."
131
- )
132
- });
133
- async function listComponentsTool(config, input) {
134
- const manifest = await fetchManifest(config.registry.url);
135
- const { items, total } = listItems(manifest, input);
136
- const lines = items.map(formatItemSummary);
137
- lines.push(`
138
- ---
139
- Showing ${items.length} of ${total} items.`);
140
- if (input.offset + items.length < total) {
141
- lines.push(`Use offset: ${input.offset + items.length} to see more.`);
142
- }
143
- return lines.join("\n\n");
144
- }
145
- var searchComponentsSchema = z.object({
146
- query: z.string().describe("Search query (name, description, or keywords)"),
147
- limit: z.number().min(1).max(50).default(10).describe("Maximum number of results"),
148
- type: z.enum(["ui", "block", "example"]).optional().describe(
149
- "Filter by item type: 'ui' for components, 'block' for full-page blocks, 'example' for named demo variants"
150
- ),
151
- category: z.string().optional().describe(
152
- "Filter by category (e.g. 'authentication', 'login'). Currently only block items carry categories."
153
- )
154
- });
155
- async function searchComponentsTool(config, input) {
156
- const manifest = await fetchManifest(config.registry.url);
157
- const { results, total } = searchItems(manifest, input.query, {
158
- limit: input.limit,
159
- type: input.type,
160
- category: input.category
161
- });
162
- if (results.length === 0) {
163
- return `No results found for "${input.query}".`;
164
- }
165
- const lines = results.map((r) => formatItemSummary(r.item));
166
- lines.push(`
167
- ---
168
- ${total} result${total === 1 ? "" : "s"} found.`);
169
- return lines.join("\n\n");
170
- }
171
- var viewComponentSchema = z.object({
172
- names: z.array(z.string()).min(1).max(5).describe(
173
- 'Component names to view (e.g. ["button", "card"]). Returns full source code.'
174
- )
175
- });
176
- async function viewComponentTool(config, input) {
177
- const results = await Promise.all(
178
- input.names.map(async (name) => {
179
- try {
180
- const item = await fetchItem(config.registry.url, name);
181
- return formatItemDetail(item);
182
- } catch {
183
- return `**${name}**: Not found in registry.`;
184
- }
185
- })
186
- );
187
- return results.join("\n\n---\n\n");
188
- }
189
- var getAddCommandSchema = z.object({
190
- names: z.array(z.string()).min(1).describe("Component names to generate install commands for")
191
- });
192
- function getAddCommandTool(config, input) {
193
- const urls = input.names.map((name) => `${config.registry.url}/${name}.json`);
194
- const lines = [
195
- "Install these components with the shadcn CLI:",
196
- "",
197
- "```bash",
198
- `npx shadcn@latest add ${urls.join(" ")}`,
199
- "```",
200
- "",
201
- "Or install individually:",
202
- ""
203
- ];
204
- for (const url of urls) {
205
- lines.push(`\`\`\`bash
206
- npx shadcn@latest add ${url}
207
- \`\`\``);
208
- }
209
- return lines.join("\n");
210
- }
211
- var getExamplesSchema = z.object({
212
- name: z.string().describe(
213
- 'Component or block name to fetch examples for (e.g. "button" or "tickets-01")'
214
- )
215
- });
216
- async function getExamplesTool(config, input) {
217
- try {
218
- const bundle = await fetchExamples(config.registry.url, input.name);
219
- if (!bundle.files.length) {
220
- return `**${input.name}**: no example files found.`;
221
- }
222
- const sections = [
223
- `# ${input.name} examples`,
224
- `${bundle.files.length} file${bundle.files.length === 1 ? "" : "s"}:`,
225
- ""
226
- ];
227
- for (const file of bundle.files) {
228
- const ext = file.path.includes(".") ? file.path.split(".").pop() : "tsx";
229
- sections.push(`### ${file.path}`);
230
- sections.push(`\`\`\`${ext}
231
- ${file.content}
232
- \`\`\``);
233
- }
234
- return sections.join("\n\n");
235
- } catch {
236
- return `**${input.name}**: examples not found in registry.`;
237
- }
238
- }
239
- function getThemeInfoTool(config) {
240
- const registryUrl = config.registry.url;
241
- return `# Keystone UI Theme
242
-
243
- ## CSS Setup
244
-
245
- \`\`\`css
246
- @import "tailwindcss";
247
- @import "@keystoneui/react/base.css";
248
- \`\`\`
249
-
250
- ## Semantic Color Tokens (OKLCH)
251
-
252
- | Token | Light | Dark | Usage |
253
- |---|---|---|---|
254
- | \`--primary\` | \`oklch(0.21 0.006 285)\` | \`oklch(0.92 0.004 286)\` | Main actions, CTAs |
255
- | \`--secondary\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Alternative actions |
256
- | \`--destructive\` | \`oklch(0.577 0.245 27)\` | \`oklch(0.704 0.191 22)\` | Destructive actions |
257
- | \`--muted\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Subdued elements |
258
- | \`--accent\` | \`oklch(0.967 0.001 286)\` | \`oklch(0.274 0.006 286)\` | Highlights |
259
- | \`--background\` | \`oklch(1 0 0)\` | \`oklch(0.141 0.005 286)\` | Page background |
260
- | \`--border\` | \`oklch(0.92 0.004 286)\` | \`oklch(1 0 0 / 10%)\` | Border color |
261
- | \`--ring\` | \`oklch(0.21 0.006 286)\` | \`oklch(0.92 0.004 286)\` | Focus ring |
262
-
263
- ## Radius Scale
264
-
265
- Base: \`--radius: 0.625rem\` (10px). Derived values:
266
- - \`rounded-sm\`: 6px
267
- - \`rounded-md\`: 8px
268
- - \`rounded-lg\`: 10px (base)
269
- - \`rounded-xl\`: 14px
270
-
271
- ## Custom Tokens
272
-
273
- - \`--input-bg\`: Form control background (transparent light, 5% white dark)
274
- - \`--popup-ring\`: Subtle popup container ring
275
- - \`--border-muted\`: Lower-contrast separator inside popups
276
-
277
- ## Dark Mode
278
-
279
- Add the \`dark\` class to a parent element.
280
-
281
- ## Registry
282
-
283
- Get the full style definition:
284
- \`\`\`bash
285
- npx shadcn@latest add ${registryUrl}/default.json
286
- \`\`\``;
287
- }
288
- function auditChecklistTool() {
289
- return `# Post-Install Audit Checklist
290
-
291
- ## 1. CSS Setup
292
- - [ ] \`@import "tailwindcss"\` is present in your CSS entry point
293
- - [ ] \`@import "@keystoneui/react/base.css"\` is imported AFTER tailwindcss
294
- - [ ] Dark mode variant is configured: \`@custom-variant dark (&:is(.dark *))\`
295
-
296
- ## 2. Tailwind Configuration
297
- - [ ] Using Tailwind CSS v4.1+
298
- - [ ] Content paths include your component files
299
-
300
- ## 3. Dependencies
301
- - [ ] \`@keystoneui/react\` is installed
302
- - [ ] Component-specific peer dependencies are installed (check each component's \`dependencies\` field)
303
- - [ ] Using React 19+
304
-
305
- ## 4. Import Pattern
306
- - [ ] Using subpath imports: \`import { Button } from "@keystoneui/react/button"\`
307
- - [ ] NOT using barrel imports from \`@keystoneui/react\`
308
-
309
- ## 5. Theme Variables
310
- - [ ] CSS custom properties are defined in \`:root\` (see \`get_theme_info\` for the full list)
311
- - [ ] Dark mode variables are defined in \`.dark\` selector
312
-
313
- ## 6. Icon Library
314
- - [ ] Using \`lucide-react\` for icons (not \`@iconify/react\` or others)
315
-
316
- ## 7. Common Issues
317
- - [ ] If hover styles feel "sticky" on mobile: ensure \`base.css\` is imported (it gates \`hover:\` with \`@media (hover: hover)\`)
318
- - [ ] If buttons don't show pointer cursor: Tailwind v4 changed the default \u2014 Keystone UI handles this internally
319
- - [ ] If focus rings look wrong: don't mix outline-based and ring-based focus patterns`;
320
- }
321
-
322
- export {
323
- loadProjectConfig,
324
- listComponentsTool,
325
- searchComponentsTool,
326
- viewComponentTool,
327
- getAddCommandTool,
328
- getExamplesTool,
329
- getThemeInfoTool,
330
- auditChecklistTool
331
- };
@@ -1,137 +0,0 @@
1
- #!/usr/bin/env node
2
- import {
3
- auditChecklistTool,
4
- getAddCommandTool,
5
- getExamplesTool,
6
- getThemeInfoTool,
7
- listComponentsTool,
8
- loadProjectConfig,
9
- searchComponentsTool,
10
- viewComponentTool
11
- } from "./chunk-DZNQW5EA.js";
12
-
13
- // src/server.ts
14
- import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
15
- import { z } from "zod";
16
- var config = loadProjectConfig();
17
- var server = new McpServer(
18
- {
19
- name: "keystoneui",
20
- version: "0.1.0"
21
- },
22
- {
23
- capabilities: {
24
- tools: {}
25
- },
26
- 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."
27
- }
28
- );
29
- server.tool(
30
- "list_components",
31
- "List all available Keystone UI components, blocks, and named examples with pagination. Returns name, description, categories, and dependency info for each item.",
32
- {
33
- limit: z.number().min(1).max(100).default(20).describe("Maximum number of items to return"),
34
- offset: z.number().min(0).default(0).describe("Number of items to skip"),
35
- type: z.enum(["ui", "block", "example"]).optional().describe(
36
- "Filter by item type: 'ui' for components, 'block' for full-page blocks, 'example' for named demo variants like 'table-with-pagination'"
37
- ),
38
- category: z.string().optional().describe(
39
- "Filter by category (e.g. 'authentication', 'login', 'signup', 'navigation', 'data', 'betting'). Currently only block items carry categories."
40
- )
41
- },
42
- async ({ limit, offset, type, category }) => ({
43
- content: [
44
- {
45
- type: "text",
46
- text: await listComponentsTool(config, {
47
- limit,
48
- offset,
49
- type,
50
- category
51
- })
52
- }
53
- ]
54
- })
55
- );
56
- server.tool(
57
- "search_components",
58
- "Fuzzy search components, blocks, and named examples (e.g., `table-with-pagination`, `card-with-image`). Categories (e.g. 'authentication', 'login') participate in fuzzy matching. Use when the exact name isn't known; pair with `view_component` or `get_examples` to see code.",
59
- {
60
- query: z.string().describe("Search query (name, description, or keywords)"),
61
- limit: z.number().min(1).max(50).default(10).describe("Maximum number of results"),
62
- type: z.enum(["ui", "block", "example"]).optional().describe(
63
- "Filter by item type: 'ui' for components, 'block' for full-page blocks, 'example' for named demo variants"
64
- ),
65
- category: z.string().optional().describe(
66
- "Filter by category (e.g. 'authentication', 'login'). Currently only block items carry categories."
67
- )
68
- },
69
- async ({ query, limit, type, category }) => ({
70
- content: [
71
- {
72
- type: "text",
73
- text: await searchComponentsTool(config, {
74
- query,
75
- limit,
76
- type,
77
- category
78
- })
79
- }
80
- ]
81
- })
82
- );
83
- server.tool(
84
- "view_component",
85
- "Get full details for one or more Keystone UI components, including complete source code, dependencies, and registry dependencies. Use this to understand how a component works before using or customizing it.",
86
- {
87
- names: z.array(z.string()).min(1).max(5).describe(
88
- 'Component names to view (e.g. ["button", "card"]). Returns full source code.'
89
- )
90
- },
91
- async ({ names }) => ({
92
- content: [
93
- { type: "text", text: await viewComponentTool(config, { names }) }
94
- ]
95
- })
96
- );
97
- server.tool(
98
- "get_add_command",
99
- "Generate the shadcn CLI command to install one or more Keystone UI components into a project.",
100
- {
101
- names: z.array(z.string()).min(1).describe("Component names to generate install commands for")
102
- },
103
- async ({ names }) => ({
104
- content: [
105
- { type: "text", text: await getAddCommandTool(config, { names }) }
106
- ]
107
- })
108
- );
109
- server.tool(
110
- "get_examples",
111
- "Fetch live demo files for a Keystone UI component or block. Returns the TSX source for every example/demo associated with the name (e.g. button, signin-01, tickets-01). Use after view_component to see real-world usage patterns.",
112
- {
113
- name: z.string().describe(
114
- 'Component or block name (e.g. "button", "signin-01", "tickets-01")'
115
- )
116
- },
117
- async ({ name }) => ({
118
- content: [{ type: "text", text: await getExamplesTool(config, { name }) }]
119
- })
120
- );
121
- server.tool(
122
- "get_theme_info",
123
- "Get Keystone UI theme configuration: CSS setup, semantic color tokens (OKLCH), radius scale, dark mode setup, and custom tokens.",
124
- async () => ({
125
- content: [{ type: "text", text: await getThemeInfoTool(config) }]
126
- })
127
- );
128
- server.tool(
129
- "audit_checklist",
130
- "Get a post-install audit checklist to verify Keystone UI is correctly configured in your project. Covers CSS setup, Tailwind config, dependencies, imports, and common issues.",
131
- async () => ({
132
- content: [{ type: "text", text: await auditChecklistTool() }]
133
- })
134
- );
135
- export {
136
- server
137
- };