@bamboocss/mcp 1.58.0 → 1.58.2
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/{cli-D5XPEiKT.mjs → cli-CS-t3UrG.mjs} +152 -20
- package/dist/{cli-BS1AweZN.cjs → cli-Dwi3db5P.cjs} +152 -20
- package/dist/cli.cjs +1 -1
- package/dist/cli.mjs +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +1 -1
- package/package.json +5 -5
|
@@ -6,8 +6,92 @@ import { TOKEN_CATEGORIES } from "@bamboocss/token-dictionary";
|
|
|
6
6
|
import { Console } from "node:console";
|
|
7
7
|
import { resolve } from "node:path";
|
|
8
8
|
import * as z from "zod/v4";
|
|
9
|
+
import { statSync } from "node:fs";
|
|
9
10
|
//#region package.json
|
|
10
|
-
var version = "1.58.
|
|
11
|
+
var version = "1.58.2";
|
|
12
|
+
//#endregion
|
|
13
|
+
//#region src/context-source.ts
|
|
14
|
+
/**
|
|
15
|
+
* The context, built again whenever a file the config was built from has changed since.
|
|
16
|
+
*
|
|
17
|
+
* An MCP server lives as long as the agent's session, and the config is what a session edits: a
|
|
18
|
+
* token or a recipe added while the server ran never reached `get_tokens` or `get_recipes` until
|
|
19
|
+
* the client restarted it. Checked when a tool is called rather than watched, so nothing has to
|
|
20
|
+
* be torn down when the client goes, and the files are few: the config, the modules it imports —
|
|
21
|
+
* a preset swapped in by the last edit among them, or one named by path in `presets` — and the
|
|
22
|
+
* files its `dependencies` match, including one that starts to match.
|
|
23
|
+
*
|
|
24
|
+
* A config that fails to load fails the call that found it, with its own message, rather than
|
|
25
|
+
* leaving the previous config answering as if nothing had changed; the next call tries again.
|
|
26
|
+
*/
|
|
27
|
+
function createContextSource(load) {
|
|
28
|
+
let ctx;
|
|
29
|
+
let stamps = /* @__PURE__ */ new Map();
|
|
30
|
+
let members;
|
|
31
|
+
let pending;
|
|
32
|
+
const reload = async () => {
|
|
33
|
+
const started = Date.now();
|
|
34
|
+
const before = new Map(Array.from(stamps.keys(), (file) => [file, stamp(file)]));
|
|
35
|
+
try {
|
|
36
|
+
const next = await load();
|
|
37
|
+
ctx = next;
|
|
38
|
+
stamps = new Map(configFiles(next).map((file) => [file, before.get(file) ?? stampSince(file, started)]));
|
|
39
|
+
members = matchedSince(next, started);
|
|
40
|
+
return next;
|
|
41
|
+
} finally {
|
|
42
|
+
pending = void 0;
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
return async () => {
|
|
46
|
+
if (ctx && !changed(stamps) && matched(ctx)?.join("\n") === members) return ctx;
|
|
47
|
+
return pending ??= reload();
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
const stamp = (file) => {
|
|
51
|
+
const stat = statSync(file, { throwIfNoEntry: false });
|
|
52
|
+
return stat ? `${stat.mtimeMs}:${stat.size}` : "missing";
|
|
53
|
+
};
|
|
54
|
+
/** A file the last load read for the first time: changed already if it was written since the load began. */
|
|
55
|
+
const stampSince = (file, started) => {
|
|
56
|
+
const stat = statSync(file, { throwIfNoEntry: false });
|
|
57
|
+
if (!stat) return "missing";
|
|
58
|
+
return stat.mtimeMs >= started ? "changed" : `${stat.mtimeMs}:${stat.size}`;
|
|
59
|
+
};
|
|
60
|
+
const changed = (stamps) => {
|
|
61
|
+
for (const [file, value] of stamps) if (stamp(file) !== value) return true;
|
|
62
|
+
return false;
|
|
63
|
+
};
|
|
64
|
+
/** The config file, every module it imports, and the files its `dependencies` match. */
|
|
65
|
+
const configFiles = (ctx) => {
|
|
66
|
+
const { cwd } = ctx.config;
|
|
67
|
+
const files = [
|
|
68
|
+
ctx.conf.path,
|
|
69
|
+
...ctx.conf.dependencies,
|
|
70
|
+
...ctx.explicitDeps
|
|
71
|
+
].filter(Boolean);
|
|
72
|
+
return [...new Set(files.map((file) => resolve(cwd, file)))];
|
|
73
|
+
};
|
|
74
|
+
/**
|
|
75
|
+
* What `dependencies` matches now. A file that starts to match is one no stamp was taken of, and a
|
|
76
|
+
* config that reads a folder — `tokens/*.json` — changes with it.
|
|
77
|
+
*/
|
|
78
|
+
const matched = (ctx) => {
|
|
79
|
+
const { dependencies, cwd } = ctx.config;
|
|
80
|
+
if (!dependencies?.length) return void 0;
|
|
81
|
+
return ctx.runtime.fs.glob({
|
|
82
|
+
include: dependencies,
|
|
83
|
+
cwd
|
|
84
|
+
}).map((file) => resolve(cwd, file)).sort();
|
|
85
|
+
};
|
|
86
|
+
/**
|
|
87
|
+
* What `dependencies` matched once a load had finished, read as changed already when a match was
|
|
88
|
+
* written since the load began: one that appeared while it ran may be missing from what it read.
|
|
89
|
+
*/
|
|
90
|
+
const matchedSince = (ctx, started) => {
|
|
91
|
+
const files = matched(ctx);
|
|
92
|
+
if (!files) return void 0;
|
|
93
|
+
return files.some((file) => (statSync(file, { throwIfNoEntry: false })?.mtimeMs ?? 0) >= started) ? "changed" : files.join("\n");
|
|
94
|
+
};
|
|
11
95
|
//#endregion
|
|
12
96
|
//#region src/server.ts
|
|
13
97
|
const tokenCategorySchema = z.enum(TOKEN_CATEGORIES).optional().describe("Filter by token category");
|
|
@@ -16,24 +100,53 @@ const json = (data) => ({ content: [{
|
|
|
16
100
|
text: JSON.stringify(data)
|
|
17
101
|
}] });
|
|
18
102
|
/**
|
|
103
|
+
* A recipe's or a pattern's name, checked against the config as of the call.
|
|
104
|
+
*
|
|
105
|
+
* Not an enum: a request is validated against the schema before any tool runs, so an enum built
|
|
106
|
+
* from the config the server started with rejected a recipe added since. The names are still in
|
|
107
|
+
* the description, refreshed when the config reloads.
|
|
108
|
+
*/
|
|
109
|
+
const nameSchema = (kind, names) => z.string().optional().describe(names.length ? `Filter by ${kind} name: ${names.join(", ")}` : `Filter by ${kind} name`);
|
|
110
|
+
const noSuchName = (kind, name, names) => ({
|
|
111
|
+
content: [{
|
|
112
|
+
type: "text",
|
|
113
|
+
text: `No ${kind} is named \`${name}\`. ${names.length ? `The ${kind}s are: ${names.join(", ")}.` : `The config defines none.`}`
|
|
114
|
+
}],
|
|
115
|
+
isError: true
|
|
116
|
+
});
|
|
117
|
+
/**
|
|
19
118
|
* Create an MCP server with all tools registered.
|
|
20
119
|
* This is separated from `startMcpServer` to allow testing with custom transports.
|
|
21
120
|
*/
|
|
22
121
|
function createMcpServer(options) {
|
|
23
|
-
const { ctx } = options;
|
|
24
122
|
const server = new McpServer({
|
|
25
123
|
name: "@bamboocss/mcp",
|
|
26
124
|
version
|
|
27
125
|
});
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
const
|
|
126
|
+
let recipeNames = options.ctx.recipes.keys;
|
|
127
|
+
let patternNames = options.ctx.patterns.keys;
|
|
128
|
+
let seen = options.ctx;
|
|
129
|
+
const context = async () => {
|
|
130
|
+
const ctx = options.current ? await options.current() : options.ctx;
|
|
131
|
+
if (ctx === seen) return ctx;
|
|
132
|
+
seen = ctx;
|
|
133
|
+
const nextRecipes = ctx.recipes.keys;
|
|
134
|
+
if (nextRecipes.join() !== recipeNames.join()) {
|
|
135
|
+
recipeNames = nextRecipes;
|
|
136
|
+
recipesTool.update({ paramsSchema: { name: nameSchema("recipe", recipeNames) } });
|
|
137
|
+
}
|
|
138
|
+
const nextPatterns = ctx.patterns.keys;
|
|
139
|
+
if (nextPatterns.join() !== patternNames.join()) {
|
|
140
|
+
patternNames = nextPatterns;
|
|
141
|
+
patternsTool.update({ paramsSchema: { name: nameSchema("pattern", patternNames) } });
|
|
142
|
+
}
|
|
143
|
+
return ctx;
|
|
144
|
+
};
|
|
32
145
|
server.registerTool("get_tokens", {
|
|
33
146
|
description: "Get all design tokens with their values, CSS variables, and usage examples",
|
|
34
147
|
inputSchema: { category: tokenCategorySchema }
|
|
35
148
|
}, async ({ category }) => {
|
|
36
|
-
const spec =
|
|
149
|
+
const spec = (await context()).getSpecOfType("tokens");
|
|
37
150
|
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
38
151
|
return json({
|
|
39
152
|
type: spec.type,
|
|
@@ -44,17 +157,19 @@ function createMcpServer(options) {
|
|
|
44
157
|
description: "Get semantic tokens with their conditional values (responsive, color modes)",
|
|
45
158
|
inputSchema: { category: tokenCategorySchema }
|
|
46
159
|
}, async ({ category }) => {
|
|
47
|
-
const spec =
|
|
160
|
+
const spec = (await context()).getSpecOfType("semantic-tokens");
|
|
48
161
|
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
49
162
|
return json({
|
|
50
163
|
type: spec.type,
|
|
51
164
|
data
|
|
52
165
|
});
|
|
53
166
|
});
|
|
54
|
-
server.registerTool("get_recipes", {
|
|
167
|
+
const recipesTool = server.registerTool("get_recipes", {
|
|
55
168
|
description: "Get component recipes with their variants, default values, and usage examples",
|
|
56
|
-
inputSchema: { name:
|
|
169
|
+
inputSchema: { name: nameSchema("recipe", recipeNames) }
|
|
57
170
|
}, async ({ name }) => {
|
|
171
|
+
const ctx = await context();
|
|
172
|
+
if (name && !recipeNames.includes(name)) return noSuchName("recipe", name, recipeNames);
|
|
58
173
|
const spec = ctx.getSpecOfType("recipes");
|
|
59
174
|
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
60
175
|
return json({
|
|
@@ -62,10 +177,12 @@ function createMcpServer(options) {
|
|
|
62
177
|
data
|
|
63
178
|
});
|
|
64
179
|
});
|
|
65
|
-
server.registerTool("get_patterns", {
|
|
180
|
+
const patternsTool = server.registerTool("get_patterns", {
|
|
66
181
|
description: "Get layout patterns with their properties and usage examples",
|
|
67
|
-
inputSchema: { name:
|
|
182
|
+
inputSchema: { name: nameSchema("pattern", patternNames) }
|
|
68
183
|
}, async ({ name }) => {
|
|
184
|
+
const ctx = await context();
|
|
185
|
+
if (name && !patternNames.includes(name)) return noSuchName("pattern", name, patternNames);
|
|
69
186
|
const spec = ctx.getSpecOfType("patterns");
|
|
70
187
|
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
71
188
|
return json({
|
|
@@ -73,13 +190,13 @@ function createMcpServer(options) {
|
|
|
73
190
|
data
|
|
74
191
|
});
|
|
75
192
|
});
|
|
76
|
-
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json(
|
|
77
|
-
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json(
|
|
78
|
-
server.registerTool("get_mixins", { description: "Get the named style bundles the theme declares, applied through the `mixin` style property" }, async () => json(
|
|
79
|
-
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json(
|
|
80
|
-
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json(
|
|
193
|
+
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json((await context()).getSpecOfType("conditions")));
|
|
194
|
+
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json((await context()).getSpecOfType("keyframes")));
|
|
195
|
+
server.registerTool("get_mixins", { description: "Get the named style bundles the theme declares, applied through the `mixin` style property" }, async () => json((await context()).getSpecOfType("mixins")));
|
|
196
|
+
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json((await context()).getSpecOfType("color-palette")));
|
|
197
|
+
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json((await context()).config));
|
|
81
198
|
server.registerTool("get_usage_report", {
|
|
82
|
-
description: "Get a usage report of the design system across the codebase: design tokens, recipes, patterns, utilities and keyframes. Shows which are used and how often, and which are defined but unused. Useful for auditing, cleanup, and identifying dead code.",
|
|
199
|
+
description: "Get a usage report of the design system across the codebase: design tokens, recipes, patterns, utilities and keyframes. Shows which are used and how often, and which are defined but unused. Useful for auditing, cleanup, and identifying dead code. `unused` lists the names the build keeps nothing for, the ones safe to remove; a `usedCount` counts direct uses only, so a token or keyframes reached through another token, a mixin or global css can be used at a count of 0.",
|
|
83
200
|
inputSchema: { scope: z.enum([
|
|
84
201
|
"all",
|
|
85
202
|
"token",
|
|
@@ -89,6 +206,7 @@ function createMcpServer(options) {
|
|
|
89
206
|
"keyframe"
|
|
90
207
|
]).optional().describe("Analysis scope: token, recipe, pattern, utility, keyframe, or all (default)") }
|
|
91
208
|
}, async ({ scope }) => {
|
|
209
|
+
const ctx = await context();
|
|
92
210
|
const result = await analyze(ctx);
|
|
93
211
|
const includes = (part) => !scope || scope === "all" || scope === part;
|
|
94
212
|
const report = {};
|
|
@@ -100,6 +218,16 @@ function createMcpServer(options) {
|
|
|
100
218
|
const keyframes = result.getKeyframeReport();
|
|
101
219
|
if (keyframes.length) report.keyframes = keyframes;
|
|
102
220
|
}
|
|
221
|
+
const kinds = [
|
|
222
|
+
"tokens",
|
|
223
|
+
"recipes",
|
|
224
|
+
"patterns",
|
|
225
|
+
"keyframes"
|
|
226
|
+
].filter((kind) => includes(kind.slice(0, -1)));
|
|
227
|
+
if (kinds.length) {
|
|
228
|
+
const unused = result.getUnused(kinds);
|
|
229
|
+
report.unused = Object.fromEntries(kinds.map((kind) => [kind, unused[kind]]));
|
|
230
|
+
}
|
|
103
231
|
return json(report);
|
|
104
232
|
});
|
|
105
233
|
return server;
|
|
@@ -151,10 +279,14 @@ async function startMcpServer(options = {}) {
|
|
|
151
279
|
if (silent) logger.level = "silent";
|
|
152
280
|
const resolvedCwd = resolve(cwd);
|
|
153
281
|
const resolvedConfigPath = configPath ? resolve(configPath) : void 0;
|
|
154
|
-
const
|
|
282
|
+
const current = createContextSource(() => loadConfigAndCreateContext({
|
|
155
283
|
cwd: resolvedCwd,
|
|
156
284
|
configPath: resolvedConfigPath
|
|
157
|
-
})
|
|
285
|
+
}));
|
|
286
|
+
const server = createMcpServer({
|
|
287
|
+
ctx: await current(),
|
|
288
|
+
current
|
|
289
|
+
});
|
|
158
290
|
const serverTransport = transport ?? new StdioServerTransport();
|
|
159
291
|
await server.connect(serverTransport);
|
|
160
292
|
console.error("Bamboo CSS MCP server started");
|
|
@@ -29,8 +29,92 @@ let node_console = require("node:console");
|
|
|
29
29
|
let node_path = require("node:path");
|
|
30
30
|
let zod_v4 = require("zod/v4");
|
|
31
31
|
zod_v4 = __toESM(zod_v4);
|
|
32
|
+
let node_fs = require("node:fs");
|
|
32
33
|
//#region package.json
|
|
33
|
-
var version = "1.58.
|
|
34
|
+
var version = "1.58.2";
|
|
35
|
+
//#endregion
|
|
36
|
+
//#region src/context-source.ts
|
|
37
|
+
/**
|
|
38
|
+
* The context, built again whenever a file the config was built from has changed since.
|
|
39
|
+
*
|
|
40
|
+
* An MCP server lives as long as the agent's session, and the config is what a session edits: a
|
|
41
|
+
* token or a recipe added while the server ran never reached `get_tokens` or `get_recipes` until
|
|
42
|
+
* the client restarted it. Checked when a tool is called rather than watched, so nothing has to
|
|
43
|
+
* be torn down when the client goes, and the files are few: the config, the modules it imports —
|
|
44
|
+
* a preset swapped in by the last edit among them, or one named by path in `presets` — and the
|
|
45
|
+
* files its `dependencies` match, including one that starts to match.
|
|
46
|
+
*
|
|
47
|
+
* A config that fails to load fails the call that found it, with its own message, rather than
|
|
48
|
+
* leaving the previous config answering as if nothing had changed; the next call tries again.
|
|
49
|
+
*/
|
|
50
|
+
function createContextSource(load) {
|
|
51
|
+
let ctx;
|
|
52
|
+
let stamps = /* @__PURE__ */ new Map();
|
|
53
|
+
let members;
|
|
54
|
+
let pending;
|
|
55
|
+
const reload = async () => {
|
|
56
|
+
const started = Date.now();
|
|
57
|
+
const before = new Map(Array.from(stamps.keys(), (file) => [file, stamp(file)]));
|
|
58
|
+
try {
|
|
59
|
+
const next = await load();
|
|
60
|
+
ctx = next;
|
|
61
|
+
stamps = new Map(configFiles(next).map((file) => [file, before.get(file) ?? stampSince(file, started)]));
|
|
62
|
+
members = matchedSince(next, started);
|
|
63
|
+
return next;
|
|
64
|
+
} finally {
|
|
65
|
+
pending = void 0;
|
|
66
|
+
}
|
|
67
|
+
};
|
|
68
|
+
return async () => {
|
|
69
|
+
if (ctx && !changed(stamps) && matched(ctx)?.join("\n") === members) return ctx;
|
|
70
|
+
return pending ??= reload();
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
const stamp = (file) => {
|
|
74
|
+
const stat = (0, node_fs.statSync)(file, { throwIfNoEntry: false });
|
|
75
|
+
return stat ? `${stat.mtimeMs}:${stat.size}` : "missing";
|
|
76
|
+
};
|
|
77
|
+
/** A file the last load read for the first time: changed already if it was written since the load began. */
|
|
78
|
+
const stampSince = (file, started) => {
|
|
79
|
+
const stat = (0, node_fs.statSync)(file, { throwIfNoEntry: false });
|
|
80
|
+
if (!stat) return "missing";
|
|
81
|
+
return stat.mtimeMs >= started ? "changed" : `${stat.mtimeMs}:${stat.size}`;
|
|
82
|
+
};
|
|
83
|
+
const changed = (stamps) => {
|
|
84
|
+
for (const [file, value] of stamps) if (stamp(file) !== value) return true;
|
|
85
|
+
return false;
|
|
86
|
+
};
|
|
87
|
+
/** The config file, every module it imports, and the files its `dependencies` match. */
|
|
88
|
+
const configFiles = (ctx) => {
|
|
89
|
+
const { cwd } = ctx.config;
|
|
90
|
+
const files = [
|
|
91
|
+
ctx.conf.path,
|
|
92
|
+
...ctx.conf.dependencies,
|
|
93
|
+
...ctx.explicitDeps
|
|
94
|
+
].filter(Boolean);
|
|
95
|
+
return [...new Set(files.map((file) => (0, node_path.resolve)(cwd, file)))];
|
|
96
|
+
};
|
|
97
|
+
/**
|
|
98
|
+
* What `dependencies` matches now. A file that starts to match is one no stamp was taken of, and a
|
|
99
|
+
* config that reads a folder — `tokens/*.json` — changes with it.
|
|
100
|
+
*/
|
|
101
|
+
const matched = (ctx) => {
|
|
102
|
+
const { dependencies, cwd } = ctx.config;
|
|
103
|
+
if (!dependencies?.length) return void 0;
|
|
104
|
+
return ctx.runtime.fs.glob({
|
|
105
|
+
include: dependencies,
|
|
106
|
+
cwd
|
|
107
|
+
}).map((file) => (0, node_path.resolve)(cwd, file)).sort();
|
|
108
|
+
};
|
|
109
|
+
/**
|
|
110
|
+
* What `dependencies` matched once a load had finished, read as changed already when a match was
|
|
111
|
+
* written since the load began: one that appeared while it ran may be missing from what it read.
|
|
112
|
+
*/
|
|
113
|
+
const matchedSince = (ctx, started) => {
|
|
114
|
+
const files = matched(ctx);
|
|
115
|
+
if (!files) return void 0;
|
|
116
|
+
return files.some((file) => ((0, node_fs.statSync)(file, { throwIfNoEntry: false })?.mtimeMs ?? 0) >= started) ? "changed" : files.join("\n");
|
|
117
|
+
};
|
|
34
118
|
//#endregion
|
|
35
119
|
//#region src/server.ts
|
|
36
120
|
const tokenCategorySchema = zod_v4.enum(_bamboocss_token_dictionary.TOKEN_CATEGORIES).optional().describe("Filter by token category");
|
|
@@ -39,24 +123,53 @@ const json = (data) => ({ content: [{
|
|
|
39
123
|
text: JSON.stringify(data)
|
|
40
124
|
}] });
|
|
41
125
|
/**
|
|
126
|
+
* A recipe's or a pattern's name, checked against the config as of the call.
|
|
127
|
+
*
|
|
128
|
+
* Not an enum: a request is validated against the schema before any tool runs, so an enum built
|
|
129
|
+
* from the config the server started with rejected a recipe added since. The names are still in
|
|
130
|
+
* the description, refreshed when the config reloads.
|
|
131
|
+
*/
|
|
132
|
+
const nameSchema = (kind, names) => zod_v4.string().optional().describe(names.length ? `Filter by ${kind} name: ${names.join(", ")}` : `Filter by ${kind} name`);
|
|
133
|
+
const noSuchName = (kind, name, names) => ({
|
|
134
|
+
content: [{
|
|
135
|
+
type: "text",
|
|
136
|
+
text: `No ${kind} is named \`${name}\`. ${names.length ? `The ${kind}s are: ${names.join(", ")}.` : `The config defines none.`}`
|
|
137
|
+
}],
|
|
138
|
+
isError: true
|
|
139
|
+
});
|
|
140
|
+
/**
|
|
42
141
|
* Create an MCP server with all tools registered.
|
|
43
142
|
* This is separated from `startMcpServer` to allow testing with custom transports.
|
|
44
143
|
*/
|
|
45
144
|
function createMcpServer(options) {
|
|
46
|
-
const { ctx } = options;
|
|
47
145
|
const server = new _modelcontextprotocol_sdk_server_mcp_js.McpServer({
|
|
48
146
|
name: "@bamboocss/mcp",
|
|
49
147
|
version
|
|
50
148
|
});
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
const
|
|
149
|
+
let recipeNames = options.ctx.recipes.keys;
|
|
150
|
+
let patternNames = options.ctx.patterns.keys;
|
|
151
|
+
let seen = options.ctx;
|
|
152
|
+
const context = async () => {
|
|
153
|
+
const ctx = options.current ? await options.current() : options.ctx;
|
|
154
|
+
if (ctx === seen) return ctx;
|
|
155
|
+
seen = ctx;
|
|
156
|
+
const nextRecipes = ctx.recipes.keys;
|
|
157
|
+
if (nextRecipes.join() !== recipeNames.join()) {
|
|
158
|
+
recipeNames = nextRecipes;
|
|
159
|
+
recipesTool.update({ paramsSchema: { name: nameSchema("recipe", recipeNames) } });
|
|
160
|
+
}
|
|
161
|
+
const nextPatterns = ctx.patterns.keys;
|
|
162
|
+
if (nextPatterns.join() !== patternNames.join()) {
|
|
163
|
+
patternNames = nextPatterns;
|
|
164
|
+
patternsTool.update({ paramsSchema: { name: nameSchema("pattern", patternNames) } });
|
|
165
|
+
}
|
|
166
|
+
return ctx;
|
|
167
|
+
};
|
|
55
168
|
server.registerTool("get_tokens", {
|
|
56
169
|
description: "Get all design tokens with their values, CSS variables, and usage examples",
|
|
57
170
|
inputSchema: { category: tokenCategorySchema }
|
|
58
171
|
}, async ({ category }) => {
|
|
59
|
-
const spec =
|
|
172
|
+
const spec = (await context()).getSpecOfType("tokens");
|
|
60
173
|
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
61
174
|
return json({
|
|
62
175
|
type: spec.type,
|
|
@@ -67,17 +180,19 @@ function createMcpServer(options) {
|
|
|
67
180
|
description: "Get semantic tokens with their conditional values (responsive, color modes)",
|
|
68
181
|
inputSchema: { category: tokenCategorySchema }
|
|
69
182
|
}, async ({ category }) => {
|
|
70
|
-
const spec =
|
|
183
|
+
const spec = (await context()).getSpecOfType("semantic-tokens");
|
|
71
184
|
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
72
185
|
return json({
|
|
73
186
|
type: spec.type,
|
|
74
187
|
data
|
|
75
188
|
});
|
|
76
189
|
});
|
|
77
|
-
server.registerTool("get_recipes", {
|
|
190
|
+
const recipesTool = server.registerTool("get_recipes", {
|
|
78
191
|
description: "Get component recipes with their variants, default values, and usage examples",
|
|
79
|
-
inputSchema: { name:
|
|
192
|
+
inputSchema: { name: nameSchema("recipe", recipeNames) }
|
|
80
193
|
}, async ({ name }) => {
|
|
194
|
+
const ctx = await context();
|
|
195
|
+
if (name && !recipeNames.includes(name)) return noSuchName("recipe", name, recipeNames);
|
|
81
196
|
const spec = ctx.getSpecOfType("recipes");
|
|
82
197
|
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
83
198
|
return json({
|
|
@@ -85,10 +200,12 @@ function createMcpServer(options) {
|
|
|
85
200
|
data
|
|
86
201
|
});
|
|
87
202
|
});
|
|
88
|
-
server.registerTool("get_patterns", {
|
|
203
|
+
const patternsTool = server.registerTool("get_patterns", {
|
|
89
204
|
description: "Get layout patterns with their properties and usage examples",
|
|
90
|
-
inputSchema: { name:
|
|
205
|
+
inputSchema: { name: nameSchema("pattern", patternNames) }
|
|
91
206
|
}, async ({ name }) => {
|
|
207
|
+
const ctx = await context();
|
|
208
|
+
if (name && !patternNames.includes(name)) return noSuchName("pattern", name, patternNames);
|
|
92
209
|
const spec = ctx.getSpecOfType("patterns");
|
|
93
210
|
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
94
211
|
return json({
|
|
@@ -96,13 +213,13 @@ function createMcpServer(options) {
|
|
|
96
213
|
data
|
|
97
214
|
});
|
|
98
215
|
});
|
|
99
|
-
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json(
|
|
100
|
-
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json(
|
|
101
|
-
server.registerTool("get_mixins", { description: "Get the named style bundles the theme declares, applied through the `mixin` style property" }, async () => json(
|
|
102
|
-
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json(
|
|
103
|
-
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json(
|
|
216
|
+
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json((await context()).getSpecOfType("conditions")));
|
|
217
|
+
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json((await context()).getSpecOfType("keyframes")));
|
|
218
|
+
server.registerTool("get_mixins", { description: "Get the named style bundles the theme declares, applied through the `mixin` style property" }, async () => json((await context()).getSpecOfType("mixins")));
|
|
219
|
+
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json((await context()).getSpecOfType("color-palette")));
|
|
220
|
+
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json((await context()).config));
|
|
104
221
|
server.registerTool("get_usage_report", {
|
|
105
|
-
description: "Get a usage report of the design system across the codebase: design tokens, recipes, patterns, utilities and keyframes. Shows which are used and how often, and which are defined but unused. Useful for auditing, cleanup, and identifying dead code.",
|
|
222
|
+
description: "Get a usage report of the design system across the codebase: design tokens, recipes, patterns, utilities and keyframes. Shows which are used and how often, and which are defined but unused. Useful for auditing, cleanup, and identifying dead code. `unused` lists the names the build keeps nothing for, the ones safe to remove; a `usedCount` counts direct uses only, so a token or keyframes reached through another token, a mixin or global css can be used at a count of 0.",
|
|
106
223
|
inputSchema: { scope: zod_v4.enum([
|
|
107
224
|
"all",
|
|
108
225
|
"token",
|
|
@@ -112,6 +229,7 @@ function createMcpServer(options) {
|
|
|
112
229
|
"keyframe"
|
|
113
230
|
]).optional().describe("Analysis scope: token, recipe, pattern, utility, keyframe, or all (default)") }
|
|
114
231
|
}, async ({ scope }) => {
|
|
232
|
+
const ctx = await context();
|
|
115
233
|
const result = await (0, _bamboocss_node.analyze)(ctx);
|
|
116
234
|
const includes = (part) => !scope || scope === "all" || scope === part;
|
|
117
235
|
const report = {};
|
|
@@ -123,6 +241,16 @@ function createMcpServer(options) {
|
|
|
123
241
|
const keyframes = result.getKeyframeReport();
|
|
124
242
|
if (keyframes.length) report.keyframes = keyframes;
|
|
125
243
|
}
|
|
244
|
+
const kinds = [
|
|
245
|
+
"tokens",
|
|
246
|
+
"recipes",
|
|
247
|
+
"patterns",
|
|
248
|
+
"keyframes"
|
|
249
|
+
].filter((kind) => includes(kind.slice(0, -1)));
|
|
250
|
+
if (kinds.length) {
|
|
251
|
+
const unused = result.getUnused(kinds);
|
|
252
|
+
report.unused = Object.fromEntries(kinds.map((kind) => [kind, unused[kind]]));
|
|
253
|
+
}
|
|
126
254
|
return json(report);
|
|
127
255
|
});
|
|
128
256
|
return server;
|
|
@@ -174,10 +302,14 @@ async function startMcpServer(options = {}) {
|
|
|
174
302
|
if (silent) _bamboocss_logger.logger.level = "silent";
|
|
175
303
|
const resolvedCwd = (0, node_path.resolve)(cwd);
|
|
176
304
|
const resolvedConfigPath = configPath ? (0, node_path.resolve)(configPath) : void 0;
|
|
177
|
-
const
|
|
305
|
+
const current = createContextSource(() => (0, _bamboocss_node.loadConfigAndCreateContext)({
|
|
178
306
|
cwd: resolvedCwd,
|
|
179
307
|
configPath: resolvedConfigPath
|
|
180
|
-
})
|
|
308
|
+
}));
|
|
309
|
+
const server = createMcpServer({
|
|
310
|
+
ctx: await current(),
|
|
311
|
+
current
|
|
312
|
+
});
|
|
181
313
|
const serverTransport = transport ?? new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
|
|
182
314
|
await server.connect(serverTransport);
|
|
183
315
|
console.error("Bamboo CSS MCP server started");
|
package/dist/cli.cjs
CHANGED
package/dist/cli.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { n as runMcpCli, t as parseArgs } from "./cli-
|
|
1
|
+
import { n as runMcpCli, t as parseArgs } from "./cli-CS-t3UrG.mjs";
|
|
2
2
|
export { parseArgs, runMcpCli };
|
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
const require_cli = require("./cli-
|
|
2
|
+
const require_cli = require("./cli-Dwi3db5P.cjs");
|
|
3
3
|
exports.createMcpServer = require_cli.createMcpServer;
|
|
4
4
|
exports.runMcpCli = require_cli.runMcpCli;
|
|
5
5
|
exports.startMcpServer = require_cli.startMcpServer;
|
package/dist/index.d.cts
CHANGED
|
@@ -6,6 +6,11 @@ import { BambooContext } from "@bamboocss/node";
|
|
|
6
6
|
//#region src/server.d.ts
|
|
7
7
|
interface CreateMcpServerOptions {
|
|
8
8
|
ctx: BambooContext;
|
|
9
|
+
/**
|
|
10
|
+
* The context as of now: `startMcpServer` passes one that reloads the config when it has changed
|
|
11
|
+
* on disk. Without it, every tool answers from `ctx`.
|
|
12
|
+
*/
|
|
13
|
+
current?: () => Promise<BambooContext>;
|
|
9
14
|
}
|
|
10
15
|
/**
|
|
11
16
|
* Create an MCP server with all tools registered.
|
package/dist/index.d.mts
CHANGED
|
@@ -6,6 +6,11 @@ import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
|
6
6
|
//#region src/server.d.ts
|
|
7
7
|
interface CreateMcpServerOptions {
|
|
8
8
|
ctx: BambooContext;
|
|
9
|
+
/**
|
|
10
|
+
* The context as of now: `startMcpServer` passes one that reloads the config when it has changed
|
|
11
|
+
* on disk. Without it, every tool answers from `ctx`.
|
|
12
|
+
*/
|
|
13
|
+
current?: () => Promise<BambooContext>;
|
|
9
14
|
}
|
|
10
15
|
/**
|
|
11
16
|
* Create an MCP server with all tools registered.
|
package/dist/index.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { i as startMcpServer, n as runMcpCli, r as createMcpServer } from "./cli-
|
|
1
|
+
import { i as startMcpServer, n as runMcpCli, r as createMcpServer } from "./cli-CS-t3UrG.mjs";
|
|
2
2
|
export { createMcpServer, runMcpCli, startMcpServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/mcp",
|
|
3
|
-
"version": "1.58.
|
|
3
|
+
"version": "1.58.2",
|
|
4
4
|
"description": "MCP server for Bamboo CSS AI assistants",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -40,10 +40,10 @@
|
|
|
40
40
|
"dependencies": {
|
|
41
41
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
42
42
|
"zod": "^4.0.0",
|
|
43
|
-
"@bamboocss/logger": "1.58.
|
|
44
|
-
"@bamboocss/node": "1.58.
|
|
45
|
-
"@bamboocss/token-dictionary": "1.58.
|
|
46
|
-
"@bamboocss/types": "1.58.
|
|
43
|
+
"@bamboocss/logger": "1.58.2",
|
|
44
|
+
"@bamboocss/node": "1.58.2",
|
|
45
|
+
"@bamboocss/token-dictionary": "1.58.2",
|
|
46
|
+
"@bamboocss/types": "1.58.2"
|
|
47
47
|
},
|
|
48
48
|
"engines": {
|
|
49
49
|
"node": ">=22.12.0"
|