@primecoderin/fast-ui-react-mcp 0.0.0-stage → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +66 -3
- package/catalog.json +15183 -0
- package/dist/catalog.js +2 -0
- package/dist/server.js +92 -0
- package/dist/tools.js +282 -0
- package/package.json +49 -6
package/dist/catalog.js
ADDED
package/dist/server.js
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// The MCP server: it answers a coding assistant's questions about @primecoderin/fast-ui-react (what to import, every
|
|
3
|
+
// component's exact props, the tokens, setup and theming guides, tested examples) over stdio. Everything comes
|
|
4
|
+
// from catalog.json, generated from the library's source. stdout is the protocol channel, so nothing else may
|
|
5
|
+
// write to it; diagnostics go to stderr.
|
|
6
|
+
import { readFileSync } from "node:fs";
|
|
7
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
8
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
9
|
+
import { z } from "zod";
|
|
10
|
+
import { createTools, EXPORT_KINDS } from "./tools.js";
|
|
11
|
+
const catalog = JSON.parse(readFileSync(new URL("../catalog.json", import.meta.url), "utf8"));
|
|
12
|
+
const tools = createTools(catalog);
|
|
13
|
+
const server = new McpServer({ name: "fast-ui", title: `${catalog.package} docs`, version: catalog.version }, {
|
|
14
|
+
instructions: [
|
|
15
|
+
`Use this server whenever you write, review or explain code that uses ${catalog.package}.`,
|
|
16
|
+
"Start with get_overview. Before using a component, call get_export: it lists every prop with its exact type",
|
|
17
|
+
"and default, so never invent props or guess names. Copy patterns from get_examples (tested stories).",
|
|
18
|
+
"For colours, radii, shadows and type sizes use the design-token utilities from list_tokens, never raw values.",
|
|
19
|
+
"Setup, Next.js, theming and white label, CSP nonce, forms, conventions and testing: list_guides, get_guide.",
|
|
20
|
+
].join(" "),
|
|
21
|
+
});
|
|
22
|
+
const text = (body) => ({ content: [{ type: "text", text: body }] });
|
|
23
|
+
const READ_ONLY = { readOnlyHint: true, openWorldHint: false };
|
|
24
|
+
server.registerTool("get_overview", {
|
|
25
|
+
title: "Overview and setup",
|
|
26
|
+
description: `What ${catalog.package} is, how to install and set it up, its entries, and how to use these tools. Call this first.`,
|
|
27
|
+
annotations: READ_ONLY,
|
|
28
|
+
}, () => text(tools.overview()));
|
|
29
|
+
server.registerTool("list_exports", {
|
|
30
|
+
title: "List exports",
|
|
31
|
+
description: "Every export of the package (components, hooks, functions, types, constants), with where to import it from and a one-line description.",
|
|
32
|
+
inputSchema: {
|
|
33
|
+
kind: z.enum(EXPORT_KINDS).optional().describe("Only this kind, e.g. component."),
|
|
34
|
+
entry: z.enum(["main", "forms", "charts", "editor", "editor-forms"]).optional().describe("main is the package; forms is its /forms entry (react-hook-form fields); charts is its /charts entry (needs recharts); editor is the rich text editor (needs TipTap); editor-forms is its react-hook-form field."),
|
|
35
|
+
},
|
|
36
|
+
annotations: READ_ONLY,
|
|
37
|
+
}, ({ kind, entry }) => text(tools.listExports({ kind, entry })));
|
|
38
|
+
server.registerTool("get_export", {
|
|
39
|
+
title: "Get an export's API",
|
|
40
|
+
description: "Everything about one export: import line, description, and for a component every prop with its type, whether it is required, its default and its doc, plus the types its props use. Call before using a component.",
|
|
41
|
+
inputSchema: { name: z.string().min(1).describe("The export's name, e.g. Button, createTheme, DesignSystemProvider.") },
|
|
42
|
+
annotations: READ_ONLY,
|
|
43
|
+
}, ({ name }) => text(tools.getExport(name)));
|
|
44
|
+
server.registerTool("get_examples", {
|
|
45
|
+
title: "Get tested examples",
|
|
46
|
+
description: "The library's tested usage of a component (its Storybook stories, full source), to copy patterns from.",
|
|
47
|
+
inputSchema: {
|
|
48
|
+
name: z.string().min(1).describe("The component's name, e.g. Dialog."),
|
|
49
|
+
limit: z.number().int().min(1).max(5).optional().describe("How many example files (default 2)."),
|
|
50
|
+
},
|
|
51
|
+
annotations: READ_ONLY,
|
|
52
|
+
}, ({ name, limit }) => text(tools.getExamples(name, limit)));
|
|
53
|
+
server.registerTool("list_tokens", {
|
|
54
|
+
title: "List design tokens",
|
|
55
|
+
description: "The design tokens (colours, font, radii, shadows, type scale) with their light, dark and right-to-left values and the Tailwind utility that reads each. Every token can be changed per tenant with createTheme.",
|
|
56
|
+
inputSchema: {
|
|
57
|
+
group: z.string().optional().describe("Only tokens whose group contains this, e.g. radius, tones, text."),
|
|
58
|
+
query: z.string().optional().describe("Only tokens whose name or note contains this, e.g. primary."),
|
|
59
|
+
},
|
|
60
|
+
annotations: READ_ONLY,
|
|
61
|
+
}, ({ group, query }) => text(tools.listTokens({ group, query })));
|
|
62
|
+
server.registerTool("list_guides", {
|
|
63
|
+
title: "List guides",
|
|
64
|
+
description: "The setup and usage guides: getting started, Next.js, theming and white label, CSP nonce, forms, prop conventions, the date picker, apps with their own Tailwind, testing, design principles.",
|
|
65
|
+
annotations: READ_ONLY,
|
|
66
|
+
}, () => text(tools.listGuides()));
|
|
67
|
+
server.registerTool("get_guide", {
|
|
68
|
+
title: "Get a guide",
|
|
69
|
+
description: "One guide in full. Topics come from list_guides; aliases such as setup, nextjs, theming, white-label, csp, forms, conventions, rtl and testing work too.",
|
|
70
|
+
inputSchema: { topic: z.string().min(1).describe("The guide's topic, e.g. getting-started or theming.") },
|
|
71
|
+
annotations: READ_ONLY,
|
|
72
|
+
}, ({ topic }) => text(tools.getGuide(topic)));
|
|
73
|
+
server.registerTool("search_docs", {
|
|
74
|
+
title: "Search the docs",
|
|
75
|
+
description: "Search exports (names, descriptions, props), guides and tokens by keywords, e.g. \"date picker\", \"dark theme\", \"toast\".",
|
|
76
|
+
inputSchema: {
|
|
77
|
+
query: z.string().min(1).describe("One or more keywords."),
|
|
78
|
+
limit: z.number().int().min(1).max(50).optional().describe("Most results to return (default 12)."),
|
|
79
|
+
},
|
|
80
|
+
annotations: READ_ONLY,
|
|
81
|
+
}, ({ query, limit }) => text(tools.search(query, limit)));
|
|
82
|
+
// The guides as resources too, for clients that browse resources.
|
|
83
|
+
for (const guide of catalog.guides) {
|
|
84
|
+
server.registerResource(guide.topic, `fast-ui://guides/${guide.topic}`, { title: guide.title, description: `${catalog.package}: ${guide.title}`, mimeType: "text/markdown" }, (uri) => ({ contents: [{ uri: uri.href, mimeType: "text/markdown", text: tools.getGuide(guide.topic) }] }));
|
|
85
|
+
}
|
|
86
|
+
try {
|
|
87
|
+
await server.connect(new StdioServerTransport());
|
|
88
|
+
}
|
|
89
|
+
catch (error) {
|
|
90
|
+
console.error("fast-ui MCP server failed to start:", error);
|
|
91
|
+
process.exitCode = 1;
|
|
92
|
+
}
|
package/dist/tools.js
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
/** What each optional peer dependency is for, and the entry that needs it: only an app that imports that entry installs it. */
|
|
2
|
+
const OPTIONAL_PEER_USE = {
|
|
3
|
+
"react-hook-form": "the form fields",
|
|
4
|
+
recharts: "the charts",
|
|
5
|
+
"@tiptap/core": "the rich text editor",
|
|
6
|
+
"@tiptap/pm": "the rich text editor",
|
|
7
|
+
"@tiptap/react": "the rich text editor",
|
|
8
|
+
"@tiptap/starter-kit": "the rich text editor",
|
|
9
|
+
};
|
|
10
|
+
const OPTIONAL_PEER_ENTRY = {
|
|
11
|
+
"react-hook-form": "forms",
|
|
12
|
+
recharts: "charts",
|
|
13
|
+
"@tiptap/core": "editor",
|
|
14
|
+
"@tiptap/pm": "editor",
|
|
15
|
+
"@tiptap/react": "editor",
|
|
16
|
+
"@tiptap/starter-kit": "editor",
|
|
17
|
+
};
|
|
18
|
+
/** The install lines for the optional peers, one for each use: the packages that serve it go on one line. */
|
|
19
|
+
const optionalInstallLines = (packageName, optional) => {
|
|
20
|
+
const uses = [...new Set(optional.map((name) => OPTIONAL_PEER_USE[name] ?? "the entries that use it"))];
|
|
21
|
+
return uses.map((use) => {
|
|
22
|
+
const names = optional.filter((name) => (OPTIONAL_PEER_USE[name] ?? "the entries that use it") === use);
|
|
23
|
+
const entry = OPTIONAL_PEER_ENTRY[names[0] ?? ""];
|
|
24
|
+
return `npm install ${names.join(" ")} # only for ${use}${entry ? ` (${packageName}/${entry})` : ""}`;
|
|
25
|
+
});
|
|
26
|
+
};
|
|
27
|
+
export const EXPORT_KINDS = ["component", "hook", "function", "type", "constant", "namespace"];
|
|
28
|
+
/** Friendlier names for guide topics; the slugs are the file names in docs/. */
|
|
29
|
+
const TOPIC_ALIASES = {
|
|
30
|
+
setup: "getting-started",
|
|
31
|
+
install: "getting-started",
|
|
32
|
+
"next-js": "nextjs",
|
|
33
|
+
next: "nextjs",
|
|
34
|
+
theme: "theming",
|
|
35
|
+
tokens: "theming",
|
|
36
|
+
"white-label": "theming",
|
|
37
|
+
branding: "theming",
|
|
38
|
+
csp: "theming",
|
|
39
|
+
nonce: "theming",
|
|
40
|
+
"own-tailwind": "theming",
|
|
41
|
+
tailwind: "theming",
|
|
42
|
+
"prop-conventions": "conventions",
|
|
43
|
+
styling: "customization",
|
|
44
|
+
styles: "customization",
|
|
45
|
+
customize: "customization",
|
|
46
|
+
types: "typescript",
|
|
47
|
+
ts: "typescript",
|
|
48
|
+
"date-time-picker": "dates-files-data",
|
|
49
|
+
dates: "dates-files-data",
|
|
50
|
+
files: "dates-files-data",
|
|
51
|
+
layout: "layout-and-navigation",
|
|
52
|
+
rtl: "internationalization",
|
|
53
|
+
i18n: "internationalization",
|
|
54
|
+
translation: "internationalization",
|
|
55
|
+
a11y: "accessibility",
|
|
56
|
+
browsers: "browser-support",
|
|
57
|
+
build: "architecture",
|
|
58
|
+
publish: "releasing",
|
|
59
|
+
troubleshooting: "faq",
|
|
60
|
+
mcp: "ai-assistants",
|
|
61
|
+
testing: "testing-apps",
|
|
62
|
+
principles: "design-principles",
|
|
63
|
+
};
|
|
64
|
+
/** The first sentence of a description, for one-line listings ("e.g." and "i.e." do not end it). */
|
|
65
|
+
const firstSentence = (text) => {
|
|
66
|
+
const flat = text.replace(/\s+/g, " ").trim();
|
|
67
|
+
const end = flat.search(/(?<!\be\.g|\bi\.e)\.(\s|$)/);
|
|
68
|
+
return end === -1 ? flat : flat.slice(0, end + 1);
|
|
69
|
+
};
|
|
70
|
+
/** Text safe inside a Markdown table cell. */
|
|
71
|
+
const cell = (text) => (text ?? "").replace(/\|/g, "\\|").replace(/\s*\n\s*/g, " ").trim();
|
|
72
|
+
const levenshtein = (a, b) => {
|
|
73
|
+
const row = Array.from({ length: b.length + 1 }, (_, i) => i);
|
|
74
|
+
for (let i = 1; i <= a.length; i += 1) {
|
|
75
|
+
let previous = row[0] ?? 0;
|
|
76
|
+
row[0] = i;
|
|
77
|
+
for (let j = 1; j <= b.length; j += 1) {
|
|
78
|
+
const current = row[j] ?? 0;
|
|
79
|
+
row[j] = Math.min((row[j] ?? 0) + 1, (row[j - 1] ?? 0) + 1, previous + (a[i - 1] === b[j - 1] ? 0 : 1));
|
|
80
|
+
previous = current;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
return row[b.length] ?? 0;
|
|
84
|
+
};
|
|
85
|
+
/** Names close to `wanted`, for a helpful "not found". */
|
|
86
|
+
const suggest = (wanted, names) => {
|
|
87
|
+
const lower = wanted.toLowerCase();
|
|
88
|
+
return names
|
|
89
|
+
.map((name) => ({ name, score: name.toLowerCase().includes(lower) || lower.includes(name.toLowerCase()) ? 0 : levenshtein(lower, name.toLowerCase()) }))
|
|
90
|
+
.filter((entry) => entry.score <= Math.max(2, Math.floor(wanted.length / 3)))
|
|
91
|
+
.sort((a, b) => a.score - b.score || a.name.localeCompare(b.name))
|
|
92
|
+
.slice(0, 5)
|
|
93
|
+
.map((entry) => entry.name);
|
|
94
|
+
};
|
|
95
|
+
export const createTools = (catalog) => {
|
|
96
|
+
const byName = new Map(catalog.exports.map((item) => [item.name, item]));
|
|
97
|
+
const exportNames = catalog.exports.map((item) => item.name);
|
|
98
|
+
const findExport = (name) => byName.get(name) ?? catalog.exports.find((item) => item.name.toLowerCase() === name.trim().toLowerCase());
|
|
99
|
+
const findGuide = (topic) => {
|
|
100
|
+
const key = topic.trim().toLowerCase();
|
|
101
|
+
const resolved = TOPIC_ALIASES[key] ?? key;
|
|
102
|
+
return catalog.guides.find((guide) => guide.topic === resolved);
|
|
103
|
+
};
|
|
104
|
+
const notFound = (what, name, names, listTool) => {
|
|
105
|
+
const close = suggest(name, names);
|
|
106
|
+
return [
|
|
107
|
+
`No ${what} named "${name}" in ${catalog.package}.`,
|
|
108
|
+
close.length > 0 ? `Did you mean: ${close.map((n) => `\`${n}\``).join(", ")}?` : "",
|
|
109
|
+
`Use \`${listTool}\` to see them all.`,
|
|
110
|
+
]
|
|
111
|
+
.filter(Boolean)
|
|
112
|
+
.join("\n");
|
|
113
|
+
};
|
|
114
|
+
const overview = () => {
|
|
115
|
+
const peers = Object.entries(catalog.peerDependencies)
|
|
116
|
+
.filter(([name]) => !catalog.optionalPeerDependencies.includes(name))
|
|
117
|
+
.map(([name]) => name);
|
|
118
|
+
const counts = EXPORT_KINDS.map((kind) => `${catalog.exports.filter((e) => e.kind === kind).length} ${kind}s`).join(", ");
|
|
119
|
+
return [
|
|
120
|
+
`# ${catalog.package} ${catalog.version}`,
|
|
121
|
+
"",
|
|
122
|
+
"A React 19 design system: accessible components on Base UI, styled with Tailwind CSS 4, themed by runtime CSS",
|
|
123
|
+
"variables (light, dark, right to left, white-label tenants). Works in React apps and in Next.js (App Router and",
|
|
124
|
+
"Pages Router; component modules are Client Components, the pure helpers run on the server).",
|
|
125
|
+
"",
|
|
126
|
+
"## Install",
|
|
127
|
+
"```bash",
|
|
128
|
+
`npm install ${catalog.package} ${peers.join(" ")}`,
|
|
129
|
+
...optionalInstallLines(catalog.package, catalog.optionalPeerDependencies),
|
|
130
|
+
"```",
|
|
131
|
+
"",
|
|
132
|
+
"## Set up (once per app)",
|
|
133
|
+
`1. Import the stylesheet at the app's entry: \`import "${catalog.package}/styles.css";\` It brings the tokens, every class the components use and the Inter font (self-hosted; no <link> to add).`,
|
|
134
|
+
"2. Wrap the app in `<DesignSystemProvider themeMode=\"light\" direction=\"ltr\">` (theme, direction, tenant theme, toasts, CSP nonce).",
|
|
135
|
+
"Details: `get_guide` with topic `getting-started`, `nextjs`, `theming`, `csp`, `forms` or `conventions`.",
|
|
136
|
+
"",
|
|
137
|
+
"## Entries",
|
|
138
|
+
...catalog.entries.map((entry) => `- \`${entry.importPath}\` (${entry.entry})`),
|
|
139
|
+
"",
|
|
140
|
+
`## What is in it\n${counts}, ${catalog.tokens.length} design tokens, ${catalog.guides.length} guides.`,
|
|
141
|
+
"",
|
|
142
|
+
"## How to use this server",
|
|
143
|
+
"- `list_exports` (filter by kind) or `search_docs` to find what to use.",
|
|
144
|
+
"- `get_export` before using a component: its props are exact; do not invent others.",
|
|
145
|
+
"- `get_examples` for tested usage of a component.",
|
|
146
|
+
"- `list_tokens` for colours, radii, shadows and type sizes and the Tailwind utility of each.",
|
|
147
|
+
"- `list_guides` / `get_guide` for setup, Next.js, theming and white label, CSP, forms, conventions, testing.",
|
|
148
|
+
].join("\n");
|
|
149
|
+
};
|
|
150
|
+
const listExports = (filter) => {
|
|
151
|
+
const items = catalog.exports.filter((item) => (!filter.kind || item.kind === filter.kind) && (!filter.entry || item.entry === filter.entry));
|
|
152
|
+
if (items.length === 0)
|
|
153
|
+
return "Nothing matches that filter.";
|
|
154
|
+
return [
|
|
155
|
+
`${items.length} export${items.length === 1 ? "" : "s"}${filter.kind ? ` of kind ${filter.kind}` : ""}${filter.entry ? ` in the ${filter.entry} entry` : ""}:`,
|
|
156
|
+
"",
|
|
157
|
+
"| Name | Kind | Import from | What it is |",
|
|
158
|
+
"| --- | --- | --- | --- |",
|
|
159
|
+
...items.map((item) => `| \`${item.name}\` | ${item.kind} | \`${item.entry === "main" ? catalog.package : `${catalog.package}/${item.entry}`}\` | ${cell(firstSentence(item.description)) || "—"} |`),
|
|
160
|
+
].join("\n");
|
|
161
|
+
};
|
|
162
|
+
const typeDeclarations = (names) => names.flatMap((name) => {
|
|
163
|
+
const type = byName.get(name);
|
|
164
|
+
return type?.declaration ? ["```ts", type.declaration, "```"] : [];
|
|
165
|
+
});
|
|
166
|
+
const examplesFor = (name) => {
|
|
167
|
+
const primary = catalog.examples.filter((example) => example.component === name);
|
|
168
|
+
const others = catalog.examples.filter((example) => example.component !== name && example.uses.includes(name));
|
|
169
|
+
return [...primary, ...others];
|
|
170
|
+
};
|
|
171
|
+
const getExport = (name) => {
|
|
172
|
+
const item = findExport(name);
|
|
173
|
+
if (!item)
|
|
174
|
+
return notFound("export", name, exportNames, "list_exports");
|
|
175
|
+
const lines = [`# ${item.name} (${item.kind})`, "", "```ts", item.import, "```", ""];
|
|
176
|
+
if (item.description)
|
|
177
|
+
lines.push(item.description, "");
|
|
178
|
+
if (item.client !== undefined) {
|
|
179
|
+
lines.push(item.client
|
|
180
|
+
? "Client Component (\"use client\"): render it anywhere; in Next.js, pass it only serializable props from a Server Component (no functions)."
|
|
181
|
+
: "Not a Client Component: it can run on the server, e.g. in a Next.js Server Component.", "");
|
|
182
|
+
}
|
|
183
|
+
if (item.clientParent && item.clientParent.length > 0) {
|
|
184
|
+
const names = item.clientParent.map((name) => `\`${name}\``).join(", ");
|
|
185
|
+
lines.push(`Render it from a Client Component: its required ${names} cannot be passed from a Server Component (functions and react-hook-form's \`control\` are not serializable).`, "");
|
|
186
|
+
}
|
|
187
|
+
if (item.kind === "component" && item.props) {
|
|
188
|
+
lines.push("## Props", "", "| Prop | Type | Required | Default | Description |", "| --- | --- | --- | --- | --- |");
|
|
189
|
+
for (const prop of item.props) {
|
|
190
|
+
lines.push(`| \`${prop.name}\` | \`${cell(prop.type)}\` | ${prop.required ? "yes" : "no"} | ${prop.default ? `\`${cell(prop.default)}\`` : ""} | ${cell(prop.description)} |`);
|
|
191
|
+
}
|
|
192
|
+
lines.push("", "Only these props exist; anything else is a type error.");
|
|
193
|
+
if (item.relatedTypes && item.relatedTypes.length > 0) {
|
|
194
|
+
lines.push("", "## Types used by the props", "", ...typeDeclarations(item.relatedTypes));
|
|
195
|
+
}
|
|
196
|
+
const examples = examplesFor(item.name);
|
|
197
|
+
if (examples.length > 0) {
|
|
198
|
+
lines.push("", `## Examples\n${examples.length} tested example file(s): ${examples.slice(0, 5).map((e) => `\`${e.file}\``).join(", ")}. Call \`get_examples\` with this name to read them.`);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
if (item.signatures)
|
|
202
|
+
lines.push("## Signature", "", "```ts", ...item.signatures.map((s) => `${item.name}${s}`), "```");
|
|
203
|
+
if (item.declaration)
|
|
204
|
+
lines.push("## Declaration", "", "```ts", item.declaration, "```");
|
|
205
|
+
if (item.type)
|
|
206
|
+
lines.push("## Type", "", "```ts", item.type, "```");
|
|
207
|
+
if (item.members)
|
|
208
|
+
lines.push("## Members", "", item.members.map((m) => `\`${m}\``).join(", "));
|
|
209
|
+
lines.push("", `Source: \`${item.source}\``);
|
|
210
|
+
return lines.join("\n");
|
|
211
|
+
};
|
|
212
|
+
const getExamples = (name, limit = 2) => {
|
|
213
|
+
const item = findExport(name);
|
|
214
|
+
if (!item)
|
|
215
|
+
return notFound("export", name, exportNames, "list_exports");
|
|
216
|
+
const examples = examplesFor(item.name).slice(0, limit);
|
|
217
|
+
if (examples.length === 0)
|
|
218
|
+
return `No example file uses \`${item.name}\` yet. Its props: call \`get_export\`.`;
|
|
219
|
+
return [
|
|
220
|
+
`Tested examples of \`${item.name}\`: the library's Storybook stories, which run in a browser in light, dark and right-to-left with an accessibility check.`,
|
|
221
|
+
"In app code, leave out the test plumbing: `fn()` from storybook/test is a stand-in for your handler, and `play` functions are the tests.",
|
|
222
|
+
...examples.flatMap((example) => ["", `## ${example.title} (\`${example.file}\`)`, "", "```tsx", example.source, "```"]),
|
|
223
|
+
].join("\n");
|
|
224
|
+
};
|
|
225
|
+
const listTokens = (filter) => {
|
|
226
|
+
const group = filter.group?.toLowerCase();
|
|
227
|
+
const query = filter.query?.toLowerCase();
|
|
228
|
+
const tokens = catalog.tokens.filter((token) => (!group || token.group.toLowerCase().includes(group)) &&
|
|
229
|
+
(!query || token.name.includes(query) || (token.description ?? "").toLowerCase().includes(query)));
|
|
230
|
+
if (tokens.length === 0) {
|
|
231
|
+
const groups = [...new Set(catalog.tokens.map((t) => t.group))];
|
|
232
|
+
return `No token matches. Groups: ${groups.map((g) => `"${g}"`).join(", ")}.`;
|
|
233
|
+
}
|
|
234
|
+
return [
|
|
235
|
+
`${tokens.length} token${tokens.length === 1 ? "" : "s"}. Each is the CSS variable \`--fast-<name>\`; set any of them per tenant with \`createTheme({ tokens, light, dark })\` (\`get_guide theming\`). In markup use the utility, never the raw value.`,
|
|
236
|
+
"",
|
|
237
|
+
"| Token | Light | Dark | Utility | Group | Note |",
|
|
238
|
+
"| --- | --- | --- | --- | --- | --- |",
|
|
239
|
+
...tokens.map((token) => `| \`${token.name}\` | \`${cell(token.light)}\` | ${token.dark ? `\`${cell(token.dark)}\`` : "same"} | ${token.utilities.map((u) => `\`${u}\``).join(" ") || "—"} | ${cell(token.group)} | ${cell(token.description)}${token.rtl ? ` (right to left: \`${cell(token.rtl)}\`)` : ""} |`),
|
|
240
|
+
].join("\n");
|
|
241
|
+
};
|
|
242
|
+
const listGuides = () => [
|
|
243
|
+
"Guides (pass the topic, or an alias such as `setup`, `nextjs`, `theming`, `white-label`, `csp`, `forms`, `conventions`, `rtl`, `testing`, to `get_guide`):",
|
|
244
|
+
"",
|
|
245
|
+
...catalog.guides.map((guide) => `- \`${guide.topic}\`: ${guide.title}`),
|
|
246
|
+
].join("\n");
|
|
247
|
+
const getGuide = (topic) => {
|
|
248
|
+
const guide = findGuide(topic);
|
|
249
|
+
if (!guide) {
|
|
250
|
+
return notFound("guide", topic, [...catalog.guides.map((g) => g.topic), ...Object.keys(TOPIC_ALIASES)], "list_guides");
|
|
251
|
+
}
|
|
252
|
+
return `# ${guide.title}\n\n${guide.content}`;
|
|
253
|
+
};
|
|
254
|
+
const search = (query, limit = 12) => {
|
|
255
|
+
const words = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
256
|
+
if (words.length === 0)
|
|
257
|
+
return "Give a word or two to search for.";
|
|
258
|
+
const score = (text, weight) => words.reduce((sum, word) => sum + (text.toLowerCase().includes(word) ? weight : 0), 0);
|
|
259
|
+
const hits = [];
|
|
260
|
+
for (const item of catalog.exports) {
|
|
261
|
+
const value = score(item.name, 6) +
|
|
262
|
+
score(item.description, 2) +
|
|
263
|
+
(item.props ?? []).reduce((sum, prop) => sum + score(`${prop.name} ${prop.description}`, 1), 0);
|
|
264
|
+
if (value > 0)
|
|
265
|
+
hits.push({ score: value + (item.kind === "component" ? 1 : 0), line: `- ${item.kind} \`${item.name}\`: ${firstSentence(item.description) || "(no description)"} → \`get_export\`` });
|
|
266
|
+
}
|
|
267
|
+
for (const guide of catalog.guides) {
|
|
268
|
+
const value = score(guide.title, 4) + score(guide.content, 1);
|
|
269
|
+
if (value > 0)
|
|
270
|
+
hits.push({ score: value, line: `- guide \`${guide.topic}\`: ${guide.title} → \`get_guide\`` });
|
|
271
|
+
}
|
|
272
|
+
for (const token of catalog.tokens) {
|
|
273
|
+
const value = score(token.name, 3) + score(`${token.group} ${token.description ?? ""}`, 1);
|
|
274
|
+
if (value > 0)
|
|
275
|
+
hits.push({ score: value, line: `- token \`${token.name}\` (${token.utilities.join(", ") || token.cssVariable}) → \`list_tokens\`` });
|
|
276
|
+
}
|
|
277
|
+
if (hits.length === 0)
|
|
278
|
+
return `Nothing found for "${query}". Try \`list_exports\` or \`list_guides\`.`;
|
|
279
|
+
return [`Results for "${query}":`, "", ...hits.sort((a, b) => b.score - a.score).slice(0, limit).map((hit) => hit.line)].join("\n");
|
|
280
|
+
};
|
|
281
|
+
return { overview, listExports, getExport, getExamples, listTokens, listGuides, getGuide, search };
|
|
282
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,49 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@primecoderin/fast-ui-react-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@primecoderin/fast-ui-react-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for @primecoderin/fast-ui-react: every component, prop, token, setup and theming guide, and tested examples, for coding assistants.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "git+https://github.com/primecoderIN/fast-ui-react.git",
|
|
9
|
+
"directory": "mcp"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/primecoderIN/fast-ui-react/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/primecoderIN/fast-ui-react/tree/master/mcp#readme",
|
|
15
|
+
"publishConfig": {
|
|
16
|
+
"access": "public"
|
|
17
|
+
},
|
|
18
|
+
"keywords": [
|
|
19
|
+
"mcp",
|
|
20
|
+
"model-context-protocol",
|
|
21
|
+
"ai",
|
|
22
|
+
"llm",
|
|
23
|
+
"design-system",
|
|
24
|
+
"react",
|
|
25
|
+
"claude",
|
|
26
|
+
"cursor"
|
|
27
|
+
],
|
|
28
|
+
"type": "module",
|
|
29
|
+
"bin": {
|
|
30
|
+
"fast-ui-react-mcp": "./dist/server.js"
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"catalog.json"
|
|
35
|
+
],
|
|
36
|
+
"engines": {
|
|
37
|
+
"node": ">=20.10.0"
|
|
38
|
+
},
|
|
39
|
+
"scripts": {
|
|
40
|
+
"prepack": "node ../scripts/generate-mcp-catalog.mjs && tsc -p tsconfig.json"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^24.19.4"
|
|
44
|
+
},
|
|
45
|
+
"dependencies": {
|
|
46
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
47
|
+
"zod": "^4.6.7"
|
|
48
|
+
}
|
|
49
|
+
}
|