@keystoneui/mcp 0.2.0-beta.1
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 +83 -0
- package/dist/chunk-DZNQW5EA.js +331 -0
- package/dist/index.js +547 -0
- package/dist/server-5ZV7UIUD.js +137 -0
- package/package.json +46 -0
package/README.md
ADDED
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
# @keystoneui/mcp
|
|
2
|
+
|
|
3
|
+
MCP server and CLI for [Keystone UI](https://keystoneui.io) — lets AI agents and shell users discover, search, view, and install components, blocks, and named examples from the Keystone UI registry.
|
|
4
|
+
|
|
5
|
+
The single binary runs in two modes:
|
|
6
|
+
|
|
7
|
+
- **No args** → Model Context Protocol stdio server (for Claude Code, Cursor, VS Code Copilot, OpenCode, Codex)
|
|
8
|
+
- **With a verb** → CLI for shells, CI, and non-MCP environments
|
|
9
|
+
|
|
10
|
+
## Quick start
|
|
11
|
+
|
|
12
|
+
### As an MCP server
|
|
13
|
+
|
|
14
|
+
```bash
|
|
15
|
+
npx -y @keystoneui/mcp init --client claude
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
Supported clients: `claude`, `cursor`, `vscode`, `opencode`, `codex`. The `init` command writes the appropriate config file for the chosen client and points it at `npx @keystoneui/mcp@latest`.
|
|
19
|
+
|
|
20
|
+
Once configured, ask your agent things like:
|
|
21
|
+
|
|
22
|
+
- *"List Keystone UI components."*
|
|
23
|
+
- *"How do I add a Keystone UI Table with pagination?"*
|
|
24
|
+
- *"Build a sign-in page using Keystone UI."*
|
|
25
|
+
|
|
26
|
+
### As a CLI
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
# Discover
|
|
30
|
+
npx keystoneui search "table pagination"
|
|
31
|
+
npx keystoneui list --type example
|
|
32
|
+
npx keystoneui blocks signin
|
|
33
|
+
|
|
34
|
+
# Inspect
|
|
35
|
+
npx keystoneui view button
|
|
36
|
+
npx keystoneui docs button # /llms.mdx/docs/components/button
|
|
37
|
+
npx keystoneui examples table # all demo files for the table component
|
|
38
|
+
|
|
39
|
+
# Install (delegates to shadcn CLI)
|
|
40
|
+
npx shadcn@latest add https://keystoneui.io/r/table-with-pagination.json
|
|
41
|
+
|
|
42
|
+
# Verify
|
|
43
|
+
npx keystoneui audit
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
## Verbs
|
|
47
|
+
|
|
48
|
+
| Verb | Purpose |
|
|
49
|
+
|---|---|
|
|
50
|
+
| `init [--client <name>]` | Configure MCP client |
|
|
51
|
+
| `search <query> [--type T] [--limit N]` | Fuzzy search components, blocks, named examples |
|
|
52
|
+
| `list [--type T] [--limit N] [--offset N]` | List items (`T` = `ui` \| `block` \| `example`) |
|
|
53
|
+
| `view <name> [<name>...]` | Show component source |
|
|
54
|
+
| `examples <name>` | All demo files for a component or block |
|
|
55
|
+
| `docs <name>` | Fetch the LLM-resolved MDX page (`/llms.mdx/docs/components/<name>`) |
|
|
56
|
+
| `audit` | Print the post-install checklist |
|
|
57
|
+
| `blocks [<filter>]` | List or filter full-page blocks |
|
|
58
|
+
|
|
59
|
+
Run `keystoneui help` for the full list. Without any verb the binary launches the MCP stdio server.
|
|
60
|
+
|
|
61
|
+
## MCP tools
|
|
62
|
+
|
|
63
|
+
When run without arguments the server exposes seven tools to MCP clients:
|
|
64
|
+
|
|
65
|
+
- `list_components` — list components, blocks, or examples with pagination
|
|
66
|
+
- `search_components` — fuzzy search across components, blocks, and examples
|
|
67
|
+
- `view_component` — full source for one or more components
|
|
68
|
+
- `get_add_command` — generate the shadcn CLI command for installing components
|
|
69
|
+
- `get_examples` — fetch live demo files for a component or block
|
|
70
|
+
- `get_theme_info` — semantic color tokens, radius scale, dark-mode setup
|
|
71
|
+
- `audit_checklist` — post-install verification checklist
|
|
72
|
+
|
|
73
|
+
## Configuration
|
|
74
|
+
|
|
75
|
+
The server reads the registry URL in this order:
|
|
76
|
+
|
|
77
|
+
1. `KEYSTONEUI_REGISTRY_URL` env var
|
|
78
|
+
2. `registries["@keystoneui"].url` from a local `components.json`
|
|
79
|
+
3. Default: `https://keystoneui.io/r`
|
|
80
|
+
|
|
81
|
+
## License
|
|
82
|
+
|
|
83
|
+
MIT
|
|
@@ -0,0 +1,331 @@
|
|
|
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
|
+
};
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import {
|
|
3
|
+
auditChecklistTool,
|
|
4
|
+
getExamplesTool,
|
|
5
|
+
listComponentsTool,
|
|
6
|
+
loadProjectConfig,
|
|
7
|
+
searchComponentsTool,
|
|
8
|
+
viewComponentTool
|
|
9
|
+
} from "./chunk-DZNQW5EA.js";
|
|
10
|
+
|
|
11
|
+
// src/info.ts
|
|
12
|
+
import { existsSync, readFileSync } from "fs";
|
|
13
|
+
import { homedir } from "os";
|
|
14
|
+
import { resolve } from "path";
|
|
15
|
+
import { fileURLToPath } from "url";
|
|
16
|
+
var DEFAULT_DOCS_URL = "https://keystoneui.io";
|
|
17
|
+
function readPackageVersion() {
|
|
18
|
+
try {
|
|
19
|
+
const pkgPath = fileURLToPath(new URL("../package.json", import.meta.url));
|
|
20
|
+
const pkg = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
21
|
+
return pkg.version ?? "unknown";
|
|
22
|
+
} catch {
|
|
23
|
+
return "unknown";
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function detectMcpClients(cwd) {
|
|
27
|
+
const candidates = [
|
|
28
|
+
{ name: "claude", path: resolve(cwd, ".mcp.json") },
|
|
29
|
+
{ name: "cursor", path: resolve(cwd, ".cursor/mcp.json") },
|
|
30
|
+
{ name: "vscode", path: resolve(cwd, ".vscode/mcp.json") },
|
|
31
|
+
{ name: "opencode", path: resolve(cwd, "opencode.json") },
|
|
32
|
+
{ name: "codex", path: resolve(homedir(), ".codex/config.toml") }
|
|
33
|
+
];
|
|
34
|
+
return candidates.map(({ name, path }) => {
|
|
35
|
+
if (!existsSync(path)) {
|
|
36
|
+
return { name, configPath: path, configured: false };
|
|
37
|
+
}
|
|
38
|
+
try {
|
|
39
|
+
const contents = readFileSync(path, "utf-8");
|
|
40
|
+
const configured = contents.includes("keystoneui");
|
|
41
|
+
return { name, configPath: path, configured };
|
|
42
|
+
} catch {
|
|
43
|
+
return { name, configPath: path, configured: false };
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
function detectInstalledPackages(cwd) {
|
|
48
|
+
const pkgPath = resolve(cwd, "package.json");
|
|
49
|
+
if (!existsSync(pkgPath)) {
|
|
50
|
+
return [];
|
|
51
|
+
}
|
|
52
|
+
let manifest;
|
|
53
|
+
try {
|
|
54
|
+
manifest = JSON.parse(readFileSync(pkgPath, "utf-8"));
|
|
55
|
+
} catch {
|
|
56
|
+
return [];
|
|
57
|
+
}
|
|
58
|
+
const declared = {
|
|
59
|
+
...manifest.dependencies ?? {},
|
|
60
|
+
...manifest.devDependencies ?? {}
|
|
61
|
+
};
|
|
62
|
+
const keystoneNames = Object.keys(declared).filter((name) => name.startsWith("@keystoneui/")).sort();
|
|
63
|
+
return keystoneNames.map((name) => {
|
|
64
|
+
const installedPkgPath = resolve(cwd, "node_modules", name, "package.json");
|
|
65
|
+
if (existsSync(installedPkgPath)) {
|
|
66
|
+
try {
|
|
67
|
+
const installed = JSON.parse(
|
|
68
|
+
readFileSync(installedPkgPath, "utf-8")
|
|
69
|
+
);
|
|
70
|
+
if (installed.version) {
|
|
71
|
+
return { name, version: installed.version };
|
|
72
|
+
}
|
|
73
|
+
} catch {
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
return { name, version: `${declared[name]} (not installed)` };
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
function collect() {
|
|
80
|
+
const cwd = process.cwd();
|
|
81
|
+
const config = loadProjectConfig();
|
|
82
|
+
const docsUrl = process.env.KEYSTONEUI_URL ?? DEFAULT_DOCS_URL;
|
|
83
|
+
const version = readPackageVersion();
|
|
84
|
+
return {
|
|
85
|
+
schema: 1,
|
|
86
|
+
package: { name: "@keystoneui/mcp", version },
|
|
87
|
+
environment: {
|
|
88
|
+
node: process.version,
|
|
89
|
+
platform: process.platform,
|
|
90
|
+
cwd,
|
|
91
|
+
registryUrl: config.registry.url,
|
|
92
|
+
docsUrl
|
|
93
|
+
},
|
|
94
|
+
mcpClients: detectMcpClients(cwd),
|
|
95
|
+
installedPackages: detectInstalledPackages(cwd),
|
|
96
|
+
links: {
|
|
97
|
+
docs: docsUrl,
|
|
98
|
+
registry: `${config.registry.url}/registry.json`,
|
|
99
|
+
llms: `${docsUrl}/llms.txt`
|
|
100
|
+
}
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
function pad(label, width = 18) {
|
|
104
|
+
if (label.length >= width) {
|
|
105
|
+
return `${label} `;
|
|
106
|
+
}
|
|
107
|
+
return label.padEnd(width, " ");
|
|
108
|
+
}
|
|
109
|
+
function printText(data) {
|
|
110
|
+
const lines = [];
|
|
111
|
+
lines.push(`${data.package.name} v${data.package.version}`);
|
|
112
|
+
lines.push("");
|
|
113
|
+
lines.push("Environment");
|
|
114
|
+
lines.push(` ${pad("Node")}${data.environment.node}`);
|
|
115
|
+
lines.push(` ${pad("Platform")}${data.environment.platform}`);
|
|
116
|
+
lines.push(` ${pad("Project root")}${data.environment.cwd}`);
|
|
117
|
+
lines.push(` ${pad("Registry URL")}${data.environment.registryUrl}`);
|
|
118
|
+
lines.push(` ${pad("Docs URL")}${data.environment.docsUrl}`);
|
|
119
|
+
lines.push("");
|
|
120
|
+
lines.push("MCP clients");
|
|
121
|
+
const configured = data.mcpClients.filter((c) => c.configured);
|
|
122
|
+
if (configured.length === 0) {
|
|
123
|
+
lines.push(" (none configured for keystoneui)");
|
|
124
|
+
} else {
|
|
125
|
+
for (const client of configured) {
|
|
126
|
+
lines.push(` ${pad(client.name)}${client.configPath}`);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
lines.push("");
|
|
130
|
+
lines.push("Installed @keystoneui packages");
|
|
131
|
+
if (data.installedPackages.length === 0) {
|
|
132
|
+
lines.push(" (none detected in this project)");
|
|
133
|
+
} else {
|
|
134
|
+
for (const pkg of data.installedPackages) {
|
|
135
|
+
lines.push(` ${pad(pkg.name, 28)}v${pkg.version}`);
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
lines.push("");
|
|
139
|
+
lines.push("Links");
|
|
140
|
+
lines.push(` ${pad("Docs")}${data.links.docs}`);
|
|
141
|
+
lines.push(` ${pad("Registry")}${data.links.registry}`);
|
|
142
|
+
lines.push(` ${pad("llms.txt")}${data.links.llms}`);
|
|
143
|
+
console.log(lines.join("\n"));
|
|
144
|
+
}
|
|
145
|
+
function runInfo(args) {
|
|
146
|
+
const json = args.includes("--json");
|
|
147
|
+
const data = collect();
|
|
148
|
+
if (json) {
|
|
149
|
+
console.log(JSON.stringify(data, null, 2));
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
printText(data);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
// src/init.ts
|
|
156
|
+
import { existsSync as existsSync2, mkdirSync, readFileSync as readFileSync2, writeFileSync } from "fs";
|
|
157
|
+
import { dirname, resolve as resolve2 } from "path";
|
|
158
|
+
var SERVER_ENTRY = {
|
|
159
|
+
command: "npx",
|
|
160
|
+
args: ["@keystoneui/mcp@latest"]
|
|
161
|
+
};
|
|
162
|
+
var CLIENTS = [
|
|
163
|
+
{
|
|
164
|
+
name: "claude",
|
|
165
|
+
configPath: ".mcp.json",
|
|
166
|
+
type: "json",
|
|
167
|
+
serverKey: "mcpServers",
|
|
168
|
+
config: { mcpServers: { keystoneui: SERVER_ENTRY } }
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: "cursor",
|
|
172
|
+
configPath: ".cursor/mcp.json",
|
|
173
|
+
type: "json",
|
|
174
|
+
serverKey: "mcpServers",
|
|
175
|
+
config: { mcpServers: { keystoneui: SERVER_ENTRY } }
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: "vscode",
|
|
179
|
+
configPath: ".vscode/mcp.json",
|
|
180
|
+
type: "json",
|
|
181
|
+
serverKey: "servers",
|
|
182
|
+
config: { servers: { keystoneui: SERVER_ENTRY } }
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
name: "codex",
|
|
186
|
+
configPath: "~/.codex/config.toml",
|
|
187
|
+
type: "toml",
|
|
188
|
+
serverKey: "",
|
|
189
|
+
config: {}
|
|
190
|
+
},
|
|
191
|
+
{
|
|
192
|
+
name: "opencode",
|
|
193
|
+
configPath: "opencode.json",
|
|
194
|
+
type: "json",
|
|
195
|
+
serverKey: "mcp",
|
|
196
|
+
config: {
|
|
197
|
+
mcp: {
|
|
198
|
+
keystoneui: {
|
|
199
|
+
type: "stdio",
|
|
200
|
+
...SERVER_ENTRY,
|
|
201
|
+
enabled: true
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
];
|
|
207
|
+
function parseArgs() {
|
|
208
|
+
const idx = process.argv.indexOf("--client");
|
|
209
|
+
if (idx === -1 || idx + 1 >= process.argv.length) {
|
|
210
|
+
return null;
|
|
211
|
+
}
|
|
212
|
+
return process.argv[idx + 1];
|
|
213
|
+
}
|
|
214
|
+
function mergeJsonConfig(existing, client) {
|
|
215
|
+
const key = client.serverKey;
|
|
216
|
+
const existingServers = existing[key] ?? {};
|
|
217
|
+
const newServers = client.config[key] ?? {};
|
|
218
|
+
return {
|
|
219
|
+
...existing,
|
|
220
|
+
[key]: { ...existingServers, ...newServers }
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
function writeJsonClient(client) {
|
|
224
|
+
const targetPath = resolve2(process.cwd(), client.configPath);
|
|
225
|
+
const dir = dirname(targetPath);
|
|
226
|
+
mkdirSync(dir, { recursive: true });
|
|
227
|
+
let existing = {};
|
|
228
|
+
if (existsSync2(targetPath)) {
|
|
229
|
+
try {
|
|
230
|
+
existing = JSON.parse(readFileSync2(targetPath, "utf-8"));
|
|
231
|
+
} catch {
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
const merged = mergeJsonConfig(existing, client);
|
|
235
|
+
writeFileSync(targetPath, `${JSON.stringify(merged, null, 2)}
|
|
236
|
+
`);
|
|
237
|
+
console.log(`Created ${client.configPath}`);
|
|
238
|
+
console.log(`Keystone UI MCP server configured for ${client.name}.`);
|
|
239
|
+
}
|
|
240
|
+
function printCodexInstructions() {
|
|
241
|
+
console.log("Codex uses a global TOML config that cannot be auto-written.");
|
|
242
|
+
console.log("");
|
|
243
|
+
console.log("Add the following to ~/.codex/config.toml:");
|
|
244
|
+
console.log("");
|
|
245
|
+
console.log(" [mcp_servers.keystoneui]");
|
|
246
|
+
console.log(' command = "npx"');
|
|
247
|
+
console.log(' args = ["@keystoneui/mcp@latest"]');
|
|
248
|
+
console.log("");
|
|
249
|
+
console.log("Then restart Codex.");
|
|
250
|
+
}
|
|
251
|
+
function printUsage() {
|
|
252
|
+
const names = CLIENTS.map((c) => c.name).join(", ");
|
|
253
|
+
console.log("Usage: npx @keystoneui/mcp init --client <name>");
|
|
254
|
+
console.log("");
|
|
255
|
+
console.log(`Supported clients: ${names}`);
|
|
256
|
+
console.log("");
|
|
257
|
+
console.log("Examples:");
|
|
258
|
+
console.log(" npx @keystoneui/mcp init --client cursor");
|
|
259
|
+
console.log(" npx @keystoneui/mcp init --client claude");
|
|
260
|
+
console.log(" npx @keystoneui/mcp init --client vscode");
|
|
261
|
+
}
|
|
262
|
+
function init() {
|
|
263
|
+
const clientName = parseArgs();
|
|
264
|
+
if (!clientName) {
|
|
265
|
+
printUsage();
|
|
266
|
+
process.exitCode = 1;
|
|
267
|
+
return;
|
|
268
|
+
}
|
|
269
|
+
const client = CLIENTS.find((c) => c.name === clientName);
|
|
270
|
+
if (!client) {
|
|
271
|
+
console.error(`Unknown client: "${clientName}"`);
|
|
272
|
+
console.error("");
|
|
273
|
+
printUsage();
|
|
274
|
+
process.exitCode = 1;
|
|
275
|
+
return;
|
|
276
|
+
}
|
|
277
|
+
if (client.type === "toml") {
|
|
278
|
+
printCodexInstructions();
|
|
279
|
+
return;
|
|
280
|
+
}
|
|
281
|
+
writeJsonClient(client);
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
// src/cli.ts
|
|
285
|
+
var VERBS = [
|
|
286
|
+
"init",
|
|
287
|
+
"info",
|
|
288
|
+
"search",
|
|
289
|
+
"list",
|
|
290
|
+
"view",
|
|
291
|
+
"examples",
|
|
292
|
+
"docs",
|
|
293
|
+
"audit",
|
|
294
|
+
"blocks"
|
|
295
|
+
];
|
|
296
|
+
var BLOCK_NAME_PATTERN = /^[a-z0-9-]+$/;
|
|
297
|
+
function isCliVerb(arg) {
|
|
298
|
+
return arg !== void 0 && VERBS.includes(arg);
|
|
299
|
+
}
|
|
300
|
+
function parseArgs2(args) {
|
|
301
|
+
const flags = {};
|
|
302
|
+
const positional = [];
|
|
303
|
+
for (let i = 0; i < args.length; i++) {
|
|
304
|
+
const arg = args[i];
|
|
305
|
+
if (arg.startsWith("--")) {
|
|
306
|
+
const key = arg.slice(2);
|
|
307
|
+
const next = args[i + 1];
|
|
308
|
+
if (next !== void 0 && !next.startsWith("--")) {
|
|
309
|
+
flags[key] = next;
|
|
310
|
+
i++;
|
|
311
|
+
} else {
|
|
312
|
+
flags[key] = "true";
|
|
313
|
+
}
|
|
314
|
+
} else {
|
|
315
|
+
positional.push(arg);
|
|
316
|
+
}
|
|
317
|
+
}
|
|
318
|
+
return { flags, positional };
|
|
319
|
+
}
|
|
320
|
+
function parseType(value) {
|
|
321
|
+
if (value === void 0) {
|
|
322
|
+
return;
|
|
323
|
+
}
|
|
324
|
+
if (value === "ui" || value === "block" || value === "example") {
|
|
325
|
+
return value;
|
|
326
|
+
}
|
|
327
|
+
throw new Error(
|
|
328
|
+
`Invalid --type value "${value}". Expected one of: ui, block, example.`
|
|
329
|
+
);
|
|
330
|
+
}
|
|
331
|
+
function parseInt10(value, fallback) {
|
|
332
|
+
if (value === void 0) {
|
|
333
|
+
return fallback;
|
|
334
|
+
}
|
|
335
|
+
const n = Number.parseInt(value, 10);
|
|
336
|
+
if (Number.isNaN(n)) {
|
|
337
|
+
throw new Error(`Expected an integer, got "${value}".`);
|
|
338
|
+
}
|
|
339
|
+
return n;
|
|
340
|
+
}
|
|
341
|
+
function printUsage2() {
|
|
342
|
+
console.log("Usage: keystoneui <verb> [args]");
|
|
343
|
+
console.log("");
|
|
344
|
+
console.log("Verbs:");
|
|
345
|
+
console.log(" init [--client <name>] Configure MCP client");
|
|
346
|
+
console.log(
|
|
347
|
+
" info [--json] Print env diagnostic (registry, MCP clients, installed packages)"
|
|
348
|
+
);
|
|
349
|
+
console.log(" search <query> [--type T] [--category C] [--limit N]");
|
|
350
|
+
console.log(
|
|
351
|
+
" Fuzzy search components, blocks, examples"
|
|
352
|
+
);
|
|
353
|
+
console.log(" list [--type T] [--category C] [--limit N] [--offset N]");
|
|
354
|
+
console.log(
|
|
355
|
+
" List items (T = ui|block|example)"
|
|
356
|
+
);
|
|
357
|
+
console.log(" view <name> [<name>...] Show component source");
|
|
358
|
+
console.log(
|
|
359
|
+
" examples <name> Show all demos for a component/block"
|
|
360
|
+
);
|
|
361
|
+
console.log(
|
|
362
|
+
" docs <name> Fetch /llms.mdx/docs/components/<name>"
|
|
363
|
+
);
|
|
364
|
+
console.log(
|
|
365
|
+
" audit Print post-install checklist"
|
|
366
|
+
);
|
|
367
|
+
console.log(
|
|
368
|
+
" blocks [<filter>] [--category C] List or filter full-page blocks"
|
|
369
|
+
);
|
|
370
|
+
console.log("");
|
|
371
|
+
console.log("Without a verb, launches the MCP stdio server.");
|
|
372
|
+
}
|
|
373
|
+
async function runSearch(args) {
|
|
374
|
+
const { flags, positional } = parseArgs2(args);
|
|
375
|
+
if (positional.length === 0) {
|
|
376
|
+
console.error(
|
|
377
|
+
"Usage: keystoneui search <query> [--type ui|block|example] [--category C] [--limit N]"
|
|
378
|
+
);
|
|
379
|
+
process.exitCode = 1;
|
|
380
|
+
return;
|
|
381
|
+
}
|
|
382
|
+
const query = positional.join(" ");
|
|
383
|
+
const type = parseType(flags.type);
|
|
384
|
+
const category = flags.category;
|
|
385
|
+
const limit = parseInt10(flags.limit, 10);
|
|
386
|
+
const config = loadProjectConfig();
|
|
387
|
+
const text = await searchComponentsTool(config, {
|
|
388
|
+
query,
|
|
389
|
+
limit,
|
|
390
|
+
type,
|
|
391
|
+
category
|
|
392
|
+
});
|
|
393
|
+
console.log(text);
|
|
394
|
+
}
|
|
395
|
+
async function runList(args) {
|
|
396
|
+
const { flags } = parseArgs2(args);
|
|
397
|
+
const type = parseType(flags.type);
|
|
398
|
+
const category = flags.category;
|
|
399
|
+
const limit = parseInt10(flags.limit, 20);
|
|
400
|
+
const offset = parseInt10(flags.offset, 0);
|
|
401
|
+
const config = loadProjectConfig();
|
|
402
|
+
const text = await listComponentsTool(config, {
|
|
403
|
+
limit,
|
|
404
|
+
offset,
|
|
405
|
+
type,
|
|
406
|
+
category
|
|
407
|
+
});
|
|
408
|
+
console.log(text);
|
|
409
|
+
}
|
|
410
|
+
async function runView(args) {
|
|
411
|
+
const { positional } = parseArgs2(args);
|
|
412
|
+
if (positional.length === 0) {
|
|
413
|
+
console.error("Usage: keystoneui view <name> [<name>...]");
|
|
414
|
+
process.exitCode = 1;
|
|
415
|
+
return;
|
|
416
|
+
}
|
|
417
|
+
const config = loadProjectConfig();
|
|
418
|
+
const text = await viewComponentTool(config, { names: positional });
|
|
419
|
+
console.log(text);
|
|
420
|
+
}
|
|
421
|
+
async function runExamples(args) {
|
|
422
|
+
const { positional } = parseArgs2(args);
|
|
423
|
+
if (positional.length === 0) {
|
|
424
|
+
console.error("Usage: keystoneui examples <name>");
|
|
425
|
+
process.exitCode = 1;
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
const config = loadProjectConfig();
|
|
429
|
+
const text = await getExamplesTool(config, { name: positional[0] });
|
|
430
|
+
console.log(text);
|
|
431
|
+
}
|
|
432
|
+
async function runDocs(args) {
|
|
433
|
+
const { positional } = parseArgs2(args);
|
|
434
|
+
if (positional.length === 0) {
|
|
435
|
+
console.error("Usage: keystoneui docs <name>");
|
|
436
|
+
process.exitCode = 1;
|
|
437
|
+
return;
|
|
438
|
+
}
|
|
439
|
+
const name = positional[0];
|
|
440
|
+
const siteUrl = process.env.KEYSTONEUI_URL ?? "https://keystoneui.io";
|
|
441
|
+
const url = `${siteUrl}/llms.mdx/docs/components/${name}`;
|
|
442
|
+
const response = await fetch(url, {
|
|
443
|
+
headers: { "User-Agent": "keystoneui-cli/0.1" }
|
|
444
|
+
});
|
|
445
|
+
if (!response.ok) {
|
|
446
|
+
console.error(
|
|
447
|
+
`Failed to fetch ${url}: ${response.status} ${response.statusText}`
|
|
448
|
+
);
|
|
449
|
+
process.exitCode = 1;
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
console.log(await response.text());
|
|
453
|
+
}
|
|
454
|
+
function runAudit() {
|
|
455
|
+
console.log(auditChecklistTool());
|
|
456
|
+
}
|
|
457
|
+
async function runBlocks(args) {
|
|
458
|
+
const { flags, positional } = parseArgs2(args);
|
|
459
|
+
const config = loadProjectConfig();
|
|
460
|
+
const category = flags.category;
|
|
461
|
+
if (positional.length === 0) {
|
|
462
|
+
const text2 = await listComponentsTool(config, {
|
|
463
|
+
limit: 100,
|
|
464
|
+
offset: 0,
|
|
465
|
+
type: "block",
|
|
466
|
+
category
|
|
467
|
+
});
|
|
468
|
+
console.log(text2);
|
|
469
|
+
return;
|
|
470
|
+
}
|
|
471
|
+
const filter = positional.join(" ");
|
|
472
|
+
if (positional.length === 1 && BLOCK_NAME_PATTERN.test(filter) && filter.includes("-")) {
|
|
473
|
+
const text2 = await viewComponentTool(config, { names: [filter] });
|
|
474
|
+
console.log(text2);
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
const text = await searchComponentsTool(config, {
|
|
478
|
+
query: filter,
|
|
479
|
+
limit: 20,
|
|
480
|
+
type: "block",
|
|
481
|
+
category
|
|
482
|
+
});
|
|
483
|
+
console.log(text);
|
|
484
|
+
}
|
|
485
|
+
async function runCli(args) {
|
|
486
|
+
const verb = args[0];
|
|
487
|
+
const rest = args.slice(1);
|
|
488
|
+
if (verb === "--help" || verb === "-h" || verb === "help") {
|
|
489
|
+
printUsage2();
|
|
490
|
+
return;
|
|
491
|
+
}
|
|
492
|
+
if (!isCliVerb(verb)) {
|
|
493
|
+
console.error(`Unknown verb: "${verb}".`);
|
|
494
|
+
console.error("");
|
|
495
|
+
printUsage2();
|
|
496
|
+
process.exitCode = 1;
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
switch (verb) {
|
|
500
|
+
case "init":
|
|
501
|
+
init();
|
|
502
|
+
return;
|
|
503
|
+
case "info":
|
|
504
|
+
runInfo(rest);
|
|
505
|
+
return;
|
|
506
|
+
case "search":
|
|
507
|
+
await runSearch(rest);
|
|
508
|
+
return;
|
|
509
|
+
case "list":
|
|
510
|
+
await runList(rest);
|
|
511
|
+
return;
|
|
512
|
+
case "view":
|
|
513
|
+
await runView(rest);
|
|
514
|
+
return;
|
|
515
|
+
case "examples":
|
|
516
|
+
await runExamples(rest);
|
|
517
|
+
return;
|
|
518
|
+
case "docs":
|
|
519
|
+
await runDocs(rest);
|
|
520
|
+
return;
|
|
521
|
+
case "audit":
|
|
522
|
+
runAudit();
|
|
523
|
+
return;
|
|
524
|
+
case "blocks":
|
|
525
|
+
await runBlocks(rest);
|
|
526
|
+
return;
|
|
527
|
+
default: {
|
|
528
|
+
const exhaustive = verb;
|
|
529
|
+
throw new Error(`Unhandled verb: ${exhaustive}`);
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
}
|
|
533
|
+
|
|
534
|
+
// src/index.ts
|
|
535
|
+
var verbCandidate = process.argv[2];
|
|
536
|
+
if (verbCandidate === "--help" || verbCandidate === "-h" || verbCandidate === "help") {
|
|
537
|
+
await runCli(process.argv.slice(2));
|
|
538
|
+
process.exit();
|
|
539
|
+
}
|
|
540
|
+
if (isCliVerb(verbCandidate)) {
|
|
541
|
+
await runCli(process.argv.slice(2));
|
|
542
|
+
process.exit();
|
|
543
|
+
}
|
|
544
|
+
var { StdioServerTransport } = await import("@modelcontextprotocol/sdk/server/stdio.js");
|
|
545
|
+
var { server } = await import("./server-5ZV7UIUD.js");
|
|
546
|
+
var transport = new StdioServerTransport();
|
|
547
|
+
await server.connect(transport);
|
|
@@ -0,0 +1,137 @@
|
|
|
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
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@keystoneui/mcp",
|
|
3
|
+
"version": "0.2.0-beta.1",
|
|
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
|
+
"type": "module",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"keystoneui",
|
|
9
|
+
"mcp",
|
|
10
|
+
"model-context-protocol",
|
|
11
|
+
"ai",
|
|
12
|
+
"shadcn",
|
|
13
|
+
"registry",
|
|
14
|
+
"components",
|
|
15
|
+
"react",
|
|
16
|
+
"tailwindcss",
|
|
17
|
+
"base-ui"
|
|
18
|
+
],
|
|
19
|
+
"bin": {
|
|
20
|
+
"keystoneui-mcp": "./dist/index.js",
|
|
21
|
+
"keystoneui": "./dist/index.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"dist",
|
|
25
|
+
"README.md"
|
|
26
|
+
],
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
29
|
+
"fuzzysort": "^3.1.0",
|
|
30
|
+
"zod": "^4.3.6"
|
|
31
|
+
},
|
|
32
|
+
"devDependencies": {
|
|
33
|
+
"@types/node": "^25.6.0",
|
|
34
|
+
"tsup": "^8.5.0",
|
|
35
|
+
"typescript": "^6.0.3",
|
|
36
|
+
"@keystoneui/typescript-config": "0.0.0"
|
|
37
|
+
},
|
|
38
|
+
"publishConfig": {
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"scripts": {
|
|
42
|
+
"build": "tsup",
|
|
43
|
+
"dev": "tsup --watch",
|
|
44
|
+
"clean": "rm -rf dist node_modules"
|
|
45
|
+
}
|
|
46
|
+
}
|