@unpunnyfuns/swatchbook-mcp 0.50.0 → 0.51.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/bin.d.mts +1 -0
- package/dist/bin.mjs +135 -0
- package/dist/bin.mjs.map +1 -0
- package/dist/index.d.mts +40 -0
- package/dist/index.mjs +2 -0
- package/dist/load-config-B-8rGfFl.mjs +646 -0
- package/dist/load-config-B-8rGfFl.mjs.map +1 -0
- package/package.json +2 -2
package/dist/bin.d.mts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { };
|
package/dist/bin.mjs
ADDED
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { n as createServer, t as loadFromConfig } from "./load-config-B-8rGfFl.mjs";
|
|
3
|
+
import { basename, dirname, isAbsolute, resolve } from "node:path";
|
|
4
|
+
import { watch } from "node:fs";
|
|
5
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
6
|
+
//#region src/bin.ts
|
|
7
|
+
/**
|
|
8
|
+
* Stdio entry for `npx @unpunnyfuns/swatchbook-mcp --config <path>`.
|
|
9
|
+
*
|
|
10
|
+
* Parses `--config <path>`, optional `--cwd <path>`, loads the project, and
|
|
11
|
+
* binds an MCP server to stdio. Watches the resolved source files + config
|
|
12
|
+
* file so token edits land in subsequent tool calls without restarting the
|
|
13
|
+
* transport. Pass `--no-watch` to opt out (e.g. CI). Loader / watcher errors
|
|
14
|
+
* print to stderr — stdout is reserved for MCP protocol frames.
|
|
15
|
+
*/
|
|
16
|
+
function parseArgs(argv) {
|
|
17
|
+
const out = { watch: true };
|
|
18
|
+
for (let i = 0; i < argv.length; i++) {
|
|
19
|
+
const arg = argv[i];
|
|
20
|
+
const next = argv[i + 1];
|
|
21
|
+
if ((arg === "--config" || arg === "-c") && next) {
|
|
22
|
+
out.config = next;
|
|
23
|
+
i++;
|
|
24
|
+
} else if (arg === "--cwd" && next) {
|
|
25
|
+
out.cwd = next;
|
|
26
|
+
i++;
|
|
27
|
+
} else if (arg === "--no-watch") out.watch = false;
|
|
28
|
+
else if (arg === "--help" || arg === "-h") {
|
|
29
|
+
console.log(`swatchbook-mcp — Model Context Protocol server for swatchbook projects
|
|
30
|
+
|
|
31
|
+
Usage:
|
|
32
|
+
swatchbook-mcp --config <path> Point at a swatchbook.config.{ts,mts,js,mjs}
|
|
33
|
+
or a DTCG resolver.json directly. Bare
|
|
34
|
+
resolvers boot with every other config
|
|
35
|
+
option at defaults.
|
|
36
|
+
swatchbook-mcp --config <path> --cwd <path> Override the project cwd for relative paths.
|
|
37
|
+
swatchbook-mcp --config <path> --no-watch Disable live-reload on token / config edits.
|
|
38
|
+
|
|
39
|
+
Tools exposed:
|
|
40
|
+
describe_project Orientation — counts, axes, permutations, presets, diagnostics.
|
|
41
|
+
list_tokens List tokens by path glob / \`$type\`.
|
|
42
|
+
search_tokens Fuzzy search across paths, descriptions, values.
|
|
43
|
+
resolve_theme Full resolved token map for an axis tuple.
|
|
44
|
+
get_token Full detail for one token path.
|
|
45
|
+
get_alias_chain Forward alias chain per theme.
|
|
46
|
+
get_aliased_by Backward alias tree.
|
|
47
|
+
get_consumer_output CSS var + data-attribute activation for a tuple.
|
|
48
|
+
get_color_formats hex / rgb / hsl / oklch / raw for a color token.
|
|
49
|
+
get_color_contrast Pair-wise contrast (WCAG 2.1 ratio or APCA Lc) + pass flags.
|
|
50
|
+
get_axis_variance Classify token variance (constant / single / multi) per axis.
|
|
51
|
+
list_axes Axes + contexts + permutations + presets.
|
|
52
|
+
get_diagnostics Project diagnostics (optional severity filter).
|
|
53
|
+
emit_css Full project stylesheet.`);
|
|
54
|
+
process.exit(0);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Watch the project's source files + config path for edits. Debounces
|
|
61
|
+
* filesystem events (editors fire 2-3 per save) into a single reload per
|
|
62
|
+
* 100 ms burst; on each settle, calls `loadFromConfig` again and swaps the
|
|
63
|
+
* fresh project into the already-connected MCP server.
|
|
64
|
+
*
|
|
65
|
+
* Watches parent directories rather than files themselves. Atomic-save
|
|
66
|
+
* editors unlink + recreate the target inode, which kills file-level
|
|
67
|
+
* watchers on the first save; a dir watcher with filename filtering
|
|
68
|
+
* survives that dance. Mirrors the addon's plugin strategy.
|
|
69
|
+
*/
|
|
70
|
+
function setupReload(initialSourceFiles, configPath, reload) {
|
|
71
|
+
const dirs = /* @__PURE__ */ new Map();
|
|
72
|
+
const add = (file) => {
|
|
73
|
+
const dir = dirname(file);
|
|
74
|
+
const set = dirs.get(dir) ?? /* @__PURE__ */ new Set();
|
|
75
|
+
set.add(basename(file));
|
|
76
|
+
dirs.set(dir, set);
|
|
77
|
+
};
|
|
78
|
+
for (const file of initialSourceFiles) add(file);
|
|
79
|
+
add(configPath);
|
|
80
|
+
let pending = null;
|
|
81
|
+
const schedule = () => {
|
|
82
|
+
if (pending) clearTimeout(pending);
|
|
83
|
+
pending = setTimeout(() => {
|
|
84
|
+
pending = null;
|
|
85
|
+
reload().catch((err) => {
|
|
86
|
+
console.error("swatchbook-mcp: reload failed —", err);
|
|
87
|
+
});
|
|
88
|
+
}, 100);
|
|
89
|
+
};
|
|
90
|
+
const watchers = [];
|
|
91
|
+
for (const [dir, names] of dirs) try {
|
|
92
|
+
const w = watch(dir, { persistent: false }, (eventType, filename) => {
|
|
93
|
+
if (!filename) return;
|
|
94
|
+
if (!names.has(filename)) return;
|
|
95
|
+
if (eventType === "change" || eventType === "rename") schedule();
|
|
96
|
+
});
|
|
97
|
+
watchers.push(w);
|
|
98
|
+
} catch {}
|
|
99
|
+
return () => {
|
|
100
|
+
if (pending) clearTimeout(pending);
|
|
101
|
+
for (const w of watchers) w.close();
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
async function main() {
|
|
105
|
+
const args = parseArgs(process.argv.slice(2));
|
|
106
|
+
if (!args.config) {
|
|
107
|
+
console.error("swatchbook-mcp: --config <path> is required. Use --help for usage.");
|
|
108
|
+
process.exit(1);
|
|
109
|
+
}
|
|
110
|
+
const configAbsolute = isAbsolute(args.config) ? args.config : resolve(process.cwd(), args.config);
|
|
111
|
+
const { project } = await loadFromConfig(configAbsolute, args.cwd);
|
|
112
|
+
const server = createServer(project);
|
|
113
|
+
const transport = new StdioServerTransport();
|
|
114
|
+
await server.connect(transport);
|
|
115
|
+
if (args.watch) {
|
|
116
|
+
let stopWatchers = setupReload(project.sourceFiles, configAbsolute, () => reload());
|
|
117
|
+
async function reload() {
|
|
118
|
+
const { project: next } = await loadFromConfig(configAbsolute, args.cwd);
|
|
119
|
+
server.setProject(next);
|
|
120
|
+
const themeCount = next.permutations.length;
|
|
121
|
+
const tokenCount = Object.keys(next.permutationsResolved[next.permutations[0]?.name ?? ""] ?? {}).length;
|
|
122
|
+
console.error(`swatchbook-mcp: project reloaded — ${tokenCount} tokens across ${themeCount} theme${themeCount === 1 ? "" : "s"}.`);
|
|
123
|
+
stopWatchers();
|
|
124
|
+
stopWatchers = setupReload(next.sourceFiles, configAbsolute, () => reload());
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
main().catch((err) => {
|
|
129
|
+
console.error("swatchbook-mcp failed to start:", err);
|
|
130
|
+
process.exit(1);
|
|
131
|
+
});
|
|
132
|
+
//#endregion
|
|
133
|
+
export {};
|
|
134
|
+
|
|
135
|
+
//# sourceMappingURL=bin.mjs.map
|
package/dist/bin.mjs.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"bin.mjs","names":["fsWatch"],"sources":["../src/bin.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * Stdio entry for `npx @unpunnyfuns/swatchbook-mcp --config <path>`.\n *\n * Parses `--config <path>`, optional `--cwd <path>`, loads the project, and\n * binds an MCP server to stdio. Watches the resolved source files + config\n * file so token edits land in subsequent tool calls without restarting the\n * transport. Pass `--no-watch` to opt out (e.g. CI). Loader / watcher errors\n * print to stderr — stdout is reserved for MCP protocol frames.\n */\nimport { type FSWatcher, watch as fsWatch } from 'node:fs';\nimport { basename, dirname, isAbsolute, resolve } from 'node:path';\nimport { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';\nimport { loadFromConfig } from '#/load-config.ts';\nimport { createServer } from '#/server.ts';\n\ninterface CliArgs {\n config?: string;\n cwd?: string;\n watch: boolean;\n}\n\nfunction parseArgs(argv: readonly string[]): CliArgs {\n const out: CliArgs = { watch: true };\n for (let i = 0; i < argv.length; i++) {\n const arg = argv[i];\n const next = argv[i + 1];\n if ((arg === '--config' || arg === '-c') && next) {\n out.config = next;\n i++;\n } else if (arg === '--cwd' && next) {\n out.cwd = next;\n i++;\n } else if (arg === '--no-watch') {\n out.watch = false;\n } else if (arg === '--help' || arg === '-h') {\n console.log(`swatchbook-mcp — Model Context Protocol server for swatchbook projects\n\nUsage:\n swatchbook-mcp --config <path> Point at a swatchbook.config.{ts,mts,js,mjs}\n or a DTCG resolver.json directly. Bare\n resolvers boot with every other config\n option at defaults.\n swatchbook-mcp --config <path> --cwd <path> Override the project cwd for relative paths.\n swatchbook-mcp --config <path> --no-watch Disable live-reload on token / config edits.\n\nTools exposed:\n describe_project Orientation — counts, axes, permutations, presets, diagnostics.\n list_tokens List tokens by path glob / \\`$type\\`.\n search_tokens Fuzzy search across paths, descriptions, values.\n resolve_theme Full resolved token map for an axis tuple.\n get_token Full detail for one token path.\n get_alias_chain Forward alias chain per theme.\n get_aliased_by Backward alias tree.\n get_consumer_output CSS var + data-attribute activation for a tuple.\n get_color_formats hex / rgb / hsl / oklch / raw for a color token.\n get_color_contrast Pair-wise contrast (WCAG 2.1 ratio or APCA Lc) + pass flags.\n get_axis_variance Classify token variance (constant / single / multi) per axis.\n list_axes Axes + contexts + permutations + presets.\n get_diagnostics Project diagnostics (optional severity filter).\n emit_css Full project stylesheet.`);\n process.exit(0);\n }\n }\n return out;\n}\n\n/**\n * Watch the project's source files + config path for edits. Debounces\n * filesystem events (editors fire 2-3 per save) into a single reload per\n * 100 ms burst; on each settle, calls `loadFromConfig` again and swaps the\n * fresh project into the already-connected MCP server.\n *\n * Watches parent directories rather than files themselves. Atomic-save\n * editors unlink + recreate the target inode, which kills file-level\n * watchers on the first save; a dir watcher with filename filtering\n * survives that dance. Mirrors the addon's plugin strategy.\n */\nfunction setupReload(\n initialSourceFiles: readonly string[],\n configPath: string,\n reload: () => Promise<void>,\n): () => void {\n const dirs = new Map<string, Set<string>>();\n const add = (file: string): void => {\n const dir = dirname(file);\n const set = dirs.get(dir) ?? new Set<string>();\n set.add(basename(file));\n dirs.set(dir, set);\n };\n for (const file of initialSourceFiles) add(file);\n add(configPath);\n\n let pending: ReturnType<typeof setTimeout> | null = null;\n const schedule = (): void => {\n if (pending) clearTimeout(pending);\n pending = setTimeout(() => {\n pending = null;\n reload().catch((err) => {\n console.error('swatchbook-mcp: reload failed —', err);\n });\n }, 100);\n };\n\n const watchers: FSWatcher[] = [];\n for (const [dir, names] of dirs) {\n try {\n const w = fsWatch(dir, { persistent: false }, (eventType, filename) => {\n if (!filename) return;\n if (!names.has(filename)) return;\n if (eventType === 'change' || eventType === 'rename') schedule();\n });\n watchers.push(w);\n } catch {\n // unwatchable dir — skip. The initial load already succeeded, so the\n // server keeps serving the current snapshot.\n }\n }\n return () => {\n if (pending) clearTimeout(pending);\n for (const w of watchers) w.close();\n };\n}\n\nasync function main(): Promise<void> {\n const args = parseArgs(process.argv.slice(2));\n if (!args.config) {\n console.error('swatchbook-mcp: --config <path> is required. Use --help for usage.');\n process.exit(1);\n }\n const configAbsolute = isAbsolute(args.config)\n ? args.config\n : resolve(process.cwd(), args.config);\n\n const { project } = await loadFromConfig(configAbsolute, args.cwd);\n const server = createServer(project);\n const transport = new StdioServerTransport();\n await server.connect(transport);\n\n if (args.watch) {\n let stopWatchers = setupReload(project.sourceFiles, configAbsolute, () => reload());\n async function reload(): Promise<void> {\n const { project: next } = await loadFromConfig(configAbsolute, args.cwd);\n server.setProject(next);\n const themeCount = next.permutations.length;\n const tokenCount = Object.keys(\n next.permutationsResolved[next.permutations[0]?.name ?? ''] ?? {},\n ).length;\n console.error(\n `swatchbook-mcp: project reloaded — ${tokenCount} tokens across ${themeCount} theme${themeCount === 1 ? '' : 's'}.`,\n );\n // Rebind watchers against the fresh source-file set so newly-referenced\n // tokens / resolvers pick up edits from here on.\n stopWatchers();\n stopWatchers = setupReload(next.sourceFiles, configAbsolute, () => reload());\n }\n }\n}\n\nmain().catch((err) => {\n console.error('swatchbook-mcp failed to start:', err);\n process.exit(1);\n});\n"],"mappings":";;;;;;;;;;;;;;;AAsBA,SAAS,UAAU,MAAkC;CACnD,MAAM,MAAe,EAAE,OAAO,MAAM;AACpC,MAAK,IAAI,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAK;EACpC,MAAM,MAAM,KAAK;EACjB,MAAM,OAAO,KAAK,IAAI;AACtB,OAAK,QAAQ,cAAc,QAAQ,SAAS,MAAM;AAChD,OAAI,SAAS;AACb;aACS,QAAQ,WAAW,MAAM;AAClC,OAAI,MAAM;AACV;aACS,QAAQ,aACjB,KAAI,QAAQ;WACH,QAAQ,YAAY,QAAQ,MAAM;AAC3C,WAAQ,IAAI;;;;;;;;;;;;;;;;;;;;;;;;gDAwB8B;AAC1C,WAAQ,KAAK,EAAE;;;AAGnB,QAAO;;;;;;;;;;;;;AAcT,SAAS,YACP,oBACA,YACA,QACY;CACZ,MAAM,uBAAO,IAAI,KAA0B;CAC3C,MAAM,OAAO,SAAuB;EAClC,MAAM,MAAM,QAAQ,KAAK;EACzB,MAAM,MAAM,KAAK,IAAI,IAAI,oBAAI,IAAI,KAAa;AAC9C,MAAI,IAAI,SAAS,KAAK,CAAC;AACvB,OAAK,IAAI,KAAK,IAAI;;AAEpB,MAAK,MAAM,QAAQ,mBAAoB,KAAI,KAAK;AAChD,KAAI,WAAW;CAEf,IAAI,UAAgD;CACpD,MAAM,iBAAuB;A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ClE,CAAC;AACF,WAAQ,MACN,sCAAsC,WAAW,iBAAiB,WAAW,QAAQ,eAAe,IAAI,KAAK,IAAI,GAClH;AAGD,iBAAc;AACd,kBAAe,YAAY,KAAK,aAAa,sBAAsB,QAAQ,CAAC;;;;AAKlF,MAAM,CAAC,OAAO,QAAQ;AACpB,SAAQ,MAAM,mCAAmC,IAAI;AACrD,SAAQ,KAAK,EAAE;EACf"}
|
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { Config, Project } from "@unpunnyfuns/swatchbook-core";
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
|
|
4
|
+
//#region src/server.d.ts
|
|
5
|
+
/**
|
|
6
|
+
* Build a swatchbook MCP server bound to a loaded project. Tools expose the
|
|
7
|
+
* project's tokens, axes, and diagnostics so an AI agent can query them
|
|
8
|
+
* without running Storybook. Tool handlers close over a live `project`
|
|
9
|
+
* reference — call the returned `setProject` to swap in a freshly loaded
|
|
10
|
+
* project (e.g. after token edits) without re-binding the transport.
|
|
11
|
+
*/
|
|
12
|
+
declare function createServer(initial: Project): McpServer & {
|
|
13
|
+
setProject: (next: Project) => void;
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/load-config.d.ts
|
|
17
|
+
/**
|
|
18
|
+
* Load a swatchbook project from either a full config module or a bare
|
|
19
|
+
* DTCG resolver JSON.
|
|
20
|
+
*
|
|
21
|
+
* `.ts` / `.mts` / `.js` / `.mjs` → jiti imports the module and uses
|
|
22
|
+
* its default export as the swatchbook {@link Config}.
|
|
23
|
+
*
|
|
24
|
+
* `.json` → treated as a DTCG resolver file; the CLI constructs a
|
|
25
|
+
* minimal `{ resolver: path }` config so agents can point at a raw
|
|
26
|
+
* resolver without authoring a wrapper. Every other config option
|
|
27
|
+
* (presets, chrome map, disabled axes, css-var prefix) falls back to
|
|
28
|
+
* `loadProject` defaults.
|
|
29
|
+
*
|
|
30
|
+
* The `cwd` returned is the directory the config / resolver lives in.
|
|
31
|
+
* `loadProject` uses it to resolve relative token references.
|
|
32
|
+
*/
|
|
33
|
+
declare function loadFromConfig(configPath: string, cwdOverride?: string): Promise<{
|
|
34
|
+
project: Project;
|
|
35
|
+
cwd: string;
|
|
36
|
+
config: Config;
|
|
37
|
+
}>;
|
|
38
|
+
//#endregion
|
|
39
|
+
export { createServer, loadFromConfig };
|
|
40
|
+
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,646 @@
|
|
|
1
|
+
import { analyzeAxisVariance, loadProject, projectCss } from "@unpunnyfuns/swatchbook-core";
|
|
2
|
+
import { fuzzyFilter, fuzzyMatches } from "@unpunnyfuns/swatchbook-core/fuzzy";
|
|
3
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import Color from "colorjs.io";
|
|
6
|
+
import { extname, isAbsolute, resolve } from "node:path";
|
|
7
|
+
import { pathToFileURL } from "node:url";
|
|
8
|
+
import { createJiti } from "jiti";
|
|
9
|
+
//#region src/contrast.ts
|
|
10
|
+
function toColor(raw) {
|
|
11
|
+
if (!raw || typeof raw !== "object") return null;
|
|
12
|
+
const n = raw;
|
|
13
|
+
const components = n.components ?? n.channels;
|
|
14
|
+
if (!components || !n.colorSpace) return null;
|
|
15
|
+
const [r = 0, g = 0, b = 0] = components.map((c) => c == null ? 0 : c);
|
|
16
|
+
try {
|
|
17
|
+
return new Color(n.colorSpace, [
|
|
18
|
+
r,
|
|
19
|
+
g,
|
|
20
|
+
b
|
|
21
|
+
], n.alpha ?? 1);
|
|
22
|
+
} catch {
|
|
23
|
+
return null;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function computeContrast(foreground, background, algorithm = "wcag21") {
|
|
27
|
+
const fg = toColor(foreground);
|
|
28
|
+
const bg = toColor(background);
|
|
29
|
+
if (!fg || !bg) return null;
|
|
30
|
+
if (algorithm === "wcag21") {
|
|
31
|
+
const ratio = fg.contrast(bg, "WCAG21");
|
|
32
|
+
return {
|
|
33
|
+
algorithm: "wcag21",
|
|
34
|
+
ratio,
|
|
35
|
+
wcag: {
|
|
36
|
+
aa: {
|
|
37
|
+
normal: ratio >= 4.5,
|
|
38
|
+
large: ratio >= 3
|
|
39
|
+
},
|
|
40
|
+
aaa: {
|
|
41
|
+
normal: ratio >= 7,
|
|
42
|
+
large: ratio >= 4.5
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* APCA thresholds from the Silver draft guidance. These are the
|
|
49
|
+
* "body text / large text / non-text" bronze tier thresholds most
|
|
50
|
+
* tooling settles on; the full table has more gradations but
|
|
51
|
+
* agents rarely need them. Non-text = icons, focus rings, UI
|
|
52
|
+
* borders.
|
|
53
|
+
*/
|
|
54
|
+
const lc = fg.contrast(bg, "APCA");
|
|
55
|
+
const absLc = Math.abs(lc);
|
|
56
|
+
return {
|
|
57
|
+
algorithm: "apca",
|
|
58
|
+
ratio: lc,
|
|
59
|
+
apca: {
|
|
60
|
+
lc,
|
|
61
|
+
body: absLc >= 75,
|
|
62
|
+
largeText: absLc >= 60,
|
|
63
|
+
nonText: absLc >= 45
|
|
64
|
+
}
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
//#endregion
|
|
68
|
+
//#region src/format-color.ts
|
|
69
|
+
function formatColor(raw, format) {
|
|
70
|
+
if (!raw || typeof raw !== "object") return null;
|
|
71
|
+
const normalized = raw;
|
|
72
|
+
if (format === "raw") return {
|
|
73
|
+
format,
|
|
74
|
+
value: JSON.stringify(raw),
|
|
75
|
+
outOfGamut: false
|
|
76
|
+
};
|
|
77
|
+
const components = normalized.components ?? normalized.channels;
|
|
78
|
+
if (!components || !normalized.colorSpace) return null;
|
|
79
|
+
let color;
|
|
80
|
+
try {
|
|
81
|
+
const [r = 0, g = 0, b = 0] = components.map((c) => c == null ? 0 : c);
|
|
82
|
+
color = new Color(normalized.colorSpace, [
|
|
83
|
+
r,
|
|
84
|
+
g,
|
|
85
|
+
b
|
|
86
|
+
], normalized.alpha ?? 1);
|
|
87
|
+
} catch {
|
|
88
|
+
return null;
|
|
89
|
+
}
|
|
90
|
+
if (format === "hex") try {
|
|
91
|
+
const inSrgb = color.to("srgb");
|
|
92
|
+
if (!inSrgb.inGamut()) return {
|
|
93
|
+
format,
|
|
94
|
+
value: inSrgb.toString({ format: "rgb" }),
|
|
95
|
+
outOfGamut: true
|
|
96
|
+
};
|
|
97
|
+
return {
|
|
98
|
+
format,
|
|
99
|
+
value: inSrgb.toString({ format: "hex" }),
|
|
100
|
+
outOfGamut: false
|
|
101
|
+
};
|
|
102
|
+
} catch {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
105
|
+
if (format === "rgb") try {
|
|
106
|
+
const inSrgb = color.to("srgb");
|
|
107
|
+
return {
|
|
108
|
+
format,
|
|
109
|
+
value: inSrgb.toString({ format: "rgb" }),
|
|
110
|
+
outOfGamut: !inSrgb.inGamut()
|
|
111
|
+
};
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (format === "hsl") try {
|
|
116
|
+
return {
|
|
117
|
+
format,
|
|
118
|
+
value: color.to("hsl").toString(),
|
|
119
|
+
outOfGamut: !color.to("srgb").inGamut()
|
|
120
|
+
};
|
|
121
|
+
} catch {
|
|
122
|
+
return null;
|
|
123
|
+
}
|
|
124
|
+
if (format === "oklch") try {
|
|
125
|
+
return {
|
|
126
|
+
format,
|
|
127
|
+
value: color.to("oklch").toString(),
|
|
128
|
+
outOfGamut: false
|
|
129
|
+
};
|
|
130
|
+
} catch {
|
|
131
|
+
return null;
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const ALL_COLOR_FORMATS = [
|
|
136
|
+
"hex",
|
|
137
|
+
"rgb",
|
|
138
|
+
"hsl",
|
|
139
|
+
"oklch",
|
|
140
|
+
"raw"
|
|
141
|
+
];
|
|
142
|
+
function formatColorEveryWay(raw) {
|
|
143
|
+
const out = {};
|
|
144
|
+
for (const format of ALL_COLOR_FORMATS) {
|
|
145
|
+
const result = formatColor(raw, format);
|
|
146
|
+
if (result) out[format] = result;
|
|
147
|
+
}
|
|
148
|
+
return out;
|
|
149
|
+
}
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/match.ts
|
|
152
|
+
/**
|
|
153
|
+
* Minimal DTCG-flavoured path matcher. Accepts exact paths (`color.bg`), single-
|
|
154
|
+
* segment globs (`color.*`), multi-segment globs (`color.**`), or a trailing `*`
|
|
155
|
+
* mid-segment (`color.palette.blue.*`). No brace expansion, no regex — DTCG
|
|
156
|
+
* paths are dot-delimited and this matches the parity the blocks' `globMatch`
|
|
157
|
+
* ships. Case-sensitive.
|
|
158
|
+
*/
|
|
159
|
+
function matchPath(path, filter) {
|
|
160
|
+
if (!filter) return true;
|
|
161
|
+
if (filter === "**" || filter === "*") return true;
|
|
162
|
+
const pathSegments = path.split(".");
|
|
163
|
+
const filterSegments = filter.split(".");
|
|
164
|
+
let pi = 0;
|
|
165
|
+
let fi = 0;
|
|
166
|
+
while (fi < filterSegments.length) {
|
|
167
|
+
const fseg = filterSegments[fi];
|
|
168
|
+
if (fseg === "**") {
|
|
169
|
+
if (fi === filterSegments.length - 1) return true;
|
|
170
|
+
const remaining = filterSegments.slice(fi + 1);
|
|
171
|
+
for (let k = pi; k <= pathSegments.length; k++) if (matchPath(pathSegments.slice(k).join("."), remaining.join("."))) return true;
|
|
172
|
+
return false;
|
|
173
|
+
}
|
|
174
|
+
if (pi >= pathSegments.length) return false;
|
|
175
|
+
const pseg = pathSegments[pi];
|
|
176
|
+
if (fseg === "*") {} else if (fseg !== pseg) return false;
|
|
177
|
+
pi++;
|
|
178
|
+
fi++;
|
|
179
|
+
}
|
|
180
|
+
return pi === pathSegments.length;
|
|
181
|
+
}
|
|
182
|
+
//#endregion
|
|
183
|
+
//#region src/server.ts
|
|
184
|
+
/**
|
|
185
|
+
* Build a swatchbook MCP server bound to a loaded project. Tools expose the
|
|
186
|
+
* project's tokens, axes, and diagnostics so an AI agent can query them
|
|
187
|
+
* without running Storybook. Tool handlers close over a live `project`
|
|
188
|
+
* reference — call the returned `setProject` to swap in a freshly loaded
|
|
189
|
+
* project (e.g. after token edits) without re-binding the transport.
|
|
190
|
+
*/
|
|
191
|
+
function createServer(initial) {
|
|
192
|
+
let project = initial;
|
|
193
|
+
const server = new McpServer({
|
|
194
|
+
name: "@unpunnyfuns/swatchbook-mcp",
|
|
195
|
+
version: project.config.cssVarPrefix ? `project:${project.config.cssVarPrefix}` : "project"
|
|
196
|
+
}, { instructions: "Query a swatchbook DTCG project: list tokens by path glob, inspect individual tokens (value, $type, alias chain, per-theme resolved values), read axes / presets, and inspect diagnostics." });
|
|
197
|
+
server.setProject = (next) => {
|
|
198
|
+
project = next;
|
|
199
|
+
};
|
|
200
|
+
server.registerTool("describe_project", {
|
|
201
|
+
description: "High-level summary of the project — total token count per theme, axes (with contexts) and how they compose, preset list, diagnostic counts by severity, css-var prefix, and the DTCG `$type`s present. Good first call for an agent that needs an orientation before querying specifics.",
|
|
202
|
+
inputSchema: {}
|
|
203
|
+
}, () => {
|
|
204
|
+
const typeCounts = {};
|
|
205
|
+
const tokensPerTheme = {};
|
|
206
|
+
for (const theme of project.permutations) {
|
|
207
|
+
const tokens = project.permutationsResolved[theme.name] ?? {};
|
|
208
|
+
tokensPerTheme[theme.name] = Object.keys(tokens).length;
|
|
209
|
+
for (const token of Object.values(tokens)) if (token.$type) typeCounts[token.$type] = (typeCounts[token.$type] ?? 0) + 1;
|
|
210
|
+
}
|
|
211
|
+
const diagBySeverity = {
|
|
212
|
+
error: 0,
|
|
213
|
+
warn: 0,
|
|
214
|
+
info: 0
|
|
215
|
+
};
|
|
216
|
+
for (const d of project.diagnostics) diagBySeverity[d.severity] = (diagBySeverity[d.severity] ?? 0) + 1;
|
|
217
|
+
return jsonResult({
|
|
218
|
+
cssVarPrefix: project.config.cssVarPrefix ?? "",
|
|
219
|
+
axes: project.axes.map((a) => ({
|
|
220
|
+
name: a.name,
|
|
221
|
+
contexts: a.contexts,
|
|
222
|
+
default: a.default
|
|
223
|
+
})),
|
|
224
|
+
permutations: project.permutations.map((t) => t.name),
|
|
225
|
+
defaultPermutation: project.permutations[0]?.name ?? null,
|
|
226
|
+
presets: project.presets.map((p) => p.name),
|
|
227
|
+
tokensPerTheme,
|
|
228
|
+
types: typeCounts,
|
|
229
|
+
diagnostics: {
|
|
230
|
+
counts: diagBySeverity,
|
|
231
|
+
total: project.diagnostics.length
|
|
232
|
+
}
|
|
233
|
+
});
|
|
234
|
+
});
|
|
235
|
+
server.registerTool("emit_css", {
|
|
236
|
+
description: "Return the full project CSS — a `:root` block with the default tuple plus one compound-selector block per non-default axis combination. Same output the addon injects into Storybook and the docs-site chrome pipeline writes to disk. Useful when an agent needs to inline the stylesheet into a generated artifact.",
|
|
237
|
+
inputSchema: {}
|
|
238
|
+
}, () => textResult(projectCss(project)));
|
|
239
|
+
server.registerTool("list_tokens", {
|
|
240
|
+
description: "List token paths in the project, optionally filtered by path glob (`color.*`, `color.palette.**`) and/or DTCG `$type` (color, dimension, typography, …). Returns path + $type + stringified value from the default theme. Use this first to discover what tokens exist; follow with get_token for details.",
|
|
241
|
+
inputSchema: {
|
|
242
|
+
filter: z.string().optional().describe("Dot-path glob, e.g. `color.*` or `color.palette.**`. Omit for all tokens."),
|
|
243
|
+
type: z.string().optional().describe("DTCG `$type` to scope the result, e.g. `color`, `dimension`, `typography`."),
|
|
244
|
+
theme: z.string().optional().describe("Permutation name to read values from. Defaults to the project default theme.")
|
|
245
|
+
}
|
|
246
|
+
}, ({ filter, type, theme }) => {
|
|
247
|
+
const themeName = theme ?? project.permutations[0]?.name;
|
|
248
|
+
if (!themeName) return textResult("No permutations in project.");
|
|
249
|
+
const tokens = project.permutationsResolved[themeName] ?? {};
|
|
250
|
+
const rows = [];
|
|
251
|
+
for (const [path, token] of Object.entries(tokens)) {
|
|
252
|
+
if (type && token.$type !== type) continue;
|
|
253
|
+
if (!matchPath(path, filter)) continue;
|
|
254
|
+
rows.push({
|
|
255
|
+
path,
|
|
256
|
+
...token.$type !== void 0 && { type: token.$type },
|
|
257
|
+
value: stringifyValue(token.$value)
|
|
258
|
+
});
|
|
259
|
+
}
|
|
260
|
+
rows.sort((a, b) => a.path.localeCompare(b.path, void 0, { numeric: true }));
|
|
261
|
+
return jsonResult({
|
|
262
|
+
theme: themeName,
|
|
263
|
+
count: rows.length,
|
|
264
|
+
tokens: rows
|
|
265
|
+
});
|
|
266
|
+
});
|
|
267
|
+
server.registerTool("get_token", {
|
|
268
|
+
description: "Get full details for a single token: resolved value in every theme, DTCG `$type`, `$description`, alias chain, aliased-by list, and CSS var reference. Use after `list_tokens` to inspect a specific path.",
|
|
269
|
+
inputSchema: { path: z.string().describe("Dot-path of the token, e.g. `color.accent.bg`.") }
|
|
270
|
+
}, ({ path }) => {
|
|
271
|
+
const perTheme = {};
|
|
272
|
+
let type;
|
|
273
|
+
let description;
|
|
274
|
+
let aliasedBy;
|
|
275
|
+
let found = false;
|
|
276
|
+
for (const theme of project.permutations) {
|
|
277
|
+
const token = project.permutationsResolved[theme.name]?.[path];
|
|
278
|
+
if (!token) continue;
|
|
279
|
+
found = true;
|
|
280
|
+
type ??= token.$type;
|
|
281
|
+
description ??= token.$description;
|
|
282
|
+
aliasedBy ??= token.aliasedBy;
|
|
283
|
+
perTheme[theme.name] = {
|
|
284
|
+
value: stringifyValue(token.$value),
|
|
285
|
+
...token.aliasOf !== void 0 && { aliasOf: token.aliasOf },
|
|
286
|
+
...token.aliasChain !== void 0 && { aliasChain: token.aliasChain }
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (!found) return textResult(`Token not found: ${path}`);
|
|
290
|
+
const prefix = project.config.cssVarPrefix ?? "";
|
|
291
|
+
const cssVar = `var(--${prefix ? `${prefix}-` : ""}${path.replaceAll(".", "-")})`;
|
|
292
|
+
return jsonResult({
|
|
293
|
+
path,
|
|
294
|
+
type,
|
|
295
|
+
description,
|
|
296
|
+
cssVar,
|
|
297
|
+
aliasedBy,
|
|
298
|
+
perTheme
|
|
299
|
+
});
|
|
300
|
+
});
|
|
301
|
+
server.registerTool("list_axes", {
|
|
302
|
+
description: "List the project axes — each axis has a name, its contexts (discrete values like `Light` / `Dark`), a default, and a source (`resolver` for DTCG-resolver-driven, `layered` for authored layered axes, `synthetic` for single-theme projects). Also returns the named permutations (every axis tuple combination) and any presets defined in the project config.",
|
|
303
|
+
inputSchema: {}
|
|
304
|
+
}, () => jsonResult({
|
|
305
|
+
axes: project.axes.map((axis) => ({
|
|
306
|
+
name: axis.name,
|
|
307
|
+
contexts: axis.contexts,
|
|
308
|
+
default: axis.default,
|
|
309
|
+
description: axis.description,
|
|
310
|
+
source: axis.source
|
|
311
|
+
})),
|
|
312
|
+
disabledAxes: project.disabledAxes,
|
|
313
|
+
permutations: project.permutations.map((t) => ({
|
|
314
|
+
name: t.name,
|
|
315
|
+
input: t.input
|
|
316
|
+
})),
|
|
317
|
+
presets: project.presets.map((p) => ({
|
|
318
|
+
name: p.name,
|
|
319
|
+
axes: p.axes,
|
|
320
|
+
description: p.description
|
|
321
|
+
}))
|
|
322
|
+
}));
|
|
323
|
+
server.registerTool("get_alias_chain", {
|
|
324
|
+
description: "Forward alias chain for a token — the sequence of paths it resolves through on the way to a primitive value (e.g. `color.accent.bg → color.brand.blue.700 → color.palette.blue.700`). Returns the chain per theme because aliases can resolve through different paths per axis context. Empty chain when the token is a primitive (no aliases) or missing.",
|
|
325
|
+
inputSchema: { path: z.string().describe("Dot-path of the token, e.g. `color.accent.bg`.") }
|
|
326
|
+
}, ({ path }) => {
|
|
327
|
+
const perTheme = {};
|
|
328
|
+
let found = false;
|
|
329
|
+
for (const theme of project.permutations) {
|
|
330
|
+
const token = project.permutationsResolved[theme.name]?.[path];
|
|
331
|
+
if (!token) continue;
|
|
332
|
+
found = true;
|
|
333
|
+
const chain = [path];
|
|
334
|
+
if (token.aliasChain && token.aliasChain.length > 0) chain.push(...token.aliasChain);
|
|
335
|
+
else if (token.aliasOf) chain.push(token.aliasOf);
|
|
336
|
+
perTheme[theme.name] = {
|
|
337
|
+
...token.aliasOf !== void 0 && { aliasOf: token.aliasOf },
|
|
338
|
+
chain
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
if (!found) return textResult(`Token not found: ${path}`);
|
|
342
|
+
return jsonResult({
|
|
343
|
+
path,
|
|
344
|
+
perTheme
|
|
345
|
+
});
|
|
346
|
+
});
|
|
347
|
+
server.registerTool("get_aliased_by", {
|
|
348
|
+
description: "Backward alias tree for a token — every token that resolves through this path at any depth. Breadth-first walk with cycle protection; `maxDepth` caps recursion (default 6). Empty when nothing aliases the token.",
|
|
349
|
+
inputSchema: {
|
|
350
|
+
path: z.string().describe("Dot-path of the token, e.g. `color.palette.blue.500`."),
|
|
351
|
+
maxDepth: z.number().int().positive().optional().describe("Maximum recursion depth. Default 6.")
|
|
352
|
+
}
|
|
353
|
+
}, ({ path, maxDepth }) => {
|
|
354
|
+
const depth = maxDepth ?? 6;
|
|
355
|
+
const themeName = project.permutations[0]?.name;
|
|
356
|
+
if (!themeName) return textResult("No permutations in project.");
|
|
357
|
+
const tokens = project.permutationsResolved[themeName] ?? {};
|
|
358
|
+
if (!tokens[path]) return textResult(`Token not found: ${path}`);
|
|
359
|
+
const visited = new Set([path]);
|
|
360
|
+
const walk = (current, d) => {
|
|
361
|
+
const direct = tokens[current]?.aliasedBy ?? [];
|
|
362
|
+
if (direct.length === 0) return {
|
|
363
|
+
path: current,
|
|
364
|
+
depth: d,
|
|
365
|
+
children: []
|
|
366
|
+
};
|
|
367
|
+
if (d >= depth) return {
|
|
368
|
+
path: current,
|
|
369
|
+
depth: d,
|
|
370
|
+
children: [],
|
|
371
|
+
truncated: true
|
|
372
|
+
};
|
|
373
|
+
const children = [];
|
|
374
|
+
for (const p of direct) {
|
|
375
|
+
if (visited.has(p)) continue;
|
|
376
|
+
visited.add(p);
|
|
377
|
+
children.push(walk(p, d + 1));
|
|
378
|
+
}
|
|
379
|
+
return {
|
|
380
|
+
path: current,
|
|
381
|
+
depth: d,
|
|
382
|
+
children
|
|
383
|
+
};
|
|
384
|
+
};
|
|
385
|
+
return jsonResult(walk(path, 0));
|
|
386
|
+
});
|
|
387
|
+
server.registerTool("get_color_formats", {
|
|
388
|
+
description: "For a color token, return its value rendered in every format the addon toolbar exposes — `hex`, `rgb`, `hsl`, `oklch`, and the raw JSON. Each entry carries an `outOfGamut` flag when the chosen colorspace can't losslessly represent the token (wide-gamut tokens rendered in sRGB, for example). Skips non-color tokens.",
|
|
389
|
+
inputSchema: {
|
|
390
|
+
path: z.string().describe("Dot-path of a color token, e.g. `color.accent.bg`."),
|
|
391
|
+
theme: z.string().optional().describe("Permutation name to read the value from. Defaults to the project default theme.")
|
|
392
|
+
}
|
|
393
|
+
}, ({ path, theme }) => {
|
|
394
|
+
const themeName = theme ?? project.permutations[0]?.name;
|
|
395
|
+
if (!themeName) return textResult("No permutations in project.");
|
|
396
|
+
const token = project.permutationsResolved[themeName]?.[path];
|
|
397
|
+
if (!token) return textResult(`Token not found: ${path}`);
|
|
398
|
+
if (token.$type !== "color") return textResult(`Token ${path} is not a color (got $type=${token.$type ?? "unknown"}).`);
|
|
399
|
+
return jsonResult({
|
|
400
|
+
path,
|
|
401
|
+
theme: themeName,
|
|
402
|
+
formats: formatColorEveryWay(token.$value)
|
|
403
|
+
});
|
|
404
|
+
});
|
|
405
|
+
server.registerTool("get_color_contrast", {
|
|
406
|
+
description: "Compute the contrast between two color tokens for a given theme. WCAG 2.1 returns the ratio (1–21) plus AA/AAA pass flags for normal + large text; APCA returns the signed Lc value plus body / large-text / non-text pass flags (absolute-value thresholds 75 / 60 / 45). Use this when reasoning about text legibility, focus-ring visibility, border contrast, etc., without having to reimplement the luminance math in the agent. Per-theme so the same pair can be checked against Light, Dark, High-contrast, etc.",
|
|
407
|
+
inputSchema: {
|
|
408
|
+
foreground: z.string().describe("Dot-path of the foreground color token, e.g. `color.text.default`."),
|
|
409
|
+
background: z.string().describe("Dot-path of the background color token, e.g. `color.surface.default`."),
|
|
410
|
+
theme: z.string().optional().describe("Permutation name. Defaults to the project default theme."),
|
|
411
|
+
algorithm: z.enum(["wcag21", "apca"]).optional().describe("Contrast algorithm. `wcag21` is the classic 4.5:1 ratio; `apca` is the perceptually-weighted Silver-draft successor. Defaults to `wcag21`.")
|
|
412
|
+
}
|
|
413
|
+
}, ({ foreground, background, theme, algorithm }) => {
|
|
414
|
+
const themeName = theme ?? project.permutations[0]?.name;
|
|
415
|
+
if (!themeName) return textResult("No permutations in project.");
|
|
416
|
+
const fgTok = project.permutationsResolved[themeName]?.[foreground];
|
|
417
|
+
const bgTok = project.permutationsResolved[themeName]?.[background];
|
|
418
|
+
if (!fgTok) return textResult(`Foreground token not found: ${foreground}`);
|
|
419
|
+
if (!bgTok) return textResult(`Background token not found: ${background}`);
|
|
420
|
+
if (fgTok.$type !== "color") return textResult(`Foreground ${foreground} is not a color (got $type=${fgTok.$type ?? "unknown"}).`);
|
|
421
|
+
if (bgTok.$type !== "color") return textResult(`Background ${background} is not a color (got $type=${bgTok.$type ?? "unknown"}).`);
|
|
422
|
+
const result = computeContrast(fgTok.$value, bgTok.$value, algorithm ?? "wcag21");
|
|
423
|
+
if (!result) return textResult("Could not compute contrast — one or both values failed to parse as a color.");
|
|
424
|
+
return jsonResult({
|
|
425
|
+
theme: themeName,
|
|
426
|
+
foreground: {
|
|
427
|
+
path: foreground,
|
|
428
|
+
value: stringifyValue(fgTok.$value)
|
|
429
|
+
},
|
|
430
|
+
background: {
|
|
431
|
+
path: background,
|
|
432
|
+
value: stringifyValue(bgTok.$value)
|
|
433
|
+
},
|
|
434
|
+
...result
|
|
435
|
+
});
|
|
436
|
+
});
|
|
437
|
+
server.registerTool("get_axis_variance", {
|
|
438
|
+
description: "Classify how a token's resolved value depends on the project's axes. Returns `kind` — `constant` (same across every tuple), `single` (varies with exactly one axis, e.g. mode only), or `multi` (varies across two or more axes). Also returns `varyingAxes` / `constantAcrossAxes` plus a `perAxis` breakdown with each context's stringified value (holding other axes at their defaults). Use when reasoning about whether a token is theme-independent, whether a refactor changed an axis dependency, or to confirm that (say) a role token only varies with `contrast`.",
|
|
439
|
+
inputSchema: { path: z.string().describe("Dot-path of the token to analyse, e.g. `color.text.default`.") }
|
|
440
|
+
}, ({ path }) => {
|
|
441
|
+
if (project.permutations.length === 0) return textResult("No permutations in project.");
|
|
442
|
+
if (!project.permutations.some((t) => project.permutationsResolved[t.name]?.[path])) return textResult(`Token not found in any theme: ${path}`);
|
|
443
|
+
return jsonResult(analyzeAxisVariance(path, project.axes, project.permutations, project.permutationsResolved));
|
|
444
|
+
});
|
|
445
|
+
server.registerTool("search_tokens", {
|
|
446
|
+
description: "Fuzzy search across token paths, `$description`, and stringified values. Case-insensitive, tolerates a single-character typo per term, and accepts out-of-order terms (`\"blue palette\"` finds `color.palette.blue.500`). Returns matches ranked by relevance with a short snippet pointing at where the match hit. Use when you know what you want but not the exact path. Scopes to a single theme (default: project default).",
|
|
447
|
+
inputSchema: {
|
|
448
|
+
query: z.string().min(1).describe("Fuzzy query (case-insensitive)."),
|
|
449
|
+
theme: z.string().optional().describe("Permutation name to search within. Defaults to the project default."),
|
|
450
|
+
limit: z.number().int().positive().optional().describe("Cap the result count. Default 50.")
|
|
451
|
+
}
|
|
452
|
+
}, ({ query, theme, limit }) => {
|
|
453
|
+
const themeName = theme ?? project.permutations[0]?.name;
|
|
454
|
+
if (!themeName) return textResult("No permutations in project.");
|
|
455
|
+
const tokens = project.permutationsResolved[themeName] ?? {};
|
|
456
|
+
const max = limit ?? 50;
|
|
457
|
+
const hits = fuzzyFilter(Object.entries(tokens).map(([path, token]) => {
|
|
458
|
+
const description = token.$description ?? "";
|
|
459
|
+
const value = stringifyValue(token.$value);
|
|
460
|
+
return {
|
|
461
|
+
path,
|
|
462
|
+
token,
|
|
463
|
+
description,
|
|
464
|
+
value,
|
|
465
|
+
composite: `${path} ${description} ${value}`
|
|
466
|
+
};
|
|
467
|
+
}), query, (c) => c.composite, { limit: max }).map((c) => {
|
|
468
|
+
const matchedIn = [];
|
|
469
|
+
if (fuzzyMatches(c.path, query)) matchedIn.push("path");
|
|
470
|
+
if (c.description && fuzzyMatches(c.description, query)) matchedIn.push("description");
|
|
471
|
+
if (fuzzyMatches(c.value, query)) matchedIn.push("value");
|
|
472
|
+
if (matchedIn.length === 0) matchedIn.push("path");
|
|
473
|
+
const snippet = matchedIn.includes("description") ? c.token.$description ?? c.path : matchedIn.includes("value") ? `${c.path} = ${c.value}` : c.path;
|
|
474
|
+
const entry = {
|
|
475
|
+
path: c.path,
|
|
476
|
+
matchedIn,
|
|
477
|
+
snippet
|
|
478
|
+
};
|
|
479
|
+
if (c.token.$type !== void 0) entry.type = c.token.$type;
|
|
480
|
+
return entry;
|
|
481
|
+
});
|
|
482
|
+
return jsonResult({
|
|
483
|
+
query,
|
|
484
|
+
theme: themeName,
|
|
485
|
+
count: hits.length,
|
|
486
|
+
truncated: hits.length === max,
|
|
487
|
+
hits
|
|
488
|
+
});
|
|
489
|
+
});
|
|
490
|
+
server.registerTool("resolve_theme", {
|
|
491
|
+
description: "Resolve the full token map for a given axis tuple. Agent passes a partial tuple (`{ mode: \"Dark\", brand: \"Brand A\" }`); any axis omitted falls back to that axis's default. Returns the matching theme name, the complete tuple after filling defaults, and the resolved `{ path: { value, type, aliasOf?, aliasChain? } }` map — effectively \"what do all tokens look like if I pin this combination\".",
|
|
492
|
+
inputSchema: {
|
|
493
|
+
tuple: z.record(z.string(), z.string()).describe("Partial axis tuple, e.g. `{ mode: \"Dark\", brand: \"Brand A\" }`."),
|
|
494
|
+
filter: z.string().optional().describe("Optional path glob to scope the returned map."),
|
|
495
|
+
type: z.string().optional().describe("Optional DTCG `$type` to scope the returned map.")
|
|
496
|
+
}
|
|
497
|
+
}, ({ tuple, filter, type }) => {
|
|
498
|
+
const active = {};
|
|
499
|
+
for (const axis of project.axes) {
|
|
500
|
+
const candidate = tuple[axis.name];
|
|
501
|
+
active[axis.name] = candidate && axis.contexts.includes(candidate) ? candidate : axis.default;
|
|
502
|
+
}
|
|
503
|
+
const themeName = project.permutations.find((t) => {
|
|
504
|
+
for (const axis of project.axes) if (t.input[axis.name] !== active[axis.name]) return false;
|
|
505
|
+
return true;
|
|
506
|
+
})?.name ?? project.permutations[0]?.name;
|
|
507
|
+
if (!themeName) return textResult("No matching theme.");
|
|
508
|
+
const tokens = project.permutationsResolved[themeName] ?? {};
|
|
509
|
+
const resolved = {};
|
|
510
|
+
let count = 0;
|
|
511
|
+
for (const [path, token] of Object.entries(tokens)) {
|
|
512
|
+
if (type && token.$type !== type) continue;
|
|
513
|
+
if (!matchPath(path, filter)) continue;
|
|
514
|
+
resolved[path] = {
|
|
515
|
+
value: stringifyValue(token.$value),
|
|
516
|
+
...token.$type !== void 0 && { type: token.$type },
|
|
517
|
+
...token.aliasOf !== void 0 && { aliasOf: token.aliasOf },
|
|
518
|
+
...token.aliasChain !== void 0 && { aliasChain: token.aliasChain }
|
|
519
|
+
};
|
|
520
|
+
count++;
|
|
521
|
+
}
|
|
522
|
+
return jsonResult({
|
|
523
|
+
theme: themeName,
|
|
524
|
+
tuple: active,
|
|
525
|
+
count,
|
|
526
|
+
tokens: resolved
|
|
527
|
+
});
|
|
528
|
+
});
|
|
529
|
+
server.registerTool("get_consumer_output", {
|
|
530
|
+
description: "CSS var reference + resolved value + HTML data-attribute activation for a token under an optional axis tuple. Tells an agent everything it needs to write a stylesheet or JSX snippet that pins a particular theme combination — `selector` is the compound CSS selector that matches the tuple on `<html>`, `attrs` is the same information as HTML attributes, `cssVar` is the `var(--…)` reference. Tuple defaults to the project default when omitted.",
|
|
531
|
+
inputSchema: {
|
|
532
|
+
path: z.string().describe("Dot-path of the token, e.g. `color.accent.bg`."),
|
|
533
|
+
tuple: z.record(z.string(), z.string()).optional().describe("Optional axis tuple (e.g. `{ mode: \"Dark\", brand: \"Brand A\" }`). Defaults to each axis's own default.")
|
|
534
|
+
}
|
|
535
|
+
}, ({ path, tuple }) => {
|
|
536
|
+
const prefix = project.config.cssVarPrefix ?? "";
|
|
537
|
+
const activeTuple = {};
|
|
538
|
+
for (const axis of project.axes) {
|
|
539
|
+
const candidate = tuple?.[axis.name];
|
|
540
|
+
activeTuple[axis.name] = candidate && axis.contexts.includes(candidate) ? candidate : axis.default;
|
|
541
|
+
}
|
|
542
|
+
const themeName = project.permutations.find((t) => {
|
|
543
|
+
for (const axis of project.axes) if (t.input[axis.name] !== activeTuple[axis.name]) return false;
|
|
544
|
+
return true;
|
|
545
|
+
})?.name ?? project.permutations[0]?.name ?? "";
|
|
546
|
+
const token = themeName ? project.permutationsResolved[themeName]?.[path] : void 0;
|
|
547
|
+
if (!token) return textResult(`Token not found: ${path}`);
|
|
548
|
+
const cssVar = `var(--${prefix ? `${prefix}-` : ""}${path.replaceAll(".", "-")})`;
|
|
549
|
+
const attrName = (axis) => prefix ? `data-${prefix}-${axis}` : `data-${axis}`;
|
|
550
|
+
const attrs = {};
|
|
551
|
+
const selectorParts = [];
|
|
552
|
+
for (const axis of project.axes) {
|
|
553
|
+
const value = activeTuple[axis.name];
|
|
554
|
+
if (value !== void 0) {
|
|
555
|
+
attrs[attrName(axis.name)] = value;
|
|
556
|
+
selectorParts.push(`[${attrName(axis.name)}="${value}"]`);
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
return jsonResult({
|
|
560
|
+
path,
|
|
561
|
+
cssVar,
|
|
562
|
+
value: stringifyValue(token.$value),
|
|
563
|
+
type: token.$type,
|
|
564
|
+
theme: themeName,
|
|
565
|
+
tuple: activeTuple,
|
|
566
|
+
attrs,
|
|
567
|
+
selector: selectorParts.join("") || ":root",
|
|
568
|
+
usageSnippet: `color: ${cssVar};`
|
|
569
|
+
});
|
|
570
|
+
});
|
|
571
|
+
server.registerTool("get_diagnostics", {
|
|
572
|
+
description: "List parser / resolver / validation diagnostics for the project. Each entry carries a severity (`error`, `warn`, `info`), group, message, and optional filename / line / column for locating the issue.",
|
|
573
|
+
inputSchema: { severity: z.enum([
|
|
574
|
+
"error",
|
|
575
|
+
"warn",
|
|
576
|
+
"info"
|
|
577
|
+
]).optional().describe("Optional severity filter. Omit for all diagnostics.") }
|
|
578
|
+
}, ({ severity }) => {
|
|
579
|
+
const rows = severity ? project.diagnostics.filter((d) => d.severity === severity) : project.diagnostics;
|
|
580
|
+
return jsonResult({
|
|
581
|
+
count: rows.length,
|
|
582
|
+
diagnostics: rows
|
|
583
|
+
});
|
|
584
|
+
});
|
|
585
|
+
return server;
|
|
586
|
+
}
|
|
587
|
+
function stringifyValue(value) {
|
|
588
|
+
if (value === null || value === void 0) return "—";
|
|
589
|
+
if (typeof value === "string") return value;
|
|
590
|
+
if (typeof value === "number" || typeof value === "boolean") return String(value);
|
|
591
|
+
try {
|
|
592
|
+
return JSON.stringify(value);
|
|
593
|
+
} catch {
|
|
594
|
+
return String(value);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
function textResult(text) {
|
|
598
|
+
return { content: [{
|
|
599
|
+
type: "text",
|
|
600
|
+
text
|
|
601
|
+
}] };
|
|
602
|
+
}
|
|
603
|
+
function jsonResult(data) {
|
|
604
|
+
return { content: [{
|
|
605
|
+
type: "text",
|
|
606
|
+
text: JSON.stringify(data, null, 2)
|
|
607
|
+
}] };
|
|
608
|
+
}
|
|
609
|
+
//#endregion
|
|
610
|
+
//#region src/load-config.ts
|
|
611
|
+
/**
|
|
612
|
+
* Load a swatchbook project from either a full config module or a bare
|
|
613
|
+
* DTCG resolver JSON.
|
|
614
|
+
*
|
|
615
|
+
* `.ts` / `.mts` / `.js` / `.mjs` → jiti imports the module and uses
|
|
616
|
+
* its default export as the swatchbook {@link Config}.
|
|
617
|
+
*
|
|
618
|
+
* `.json` → treated as a DTCG resolver file; the CLI constructs a
|
|
619
|
+
* minimal `{ resolver: path }` config so agents can point at a raw
|
|
620
|
+
* resolver without authoring a wrapper. Every other config option
|
|
621
|
+
* (presets, chrome map, disabled axes, css-var prefix) falls back to
|
|
622
|
+
* `loadProject` defaults.
|
|
623
|
+
*
|
|
624
|
+
* The `cwd` returned is the directory the config / resolver lives in.
|
|
625
|
+
* `loadProject` uses it to resolve relative token references.
|
|
626
|
+
*/
|
|
627
|
+
async function loadFromConfig(configPath, cwdOverride) {
|
|
628
|
+
const absolute = isAbsolute(configPath) ? configPath : resolve(process.cwd(), configPath);
|
|
629
|
+
const cwd = cwdOverride ?? resolve(absolute, "..");
|
|
630
|
+
const config = extname(absolute).toLowerCase() === ".json" ? { resolver: absolute } : await loadTsConfig(absolute);
|
|
631
|
+
return {
|
|
632
|
+
project: await loadProject(config, cwd),
|
|
633
|
+
cwd,
|
|
634
|
+
config
|
|
635
|
+
};
|
|
636
|
+
}
|
|
637
|
+
async function loadTsConfig(absolute) {
|
|
638
|
+
return await createJiti(new URL("./", pathToFileURL(absolute)).href, {
|
|
639
|
+
interopDefault: true,
|
|
640
|
+
moduleCache: false
|
|
641
|
+
}).import(absolute, { default: true });
|
|
642
|
+
}
|
|
643
|
+
//#endregion
|
|
644
|
+
export { createServer as n, loadFromConfig as t };
|
|
645
|
+
|
|
646
|
+
//# sourceMappingURL=load-config-B-8rGfFl.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"load-config-B-8rGfFl.mjs","names":[],"sources":["../src/contrast.ts","../src/format-color.ts","../src/match.ts","../src/server.ts","../src/load-config.ts"],"sourcesContent":["import Color from 'colorjs.io';\n\n/**\n * Pair-wise contrast between two DTCG color `$value`s. Wraps\n * `colorjs.io`'s contrast primitives with pass/fail grids for the\n * thresholds agents typically reason against (WCAG 2.1 AA/AAA\n * normal/large; APCA body / large text / non-text).\n *\n * Kept separate from `format-color.ts` even though both build\n * `Color` instances from the same DTCG shape — the color-format\n * formatter stringifies, this one does arithmetic, and they're\n * called from different tool paths.\n */\n\ninterface ColorInput {\n colorSpace?: string;\n components?: readonly (number | null)[];\n channels?: readonly (number | null)[];\n alpha?: number;\n}\n\nfunction toColor(raw: unknown): Color | null {\n if (!raw || typeof raw !== 'object') return null;\n const n = raw as ColorInput;\n const components = n.components ?? n.channels;\n if (!components || !n.colorSpace) return null;\n const coords = components.map((c) => (c == null ? 0 : c));\n const [r = 0, g = 0, b = 0] = coords;\n try {\n return new Color(n.colorSpace, [r, g, b], n.alpha ?? 1);\n } catch {\n return null;\n }\n}\n\nexport type ContrastAlgorithm = 'wcag21' | 'apca';\n\nexport interface WcagPasses {\n aa: { normal: boolean; large: boolean };\n aaa: { normal: boolean; large: boolean };\n}\n\nexport interface ApcaPasses {\n lc: number;\n body: boolean;\n largeText: boolean;\n nonText: boolean;\n}\n\nexport interface ContrastResult {\n algorithm: ContrastAlgorithm;\n /**\n * WCAG 2.1 returns the contrast ratio (1–21). APCA returns a signed\n * Lc value (-108..+106); the sign marks polarity (negative = dark\n * text on light background; positive = light on dark). Consumers\n * usually care about `Math.abs(ratio)` for threshold checks.\n */\n ratio: number;\n wcag?: WcagPasses;\n apca?: ApcaPasses;\n}\n\nexport function computeContrast(\n foreground: unknown,\n background: unknown,\n algorithm: ContrastAlgorithm = 'wcag21',\n): ContrastResult | null {\n const fg = toColor(foreground);\n const bg = toColor(background);\n if (!fg || !bg) return null;\n\n if (algorithm === 'wcag21') {\n const ratio = fg.contrast(bg, 'WCAG21');\n return {\n algorithm: 'wcag21',\n ratio,\n wcag: {\n aa: { normal: ratio >= 4.5, large: ratio >= 3 },\n aaa: { normal: ratio >= 7, large: ratio >= 4.5 },\n },\n };\n }\n\n /**\n * APCA thresholds from the Silver draft guidance. These are the\n * \"body text / large text / non-text\" bronze tier thresholds most\n * tooling settles on; the full table has more gradations but\n * agents rarely need them. Non-text = icons, focus rings, UI\n * borders.\n */\n const lc = fg.contrast(bg, 'APCA');\n const absLc = Math.abs(lc);\n return {\n algorithm: 'apca',\n ratio: lc,\n apca: {\n lc,\n body: absLc >= 75,\n largeText: absLc >= 60,\n nonText: absLc >= 45,\n },\n };\n}\n","import Color from 'colorjs.io';\n\n/**\n * Convert a DTCG color `$value` into the same format menu the\n * addon's toolbar exposes — hex / rgb / hsl / oklch / raw JSON. Mirrors\n * the narrower version in `@unpunnyfuns/swatchbook-blocks/format-color.ts`\n * without pulling blocks (and React) into the MCP server.\n *\n * Out-of-gamut colours still stringify — the caller gets both the\n * rendered string and an `outOfGamut` flag so agents can warn.\n */\n\nexport type ColorFormat = 'hex' | 'rgb' | 'hsl' | 'oklch' | 'raw';\n\nexport interface FormatColorResult {\n format: ColorFormat;\n value: string;\n outOfGamut: boolean;\n}\n\ninterface NormalizedColor {\n colorSpace?: string;\n components?: readonly (number | null)[];\n channels?: readonly (number | null)[];\n alpha?: number;\n hex?: string;\n}\n\nexport function formatColor(raw: unknown, format: ColorFormat): FormatColorResult | null {\n if (!raw || typeof raw !== 'object') return null;\n const normalized = raw as NormalizedColor;\n\n if (format === 'raw') {\n return { format, value: JSON.stringify(raw), outOfGamut: false };\n }\n\n const components = normalized.components ?? normalized.channels;\n if (!components || !normalized.colorSpace) return null;\n\n let color: Color;\n try {\n const coords = components.map((c) => (c == null ? 0 : c));\n const [r = 0, g = 0, b = 0] = coords;\n color = new Color(normalized.colorSpace, [r, g, b], normalized.alpha ?? 1);\n } catch {\n return null;\n }\n\n if (format === 'hex') {\n try {\n const inSrgb = color.to('srgb');\n const outOfGamut = !inSrgb.inGamut();\n if (outOfGamut) {\n return { format, value: inSrgb.toString({ format: 'rgb' }), outOfGamut: true };\n }\n return { format, value: inSrgb.toString({ format: 'hex' }), outOfGamut: false };\n } catch {\n return null;\n }\n }\n\n if (format === 'rgb') {\n try {\n const inSrgb = color.to('srgb');\n return {\n format,\n value: inSrgb.toString({ format: 'rgb' }),\n outOfGamut: !inSrgb.inGamut(),\n };\n } catch {\n return null;\n }\n }\n\n if (format === 'hsl') {\n try {\n const inHsl = color.to('hsl');\n return {\n format,\n value: inHsl.toString(),\n outOfGamut: !color.to('srgb').inGamut(),\n };\n } catch {\n return null;\n }\n }\n\n if (format === 'oklch') {\n try {\n const inOklch = color.to('oklch');\n return { format, value: inOklch.toString(), outOfGamut: false };\n } catch {\n return null;\n }\n }\n\n return null;\n}\n\nexport const ALL_COLOR_FORMATS: readonly ColorFormat[] = ['hex', 'rgb', 'hsl', 'oklch', 'raw'];\n\nexport function formatColorEveryWay(raw: unknown): Partial<Record<ColorFormat, FormatColorResult>> {\n const out: Partial<Record<ColorFormat, FormatColorResult>> = {};\n for (const format of ALL_COLOR_FORMATS) {\n const result = formatColor(raw, format);\n if (result) out[format] = result;\n }\n return out;\n}\n","/**\n * Minimal DTCG-flavoured path matcher. Accepts exact paths (`color.bg`), single-\n * segment globs (`color.*`), multi-segment globs (`color.**`), or a trailing `*`\n * mid-segment (`color.palette.blue.*`). No brace expansion, no regex — DTCG\n * paths are dot-delimited and this matches the parity the blocks' `globMatch`\n * ships. Case-sensitive.\n */\nexport function matchPath(path: string, filter: string | undefined): boolean {\n if (!filter) return true;\n if (filter === '**' || filter === '*') return true;\n\n const pathSegments = path.split('.');\n const filterSegments = filter.split('.');\n\n let pi = 0;\n let fi = 0;\n while (fi < filterSegments.length) {\n const fseg = filterSegments[fi];\n if (fseg === '**') {\n // Match zero or more path segments. The next filter segment must match\n // somewhere in the remaining path, or we accept the tail.\n if (fi === filterSegments.length - 1) return true;\n const remaining = filterSegments.slice(fi + 1);\n for (let k = pi; k <= pathSegments.length; k++) {\n if (matchPath(pathSegments.slice(k).join('.'), remaining.join('.'))) {\n return true;\n }\n }\n return false;\n }\n if (pi >= pathSegments.length) return false;\n const pseg = pathSegments[pi];\n if (fseg === '*') {\n // pass\n } else if (fseg !== pseg) {\n return false;\n }\n pi++;\n fi++;\n }\n return pi === pathSegments.length;\n}\n","import type { Project } from '@unpunnyfuns/swatchbook-core';\nimport { analyzeAxisVariance, projectCss } from '@unpunnyfuns/swatchbook-core';\nimport { fuzzyFilter, fuzzyMatches } from '@unpunnyfuns/swatchbook-core/fuzzy';\nimport { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';\nimport { z } from 'zod';\nimport { computeContrast } from '#/contrast.ts';\nimport { formatColorEveryWay } from '#/format-color.ts';\nimport { matchPath } from '#/match.ts';\n\n/**\n * Build a swatchbook MCP server bound to a loaded project. Tools expose the\n * project's tokens, axes, and diagnostics so an AI agent can query them\n * without running Storybook. Tool handlers close over a live `project`\n * reference — call the returned `setProject` to swap in a freshly loaded\n * project (e.g. after token edits) without re-binding the transport.\n */\nexport function createServer(initial: Project): McpServer & {\n setProject: (next: Project) => void;\n} {\n let project = initial;\n const server = new McpServer(\n {\n name: '@unpunnyfuns/swatchbook-mcp',\n version: project.config.cssVarPrefix ? `project:${project.config.cssVarPrefix}` : 'project',\n },\n {\n instructions:\n 'Query a swatchbook DTCG project: list tokens by path glob, inspect individual tokens (value, $type, alias chain, per-theme resolved values), read axes / presets, and inspect diagnostics.',\n },\n ) as McpServer & { setProject: (next: Project) => void };\n server.setProject = (next: Project) => {\n project = next;\n };\n\n server.registerTool(\n 'describe_project',\n {\n description:\n 'High-level summary of the project — total token count per theme, axes (with contexts) and how they compose, preset list, diagnostic counts by severity, css-var prefix, and the DTCG `$type`s present. Good first call for an agent that needs an orientation before querying specifics.',\n inputSchema: {},\n },\n () => {\n const typeCounts: Record<string, number> = {};\n const tokensPerTheme: Record<string, number> = {};\n for (const theme of project.permutations) {\n const tokens = project.permutationsResolved[theme.name] ?? {};\n tokensPerTheme[theme.name] = Object.keys(tokens).length;\n for (const token of Object.values(tokens)) {\n if (token.$type) typeCounts[token.$type] = (typeCounts[token.$type] ?? 0) + 1;\n }\n }\n const diagBySeverity = { error: 0, warn: 0, info: 0 } as Record<string, number>;\n for (const d of project.diagnostics) {\n diagBySeverity[d.severity] = (diagBySeverity[d.severity] ?? 0) + 1;\n }\n return jsonResult({\n cssVarPrefix: project.config.cssVarPrefix ?? '',\n axes: project.axes.map((a) => ({ name: a.name, contexts: a.contexts, default: a.default })),\n permutations: project.permutations.map((t) => t.name),\n defaultPermutation: project.permutations[0]?.name ?? null,\n presets: project.presets.map((p) => p.name),\n tokensPerTheme,\n types: typeCounts,\n diagnostics: {\n counts: diagBySeverity,\n total: project.diagnostics.length,\n },\n });\n },\n );\n\n server.registerTool(\n 'emit_css',\n {\n description:\n 'Return the full project CSS — a `:root` block with the default tuple plus one compound-selector block per non-default axis combination. Same output the addon injects into Storybook and the docs-site chrome pipeline writes to disk. Useful when an agent needs to inline the stylesheet into a generated artifact.',\n inputSchema: {},\n },\n () => textResult(projectCss(project)),\n );\n\n server.registerTool(\n 'list_tokens',\n {\n description:\n 'List token paths in the project, optionally filtered by path glob (`color.*`, `color.palette.**`) and/or DTCG `$type` (color, dimension, typography, …). Returns path + $type + stringified value from the default theme. Use this first to discover what tokens exist; follow with get_token for details.',\n inputSchema: {\n filter: z\n .string()\n .optional()\n .describe('Dot-path glob, e.g. `color.*` or `color.palette.**`. Omit for all tokens.'),\n type: z\n .string()\n .optional()\n .describe('DTCG `$type` to scope the result, e.g. `color`, `dimension`, `typography`.'),\n theme: z\n .string()\n .optional()\n .describe('Permutation name to read values from. Defaults to the project default theme.'),\n },\n },\n ({ filter, type, theme }) => {\n const themeName = theme ?? project.permutations[0]?.name;\n if (!themeName) {\n return textResult('No permutations in project.');\n }\n const tokens = project.permutationsResolved[themeName] ?? {};\n const rows: { path: string; type?: string; value: string }[] = [];\n for (const [path, token] of Object.entries(tokens)) {\n if (type && token.$type !== type) continue;\n if (!matchPath(path, filter)) continue;\n rows.push({\n path,\n ...(token.$type !== undefined && { type: token.$type }),\n value: stringifyValue(token.$value),\n });\n }\n rows.sort((a, b) => a.path.localeCompare(b.path, undefined, { numeric: true }));\n return jsonResult({ theme: themeName, count: rows.length, tokens: rows });\n },\n );\n\n server.registerTool(\n 'get_token',\n {\n description:\n 'Get full details for a single token: resolved value in every theme, DTCG `$type`, `$description`, alias chain, aliased-by list, and CSS var reference. Use after `list_tokens` to inspect a specific path.',\n inputSchema: {\n path: z.string().describe('Dot-path of the token, e.g. `color.accent.bg`.'),\n },\n },\n ({ path }) => {\n const perTheme: Record<\n string,\n { value: string; aliasOf?: string; aliasChain?: readonly string[] }\n > = {};\n let type: string | undefined;\n let description: string | undefined;\n let aliasedBy: readonly string[] | undefined;\n let found = false;\n\n for (const theme of project.permutations) {\n const token = project.permutationsResolved[theme.name]?.[path];\n if (!token) continue;\n found = true;\n type ??= token.$type;\n description ??= token.$description;\n aliasedBy ??= token.aliasedBy;\n perTheme[theme.name] = {\n value: stringifyValue(token.$value),\n ...(token.aliasOf !== undefined && { aliasOf: token.aliasOf }),\n ...(token.aliasChain !== undefined && { aliasChain: token.aliasChain }),\n };\n }\n\n if (!found) return textResult(`Token not found: ${path}`);\n\n const prefix = project.config.cssVarPrefix ?? '';\n const cssVar = `var(--${prefix ? `${prefix}-` : ''}${path.replaceAll('.', '-')})`;\n\n return jsonResult({\n path,\n type,\n description,\n cssVar,\n aliasedBy,\n perTheme,\n });\n },\n );\n\n server.registerTool(\n 'list_axes',\n {\n description:\n 'List the project axes — each axis has a name, its contexts (discrete values like `Light` / `Dark`), a default, and a source (`resolver` for DTCG-resolver-driven, `layered` for authored layered axes, `synthetic` for single-theme projects). Also returns the named permutations (every axis tuple combination) and any presets defined in the project config.',\n inputSchema: {},\n },\n () =>\n jsonResult({\n axes: project.axes.map((axis) => ({\n name: axis.name,\n contexts: axis.contexts,\n default: axis.default,\n description: axis.description,\n source: axis.source,\n })),\n disabledAxes: project.disabledAxes,\n permutations: project.permutations.map((t) => ({ name: t.name, input: t.input })),\n presets: project.presets.map((p) => ({\n name: p.name,\n axes: p.axes,\n description: p.description,\n })),\n }),\n );\n\n server.registerTool(\n 'get_alias_chain',\n {\n description:\n 'Forward alias chain for a token — the sequence of paths it resolves through on the way to a primitive value (e.g. `color.accent.bg → color.brand.blue.700 → color.palette.blue.700`). Returns the chain per theme because aliases can resolve through different paths per axis context. Empty chain when the token is a primitive (no aliases) or missing.',\n inputSchema: {\n path: z.string().describe('Dot-path of the token, e.g. `color.accent.bg`.'),\n },\n },\n ({ path }) => {\n const perTheme: Record<string, { aliasOf?: string; chain: readonly string[] }> = {};\n let found = false;\n for (const theme of project.permutations) {\n const token = project.permutationsResolved[theme.name]?.[path];\n if (!token) continue;\n found = true;\n const chain: string[] = [path];\n if (token.aliasChain && token.aliasChain.length > 0) chain.push(...token.aliasChain);\n else if (token.aliasOf) chain.push(token.aliasOf);\n perTheme[theme.name] = {\n ...(token.aliasOf !== undefined && { aliasOf: token.aliasOf }),\n chain,\n };\n }\n if (!found) return textResult(`Token not found: ${path}`);\n return jsonResult({ path, perTheme });\n },\n );\n\n server.registerTool(\n 'get_aliased_by',\n {\n description:\n 'Backward alias tree for a token — every token that resolves through this path at any depth. Breadth-first walk with cycle protection; `maxDepth` caps recursion (default 6). Empty when nothing aliases the token.',\n inputSchema: {\n path: z.string().describe('Dot-path of the token, e.g. `color.palette.blue.500`.'),\n maxDepth: z\n .number()\n .int()\n .positive()\n .optional()\n .describe('Maximum recursion depth. Default 6.'),\n },\n },\n ({ path, maxDepth }) => {\n const depth = maxDepth ?? 6;\n const themeName = project.permutations[0]?.name;\n if (!themeName) return textResult('No permutations in project.');\n const tokens = project.permutationsResolved[themeName] ?? {};\n if (!tokens[path]) return textResult(`Token not found: ${path}`);\n\n interface Node {\n path: string;\n depth: number;\n children: Node[];\n truncated?: boolean;\n }\n const visited = new Set<string>([path]);\n const walk = (current: string, d: number): Node => {\n const tok = tokens[current];\n const direct = tok?.aliasedBy ?? [];\n if (direct.length === 0) return { path: current, depth: d, children: [] };\n if (d >= depth) return { path: current, depth: d, children: [], truncated: true };\n const children: Node[] = [];\n for (const p of direct) {\n if (visited.has(p)) continue;\n visited.add(p);\n children.push(walk(p, d + 1));\n }\n return { path: current, depth: d, children };\n };\n const root = walk(path, 0);\n return jsonResult(root);\n },\n );\n\n server.registerTool(\n 'get_color_formats',\n {\n description:\n \"For a color token, return its value rendered in every format the addon toolbar exposes — `hex`, `rgb`, `hsl`, `oklch`, and the raw JSON. Each entry carries an `outOfGamut` flag when the chosen colorspace can't losslessly represent the token (wide-gamut tokens rendered in sRGB, for example). Skips non-color tokens.\",\n inputSchema: {\n path: z.string().describe('Dot-path of a color token, e.g. `color.accent.bg`.'),\n theme: z\n .string()\n .optional()\n .describe(\n 'Permutation name to read the value from. Defaults to the project default theme.',\n ),\n },\n },\n ({ path, theme }) => {\n const themeName = theme ?? project.permutations[0]?.name;\n if (!themeName) return textResult('No permutations in project.');\n const token = project.permutationsResolved[themeName]?.[path];\n if (!token) return textResult(`Token not found: ${path}`);\n if (token.$type !== 'color') {\n return textResult(`Token ${path} is not a color (got $type=${token.$type ?? 'unknown'}).`);\n }\n return jsonResult({\n path,\n theme: themeName,\n formats: formatColorEveryWay(token.$value),\n });\n },\n );\n\n server.registerTool(\n 'get_color_contrast',\n {\n description:\n 'Compute the contrast between two color tokens for a given theme. WCAG 2.1 returns the ratio (1–21) plus AA/AAA pass flags for normal + large text; APCA returns the signed Lc value plus body / large-text / non-text pass flags (absolute-value thresholds 75 / 60 / 45). Use this when reasoning about text legibility, focus-ring visibility, border contrast, etc., without having to reimplement the luminance math in the agent. Per-theme so the same pair can be checked against Light, Dark, High-contrast, etc.',\n inputSchema: {\n foreground: z\n .string()\n .describe('Dot-path of the foreground color token, e.g. `color.text.default`.'),\n background: z\n .string()\n .describe('Dot-path of the background color token, e.g. `color.surface.default`.'),\n theme: z\n .string()\n .optional()\n .describe('Permutation name. Defaults to the project default theme.'),\n algorithm: z\n .enum(['wcag21', 'apca'])\n .optional()\n .describe(\n 'Contrast algorithm. `wcag21` is the classic 4.5:1 ratio; `apca` is the perceptually-weighted Silver-draft successor. Defaults to `wcag21`.',\n ),\n },\n },\n ({ foreground, background, theme, algorithm }) => {\n const themeName = theme ?? project.permutations[0]?.name;\n if (!themeName) return textResult('No permutations in project.');\n const fgTok = project.permutationsResolved[themeName]?.[foreground];\n const bgTok = project.permutationsResolved[themeName]?.[background];\n if (!fgTok) return textResult(`Foreground token not found: ${foreground}`);\n if (!bgTok) return textResult(`Background token not found: ${background}`);\n if (fgTok.$type !== 'color') {\n return textResult(\n `Foreground ${foreground} is not a color (got $type=${fgTok.$type ?? 'unknown'}).`,\n );\n }\n if (bgTok.$type !== 'color') {\n return textResult(\n `Background ${background} is not a color (got $type=${bgTok.$type ?? 'unknown'}).`,\n );\n }\n const result = computeContrast(fgTok.$value, bgTok.$value, algorithm ?? 'wcag21');\n if (!result) {\n return textResult(\n 'Could not compute contrast — one or both values failed to parse as a color.',\n );\n }\n return jsonResult({\n theme: themeName,\n foreground: { path: foreground, value: stringifyValue(fgTok.$value) },\n background: { path: background, value: stringifyValue(bgTok.$value) },\n ...result,\n });\n },\n );\n\n server.registerTool(\n 'get_axis_variance',\n {\n description:\n \"Classify how a token's resolved value depends on the project's axes. Returns `kind` — `constant` (same across every tuple), `single` (varies with exactly one axis, e.g. mode only), or `multi` (varies across two or more axes). Also returns `varyingAxes` / `constantAcrossAxes` plus a `perAxis` breakdown with each context's stringified value (holding other axes at their defaults). Use when reasoning about whether a token is theme-independent, whether a refactor changed an axis dependency, or to confirm that (say) a role token only varies with `contrast`.\",\n inputSchema: {\n path: z.string().describe('Dot-path of the token to analyse, e.g. `color.text.default`.'),\n },\n },\n ({ path }) => {\n if (project.permutations.length === 0) return textResult('No permutations in project.');\n const exists = project.permutations.some((t) => project.permutationsResolved[t.name]?.[path]);\n if (!exists) return textResult(`Token not found in any theme: ${path}`);\n return jsonResult(\n analyzeAxisVariance(path, project.axes, project.permutations, project.permutationsResolved),\n );\n },\n );\n\n server.registerTool(\n 'search_tokens',\n {\n description:\n 'Fuzzy search across token paths, `$description`, and stringified values. Case-insensitive, tolerates a single-character typo per term, and accepts out-of-order terms (`\"blue palette\"` finds `color.palette.blue.500`). Returns matches ranked by relevance with a short snippet pointing at where the match hit. Use when you know what you want but not the exact path. Scopes to a single theme (default: project default).',\n inputSchema: {\n query: z.string().min(1).describe('Fuzzy query (case-insensitive).'),\n theme: z\n .string()\n .optional()\n .describe('Permutation name to search within. Defaults to the project default.'),\n limit: z.number().int().positive().optional().describe('Cap the result count. Default 50.'),\n },\n },\n ({ query, theme, limit }) => {\n const themeName = theme ?? project.permutations[0]?.name;\n if (!themeName) return textResult('No permutations in project.');\n const tokens = project.permutationsResolved[themeName] ?? {};\n const max = limit ?? 50;\n\n const candidates = Object.entries(tokens).map(([path, token]) => {\n const description = token.$description ?? '';\n const value = stringifyValue(token.$value);\n return { path, token, description, value, composite: `${path} ${description} ${value}` };\n });\n const ranked = fuzzyFilter(candidates, query, (c) => c.composite, { limit: max });\n const hits = ranked.map((c) => {\n const matchedIn: ('path' | 'description' | 'value')[] = [];\n if (fuzzyMatches(c.path, query)) matchedIn.push('path');\n if (c.description && fuzzyMatches(c.description, query)) matchedIn.push('description');\n if (fuzzyMatches(c.value, query)) matchedIn.push('value');\n if (matchedIn.length === 0) matchedIn.push('path');\n const snippet = matchedIn.includes('description')\n ? (c.token.$description ?? c.path)\n : matchedIn.includes('value')\n ? `${c.path} = ${c.value}`\n : c.path;\n const entry: { path: string; type?: string; matchedIn: typeof matchedIn; snippet: string } =\n {\n path: c.path,\n matchedIn,\n snippet,\n };\n if (c.token.$type !== undefined) entry.type = c.token.$type;\n return entry;\n });\n return jsonResult({\n query,\n theme: themeName,\n count: hits.length,\n truncated: hits.length === max,\n hits,\n });\n },\n );\n\n server.registerTool(\n 'resolve_theme',\n {\n description:\n 'Resolve the full token map for a given axis tuple. Agent passes a partial tuple (`{ mode: \"Dark\", brand: \"Brand A\" }`); any axis omitted falls back to that axis\\'s default. Returns the matching theme name, the complete tuple after filling defaults, and the resolved `{ path: { value, type, aliasOf?, aliasChain? } }` map — effectively \"what do all tokens look like if I pin this combination\".',\n inputSchema: {\n tuple: z\n .record(z.string(), z.string())\n .describe('Partial axis tuple, e.g. `{ mode: \"Dark\", brand: \"Brand A\" }`.'),\n filter: z.string().optional().describe('Optional path glob to scope the returned map.'),\n type: z.string().optional().describe('Optional DTCG `$type` to scope the returned map.'),\n },\n },\n ({ tuple, filter, type }) => {\n const active: Record<string, string> = {};\n for (const axis of project.axes) {\n const candidate = tuple[axis.name];\n active[axis.name] =\n candidate && axis.contexts.includes(candidate) ? candidate : axis.default;\n }\n const themeName =\n project.permutations.find((t) => {\n for (const axis of project.axes) {\n if ((t.input as Record<string, string>)[axis.name] !== active[axis.name]) {\n return false;\n }\n }\n return true;\n })?.name ?? project.permutations[0]?.name;\n if (!themeName) return textResult('No matching theme.');\n const tokens = project.permutationsResolved[themeName] ?? {};\n const resolved: Record<\n string,\n { value: string; type?: string; aliasOf?: string; aliasChain?: readonly string[] }\n > = {};\n let count = 0;\n for (const [path, token] of Object.entries(tokens)) {\n if (type && token.$type !== type) continue;\n if (!matchPath(path, filter)) continue;\n resolved[path] = {\n value: stringifyValue(token.$value),\n ...(token.$type !== undefined && { type: token.$type }),\n ...(token.aliasOf !== undefined && { aliasOf: token.aliasOf }),\n ...(token.aliasChain !== undefined && { aliasChain: token.aliasChain }),\n };\n count++;\n }\n return jsonResult({ theme: themeName, tuple: active, count, tokens: resolved });\n },\n );\n\n server.registerTool(\n 'get_consumer_output',\n {\n description:\n 'CSS var reference + resolved value + HTML data-attribute activation for a token under an optional axis tuple. Tells an agent everything it needs to write a stylesheet or JSX snippet that pins a particular theme combination — `selector` is the compound CSS selector that matches the tuple on `<html>`, `attrs` is the same information as HTML attributes, `cssVar` is the `var(--…)` reference. Tuple defaults to the project default when omitted.',\n inputSchema: {\n path: z.string().describe('Dot-path of the token, e.g. `color.accent.bg`.'),\n tuple: z\n .record(z.string(), z.string())\n .optional()\n .describe(\n 'Optional axis tuple (e.g. `{ mode: \"Dark\", brand: \"Brand A\" }`). Defaults to each axis\\'s own default.',\n ),\n },\n },\n ({ path, tuple }) => {\n const prefix = project.config.cssVarPrefix ?? '';\n const activeTuple: Record<string, string> = {};\n for (const axis of project.axes) {\n const candidate = tuple?.[axis.name];\n activeTuple[axis.name] =\n candidate && axis.contexts.includes(candidate) ? candidate : axis.default;\n }\n const themeName =\n project.permutations.find((t) => {\n for (const axis of project.axes) {\n if ((t.input as Record<string, string>)[axis.name] !== activeTuple[axis.name]) {\n return false;\n }\n }\n return true;\n })?.name ??\n project.permutations[0]?.name ??\n '';\n const token = themeName ? project.permutationsResolved[themeName]?.[path] : undefined;\n if (!token) return textResult(`Token not found: ${path}`);\n\n const cssVar = `var(--${prefix ? `${prefix}-` : ''}${path.replaceAll('.', '-')})`;\n const attrName = (axis: string): string =>\n prefix ? `data-${prefix}-${axis}` : `data-${axis}`;\n const attrs: Record<string, string> = {};\n const selectorParts: string[] = [];\n for (const axis of project.axes) {\n const value = activeTuple[axis.name];\n if (value !== undefined) {\n attrs[attrName(axis.name)] = value;\n selectorParts.push(`[${attrName(axis.name)}=\"${value}\"]`);\n }\n }\n\n return jsonResult({\n path,\n cssVar,\n value: stringifyValue(token.$value),\n type: token.$type,\n theme: themeName,\n tuple: activeTuple,\n attrs,\n selector: selectorParts.join('') || ':root',\n usageSnippet: `color: ${cssVar};`,\n });\n },\n );\n\n server.registerTool(\n 'get_diagnostics',\n {\n description:\n 'List parser / resolver / validation diagnostics for the project. Each entry carries a severity (`error`, `warn`, `info`), group, message, and optional filename / line / column for locating the issue.',\n inputSchema: {\n severity: z\n .enum(['error', 'warn', 'info'])\n .optional()\n .describe('Optional severity filter. Omit for all diagnostics.'),\n },\n },\n ({ severity }) => {\n const rows = severity\n ? project.diagnostics.filter((d) => d.severity === severity)\n : project.diagnostics;\n return jsonResult({ count: rows.length, diagnostics: rows });\n },\n );\n\n return server;\n}\n\nfunction stringifyValue(value: unknown): string {\n if (value === null || value === undefined) return '—';\n if (typeof value === 'string') return value;\n if (typeof value === 'number' || typeof value === 'boolean') return String(value);\n try {\n return JSON.stringify(value);\n } catch {\n return String(value);\n }\n}\n\nfunction textResult(text: string): { content: { type: 'text'; text: string }[] } {\n return { content: [{ type: 'text', text }] };\n}\n\nfunction jsonResult(data: unknown): { content: { type: 'text'; text: string }[] } {\n return {\n content: [\n {\n type: 'text',\n text: JSON.stringify(data, null, 2),\n },\n ],\n };\n}\n","import { extname, isAbsolute, resolve } from 'node:path';\nimport { pathToFileURL } from 'node:url';\nimport type { Config, Project } from '@unpunnyfuns/swatchbook-core';\nimport { loadProject } from '@unpunnyfuns/swatchbook-core';\nimport { createJiti } from 'jiti';\n\n/**\n * Load a swatchbook project from either a full config module or a bare\n * DTCG resolver JSON.\n *\n * `.ts` / `.mts` / `.js` / `.mjs` → jiti imports the module and uses\n * its default export as the swatchbook {@link Config}.\n *\n * `.json` → treated as a DTCG resolver file; the CLI constructs a\n * minimal `{ resolver: path }` config so agents can point at a raw\n * resolver without authoring a wrapper. Every other config option\n * (presets, chrome map, disabled axes, css-var prefix) falls back to\n * `loadProject` defaults.\n *\n * The `cwd` returned is the directory the config / resolver lives in.\n * `loadProject` uses it to resolve relative token references.\n */\nexport async function loadFromConfig(\n configPath: string,\n cwdOverride?: string,\n): Promise<{ project: Project; cwd: string; config: Config }> {\n const absolute = isAbsolute(configPath) ? configPath : resolve(process.cwd(), configPath);\n const cwd = cwdOverride ?? resolve(absolute, '..');\n const ext = extname(absolute).toLowerCase();\n\n const config =\n ext === '.json' ? ({ resolver: absolute } satisfies Config) : await loadTsConfig(absolute);\n\n const project = await loadProject(config, cwd);\n return { project, cwd, config };\n}\n\nasync function loadTsConfig(absolute: string): Promise<Config> {\n /**\n * jiti's first arg is a directory-shaped \"from\" URL it uses to resolve\n * the target's relative imports. Passing a file URL leaves jiti\n * unsure whether to treat the path as a dir, which on some Node\n * versions falls through to a plain JSON read and surfaces as\n * `Unexpected token 'i', \"import { d\"...`. A trailing slash on a\n * directory URL avoids the ambiguity.\n */\n const fromUrl = new URL('./', pathToFileURL(absolute));\n const jiti = createJiti(fromUrl.href, {\n interopDefault: true,\n moduleCache: false,\n });\n return (await jiti.import(absolute, { default: true })) as Config;\n}\n"],"mappings":";;;;;;;;;AAqBA,SAAS,QAAQ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D;CAC5D,MAAM,WAAW,WAAW,WAAW,GAAG,aAAa,QAAQ,QAAQ,KAAK,EAAE,WAAW;CACzF,MAAM,MAAM,eAAe,QAAQ,UAAU,KAAK;CAGlD,MAAM,SAFM,QAAQ,SAAS,CAAC,aAAa,KAGjC,UAAW,EAAE,UAAU,UAAU,GAAqB,MAAM,aAAa,SAAS;AAG5F,QAAO;EAAE,SADO,MAAM,YAAY,QAAQ,IAAI;EAC5B;EAAK;EAAQ;;AAGjC,eAAe,aAAa,UAAmC;AAc7D,QAAQ,MAJK,WADG,IAAI,IAAI,MAAM,cAAc,SAAS,CAAC,CACtB,MAAM;EACpC,gBAAgB;EAChB,aAAa;EACd,CAAC,CACiB,OAAO,UAAU,EAAE,SAAS,MAAM,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@unpunnyfuns/swatchbook-mcp",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.51.0",
|
|
4
4
|
"description": "Model Context Protocol server for swatchbook — exposes a DTCG project's tokens, axes, and diagnostics to AI agents without running Storybook.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"author": "unpunnyfuns <unpunnyfuns@gmail.com>",
|
|
@@ -51,7 +51,7 @@
|
|
|
51
51
|
"colorjs.io": "0.6.1",
|
|
52
52
|
"jiti": "^2.4.0",
|
|
53
53
|
"zod": "^3.23.8",
|
|
54
|
-
"@unpunnyfuns/swatchbook-core": "0.
|
|
54
|
+
"@unpunnyfuns/swatchbook-core": "0.51.0"
|
|
55
55
|
},
|
|
56
56
|
"devDependencies": {
|
|
57
57
|
"@modelcontextprotocol/inspector": "^0.21.2",
|