@senvenli/mcp 0.0.0-stage → 0.2.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/dist/http.d.ts ADDED
@@ -0,0 +1,5 @@
1
+ import { type IncomingMessage, type ServerResponse } from "node:http";
2
+ /** Handles one MCP request: a new server and transport per request (stateless), closed when the response ends. */
3
+ export declare function handleMcpRequest(req: IncomingMessage, res: ServerResponse): Promise<void>;
4
+ /** A tiny node:http server: POST /mcp only, a body size cap, CORS for browser-based clients. */
5
+ export declare function startHttpServer(port?: number, host?: string): import("node:http").Server<typeof IncomingMessage, typeof ServerResponse>;
package/dist/http.js ADDED
@@ -0,0 +1,46 @@
1
+ // Hosted mode: Streamable HTTP, stateless (every request gets a fresh server; no sessions to keep). The same server
2
+ // definition as stdio. `node dist/http.js` listens on HOST:PORT (default 127.0.0.1:8787) at /mcp; nginx in front at launch.
3
+ import { createServer as createHttpServer } from "node:http";
4
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
5
+ import { createServer } from "./server.js";
6
+ const MAX_BODY = 64 * 1024;
7
+ /** Handles one MCP request: a new server and transport per request (stateless), closed when the response ends. */
8
+ export async function handleMcpRequest(req, res) {
9
+ const server = createServer();
10
+ const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
11
+ res.on("close", () => {
12
+ void transport.close();
13
+ void server.close();
14
+ });
15
+ await server.connect(transport);
16
+ await transport.handleRequest(req, res);
17
+ }
18
+ /** A tiny node:http server: POST /mcp only, a body size cap, CORS for browser-based clients. */
19
+ export function startHttpServer(port = Number(process.env.PORT ?? 8787), host = process.env.HOST ?? "127.0.0.1") {
20
+ const http = createHttpServer(async (req, res) => {
21
+ res.setHeader("Access-Control-Allow-Origin", "*");
22
+ res.setHeader("Access-Control-Allow-Methods", "POST, OPTIONS");
23
+ res.setHeader("Access-Control-Allow-Headers", "Content-Type, Accept, Mcp-Protocol-Version");
24
+ if (req.method === "OPTIONS")
25
+ return void res.writeHead(204).end();
26
+ if (req.url !== "/mcp" || req.method !== "POST")
27
+ return void res.writeHead(req.url === "/mcp" ? 405 : 404).end();
28
+ if (Number(req.headers["content-length"] ?? 0) > MAX_BODY)
29
+ return void res.writeHead(413).end();
30
+ try {
31
+ await handleMcpRequest(req, res);
32
+ }
33
+ catch {
34
+ if (!res.headersSent)
35
+ res.writeHead(500).end();
36
+ }
37
+ });
38
+ // Loopback only by default: the public way in is the proxy. HOST=0.0.0.0 opts in to every interface.
39
+ http.listen(port, host);
40
+ return http;
41
+ }
42
+ if (import.meta.url === `file://${process.argv[1]}`) {
43
+ startHttpServer();
44
+ console.log(`Senvenli UI MCP on http://${process.env.HOST ?? "127.0.0.1"}:${process.env.PORT ?? 8787}/mcp`);
45
+ }
46
+ //# sourceMappingURL=http.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"http.js","sourceRoot":"","sources":["../src/http.ts"],"names":[],"mappings":"AAAA,oHAAoH;AACpH,4HAA4H;AAC5H,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAA6C,MAAM,WAAW,CAAC;AACxG,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,QAAQ,GAAG,EAAE,GAAG,IAAI,CAAC;AAE3B,kHAAkH;AAClH,MAAM,CAAC,KAAK,UAAU,gBAAgB,CAAC,GAAoB,EAAE,GAAmB;IAC9E,MAAM,MAAM,GAAG,YAAY,EAAE,CAAC;IAC9B,MAAM,SAAS,GAAG,IAAI,6BAA6B,CAAC,EAAE,kBAAkB,EAAE,SAAS,EAAE,kBAAkB,EAAE,IAAI,EAAE,CAAC,CAAC;IACjH,GAAG,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,EAAE;QACnB,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;QACvB,KAAK,MAAM,CAAC,KAAK,EAAE,C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AAC;YACP,IAAI,CAAC,GAAG,CAAC,WAAW;gBAAE,GAAG,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC;QACjD,CAAC;IACH,CAAC,CAAC,CAAC;IACH,qGAAqG;IACrG,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IACxB,OAAO,IAAI,CAAC;AACd,CAAC;AAED,IAAI,MAAM,CAAC,IAAI,CAAC,GAAG,KAAK,UAAU,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC;IACpD,eAAe,EAAE,CAAC;IAClB,OAAO,CAAC,GAAG,CAAC,6BAA6B,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,WAAW,IAAI,OAAO,CAAC,GAAG,CAAC,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC;AAC9G,CAAC","sourcesContent":["// Hosted mode: Streamable HTTP, stateless (every request gets a fresh server; no sessions to keep). The same server\n// definition as stdio. `node dist/http.js` listens on HOST:PORT (default 127.0.0.1:8787) at /mcp; nginx in front at launch.\nimport { createServer as createHttpServer, type IncomingMessage, type ServerResponse } from \"node:http\";\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\nimport { createServer } from \"./server.js\";\n\nconst MAX_BODY = 64 * 1024;\n\n/** Handles one MCP request: a new server and transport per request (stateless), closed when the response ends. */\nexport async function handleMcpRequest(req: IncomingMessage, res: ServerResponse) {\n const server = createServer();\n const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });\n res.on(\"close\", () => {\n void transport.close();\n void server.close();\n });\n await server.connect(transport);\n await transport.handleRequest(req, res);\n}\n\n/** A tiny node:http server: POST /mcp only, a body size cap, CORS for browser-based clients. */\nexport function startHttpServer(port = Number(process.env.PORT ?? 8787), host = process.env.HOST ?? \"127.0.0.1\") {\n const http = createHttpServer(async (req, res) => {\n res.setHeader(\"Access-Control-Allow-Origin\", \"*\");\n res.setHeader(\"Access-Control-Allow-Methods\", \"POST, OPTIONS\");\n res.setHeader(\"Access-Control-Allow-Headers\", \"Content-Type, Accept, Mcp-Protocol-Version\");\n if (req.method === \"OPTIONS\") return void res.writeHead(204).end();\n if (req.url !== \"/mcp\" || req.method !== \"POST\") return void res.writeHead(req.url === \"/mcp\" ? 405 : 404).end();\n if (Number(req.headers[\"content-length\"] ?? 0) > MAX_BODY) return void res.writeHead(413).end();\n try {\n await handleMcpRequest(req, res);\n } catch {\n if (!res.headersSent) res.writeHead(500).end();\n }\n });\n // Loopback only by default: the public way in is the proxy. HOST=0.0.0.0 opts in to every interface.\n http.listen(port, host);\n return http;\n}\n\nif (import.meta.url === `file://${process.argv[1]}`) {\n startHttpServer();\n console.log(`Senvenli UI MCP on http://${process.env.HOST ?? \"127.0.0.1\"}:${process.env.PORT ?? 8787}/mcp`);\n}\n"]}
@@ -0,0 +1,46 @@
1
+ export type Example = {
2
+ id: string;
3
+ title: string;
4
+ description?: string;
5
+ code: string;
6
+ };
7
+ export type Component = {
8
+ name: string;
9
+ title: string;
10
+ family: string;
11
+ description: string;
12
+ keywords: string[];
13
+ import: string;
14
+ exports: string[];
15
+ manifest: Record<string, unknown> & {
16
+ usage?: {
17
+ when?: string[];
18
+ instead?: {
19
+ use: string;
20
+ when: string;
21
+ }[];
22
+ };
23
+ guidance?: {
24
+ rule: string;
25
+ }[];
26
+ };
27
+ markdown: string;
28
+ examples: Example[];
29
+ };
30
+ export type Doc = {
31
+ slug: string;
32
+ title: string;
33
+ description: string;
34
+ group: string;
35
+ order: number;
36
+ markdown: string;
37
+ };
38
+ export type Registry = {
39
+ reactVersion: string;
40
+ components: Component[];
41
+ docs: Doc[];
42
+ };
43
+ /** The bundled data (data/registry.json, built from the manifests, examples and docs). Read once. */
44
+ export declare function registry(): Registry;
45
+ export declare const findComponent: (name: string) => Component | undefined;
46
+ export declare const findDoc: (slug: string) => Doc | undefined;
@@ -0,0 +1,13 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { fileURLToPath } from "node:url";
3
+ // A helper, not an inline `new URL(…, import.meta.url)`: bundlers (Vite in tests) rewrite the inline form into an asset URL.
4
+ const here = (path) => fileURLToPath(new URL(path, import.meta.url));
5
+ let cached = null;
6
+ /** The bundled data (data/registry.json, built from the manifests, examples and docs). Read once. */
7
+ export function registry() {
8
+ cached ??= JSON.parse(readFileSync(here("../data/registry.json"), "utf8"));
9
+ return cached;
10
+ }
11
+ export const findComponent = (name) => registry().components.find((item) => item.name === name.trim().toLowerCase());
12
+ export const findDoc = (slug) => registry().docs.find((item) => item.slug === slug.trim().toLowerCase());
13
+ //# sourceMappingURL=registry.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"registry.js","sourceRoot":"","sources":["../src/registry.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,6HAA6H;AAC7H,MAAM,IAAI,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,aAAa,CAAC,IAAI,GAAG,CAAC,IAAI,EAAE,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;AAqB7E,IAAI,MAAM,GAAoB,IAAI,CAAC;AAEnC,qGAAqG;AACrG,MAAM,UAAU,QAAQ;IACtB,MAAM,KAAK,IAAI,CAAC,KAAK,CAAC,YAAY,CAAC,IAAI,CAAC,uBAAuB,CAAC,EAAE,MAAM,CAAC,CAAa,CAAC;IACvF,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,MAAM,CAAC,MAAM,aAAa,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,UAAU,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC;AAC7H,MAAM,CAAC,MAAM,OAAO,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,QAAQ,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,WAAW,EAAE,CAAC,CAAC","sourcesContent":["import { readFileSync } from \"node:fs\";\nimport { fileURLToPath } from \"node:url\";\n\n// A helper, not an inline `new URL(…, import.meta.url)`: bundlers (Vite in tests) rewrite the inline form into an asset URL.\nconst here = (path: string) => fileURLToPath(new URL(path, import.meta.url));\n\nexport type Example = { id: string; title: string; description?: string; code: string };\nexport type Component = {\n name: string;\n title: string;\n family: string;\n description: string;\n keywords: string[];\n import: string;\n exports: string[];\n manifest: Record<string, unknown> & {\n usage?: { when?: string[]; instead?: { use: string; when: string }[] };\n guidance?: { rule: string }[];\n };\n markdown: string;\n examples: Example[];\n};\nexport type Doc = { slug: string; title: string; description: string; group: string; order: number; markdown: string };\nexport type Registry = { reactVersion: string; components: Component[]; docs: Doc[] };\n\nlet cached: Registry | null = null;\n\n/** The bundled data (data/registry.json, built from the manifests, examples and docs). Read once. */\nexport function registry(): Registry {\n cached ??= JSON.parse(readFileSync(here(\"../data/registry.json\"), \"utf8\")) as Registry;\n return cached;\n}\n\nexport const findComponent = (name: string) => registry().components.find((item) => item.name === name.trim().toLowerCase());\nexport const findDoc = (slug: string) => registry().docs.find((item) => item.slug === slug.trim().toLowerCase());\n"]}
@@ -0,0 +1,10 @@
1
+ import type { Component } from "./registry.js";
2
+ /**
3
+ * Ranks components for a query by where each word is found: the name, title and exports weigh most, then keywords,
4
+ * then the description, then "when to use it" and guidance (a prefix counts for less). A component that matches more
5
+ * of the query's words ranks above one that matches fewer, so a long, chatty query still finds the right one.
6
+ */
7
+ export declare function searchComponents(components: Component[], query: string, limit?: number): {
8
+ component: Component;
9
+ score: number;
10
+ }[];
package/dist/search.js ADDED
@@ -0,0 +1,63 @@
1
+ /** Words that say nothing about which component is wanted. */
2
+ const STOP = new Set("a an and the to of for in on at by with from or my our your their his her its it this that these those i we you me us is are be want need needs show shows let lets user users some any component components ui".split(" "));
3
+ /** Case and accent insensitive words; "DatePicker" also gives "date" and "picker". */
4
+ const words = (text) => text
5
+ .replace(/(\p{Ll})(\p{Lu})/gu, "$1 $2")
6
+ .normalize("NFD")
7
+ .replace(/\p{M}/gu, "")
8
+ .toLowerCase()
9
+ .split(/[^\p{L}\p{N}]+/u)
10
+ .filter(Boolean)
11
+ .map(stem);
12
+ /** A light English stem, so "sorting", "sorts" and "sorted" all meet "sort". */
13
+ function stem(word) {
14
+ if (word.length <= 4)
15
+ return word;
16
+ return word.replace(/(?:ing|ed|es|s)$/, "") || word;
17
+ }
18
+ /** Words of an identifier both whole ("datepicker") and split ("date", "picker"). */
19
+ const identifier = (name) => [stem(name.toLowerCase()), ...words(name)];
20
+ /**
21
+ * Ranks components for a query by where each word is found: the name, title and exports weigh most, then keywords,
22
+ * then the description, then "when to use it" and guidance (a prefix counts for less). A component that matches more
23
+ * of the query's words ranks above one that matches fewer, so a long, chatty query still finds the right one.
24
+ */
25
+ export function searchComponents(components, query, limit = 8) {
26
+ const all = words(query);
27
+ const terms = all.filter((term) => !STOP.has(term));
28
+ if (!terms.length)
29
+ terms.push(...all);
30
+ if (!terms.length)
31
+ return [];
32
+ const needed = terms.length <= 2 ? terms.length : Math.ceil(terms.length / 2);
33
+ const fields = (component) => [
34
+ [[...words(`${component.name} ${component.title}`), stem(component.name.replaceAll("-", "")), ...component.exports.flatMap(identifier)], 10],
35
+ [component.keywords.flatMap(words), 6],
36
+ [words(component.description), 3],
37
+ [words([...(component.manifest.usage?.when ?? []), ...(component.manifest.guidance ?? []).map((item) => item.rule)].join(" ")), 1],
38
+ ];
39
+ const results = [];
40
+ for (const component of components) {
41
+ let score = 0;
42
+ let matched = 0;
43
+ const lists = fields(component);
44
+ for (const term of terms) {
45
+ let best = 0;
46
+ for (const [list, weight] of lists) {
47
+ if (list.includes(term))
48
+ best = Math.max(best, weight);
49
+ else if (term.length > 2 && list.some((word) => word.startsWith(term)))
50
+ best = Math.max(best, weight * 0.6);
51
+ }
52
+ if (best)
53
+ matched++;
54
+ score += best;
55
+ }
56
+ // The query is the component's name ("tooltip", "date picker", "DatePicker"): put it first.
57
+ const exact = words(query).join("") === words(component.name).join("") ? 100 : 0;
58
+ if (matched >= needed)
59
+ results.push({ component, score: score * (matched / terms.length) + exact });
60
+ }
61
+ return results.sort((a, b) => b.score - a.score || a.component.name.localeCompare(b.component.name)).slice(0, limit);
62
+ }
63
+ //# sourceMappingURL=search.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search.js","sourceRoot":"","sources":["../src/search.ts"],"names":[],"mappings":"AAEA,8DAA8D;AAC9D,MAAM,IAAI,GAAG,IAAI,GAAG,CAClB,iNAAiN,CAAC,KAAK,CAAC,GAAG,CAAC,CAC7N,CAAC;AAEF,sFAAsF;AACtF,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,EAAE,CAC7B,IAAI;KACD,OAAO,CAAC,oBAAoB,EAAE,OAAO,CAAC;KACtC,SAAS,CAAC,KAAK,CAAC;KAChB,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC;KACtB,WAAW,EAAE;KACb,KAAK,CAAC,iBAAiB,CAAC;KACxB,MAAM,CAAC,OAAO,CAAC;KACf,GAAG,CAAC,IAAI,CAAC,CAAC;AAEf,gFAAgF;AAChF,SAAS,IAAI,CAAC,IAAY;IACxB,IAAI,IAAI,CAAC,MAAM,IAAI,CAAC;QAAE,OAAO,IAAI,CAAC;IAClC,OAAO,IAAI,CAAC,OAAO,CAAC,kBAAkB,EAAE,EAAE,CAAC,IAAI,IAAI,CAAC;AACtD,CAAC;AAED,qFAAqF;AACrF,MAAM,UAAU,GAAG,CAAC,IAAY,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,EAAE,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC;AAEhF;;;;GAIG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I,CAAC,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,GAAG,CAAC,OAAO,GAAG,KAAK,CAAC,MAAM,CAAC,GAAG,KAAK,EAAE,CAAC,CAAC;IACtG,CAAC;IACD,OAAO,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,aAAa,CAAC,CAAC,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC;AACvH,CAAC","sourcesContent":["import type { Component } from \"./registry.js\";\n\n/** Words that say nothing about which component is wanted. */\nconst STOP = new Set(\n \"a an and the to of for in on at by with from or my our your their his her its it this that these those i we you me us is are be want need needs show shows let lets user users some any component components ui\".split(\" \"),\n);\n\n/** Case and accent insensitive words; \"DatePicker\" also gives \"date\" and \"picker\". */\nconst words = (text: string) =>\n text\n .replace(/(\\p{Ll})(\\p{Lu})/gu, \"$1 $2\")\n .normalize(\"NFD\")\n .replace(/\\p{M}/gu, \"\")\n .toLowerCase()\n .split(/[^\\p{L}\\p{N}]+/u)\n .filter(Boolean)\n .map(stem);\n\n/** A light English stem, so \"sorting\", \"sorts\" and \"sorted\" all meet \"sort\". */\nfunction stem(word: string) {\n if (word.length <= 4) return word;\n return word.replace(/(?:ing|ed|es|s)$/, \"\") || word;\n}\n\n/** Words of an identifier both whole (\"datepicker\") and split (\"date\", \"picker\"). */\nconst identifier = (name: string) => [stem(name.toLowerCase()), ...words(name)];\n\n/**\n * Ranks components for a query by where each word is found: the name, title and exports weigh most, then keywords,\n * then the description, then \"when to use it\" and guidance (a prefix counts for less). A component that matches more\n * of the query's words ranks above one that matches fewer, so a long, chatty query still finds the right one.\n */\nexport function searchComponents(components: Component[], query: string, limit = 8): { component: Component; score: number }[] {\n const all = words(query);\n const terms = all.filter((term) => !STOP.has(term));\n if (!terms.length) terms.push(...all);\n if (!terms.length) return [];\n const needed = terms.length <= 2 ? terms.length : Math.ceil(terms.length / 2);\n const fields = (component: Component): [string[], number][] => [\n [[...words(`${component.name} ${component.title}`), stem(component.name.replaceAll(\"-\", \"\")), ...component.exports.flatMap(identifier)], 10],\n [component.keywords.flatMap(words), 6],\n [words(component.description), 3],\n [words([...(component.manifest.usage?.when ?? []), ...(component.manifest.guidance ?? []).map((item) => item.rule)].join(\" \")), 1],\n ];\n const results: { component: Component; score: number }[] = [];\n for (const component of components) {\n let score = 0;\n let matched = 0;\n const lists = fields(component);\n for (const term of terms) {\n let best = 0;\n for (const [list, weight] of lists) {\n if (list.includes(term)) best = Math.max(best, weight);\n else if (term.length > 2 && list.some((word) => word.startsWith(term))) best = Math.max(best, weight * 0.6);\n }\n if (best) matched++;\n score += best;\n }\n // The query is the component's name (\"tooltip\", \"date picker\", \"DatePicker\"): put it first.\n const exact = words(query).join(\"\") === words(component.name).join(\"\") ? 100 : 0;\n if (matched >= needed) results.push({ component, score: score * (matched / terms.length) + exact });\n }\n return results.sort((a, b) => b.score - a.score || a.component.name.localeCompare(b.component.name)).slice(0, limit);\n}\n"]}
@@ -0,0 +1,6 @@
1
+ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ /**
3
+ * The Senvenli UI MCP server: components (search, pages, manifests, examples), docs and themes, from data bundled at
4
+ * build time. Read-only: it never touches files or the network. One definition serves stdio and Streamable HTTP.
5
+ */
6
+ export declare function createServer(): McpServer;
package/dist/server.js ADDED
@@ -0,0 +1,282 @@
1
+ import { McpServer, ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import { checkThemeCss, createTheme, decodePreset, encodePreset, formatHex, parseColor, toCSS, toNative } from "@senvenli/tokens";
3
+ import { z } from "zod";
4
+ import { findComponent, findDoc, registry } from "./registry.js";
5
+ import { searchComponents } from "./search.js";
6
+ const SITE = "https://design.senvenli.com";
7
+ const text = (value) => ({ content: [{ type: "text", text: value }] });
8
+ const fail = (value) => ({ content: [{ type: "text", text: value }], isError: true });
9
+ /** A component that does not exist: say so, and name the closest ones so the agent can retry. */
10
+ function unknownComponent(name) {
11
+ const near = searchComponents(registry().components, name, 5).map((hit) => hit.component.name);
12
+ return fail(`No component named "${name}".${near.length ? ` Did you mean: ${near.join(", ")}?` : " Use search_components or list_components."}`);
13
+ }
14
+ const COLOR_FORMATS = 'a hex "#rrggbb" (or "#rgb") or "oklch(L C H)", like "oklch(0.55 0.15 250)"';
15
+ const themeInputShape = {
16
+ preset: z.string().optional().describe("A preset code from the theme builder (the ?p= value). The other fields override it."),
17
+ primary: z.string().optional().describe(`The brand color: ${COLOR_FORMATS}. Leave out for the neutral default.`),
18
+ secondary: z.string().optional().describe("A second brand color, same formats."),
19
+ tertiary: z.string().optional().describe("A third brand color, same formats."),
20
+ primaryDark: z.string().optional().describe(`A hand-picked brand color for dark mode, same formats. Leave out to derive it from primary.`),
21
+ radius: z.number().min(0).max(2).optional().describe("Base corner radius in rem (default 0.625)."),
22
+ controlShape: z.enum(["rounded", "pill"]).optional().describe('Single-line controls (buttons, fields, badges, segmented controls) follow the radius ("rounded", default) or are fully round ("pill"); cards keep the radius.'),
23
+ density: z.enum(["compact", "default", "comfortable"]).optional(),
24
+ borderWidth: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional(),
25
+ };
26
+ /** The engine's input from the tool's arguments, or why it cannot be made (a bad preset code, a color it cannot read). */
27
+ function themeInput(args) {
28
+ let input = {};
29
+ if (args.preset) {
30
+ const decoded = decodePreset(args.preset);
31
+ if (!decoded)
32
+ return `Invalid preset code "${args.preset}". Copy it from the builder's address (?p=…), or pass the colors instead.`;
33
+ input = decoded;
34
+ }
35
+ for (const key of ["primary", "secondary", "tertiary"]) {
36
+ const value = args[key];
37
+ if (value === undefined)
38
+ continue;
39
+ if (!parseColor(value))
40
+ return `${key} "${value}" is not a color the engine reads. Use ${COLOR_FORMATS}; names, rgb() and hsl() are not read.`;
41
+ input[key] = value;
42
+ }
43
+ if (args.primaryDark !== undefined) {
44
+ if (!parseColor(args.primaryDark))
45
+ return `primaryDark "${args.primaryDark}" is not a color the engine reads. Use ${COLOR_FORMATS}.`;
46
+ input.darkColors = { ...input.darkColors, primary: args.primaryDark };
47
+ }
48
+ for (const key of ["radius", "controlShape", "density", "borderWidth"]) {
49
+ if (args[key] !== undefined)
50
+ input[key] = args[key];
51
+ }
52
+ return input;
53
+ }
54
+ const failLine = (check) => `- FAIL ${check.mode}: ${check.foreground} on ${check.background} = ${check.ratio.toFixed(2)} (needs ${check.required})`;
55
+ /** The contrast summary: the count, the failing pairs, and the colors the engine moved. */
56
+ function report(theme) {
57
+ const failing = theme.checks.filter((check) => !check.pass);
58
+ const lines = [`Contrast: ${theme.checks.length - failing.length} of ${theme.checks.length} pairs pass WCAG AA (light and dark).`, ...failing.map(failLine)];
59
+ for (const role of theme.adjusted) {
60
+ lines.push(`- ${role} was moved to ${formatHex(theme.light[role === "primary" ? "ds-background-brand-bold" : `ds-background-${role === "info" ? "information" : role}-bold`])} so text on it passes AA.`);
61
+ }
62
+ return lines.join("\n");
63
+ }
64
+ /** The most one component answer should cost an agent's context, in characters (about 5k tokens). */
65
+ const PAGE_BUDGET = 20_000;
66
+ /** The sections of a component page, by the `## ` heading that opens each. The title and intro always come first. */
67
+ const SECTIONS = {
68
+ example: /^## Example:/,
69
+ examples: /^## Examples(\n|$)/,
70
+ guidelines: /^## Guidelines(\n|$)/,
71
+ accessibility: /^## Accessibility(\n|$)/,
72
+ api: /^## API reference(\n|$)/,
73
+ related: /^## Related(\n|$)/,
74
+ };
75
+ function pageSections(markdown, wanted) {
76
+ const parts = markdown.split(/\n(?=## )/);
77
+ const keep = parts.filter((part, index) => index === 0 || wanted.some((section) => SECTIONS[section].test(part)));
78
+ return keep.join("\n");
79
+ }
80
+ /** A manifest's props by export, with the React Aria behavior props or the DOM attributes left out, as asked. */
81
+ function manifestFor(manifest, props, minified) {
82
+ const origins = props === "own" ? ["own"] : props === "own+aria" ? ["own", "aria"] : ["own", "aria", "dom"];
83
+ const byExport = (manifest.props ?? {});
84
+ const kept = {};
85
+ let dropped = 0;
86
+ for (const [name, list] of Object.entries(byExport)) {
87
+ const shown = list.filter((prop) => origins.includes(prop.origin ?? "own"));
88
+ dropped += list.length - shown.length;
89
+ kept[name] = minified ? shown.map(({ schema: _schema, ...rest }) => rest) : shown;
90
+ }
91
+ const { quality: _quality, source: _source, ...rest } = manifest;
92
+ const out = { ...(minified ? rest : manifest), props: kept, ...(dropped ? { propsLeftOut: `${dropped} ${props === "own" ? "React Aria and DOM" : "DOM and ARIA attribute"} props; pass props: "all" for them.` } : {}) };
93
+ return minified ? JSON.stringify(out) : JSON.stringify(out, null, 2);
94
+ }
95
+ /**
96
+ * The Senvenli UI MCP server: components (search, pages, manifests, examples), docs and themes, from data bundled at
97
+ * build time. Read-only: it never touches files or the network. One definition serves stdio and Streamable HTTP.
98
+ */
99
+ export function createServer() {
100
+ const data = registry();
101
+ const docSlugs = data.docs.map((doc) => doc.slug);
102
+ const server = new McpServer({ name: "senvenli-ui", version: data.reactVersion }, {
103
+ instructions: "Senvenli UI is a React design system on React Aria (`npm i @senvenli/react`). Find components with search_components, " +
104
+ "then read one with get_component before writing code: it has the import, example code, guidelines, accessibility and props. " +
105
+ "Use only the props it lists. Setup is get_doc('getting-started'). Themes: create_theme from up to three colors, " +
106
+ "validate_theme to check a theme.css for WCAG AA contrast.",
107
+ });
108
+ server.registerTool("list_components", {
109
+ title: "List components",
110
+ description: "List every Senvenli UI component (name, family, one-line description), or one family's. To browse; search_components finds one by purpose.",
111
+ inputSchema: { family: z.string().optional().describe(`A family: ${[...new Set(data.components.map((item) => item.family))].join(", ")}.`) },
112
+ annotations: { readOnlyHint: true },
113
+ }, async ({ family }) => {
114
+ const items = data.components.filter((item) => !family || item.family === family.trim().toLowerCase());
115
+ if (!items.length)
116
+ return fail(`No family "${family}". Families: ${[...new Set(data.components.map((item) => item.family))].join(", ")}.`);
117
+ return text(items.map((item) => `${item.name} (${item.family}): ${item.description}`).join("\n"));
118
+ });
119
+ server.registerTool("search_components", {
120
+ title: "Search components",
121
+ description: 'Find components by what they are for ("date range", "upload a file", "confirm a delete") or by export name ("DatePicker"). Returns names for get_component, with the import.',
122
+ inputSchema: { query: z.string().min(1), limit: z.number().int().min(1).max(20).optional().describe("Default 8.") },
123
+ annotations: { readOnlyHint: true },
124
+ }, async ({ query, limit }) => {
125
+ const hits = searchComponents(data.components, query, limit ?? 8);
126
+ if (!hits.length)
127
+ return text(`No component matches "${query}". Try a shorter phrase of what it is for, or list_components.`);
128
+ return text(hits.map(({ component }) => `${component.name} (${component.family}): ${component.description}\n import { ${component.exports.join(", ")} } from "${component.import}";`).join("\n"));
129
+ });
130
+ server.registerTool("get_component", {
131
+ title: "Get a component",
132
+ description: "Read one component's page as Markdown: import, example code, when to use it (and what instead), do and avoid, accessibility, and props. " +
133
+ "Read it before using a component. Pass sections to read less of a long page.",
134
+ inputSchema: {
135
+ name: z.string().describe('The component name, as search_components gives it: "date-picker".'),
136
+ sections: z
137
+ .array(z.enum(Object.keys(SECTIONS)))
138
+ .optional()
139
+ .describe("Only these parts (the title, import and intro always come): example (the main one), examples, guidelines, accessibility, api, related. Default: all."),
140
+ },
141
+ annotations: { readOnlyHint: true },
142
+ }, async ({ name, sections }) => {
143
+ const component = findComponent(name);
144
+ if (!component)
145
+ return unknownComponent(name);
146
+ if (sections?.length)
147
+ return text(pageSections(component.markdown, sections));
148
+ // A page too long for one answer (a component with several shapes, such as Input) comes without its API
149
+ // reference, and says how to read it; nothing is cut silently.
150
+ if (component.markdown.length <= PAGE_BUDGET)
151
+ return text(component.markdown);
152
+ const rest = Object.keys(SECTIONS).filter((section) => section !== "api");
153
+ return text(`${pageSections(component.markdown, rest)}\n\n> The API reference is long: read it with get_component({ name: "${component.name}", sections: ["api"] }) or get_component_manifest.`);
154
+ });
155
+ server.registerTool("get_component_manifest", {
156
+ title: "Get a component's manifest",
157
+ description: "The component's manifest as JSON: exports, usage, a11y, every prop with type, default and origin, tokens and strings. For tools that need structured data; to read, prefer get_component.",
158
+ inputSchema: {
159
+ name: z.string(),
160
+ props: z.enum(["own", "own+aria", "all"]).optional().describe('Which props: own; own+aria (default: also React Aria behavior props like onPress); all (also DOM and ARIA attributes).'),
161
+ minified: z.boolean().optional().describe("Default true: one line, without the JSON Schema of each prop or the build fields."),
162
+ },
163
+ annotations: { readOnlyHint: true },
164
+ }, async ({ name, props, minified }) => {
165
+ const component = findComponent(name);
166
+ if (!component)
167
+ return unknownComponent(name);
168
+ const answer = manifestFor(component.manifest, props ?? "own+aria", minified ?? true);
169
+ // Over the budget by default (a component with several shapes): its own props only, and the note in the JSON
170
+ // (propsLeftOut) says how to ask for the rest.
171
+ if (props === undefined && answer.length > PAGE_BUDGET)
172
+ return text(manifestFor(component.manifest, "own", minified ?? true));
173
+ return text(answer);
174
+ });
175
+ server.registerTool("get_doc", {
176
+ title: "Get a doc",
177
+ description: `Read a doc as Markdown. ${data.docs.map((doc) => `${doc.slug}: ${doc.description}`).join(" ")}`,
178
+ inputSchema: { name: z.enum(docSlugs) },
179
+ annotations: { readOnlyHint: true },
180
+ }, async ({ name }) => {
181
+ const doc = findDoc(name);
182
+ return doc ? text(doc.markdown) : fail(`No doc "${name}". Docs: ${docSlugs.join(", ")}.`);
183
+ });
184
+ server.registerTool("create_theme", {
185
+ title: "Create a theme",
186
+ description: "Make a theme from up to three colors (all optional) and layout settings. Every text pair is checked against WCAG AA in light and dark, " +
187
+ "and the engine moves a color that would fail. The default answer is the contrast report and the CLI command that writes theme.css; " +
188
+ "ask for format tailwind, css or native to get the file's contents instead.",
189
+ inputSchema: {
190
+ ...themeInputShape,
191
+ format: z
192
+ .enum(["command", "tailwind", "css", "native"])
193
+ .optional()
194
+ .describe("command (default): the report and a command to run; tailwind: the CSS with a Tailwind v4 @theme block; css: the variables only; native: hex JSON for React Native."),
195
+ },
196
+ annotations: { readOnlyHint: true },
197
+ }, async (args) => {
198
+ const input = themeInput(args);
199
+ if (typeof input === "string")
200
+ return fail(input);
201
+ const theme = createTheme(input);
202
+ const code = encodePreset(input);
203
+ const format = args.format ?? "command";
204
+ const head = [report(theme), `Preset code: ${code}\nBuilder: ${SITE}/create?p=${code}`];
205
+ if (format === "command") {
206
+ return text([...head, `Write theme.css (with the Tailwind block) in the app:\n\nnpx @senvenli/cli theme ${code} --tailwind`, "Then import it after Tailwind: get_doc('getting-started')."].join("\n\n"));
207
+ }
208
+ const output = format === "native" ? JSON.stringify(toNative(theme), null, 2) : toCSS(theme, { tailwind: format === "tailwind" });
209
+ return text([...head, format === "native" ? "Save as theme.json:" : "Save as theme.css and import it after Tailwind (get_doc('getting-started')):", output].join("\n\n"));
210
+ });
211
+ server.registerTool("validate_theme", {
212
+ title: "Validate a theme",
213
+ description: "Check a theme.css (as create_theme or the CLI wrote it, edited or not) against WCAG AA: every text, icon and border pair, light and dark. " +
214
+ "Lists the failing pairs and any token the CSS lacks.",
215
+ inputSchema: { css: z.string().min(1).describe("The theme's CSS: the :root block and the [data-theme=\"dark\"] block.") },
216
+ annotations: { readOnlyHint: true },
217
+ }, async ({ css }) => {
218
+ const { checks, missing } = checkThemeCss(css);
219
+ if (!checks.length && missing.length)
220
+ return fail("No Senvenli UI tokens (--ds-…) found in this CSS. Pass the theme.css that create_theme or the CLI wrote.");
221
+ const failing = checks.filter((check) => !check.pass);
222
+ const lines = [`Contrast: ${checks.length - failing.length} of ${checks.length} checked pairs pass WCAG AA.`, ...failing.map(failLine)];
223
+ if (missing.length)
224
+ lines.push(`Missing or not a color (${missing.length}), so their pairs were not checked: ${missing.map((item) => `${item.token} (${item.mode})`).join(", ")}.`);
225
+ if (failing.length)
226
+ lines.push("Fix: regenerate with create_theme from the brand colors, or darken (light) / lighten (dark) the failing foreground.");
227
+ return text(lines.join("\n"));
228
+ });
229
+ server.registerPrompt("build_form", {
230
+ title: "Build a form",
231
+ description: "Build a form with Senvenli UI components, the way the system wants it: labels, validation, errors and the submit flow.",
232
+ argsSchema: { form: z.string().describe('What the form is for: "sign up with email and password", "shipping address".') },
233
+ }, ({ form }) => ({
234
+ messages: [
235
+ {
236
+ role: "user",
237
+ content: {
238
+ type: "text",
239
+ text: `Build this form with Senvenli UI (@senvenli/react): ${form}\n\n` +
240
+ "1. get_component('form') and get_component('field'), then search_components for each input it needs (dates, phone, password, choices).\n" +
241
+ "2. Read every component you use with get_component before writing it; use only the props it lists.\n" +
242
+ "3. Every field has a visible label; required fields say so; errors are shown on the field and announced, not only in color.\n" +
243
+ "4. One primary submit button; it shows pending state while submitting.\n" +
244
+ "5. Use the design tokens (ds- classes), never raw colors or pixel sizes.",
245
+ },
246
+ },
247
+ ],
248
+ }));
249
+ server.registerPrompt("theme_app", {
250
+ title: "Theme an app",
251
+ description: "Set up Senvenli UI's theme in an app from its brand colors, checked against WCAG AA.",
252
+ argsSchema: { colors: z.string().optional().describe('The brand colors, "#1268ae" or "oklch(…)", up to three. Leave out for the neutral default.') },
253
+ }, ({ colors }) => ({
254
+ messages: [
255
+ {
256
+ role: "user",
257
+ content: {
258
+ type: "text",
259
+ text: `Theme this app with Senvenli UI${colors ? ` from these brand colors: ${colors}` : ""}.\n\n` +
260
+ "1. get_doc('getting-started') for install and where the theme CSS goes; get_doc('theming') for what the colors drive.\n" +
261
+ "2. create_theme with the colors (primary first); run the command it gives, or save its CSS.\n" +
262
+ "3. If a color was moved for contrast, say which and why.\n" +
263
+ "4. If the app's theme.css is edited by hand later, check it with validate_theme.",
264
+ },
265
+ },
266
+ ],
267
+ }));
268
+ server.registerResource("component", new ResourceTemplate("senvenli://components/{name}", {
269
+ list: async () => ({ resources: data.components.map((item) => ({ uri: `senvenli://components/${item.name}`, name: item.title, description: item.description, mimeType: "text/markdown" })) }),
270
+ }), { title: "Component page", description: "A component's page as Markdown.", mimeType: "text/markdown" }, async (uri, { name }) => {
271
+ const component = findComponent(String(name));
272
+ return { contents: [{ uri: uri.href, mimeType: "text/markdown", text: component?.markdown ?? `No component named "${name}".` }] };
273
+ });
274
+ server.registerResource("doc", new ResourceTemplate("senvenli://docs/{name}", {
275
+ list: async () => ({ resources: data.docs.map((doc) => ({ uri: `senvenli://docs/${doc.slug}`, name: doc.title, description: doc.description, mimeType: "text/markdown" })) }),
276
+ }), { title: "Doc", description: "A doc as Markdown.", mimeType: "text/markdown" }, async (uri, { name }) => {
277
+ const doc = findDoc(String(name));
278
+ return { contents: [{ uri: uri.href, mimeType: "text/markdown", text: doc?.markdown ?? `No doc named "${name}".` }] };
279
+ });
280
+ return server;
281
+ }
282
+ //# sourceMappingURL=server.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AACtF,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,YAAY,EAAE,YAAY,EAAE,SAAS,EAAE,UAAU,EAAE,KAAK,EAAE,QAAQ,EAAmD,MAAM,kBAAkB,CAAC;AACnL,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,QAAQ,EAAkB,MAAM,eAAe,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,IAAI,GAAG,6BAA6B,CAAC;AAE3C,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,CAAC,CAAC;AACxF,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC;AAEvG,iGAAiG;AACjG,SA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AE,IAAI,EAAE,SAAS,EAAE,QAAQ,IAAI,uBAAuB,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;IACpI,CAAC,CACF,CAAC;IAEF,MAAM,CAAC,gBAAgB,CACrB,KAAK,EACL,IAAI,gBAAgB,CAAC,wBAAwB,EAAE;QAC7C,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,SAAS,EAAE,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,EAAE,GAAG,EAAE,mBAAmB,GAAG,CAAC,IAAI,EAAE,EAAE,IAAI,EAAE,GAAG,CAAC,KAAK,EAAE,WAAW,EAAE,GAAG,CAAC,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,CAAC,CAAC,EAAE,CAAC;KAC9K,CAAC,EACF,EAAE,KAAK,EAAE,KAAK,EAAE,WAAW,EAAE,oBAAoB,EAAE,QAAQ,EAAE,eAAe,EAAE,EAC9E,KAAK,EAAE,GAAG,EAAE,EAAE,IAAI,EAAE,EAAE,EAAE;QACtB,MAAM,GAAG,GAAG,OAAO,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,CAAC;QAClC,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,eAAe,EAAE,IAAI,EAAE,GAAG,EAAE,QAAQ,IAAI,iBAAiB,IAAI,IAAI,EAAE,CAAC,EAAE,CAAC;IACxH,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { McpServer, ResourceTemplate } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { checkThemeCss, createTheme, decodePreset, encodePreset, formatHex, parseColor, toCSS, toNative, type ContrastCheck, type Theme, type ThemeInput } from \"@senvenli/tokens\";\nimport { z } from \"zod\";\nimport { findComponent, findDoc, registry, type Component } from \"./registry.js\";\nimport { searchComponents } from \"./search.js\";\n\nconst SITE = \"https://design.senvenli.com\";\n\nconst text = (value: string) => ({ content: [{ type: \"text\" as const, text: value }] });\nconst fail = (value: string) => ({ content: [{ type: \"text\" as const, text: value }], isError: true });\n\n/** A component that does not exist: say so, and name the closest ones so the agent can retry. */\nfunction unknownComponent(name: string) {\n const near = searchComponents(registry().components, name, 5).map((hit) => hit.component.name);\n return fail(`No component named \"${name}\".${near.length ? ` Did you mean: ${near.join(\", \")}?` : \" Use search_components or list_components.\"}`);\n}\n\nconst COLOR_FORMATS = 'a hex \"#rrggbb\" (or \"#rgb\") or \"oklch(L C H)\", like \"oklch(0.55 0.15 250)\"';\n\nconst themeInputShape = {\n preset: z.string().optional().describe(\"A preset code from the theme builder (the ?p= value). The other fields override it.\"),\n primary: z.string().optional().describe(`The brand color: ${COLOR_FORMATS}. Leave out for the neutral default.`),\n secondary: z.string().optional().describe(\"A second brand color, same formats.\"),\n tertiary: z.string().optional().describe(\"A third brand color, same formats.\"),\n primaryDark: z.string().optional().describe(`A hand-picked brand color for dark mode, same formats. Leave out to derive it from primary.`),\n radius: z.number().min(0).max(2).optional().describe(\"Base corner radius in rem (default 0.625).\"),\n controlShape: z.enum([\"rounded\", \"pill\"]).optional().describe('Single-line controls (buttons, fields, badges, segmented controls) follow the radius (\"rounded\", default) or are fully round (\"pill\"); cards keep the radius.'),\n density: z.enum([\"compact\", \"default\", \"comfortable\"]).optional(),\n borderWidth: z.union([z.literal(0), z.literal(1), z.literal(2)]).optional(),\n};\ntype ThemeArgs = { preset?: string; primary?: string; secondary?: string; tertiary?: string; primaryDark?: string; radius?: number; controlShape?: ThemeInput[\"controlShape\"]; density?: ThemeInput[\"density\"]; borderWidth?: ThemeInput[\"borderWidth\"] };\n\n/** The engine's input from the tool's arguments, or why it cannot be made (a bad preset code, a color it cannot read). */\nfunction themeInput(args: ThemeArgs): ThemeInput | string {\n let input: ThemeInput = {};\n if (args.preset) {\n const decoded = decodePreset(args.preset);\n if (!decoded) return `Invalid preset code \"${args.preset}\". Copy it from the builder's address (?p=…), or pass the colors instead.`;\n input = decoded;\n }\n for (const key of [\"primary\", \"secondary\", \"tertiary\"] as const) {\n const value = args[key];\n if (value === undefined) continue;\n if (!parseColor(value)) return `${key} \"${value}\" is not a color the engine reads. Use ${COLOR_FORMATS}; names, rgb() and hsl() are not read.`;\n input[key] = value;\n }\n if (args.primaryDark !== undefined) {\n if (!parseColor(args.primaryDark)) return `primaryDark \"${args.primaryDark}\" is not a color the engine reads. Use ${COLOR_FORMATS}.`;\n input.darkColors = { ...input.darkColors, primary: args.primaryDark };\n }\n for (const key of [\"radius\", \"controlShape\", \"density\", \"borderWidth\"] as const) {\n if (args[key] !== undefined) (input as Record<string, unknown>)[key] = args[key];\n }\n return input;\n}\n\nconst failLine = (check: ContrastCheck) => `- FAIL ${check.mode}: ${check.foreground} on ${check.background} = ${check.ratio.toFixed(2)} (needs ${check.required})`;\n\n/** The contrast summary: the count, the failing pairs, and the colors the engine moved. */\nfunction report(theme: Theme): string {\n const failing = theme.checks.filter((check) => !check.pass);\n const lines = [`Contrast: ${theme.checks.length - failing.length} of ${theme.checks.length} pairs pass WCAG AA (light and dark).`, ...failing.map(failLine)];\n for (const role of theme.adjusted) {\n lines.push(`- ${role} was moved to ${formatHex(theme.light[role === \"primary\" ? \"ds-background-brand-bold\" : `ds-background-${role === \"info\" ? \"information\" : role}-bold`]!)} so text on it passes AA.`);\n }\n return lines.join(\"\\n\");\n}\n\n/** The most one component answer should cost an agent's context, in characters (about 5k tokens). */\nconst PAGE_BUDGET = 20_000;\n\n/** The sections of a component page, by the `## ` heading that opens each. The title and intro always come first. */\nconst SECTIONS = {\n example: /^## Example:/,\n examples: /^## Examples(\\n|$)/,\n guidelines: /^## Guidelines(\\n|$)/,\n accessibility: /^## Accessibility(\\n|$)/,\n api: /^## API reference(\\n|$)/,\n related: /^## Related(\\n|$)/,\n} as const;\ntype Section = keyof typeof SECTIONS;\n\nfunction pageSections(markdown: string, wanted: Section[]): string {\n const parts = markdown.split(/\\n(?=## )/);\n const keep = parts.filter((part, index) => index === 0 || wanted.some((section) => SECTIONS[section].test(part)));\n return keep.join(\"\\n\");\n}\n\n/** A manifest's props by export, with the React Aria behavior props or the DOM attributes left out, as asked. */\nfunction manifestFor(manifest: Component[\"manifest\"], props: \"own\" | \"own+aria\" | \"all\", minified: boolean) {\n const origins = props === \"own\" ? [\"own\"] : props === \"own+aria\" ? [\"own\", \"aria\"] : [\"own\", \"aria\", \"dom\"];\n const byExport = (manifest.props ?? {}) as Record<string, (Record<string, unknown> & { origin?: string })[]>;\n const kept: Record<string, unknown[]> = {};\n let dropped = 0;\n for (const [name, list] of Object.entries(byExport)) {\n const shown = list.filter((prop) => origins.includes(prop.origin ?? \"own\"));\n dropped += list.length - shown.length;\n kept[name] = minified ? shown.map(({ schema: _schema, ...rest }) => rest) : shown;\n }\n const { quality: _quality, source: _source, ...rest } = manifest as Record<string, unknown>;\n const out = { ...(minified ? rest : manifest), props: kept, ...(dropped ? { propsLeftOut: `${dropped} ${props === \"own\" ? \"React Aria and DOM\" : \"DOM and ARIA attribute\"} props; pass props: \"all\" for them.` } : {}) };\n return minified ? JSON.stringify(out) : JSON.stringify(out, null, 2);\n}\n\n/**\n * The Senvenli UI MCP server: components (search, pages, manifests, examples), docs and themes, from data bundled at\n * build time. Read-only: it never touches files or the network. One definition serves stdio and Streamable HTTP.\n */\nexport function createServer(): McpServer {\n const data = registry();\n const docSlugs = data.docs.map((doc) => doc.slug) as [string, ...string[]];\n const server = new McpServer(\n { name: \"senvenli-ui\", version: data.reactVersion },\n {\n instructions:\n \"Senvenli UI is a React design system on React Aria (`npm i @senvenli/react`). Find components with search_components, \" +\n \"then read one with get_component before writing code: it has the import, example code, guidelines, accessibility and props. \" +\n \"Use only the props it lists. Setup is get_doc('getting-started'). Themes: create_theme from up to three colors, \" +\n \"validate_theme to check a theme.css for WCAG AA contrast.\",\n },\n );\n\n server.registerTool(\n \"list_components\",\n {\n title: \"List components\",\n description: \"List every Senvenli UI component (name, family, one-line description), or one family's. To browse; search_components finds one by purpose.\",\n inputSchema: { family: z.string().optional().describe(`A family: ${[...new Set(data.components.map((item) => item.family))].join(\", \")}.`) },\n annotations: { readOnlyHint: true },\n },\n async ({ family }) => {\n const items = data.components.filter((item) => !family || item.family === family.trim().toLowerCase());\n if (!items.length) return fail(`No family \"${family}\". Families: ${[...new Set(data.components.map((item) => item.family))].join(\", \")}.`);\n return text(items.map((item) => `${item.name} (${item.family}): ${item.description}`).join(\"\\n\"));\n },\n );\n\n server.registerTool(\n \"search_components\",\n {\n title: \"Search components\",\n description: 'Find components by what they are for (\"date range\", \"upload a file\", \"confirm a delete\") or by export name (\"DatePicker\"). Returns names for get_component, with the import.',\n inputSchema: { query: z.string().min(1), limit: z.number().int().min(1).max(20).optional().describe(\"Default 8.\") },\n annotations: { readOnlyHint: true },\n },\n async ({ query, limit }) => {\n const hits = searchComponents(data.components, query, limit ?? 8);\n if (!hits.length) return text(`No component matches \"${query}\". Try a shorter phrase of what it is for, or list_components.`);\n return text(hits.map(({ component }) => `${component.name} (${component.family}): ${component.description}\\n import { ${component.exports.join(\", \")} } from \"${component.import}\";`).join(\"\\n\"));\n },\n );\n\n server.registerTool(\n \"get_component\",\n {\n title: \"Get a component\",\n description:\n \"Read one component's page as Markdown: import, example code, when to use it (and what instead), do and avoid, accessibility, and props. \" +\n \"Read it before using a component. Pass sections to read less of a long page.\",\n inputSchema: {\n name: z.string().describe('The component name, as search_components gives it: \"date-picker\".'),\n sections: z\n .array(z.enum(Object.keys(SECTIONS) as [Section, ...Section[]]))\n .optional()\n .describe(\"Only these parts (the title, import and intro always come): example (the main one), examples, guidelines, accessibility, api, related. Default: all.\"),\n },\n annotations: { readOnlyHint: true },\n },\n async ({ name, sections }) => {\n const component = findComponent(name);\n if (!component) return unknownComponent(name);\n if (sections?.length) return text(pageSections(component.markdown, sections));\n // A page too long for one answer (a component with several shapes, such as Input) comes without its API\n // reference, and says how to read it; nothing is cut silently.\n if (component.markdown.length <= PAGE_BUDGET) return text(component.markdown);\n const rest = (Object.keys(SECTIONS) as Section[]).filter((section) => section !== \"api\");\n return text(\n `${pageSections(component.markdown, rest)}\\n\\n> The API reference is long: read it with get_component({ name: \"${component.name}\", sections: [\"api\"] }) or get_component_manifest.`,\n );\n },\n );\n\n server.registerTool(\n \"get_component_manifest\",\n {\n title: \"Get a component's manifest\",\n description:\n \"The component's manifest as JSON: exports, usage, a11y, every prop with type, default and origin, tokens and strings. For tools that need structured data; to read, prefer get_component.\",\n inputSchema: {\n name: z.string(),\n props: z.enum([\"own\", \"own+aria\", \"all\"]).optional().describe('Which props: own; own+aria (default: also React Aria behavior props like onPress); all (also DOM and ARIA attributes).'),\n minified: z.boolean().optional().describe(\"Default true: one line, without the JSON Schema of each prop or the build fields.\"),\n },\n annotations: { readOnlyHint: true },\n },\n async ({ name, props, minified }) => {\n const component = findComponent(name);\n if (!component) return unknownComponent(name);\n const answer = manifestFor(component.manifest, props ?? \"own+aria\", minified ?? true);\n // Over the budget by default (a component with several shapes): its own props only, and the note in the JSON\n // (propsLeftOut) says how to ask for the rest.\n if (props === undefined && answer.length > PAGE_BUDGET) return text(manifestFor(component.manifest, \"own\", minified ?? true));\n return text(answer);\n },\n );\n\n server.registerTool(\n \"get_doc\",\n {\n title: \"Get a doc\",\n description: `Read a doc as Markdown. ${data.docs.map((doc) => `${doc.slug}: ${doc.description}`).join(\" \")}`,\n inputSchema: { name: z.enum(docSlugs) },\n annotations: { readOnlyHint: true },\n },\n async ({ name }) => {\n const doc = findDoc(name);\n return doc ? text(doc.markdown) : fail(`No doc \"${name}\". Docs: ${docSlugs.join(\", \")}.`);\n },\n );\n\n server.registerTool(\n \"create_theme\",\n {\n title: \"Create a theme\",\n description:\n \"Make a theme from up to three colors (all optional) and layout settings. Every text pair is checked against WCAG AA in light and dark, \" +\n \"and the engine moves a color that would fail. The default answer is the contrast report and the CLI command that writes theme.css; \" +\n \"ask for format tailwind, css or native to get the file's contents instead.\",\n inputSchema: {\n ...themeInputShape,\n format: z\n .enum([\"command\", \"tailwind\", \"css\", \"native\"])\n .optional()\n .describe(\"command (default): the report and a command to run; tailwind: the CSS with a Tailwind v4 @theme block; css: the variables only; native: hex JSON for React Native.\"),\n },\n annotations: { readOnlyHint: true },\n },\n async (args) => {\n const input = themeInput(args);\n if (typeof input === \"string\") return fail(input);\n const theme = createTheme(input);\n const code = encodePreset(input);\n const format = args.format ?? \"command\";\n const head = [report(theme), `Preset code: ${code}\\nBuilder: ${SITE}/create?p=${code}`];\n if (format === \"command\") {\n return text(\n [...head, `Write theme.css (with the Tailwind block) in the app:\\n\\nnpx @senvenli/cli theme ${code} --tailwind`, \"Then import it after Tailwind: get_doc('getting-started').\"].join(\"\\n\\n\"),\n );\n }\n const output = format === \"native\" ? JSON.stringify(toNative(theme), null, 2) : toCSS(theme, { tailwind: format === \"tailwind\" });\n return text([...head, format === \"native\" ? \"Save as theme.json:\" : \"Save as theme.css and import it after Tailwind (get_doc('getting-started')):\", output].join(\"\\n\\n\"));\n },\n );\n\n server.registerTool(\n \"validate_theme\",\n {\n title: \"Validate a theme\",\n description:\n \"Check a theme.css (as create_theme or the CLI wrote it, edited or not) against WCAG AA: every text, icon and border pair, light and dark. \" +\n \"Lists the failing pairs and any token the CSS lacks.\",\n inputSchema: { css: z.string().min(1).describe(\"The theme's CSS: the :root block and the [data-theme=\\\"dark\\\"] block.\") },\n annotations: { readOnlyHint: true },\n },\n async ({ css }) => {\n const { checks, missing } = checkThemeCss(css);\n if (!checks.length && missing.length) return fail(\"No Senvenli UI tokens (--ds-…) found in this CSS. Pass the theme.css that create_theme or the CLI wrote.\");\n const failing = checks.filter((check) => !check.pass);\n const lines = [`Contrast: ${checks.length - failing.length} of ${checks.length} checked pairs pass WCAG AA.`, ...failing.map(failLine)];\n if (missing.length) lines.push(`Missing or not a color (${missing.length}), so their pairs were not checked: ${missing.map((item) => `${item.token} (${item.mode})`).join(\", \")}.`);\n if (failing.length) lines.push(\"Fix: regenerate with create_theme from the brand colors, or darken (light) / lighten (dark) the failing foreground.\");\n return text(lines.join(\"\\n\"));\n },\n );\n\n server.registerPrompt(\n \"build_form\",\n {\n title: \"Build a form\",\n description: \"Build a form with Senvenli UI components, the way the system wants it: labels, validation, errors and the submit flow.\",\n argsSchema: { form: z.string().describe('What the form is for: \"sign up with email and password\", \"shipping address\".') },\n },\n ({ form }) => ({\n messages: [\n {\n role: \"user\",\n content: {\n type: \"text\",\n text:\n `Build this form with Senvenli UI (@senvenli/react): ${form}\\n\\n` +\n \"1. get_component('form') and get_component('field'), then search_components for each input it needs (dates, phone, password, choices).\\n\" +\n \"2. Read every component you use with get_component before writing it; use only the props it lists.\\n\" +\n \"3. Every field has a visible label; required fields say so; errors are shown on the field and announced, not only in color.\\n\" +\n \"4. One primary submit button; it shows pending state while submitting.\\n\" +\n \"5. Use the design tokens (ds- classes), never raw colors or pixel sizes.\",\n },\n },\n ],\n }),\n );\n\n server.registerPrompt(\n \"theme_app\",\n {\n title: \"Theme an app\",\n description: \"Set up Senvenli UI's theme in an app from its brand colors, checked against WCAG AA.\",\n argsSchema: { colors: z.string().optional().describe('The brand colors, \"#1268ae\" or \"oklch(…)\", up to three. Leave out for the neutral default.') },\n },\n ({ colors }) => ({\n messages: [\n {\n role: \"user\",\n content: {\n type: \"text\",\n text:\n `Theme this app with Senvenli UI${colors ? ` from these brand colors: ${colors}` : \"\"}.\\n\\n` +\n \"1. get_doc('getting-started') for install and where the theme CSS goes; get_doc('theming') for what the colors drive.\\n\" +\n \"2. create_theme with the colors (primary first); run the command it gives, or save its CSS.\\n\" +\n \"3. If a color was moved for contrast, say which and why.\\n\" +\n \"4. If the app's theme.css is edited by hand later, check it with validate_theme.\",\n },\n },\n ],\n }),\n );\n\n server.registerResource(\n \"component\",\n new ResourceTemplate(\"senvenli://components/{name}\", {\n list: async () => ({ resources: data.components.map((item) => ({ uri: `senvenli://components/${item.name}`, name: item.title, description: item.description, mimeType: \"text/markdown\" })) }),\n }),\n { title: \"Component page\", description: \"A component's page as Markdown.\", mimeType: \"text/markdown\" },\n async (uri, { name }) => {\n const component = findComponent(String(name));\n return { contents: [{ uri: uri.href, mimeType: \"text/markdown\", text: component?.markdown ?? `No component named \"${name}\".` }] };\n },\n );\n\n server.registerResource(\n \"doc\",\n new ResourceTemplate(\"senvenli://docs/{name}\", {\n list: async () => ({ resources: data.docs.map((doc) => ({ uri: `senvenli://docs/${doc.slug}`, name: doc.title, description: doc.description, mimeType: \"text/markdown\" })) }),\n }),\n { title: \"Doc\", description: \"A doc as Markdown.\", mimeType: \"text/markdown\" },\n async (uri, { name }) => {\n const doc = findDoc(String(name));\n return { contents: [{ uri: uri.href, mimeType: \"text/markdown\", text: doc?.markdown ?? `No doc named \"${name}\".` }] };\n },\n );\n\n return server;\n}\n"]}
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/stdio.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ // Local mode: `npx @senvenli/mcp` starts the server on stdio for Claude Code, Cursor, VS Code and others.
3
+ import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import { createServer } from "./server.js";
5
+ await createServer().connect(new StdioServerTransport());
6
+ //# sourceMappingURL=stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stdio.js","sourceRoot":"","sources":["../src/stdio.ts"],"names":[],"mappings":";AACA,0GAA0G;AAC1G,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAE3C,MAAM,YAAY,EAAE,CAAC,OAAO,CAAC,IAAI,oBAAoB,EAAE,CAAC,CAAC","sourcesContent":["#!/usr/bin/env node\n// Local mode: `npx @senvenli/mcp` starts the server on stdio for Claude Code, Cursor, VS Code and others.\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\nimport { createServer } from \"./server.js\";\n\nawait createServer().connect(new StdioServerTransport());\n"]}