@bamboocss/mcp 1.13.2 → 1.15.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/README.md +39 -0
- package/bin.js +12 -0
- package/dist/cli-B_J0FSVI.cjs +219 -0
- package/dist/cli-Dg1YlnHA.mjs +173 -0
- package/dist/cli.cjs +4 -0
- package/dist/cli.d.cts +14 -0
- package/dist/cli.d.mts +14 -0
- package/dist/cli.mjs +2 -0
- package/dist/index.cjs +4 -257
- package/dist/index.d.cts +2 -22
- package/dist/index.d.mts +2 -22
- package/dist/index.mjs +2 -230
- package/package.json +13 -9
package/README.md
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# @bamboocss/mcp
|
|
2
|
+
|
|
3
|
+
MCP server for [Bamboo CSS](https://bamboocss.com). Exposes your project's design system — tokens, recipes, patterns,
|
|
4
|
+
conditions and usage reports — to AI assistants that speak the
|
|
5
|
+
[Model Context Protocol](https://modelcontextprotocol.io/).
|
|
6
|
+
|
|
7
|
+
## Usage
|
|
8
|
+
|
|
9
|
+
You do not normally install this. Run `bamboo init-mcp` in your project and it writes a config for your AI client that
|
|
10
|
+
starts the server on demand, pinned to the Bamboo version that generated it:
|
|
11
|
+
|
|
12
|
+
```json
|
|
13
|
+
{
|
|
14
|
+
"mcpServers": {
|
|
15
|
+
"bamboo": {
|
|
16
|
+
"command": "npx",
|
|
17
|
+
"args": ["-y", "@bamboocss/mcp@<version>"]
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
To run it by hand:
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
npx -y @bamboocss/mcp [--config <path>] [--cwd <dir>]
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
It speaks MCP over stdio and loads `bamboo.config.ts` from the working directory.
|
|
30
|
+
|
|
31
|
+
## Why it is a separate package
|
|
32
|
+
|
|
33
|
+
The protocol SDK depends on an HTTP server and a JOSE implementation, which come to roughly 18 MB — several times the
|
|
34
|
+
weight of Bamboo's CSS toolchain. Shipping it inside `@bamboocss/dev` would put all of that in every project, including
|
|
35
|
+
the ones that never start an AI client. Kept here, it is downloaded only when something actually asks for it.
|
|
36
|
+
|
|
37
|
+
## Documentation
|
|
38
|
+
|
|
39
|
+
[bamboocss.com/docs/ai/mcp-server](https://bamboocss.com/docs/ai/mcp-server)
|
package/bin.js
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
// The failure has to reach stderr by hand. `runMcpCli` silences the logger so that nothing
|
|
4
|
+
// pollutes stdout, which is the protocol channel — and `@bamboocss/node` routes unhandled
|
|
5
|
+
// rejections through that same logger, so without this a missing config exits 0 having
|
|
6
|
+
// written nothing to either stream, and the client sees a server that started and stopped.
|
|
7
|
+
require(`./dist/cli.cjs`)
|
|
8
|
+
.runMcpCli()
|
|
9
|
+
.catch((error) => {
|
|
10
|
+
process.stderr.write(`${error?.stack ?? error}\n`)
|
|
11
|
+
process.exitCode = 1
|
|
12
|
+
})
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
//#region \0rolldown/runtime.js
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __copyProps = (to, from, except, desc) => {
|
|
9
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
10
|
+
key = keys[i];
|
|
11
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
12
|
+
get: ((k) => from[k]).bind(null, key),
|
|
13
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
19
|
+
value: mod,
|
|
20
|
+
enumerable: true
|
|
21
|
+
}) : target, mod));
|
|
22
|
+
//#endregion
|
|
23
|
+
let _modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
24
|
+
let _modelcontextprotocol_sdk_server_stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
25
|
+
let _bamboocss_logger = require("@bamboocss/logger");
|
|
26
|
+
let _bamboocss_node = require("@bamboocss/node");
|
|
27
|
+
let _bamboocss_token_dictionary = require("@bamboocss/token-dictionary");
|
|
28
|
+
let path = require("path");
|
|
29
|
+
let zod_v4 = require("zod/v4");
|
|
30
|
+
zod_v4 = __toESM(zod_v4);
|
|
31
|
+
//#region src/server.ts
|
|
32
|
+
const tokenCategorySchema = zod_v4.enum(_bamboocss_token_dictionary.TOKEN_CATEGORIES).optional().describe("Filter by token category");
|
|
33
|
+
const json = (data) => ({ content: [{
|
|
34
|
+
type: "text",
|
|
35
|
+
text: JSON.stringify(data)
|
|
36
|
+
}] });
|
|
37
|
+
/**
|
|
38
|
+
* Create an MCP server with all tools registered.
|
|
39
|
+
* This is separated from `startMcpServer` to allow testing with custom transports.
|
|
40
|
+
*/
|
|
41
|
+
function createMcpServer(options) {
|
|
42
|
+
const { ctx } = options;
|
|
43
|
+
const server = new _modelcontextprotocol_sdk_server_mcp_js.McpServer({
|
|
44
|
+
name: "@bamboocss/mcp",
|
|
45
|
+
version: "1.0.0"
|
|
46
|
+
});
|
|
47
|
+
const recipeNames = ctx.recipes.keys;
|
|
48
|
+
const patternNames = ctx.patterns.keys;
|
|
49
|
+
const recipeNameSchema = recipeNames.length ? zod_v4.enum(recipeNames).optional().describe("Filter by recipe name") : zod_v4.string().optional().describe("Filter by recipe name");
|
|
50
|
+
const patternNameSchema = patternNames.length ? zod_v4.enum(patternNames).optional().describe("Filter by pattern name") : zod_v4.string().optional().describe("Filter by pattern name");
|
|
51
|
+
server.registerTool("get_tokens", {
|
|
52
|
+
description: "Get all design tokens with their values, CSS variables, and usage examples",
|
|
53
|
+
inputSchema: { category: tokenCategorySchema }
|
|
54
|
+
}, async ({ category }) => {
|
|
55
|
+
const spec = ctx.getSpecOfType("tokens");
|
|
56
|
+
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
57
|
+
return json({
|
|
58
|
+
type: spec.type,
|
|
59
|
+
data
|
|
60
|
+
});
|
|
61
|
+
});
|
|
62
|
+
server.registerTool("get_semantic_tokens", {
|
|
63
|
+
description: "Get semantic tokens with their conditional values (responsive, color modes)",
|
|
64
|
+
inputSchema: { category: tokenCategorySchema }
|
|
65
|
+
}, async ({ category }) => {
|
|
66
|
+
const spec = ctx.getSpecOfType("semantic-tokens");
|
|
67
|
+
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
68
|
+
return json({
|
|
69
|
+
type: spec.type,
|
|
70
|
+
data
|
|
71
|
+
});
|
|
72
|
+
});
|
|
73
|
+
server.registerTool("get_recipes", {
|
|
74
|
+
description: "Get component recipes with their variants, default values, and usage examples",
|
|
75
|
+
inputSchema: { name: recipeNameSchema }
|
|
76
|
+
}, async ({ name }) => {
|
|
77
|
+
const spec = ctx.getSpecOfType("recipes");
|
|
78
|
+
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
79
|
+
return json({
|
|
80
|
+
type: spec.type,
|
|
81
|
+
data
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
server.registerTool("get_patterns", {
|
|
85
|
+
description: "Get layout patterns with their properties and usage examples",
|
|
86
|
+
inputSchema: { name: patternNameSchema }
|
|
87
|
+
}, async ({ name }) => {
|
|
88
|
+
const spec = ctx.getSpecOfType("patterns");
|
|
89
|
+
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
90
|
+
return json({
|
|
91
|
+
type: spec.type,
|
|
92
|
+
data
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json(ctx.getSpecOfType("conditions")));
|
|
96
|
+
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json(ctx.getSpecOfType("keyframes")));
|
|
97
|
+
server.registerTool("get_text_styles", { description: "Get text style compositions for typography" }, async () => json(ctx.getSpecOfType("text-styles")));
|
|
98
|
+
server.registerTool("get_layer_styles", { description: "Get layer style compositions for visual styling" }, async () => json(ctx.getSpecOfType("layer-styles")));
|
|
99
|
+
server.registerTool("get_animation_styles", { description: "Get animation style compositions" }, async () => json(ctx.getSpecOfType("animation-styles")));
|
|
100
|
+
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json(ctx.getSpecOfType("color-palette")));
|
|
101
|
+
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json(ctx.config));
|
|
102
|
+
server.registerTool("get_usage_report", {
|
|
103
|
+
description: "Get a usage report of design tokens and recipes across the codebase. Shows which tokens/recipes are used, unused, or missing. Useful for auditing, cleanup, and identifying dead code.",
|
|
104
|
+
inputSchema: { scope: zod_v4.enum([
|
|
105
|
+
"all",
|
|
106
|
+
"token",
|
|
107
|
+
"recipe"
|
|
108
|
+
]).optional().describe("Analysis scope: token, recipe, or all (default)") }
|
|
109
|
+
}, async ({ scope }) => {
|
|
110
|
+
const result = (0, _bamboocss_node.analyze)(ctx);
|
|
111
|
+
const includeTokens = !scope || scope === "all" || scope === "token";
|
|
112
|
+
const includeRecipes = !scope || scope === "all" || scope === "recipe";
|
|
113
|
+
const report = {};
|
|
114
|
+
if (includeTokens && !ctx.tokens.isEmpty) report.tokens = result.getTokenReport().report.getSummary();
|
|
115
|
+
if (includeRecipes && !ctx.recipes.isEmpty()) report.recipes = result.getRecipeReport().report;
|
|
116
|
+
return json(report);
|
|
117
|
+
});
|
|
118
|
+
return server;
|
|
119
|
+
}
|
|
120
|
+
/**
|
|
121
|
+
* Start the MCP server with the given options.
|
|
122
|
+
* By default, uses StdioServerTransport for CLI usage.
|
|
123
|
+
*/
|
|
124
|
+
async function startMcpServer(options = {}) {
|
|
125
|
+
const { cwd = process.cwd(), config: configPath, silent = false, transport } = options;
|
|
126
|
+
if (silent) _bamboocss_logger.logger.level = "silent";
|
|
127
|
+
const resolvedCwd = (0, path.resolve)(cwd);
|
|
128
|
+
const resolvedConfigPath = configPath ? (0, path.resolve)(configPath) : void 0;
|
|
129
|
+
const server = createMcpServer({ ctx: await (0, _bamboocss_node.loadConfigAndCreateContext)({
|
|
130
|
+
cwd: resolvedCwd,
|
|
131
|
+
configPath: resolvedConfigPath
|
|
132
|
+
}) });
|
|
133
|
+
const serverTransport = transport ?? new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
|
|
134
|
+
await server.connect(serverTransport);
|
|
135
|
+
console.error("Bamboo CSS MCP server started");
|
|
136
|
+
console.error(`Working directory: ${resolvedCwd}`);
|
|
137
|
+
if (resolvedConfigPath) console.error(`Config path: ${resolvedConfigPath}`);
|
|
138
|
+
return server;
|
|
139
|
+
}
|
|
140
|
+
//#endregion
|
|
141
|
+
//#region src/cli.ts
|
|
142
|
+
const HELP = `bamboo-mcp — MCP server for Bamboo CSS
|
|
143
|
+
|
|
144
|
+
Usage
|
|
145
|
+
npx -y @bamboocss/mcp [options]
|
|
146
|
+
|
|
147
|
+
Options
|
|
148
|
+
-c, --config <path> Path to the bamboo config file
|
|
149
|
+
--cwd <dir> Directory to load the config from (default: .)
|
|
150
|
+
-h, --help Show this message
|
|
151
|
+
|
|
152
|
+
The server speaks MCP over stdio, so it is normally started by an AI client from
|
|
153
|
+
the config \`bamboo init-mcp\` writes rather than run by hand.
|
|
154
|
+
`;
|
|
155
|
+
/**
|
|
156
|
+
* Reads only what the generated client configs pass, which is why this is hand-rolled rather
|
|
157
|
+
* than another `cac` dependency: the point of shipping this separately is that installing it
|
|
158
|
+
* pulls in as little as possible.
|
|
159
|
+
*/
|
|
160
|
+
function parseArgs(argv) {
|
|
161
|
+
const options = {};
|
|
162
|
+
const value = (flag, raw) => {
|
|
163
|
+
if (!raw) throw new Error(`Missing value for ${flag}`);
|
|
164
|
+
return raw;
|
|
165
|
+
};
|
|
166
|
+
for (let i = 0; i < argv.length; i++) {
|
|
167
|
+
const arg = argv[i];
|
|
168
|
+
if (arg === "-h" || arg === "--help") options.help = true;
|
|
169
|
+
else if (arg === "-c" || arg === "--config") options.config = value(arg, argv[++i]);
|
|
170
|
+
else if (arg === "--cwd") options.cwd = value(arg, argv[++i]);
|
|
171
|
+
else if (arg?.startsWith("--config=")) options.config = value("--config", arg.slice(9));
|
|
172
|
+
else if (arg?.startsWith("--cwd=")) options.cwd = value("--cwd", arg.slice(6));
|
|
173
|
+
else throw new Error(`Unknown option: ${arg}`);
|
|
174
|
+
}
|
|
175
|
+
return options;
|
|
176
|
+
}
|
|
177
|
+
async function runMcpCli(argv = process.argv.slice(2)) {
|
|
178
|
+
let options;
|
|
179
|
+
try {
|
|
180
|
+
options = parseArgs(argv);
|
|
181
|
+
} catch (error) {
|
|
182
|
+
process.stderr.write(`${error.message}\n\n${HELP}`);
|
|
183
|
+
process.exitCode = 1;
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
if (options.help) {
|
|
187
|
+
process.stdout.write(HELP);
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
await startMcpServer({
|
|
191
|
+
...options,
|
|
192
|
+
silent: true
|
|
193
|
+
});
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
196
|
+
Object.defineProperty(exports, "createMcpServer", {
|
|
197
|
+
enumerable: true,
|
|
198
|
+
get: function() {
|
|
199
|
+
return createMcpServer;
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
Object.defineProperty(exports, "parseArgs", {
|
|
203
|
+
enumerable: true,
|
|
204
|
+
get: function() {
|
|
205
|
+
return parseArgs;
|
|
206
|
+
}
|
|
207
|
+
});
|
|
208
|
+
Object.defineProperty(exports, "runMcpCli", {
|
|
209
|
+
enumerable: true,
|
|
210
|
+
get: function() {
|
|
211
|
+
return runMcpCli;
|
|
212
|
+
}
|
|
213
|
+
});
|
|
214
|
+
Object.defineProperty(exports, "startMcpServer", {
|
|
215
|
+
enumerable: true,
|
|
216
|
+
get: function() {
|
|
217
|
+
return startMcpServer;
|
|
218
|
+
}
|
|
219
|
+
});
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
3
|
+
import { logger } from "@bamboocss/logger";
|
|
4
|
+
import { analyze, loadConfigAndCreateContext } from "@bamboocss/node";
|
|
5
|
+
import { TOKEN_CATEGORIES } from "@bamboocss/token-dictionary";
|
|
6
|
+
import { resolve } from "path";
|
|
7
|
+
import * as z from "zod/v4";
|
|
8
|
+
//#region src/server.ts
|
|
9
|
+
const tokenCategorySchema = z.enum(TOKEN_CATEGORIES).optional().describe("Filter by token category");
|
|
10
|
+
const json = (data) => ({ content: [{
|
|
11
|
+
type: "text",
|
|
12
|
+
text: JSON.stringify(data)
|
|
13
|
+
}] });
|
|
14
|
+
/**
|
|
15
|
+
* Create an MCP server with all tools registered.
|
|
16
|
+
* This is separated from `startMcpServer` to allow testing with custom transports.
|
|
17
|
+
*/
|
|
18
|
+
function createMcpServer(options) {
|
|
19
|
+
const { ctx } = options;
|
|
20
|
+
const server = new McpServer({
|
|
21
|
+
name: "@bamboocss/mcp",
|
|
22
|
+
version: "1.0.0"
|
|
23
|
+
});
|
|
24
|
+
const recipeNames = ctx.recipes.keys;
|
|
25
|
+
const patternNames = ctx.patterns.keys;
|
|
26
|
+
const recipeNameSchema = recipeNames.length ? z.enum(recipeNames).optional().describe("Filter by recipe name") : z.string().optional().describe("Filter by recipe name");
|
|
27
|
+
const patternNameSchema = patternNames.length ? z.enum(patternNames).optional().describe("Filter by pattern name") : z.string().optional().describe("Filter by pattern name");
|
|
28
|
+
server.registerTool("get_tokens", {
|
|
29
|
+
description: "Get all design tokens with their values, CSS variables, and usage examples",
|
|
30
|
+
inputSchema: { category: tokenCategorySchema }
|
|
31
|
+
}, async ({ category }) => {
|
|
32
|
+
const spec = ctx.getSpecOfType("tokens");
|
|
33
|
+
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
34
|
+
return json({
|
|
35
|
+
type: spec.type,
|
|
36
|
+
data
|
|
37
|
+
});
|
|
38
|
+
});
|
|
39
|
+
server.registerTool("get_semantic_tokens", {
|
|
40
|
+
description: "Get semantic tokens with their conditional values (responsive, color modes)",
|
|
41
|
+
inputSchema: { category: tokenCategorySchema }
|
|
42
|
+
}, async ({ category }) => {
|
|
43
|
+
const spec = ctx.getSpecOfType("semantic-tokens");
|
|
44
|
+
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
45
|
+
return json({
|
|
46
|
+
type: spec.type,
|
|
47
|
+
data
|
|
48
|
+
});
|
|
49
|
+
});
|
|
50
|
+
server.registerTool("get_recipes", {
|
|
51
|
+
description: "Get component recipes with their variants, default values, and usage examples",
|
|
52
|
+
inputSchema: { name: recipeNameSchema }
|
|
53
|
+
}, async ({ name }) => {
|
|
54
|
+
const spec = ctx.getSpecOfType("recipes");
|
|
55
|
+
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
56
|
+
return json({
|
|
57
|
+
type: spec.type,
|
|
58
|
+
data
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
server.registerTool("get_patterns", {
|
|
62
|
+
description: "Get layout patterns with their properties and usage examples",
|
|
63
|
+
inputSchema: { name: patternNameSchema }
|
|
64
|
+
}, async ({ name }) => {
|
|
65
|
+
const spec = ctx.getSpecOfType("patterns");
|
|
66
|
+
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
67
|
+
return json({
|
|
68
|
+
type: spec.type,
|
|
69
|
+
data
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json(ctx.getSpecOfType("conditions")));
|
|
73
|
+
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json(ctx.getSpecOfType("keyframes")));
|
|
74
|
+
server.registerTool("get_text_styles", { description: "Get text style compositions for typography" }, async () => json(ctx.getSpecOfType("text-styles")));
|
|
75
|
+
server.registerTool("get_layer_styles", { description: "Get layer style compositions for visual styling" }, async () => json(ctx.getSpecOfType("layer-styles")));
|
|
76
|
+
server.registerTool("get_animation_styles", { description: "Get animation style compositions" }, async () => json(ctx.getSpecOfType("animation-styles")));
|
|
77
|
+
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json(ctx.getSpecOfType("color-palette")));
|
|
78
|
+
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json(ctx.config));
|
|
79
|
+
server.registerTool("get_usage_report", {
|
|
80
|
+
description: "Get a usage report of design tokens and recipes across the codebase. Shows which tokens/recipes are used, unused, or missing. Useful for auditing, cleanup, and identifying dead code.",
|
|
81
|
+
inputSchema: { scope: z.enum([
|
|
82
|
+
"all",
|
|
83
|
+
"token",
|
|
84
|
+
"recipe"
|
|
85
|
+
]).optional().describe("Analysis scope: token, recipe, or all (default)") }
|
|
86
|
+
}, async ({ scope }) => {
|
|
87
|
+
const result = analyze(ctx);
|
|
88
|
+
const includeTokens = !scope || scope === "all" || scope === "token";
|
|
89
|
+
const includeRecipes = !scope || scope === "all" || scope === "recipe";
|
|
90
|
+
const report = {};
|
|
91
|
+
if (includeTokens && !ctx.tokens.isEmpty) report.tokens = result.getTokenReport().report.getSummary();
|
|
92
|
+
if (includeRecipes && !ctx.recipes.isEmpty()) report.recipes = result.getRecipeReport().report;
|
|
93
|
+
return json(report);
|
|
94
|
+
});
|
|
95
|
+
return server;
|
|
96
|
+
}
|
|
97
|
+
/**
|
|
98
|
+
* Start the MCP server with the given options.
|
|
99
|
+
* By default, uses StdioServerTransport for CLI usage.
|
|
100
|
+
*/
|
|
101
|
+
async function startMcpServer(options = {}) {
|
|
102
|
+
const { cwd = process.cwd(), config: configPath, silent = false, transport } = options;
|
|
103
|
+
if (silent) logger.level = "silent";
|
|
104
|
+
const resolvedCwd = resolve(cwd);
|
|
105
|
+
const resolvedConfigPath = configPath ? resolve(configPath) : void 0;
|
|
106
|
+
const server = createMcpServer({ ctx: await loadConfigAndCreateContext({
|
|
107
|
+
cwd: resolvedCwd,
|
|
108
|
+
configPath: resolvedConfigPath
|
|
109
|
+
}) });
|
|
110
|
+
const serverTransport = transport ?? new StdioServerTransport();
|
|
111
|
+
await server.connect(serverTransport);
|
|
112
|
+
console.error("Bamboo CSS MCP server started");
|
|
113
|
+
console.error(`Working directory: ${resolvedCwd}`);
|
|
114
|
+
if (resolvedConfigPath) console.error(`Config path: ${resolvedConfigPath}`);
|
|
115
|
+
return server;
|
|
116
|
+
}
|
|
117
|
+
//#endregion
|
|
118
|
+
//#region src/cli.ts
|
|
119
|
+
const HELP = `bamboo-mcp — MCP server for Bamboo CSS
|
|
120
|
+
|
|
121
|
+
Usage
|
|
122
|
+
npx -y @bamboocss/mcp [options]
|
|
123
|
+
|
|
124
|
+
Options
|
|
125
|
+
-c, --config <path> Path to the bamboo config file
|
|
126
|
+
--cwd <dir> Directory to load the config from (default: .)
|
|
127
|
+
-h, --help Show this message
|
|
128
|
+
|
|
129
|
+
The server speaks MCP over stdio, so it is normally started by an AI client from
|
|
130
|
+
the config \`bamboo init-mcp\` writes rather than run by hand.
|
|
131
|
+
`;
|
|
132
|
+
/**
|
|
133
|
+
* Reads only what the generated client configs pass, which is why this is hand-rolled rather
|
|
134
|
+
* than another `cac` dependency: the point of shipping this separately is that installing it
|
|
135
|
+
* pulls in as little as possible.
|
|
136
|
+
*/
|
|
137
|
+
function parseArgs(argv) {
|
|
138
|
+
const options = {};
|
|
139
|
+
const value = (flag, raw) => {
|
|
140
|
+
if (!raw) throw new Error(`Missing value for ${flag}`);
|
|
141
|
+
return raw;
|
|
142
|
+
};
|
|
143
|
+
for (let i = 0; i < argv.length; i++) {
|
|
144
|
+
const arg = argv[i];
|
|
145
|
+
if (arg === "-h" || arg === "--help") options.help = true;
|
|
146
|
+
else if (arg === "-c" || arg === "--config") options.config = value(arg, argv[++i]);
|
|
147
|
+
else if (arg === "--cwd") options.cwd = value(arg, argv[++i]);
|
|
148
|
+
else if (arg?.startsWith("--config=")) options.config = value("--config", arg.slice(9));
|
|
149
|
+
else if (arg?.startsWith("--cwd=")) options.cwd = value("--cwd", arg.slice(6));
|
|
150
|
+
else throw new Error(`Unknown option: ${arg}`);
|
|
151
|
+
}
|
|
152
|
+
return options;
|
|
153
|
+
}
|
|
154
|
+
async function runMcpCli(argv = process.argv.slice(2)) {
|
|
155
|
+
let options;
|
|
156
|
+
try {
|
|
157
|
+
options = parseArgs(argv);
|
|
158
|
+
} catch (error) {
|
|
159
|
+
process.stderr.write(`${error.message}\n\n${HELP}`);
|
|
160
|
+
process.exitCode = 1;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
if (options.help) {
|
|
164
|
+
process.stdout.write(HELP);
|
|
165
|
+
return;
|
|
166
|
+
}
|
|
167
|
+
await startMcpServer({
|
|
168
|
+
...options,
|
|
169
|
+
silent: true
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { startMcpServer as i, runMcpCli as n, createMcpServer as r, parseArgs as t };
|
package/dist/cli.cjs
ADDED
package/dist/cli.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/cli.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Reads only what the generated client configs pass, which is why this is hand-rolled rather
|
|
4
|
+
* than another `cac` dependency: the point of shipping this separately is that installing it
|
|
5
|
+
* pulls in as little as possible.
|
|
6
|
+
*/
|
|
7
|
+
declare function parseArgs(argv: readonly string[]): {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
config?: string;
|
|
10
|
+
help?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function runMcpCli(argv?: readonly string[]): Promise<void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { parseArgs, runMcpCli };
|
package/dist/cli.d.mts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
//#region src/cli.d.ts
|
|
2
|
+
/**
|
|
3
|
+
* Reads only what the generated client configs pass, which is why this is hand-rolled rather
|
|
4
|
+
* than another `cac` dependency: the point of shipping this separately is that installing it
|
|
5
|
+
* pulls in as little as possible.
|
|
6
|
+
*/
|
|
7
|
+
declare function parseArgs(argv: readonly string[]): {
|
|
8
|
+
cwd?: string;
|
|
9
|
+
config?: string;
|
|
10
|
+
help?: boolean;
|
|
11
|
+
};
|
|
12
|
+
declare function runMcpCli(argv?: readonly string[]): Promise<void>;
|
|
13
|
+
//#endregion
|
|
14
|
+
export { parseArgs, runMcpCli };
|
package/dist/cli.mjs
ADDED
package/dist/index.cjs
CHANGED
|
@@ -1,258 +1,5 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __copyProps = (to, from, except, desc) => {
|
|
10
|
-
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
-
key = keys[i];
|
|
12
|
-
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
-
get: ((k) => from[k]).bind(null, key),
|
|
14
|
-
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
-
});
|
|
16
|
-
}
|
|
17
|
-
return to;
|
|
18
|
-
};
|
|
19
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
-
value: mod,
|
|
21
|
-
enumerable: true
|
|
22
|
-
}) : target, mod));
|
|
23
|
-
//#endregion
|
|
24
|
-
let _modelcontextprotocol_sdk_server_mcp_js = require("@modelcontextprotocol/sdk/server/mcp.js");
|
|
25
|
-
let _modelcontextprotocol_sdk_server_stdio_js = require("@modelcontextprotocol/sdk/server/stdio.js");
|
|
26
|
-
let _bamboocss_logger = require("@bamboocss/logger");
|
|
27
|
-
let _bamboocss_node = require("@bamboocss/node");
|
|
28
|
-
let _bamboocss_token_dictionary = require("@bamboocss/token-dictionary");
|
|
29
|
-
let path = require("path");
|
|
30
|
-
let zod_v4 = require("zod/v4");
|
|
31
|
-
zod_v4 = __toESM(zod_v4);
|
|
32
|
-
let _clack_prompts = require("@clack/prompts");
|
|
33
|
-
_clack_prompts = __toESM(_clack_prompts);
|
|
34
|
-
let fs = require("fs");
|
|
35
|
-
//#region src/server.ts
|
|
36
|
-
const tokenCategorySchema = zod_v4.enum(_bamboocss_token_dictionary.TOKEN_CATEGORIES).optional().describe("Filter by token category");
|
|
37
|
-
const json = (data) => ({ content: [{
|
|
38
|
-
type: "text",
|
|
39
|
-
text: JSON.stringify(data)
|
|
40
|
-
}] });
|
|
41
|
-
/**
|
|
42
|
-
* Create an MCP server with all tools registered.
|
|
43
|
-
* This is separated from `startMcpServer` to allow testing with custom transports.
|
|
44
|
-
*/
|
|
45
|
-
function createMcpServer(options) {
|
|
46
|
-
const { ctx } = options;
|
|
47
|
-
const server = new _modelcontextprotocol_sdk_server_mcp_js.McpServer({
|
|
48
|
-
name: "@bamboocss/mcp",
|
|
49
|
-
version: "1.0.0"
|
|
50
|
-
});
|
|
51
|
-
const recipeNames = ctx.recipes.keys;
|
|
52
|
-
const patternNames = ctx.patterns.keys;
|
|
53
|
-
const recipeNameSchema = recipeNames.length ? zod_v4.enum(recipeNames).optional().describe("Filter by recipe name") : zod_v4.string().optional().describe("Filter by recipe name");
|
|
54
|
-
const patternNameSchema = patternNames.length ? zod_v4.enum(patternNames).optional().describe("Filter by pattern name") : zod_v4.string().optional().describe("Filter by pattern name");
|
|
55
|
-
server.registerTool("get_tokens", {
|
|
56
|
-
description: "Get all design tokens with their values, CSS variables, and usage examples",
|
|
57
|
-
inputSchema: { category: tokenCategorySchema }
|
|
58
|
-
}, async ({ category }) => {
|
|
59
|
-
const spec = ctx.getSpecOfType("tokens");
|
|
60
|
-
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
61
|
-
return json({
|
|
62
|
-
type: spec.type,
|
|
63
|
-
data
|
|
64
|
-
});
|
|
65
|
-
});
|
|
66
|
-
server.registerTool("get_semantic_tokens", {
|
|
67
|
-
description: "Get semantic tokens with their conditional values (responsive, color modes)",
|
|
68
|
-
inputSchema: { category: tokenCategorySchema }
|
|
69
|
-
}, async ({ category }) => {
|
|
70
|
-
const spec = ctx.getSpecOfType("semantic-tokens");
|
|
71
|
-
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
72
|
-
return json({
|
|
73
|
-
type: spec.type,
|
|
74
|
-
data
|
|
75
|
-
});
|
|
76
|
-
});
|
|
77
|
-
server.registerTool("get_recipes", {
|
|
78
|
-
description: "Get component recipes with their variants, default values, and usage examples",
|
|
79
|
-
inputSchema: { name: recipeNameSchema }
|
|
80
|
-
}, async ({ name }) => {
|
|
81
|
-
const spec = ctx.getSpecOfType("recipes");
|
|
82
|
-
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
83
|
-
return json({
|
|
84
|
-
type: spec.type,
|
|
85
|
-
data
|
|
86
|
-
});
|
|
87
|
-
});
|
|
88
|
-
server.registerTool("get_patterns", {
|
|
89
|
-
description: "Get layout patterns with their properties and usage examples",
|
|
90
|
-
inputSchema: { name: patternNameSchema }
|
|
91
|
-
}, async ({ name }) => {
|
|
92
|
-
const spec = ctx.getSpecOfType("patterns");
|
|
93
|
-
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
94
|
-
return json({
|
|
95
|
-
type: spec.type,
|
|
96
|
-
data
|
|
97
|
-
});
|
|
98
|
-
});
|
|
99
|
-
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json(ctx.getSpecOfType("conditions")));
|
|
100
|
-
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json(ctx.getSpecOfType("keyframes")));
|
|
101
|
-
server.registerTool("get_text_styles", { description: "Get text style compositions for typography" }, async () => json(ctx.getSpecOfType("text-styles")));
|
|
102
|
-
server.registerTool("get_layer_styles", { description: "Get layer style compositions for visual styling" }, async () => json(ctx.getSpecOfType("layer-styles")));
|
|
103
|
-
server.registerTool("get_animation_styles", { description: "Get animation style compositions" }, async () => json(ctx.getSpecOfType("animation-styles")));
|
|
104
|
-
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json(ctx.getSpecOfType("color-palette")));
|
|
105
|
-
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json(ctx.config));
|
|
106
|
-
server.registerTool("get_usage_report", {
|
|
107
|
-
description: "Get a usage report of design tokens and recipes across the codebase. Shows which tokens/recipes are used, unused, or missing. Useful for auditing, cleanup, and identifying dead code.",
|
|
108
|
-
inputSchema: { scope: zod_v4.enum([
|
|
109
|
-
"all",
|
|
110
|
-
"token",
|
|
111
|
-
"recipe"
|
|
112
|
-
]).optional().describe("Analysis scope: token, recipe, or all (default)") }
|
|
113
|
-
}, async ({ scope }) => {
|
|
114
|
-
const result = (0, _bamboocss_node.analyze)(ctx);
|
|
115
|
-
const includeTokens = !scope || scope === "all" || scope === "token";
|
|
116
|
-
const includeRecipes = !scope || scope === "all" || scope === "recipe";
|
|
117
|
-
const report = {};
|
|
118
|
-
if (includeTokens && !ctx.tokens.isEmpty) report.tokens = result.getTokenReport().report.getSummary();
|
|
119
|
-
if (includeRecipes && !ctx.recipes.isEmpty()) report.recipes = result.getRecipeReport().report;
|
|
120
|
-
return json(report);
|
|
121
|
-
});
|
|
122
|
-
return server;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* Start the MCP server with the given options.
|
|
126
|
-
* By default, uses StdioServerTransport for CLI usage.
|
|
127
|
-
*/
|
|
128
|
-
async function startMcpServer(options = {}) {
|
|
129
|
-
const { cwd = process.cwd(), config: configPath, silent = false, transport } = options;
|
|
130
|
-
if (silent) _bamboocss_logger.logger.level = "silent";
|
|
131
|
-
const resolvedCwd = (0, path.resolve)(cwd);
|
|
132
|
-
const resolvedConfigPath = configPath ? (0, path.resolve)(configPath) : void 0;
|
|
133
|
-
const server = createMcpServer({ ctx: await (0, _bamboocss_node.loadConfigAndCreateContext)({
|
|
134
|
-
cwd: resolvedCwd,
|
|
135
|
-
configPath: resolvedConfigPath
|
|
136
|
-
}) });
|
|
137
|
-
const serverTransport = transport ?? new _modelcontextprotocol_sdk_server_stdio_js.StdioServerTransport();
|
|
138
|
-
await server.connect(serverTransport);
|
|
139
|
-
console.error("Bamboo CSS MCP server started");
|
|
140
|
-
console.error(`Working directory: ${resolvedCwd}`);
|
|
141
|
-
if (resolvedConfigPath) console.error(`Config path: ${resolvedConfigPath}`);
|
|
142
|
-
return server;
|
|
143
|
-
}
|
|
144
|
-
//#endregion
|
|
145
|
-
//#region src/clients.ts
|
|
146
|
-
const MCP_CLIENTS = {
|
|
147
|
-
claude: {
|
|
148
|
-
name: "claude",
|
|
149
|
-
label: "Claude (.mcp.json)",
|
|
150
|
-
configPath: ".mcp.json",
|
|
151
|
-
configKey: "mcpServers"
|
|
152
|
-
},
|
|
153
|
-
cursor: {
|
|
154
|
-
name: "cursor",
|
|
155
|
-
label: "Cursor (.cursor/mcp.json)",
|
|
156
|
-
configPath: ".cursor/mcp.json",
|
|
157
|
-
configKey: "mcpServers"
|
|
158
|
-
},
|
|
159
|
-
vscode: {
|
|
160
|
-
name: "vscode",
|
|
161
|
-
label: "VS Code (.vscode/mcp.json)",
|
|
162
|
-
configPath: ".vscode/mcp.json",
|
|
163
|
-
configKey: "servers"
|
|
164
|
-
},
|
|
165
|
-
windsurf: {
|
|
166
|
-
name: "windsurf",
|
|
167
|
-
label: "Windsurf (.windsurf/mcp.json)",
|
|
168
|
-
configPath: ".windsurf/mcp.json",
|
|
169
|
-
configKey: "mcpServers"
|
|
170
|
-
},
|
|
171
|
-
codex: {
|
|
172
|
-
name: "codex",
|
|
173
|
-
label: "Codex (.codex/mcp.json)",
|
|
174
|
-
configPath: ".codex/mcp.json",
|
|
175
|
-
configKey: "mcpServers"
|
|
176
|
-
}
|
|
177
|
-
};
|
|
178
|
-
const CLIENT_NAMES = Object.keys(MCP_CLIENTS);
|
|
179
|
-
function isValidClient(client) {
|
|
180
|
-
return CLIENT_NAMES.includes(client);
|
|
181
|
-
}
|
|
182
|
-
function getClientConfig(client) {
|
|
183
|
-
return MCP_CLIENTS[client];
|
|
184
|
-
}
|
|
185
|
-
function generateMcpConfig(clientConfig) {
|
|
186
|
-
const serverConfig = {
|
|
187
|
-
command: "npx",
|
|
188
|
-
args: ["bamboo", "mcp"]
|
|
189
|
-
};
|
|
190
|
-
return { [clientConfig.configKey]: { bamboo: serverConfig } };
|
|
191
|
-
}
|
|
192
|
-
//#endregion
|
|
193
|
-
//#region src/init.ts
|
|
194
|
-
async function initMcpConfig(options = {}) {
|
|
195
|
-
const { cwd = process.cwd() } = options;
|
|
196
|
-
let { clients } = options;
|
|
197
|
-
_clack_prompts.intro("Bamboo MCP Setup");
|
|
198
|
-
if (!clients || clients.length === 0) {
|
|
199
|
-
const selected = await _clack_prompts.multiselect({
|
|
200
|
-
message: "Select AI clients to configure:",
|
|
201
|
-
options: CLIENT_NAMES.map((client) => ({
|
|
202
|
-
value: client,
|
|
203
|
-
label: MCP_CLIENTS[client].label
|
|
204
|
-
})),
|
|
205
|
-
required: true
|
|
206
|
-
});
|
|
207
|
-
if (_clack_prompts.isCancel(selected)) {
|
|
208
|
-
_clack_prompts.cancel("Setup cancelled.");
|
|
209
|
-
process.exit(0);
|
|
210
|
-
}
|
|
211
|
-
clients = selected;
|
|
212
|
-
}
|
|
213
|
-
const validClients = clients.filter((client) => {
|
|
214
|
-
if (!isValidClient(client)) {
|
|
215
|
-
_bamboocss_logger.logger.warn("mcp:init", `Unknown client: ${client}`);
|
|
216
|
-
return false;
|
|
217
|
-
}
|
|
218
|
-
return true;
|
|
219
|
-
});
|
|
220
|
-
if (validClients.length === 0) {
|
|
221
|
-
_clack_prompts.cancel("No valid clients selected.");
|
|
222
|
-
process.exit(1);
|
|
223
|
-
}
|
|
224
|
-
const results = [];
|
|
225
|
-
for (const client of validClients) {
|
|
226
|
-
const clientConfig = getClientConfig(client);
|
|
227
|
-
const configPath = (0, path.resolve)(cwd, clientConfig.configPath);
|
|
228
|
-
const configDir = (0, path.dirname)(configPath);
|
|
229
|
-
if (!(0, fs.existsSync)(configDir)) (0, fs.mkdirSync)(configDir, { recursive: true });
|
|
230
|
-
const newConfig = generateMcpConfig(clientConfig);
|
|
231
|
-
let finalConfig = newConfig;
|
|
232
|
-
if ((0, fs.existsSync)(configPath)) try {
|
|
233
|
-
const existingContent = (0, fs.readFileSync)(configPath, "utf-8");
|
|
234
|
-
const existingConfig = JSON.parse(existingContent);
|
|
235
|
-
finalConfig = {
|
|
236
|
-
...existingConfig,
|
|
237
|
-
[clientConfig.configKey]: {
|
|
238
|
-
...existingConfig[clientConfig.configKey],
|
|
239
|
-
...newConfig[clientConfig.configKey]
|
|
240
|
-
}
|
|
241
|
-
};
|
|
242
|
-
} catch {}
|
|
243
|
-
(0, fs.writeFileSync)(configPath, JSON.stringify(finalConfig, null, 2));
|
|
244
|
-
results.push({
|
|
245
|
-
client,
|
|
246
|
-
path: clientConfig.configPath,
|
|
247
|
-
created: true
|
|
248
|
-
});
|
|
249
|
-
}
|
|
250
|
-
_clack_prompts.note(results.map((r) => `${r.client}: ${r.path}`).join("\n"), "Created MCP configurations");
|
|
251
|
-
_clack_prompts.outro("MCP setup complete! Your AI assistants can now use Bamboo CSS tools.");
|
|
252
|
-
return results;
|
|
253
|
-
}
|
|
254
|
-
//#endregion
|
|
255
|
-
exports.MCP_CLIENTS = MCP_CLIENTS;
|
|
256
|
-
exports.createMcpServer = createMcpServer;
|
|
257
|
-
exports.initMcpConfig = initMcpConfig;
|
|
258
|
-
exports.startMcpServer = startMcpServer;
|
|
2
|
+
const require_cli = require("./cli-B_J0FSVI.cjs");
|
|
3
|
+
exports.createMcpServer = require_cli.createMcpServer;
|
|
4
|
+
exports.runMcpCli = require_cli.runMcpCli;
|
|
5
|
+
exports.startMcpServer = require_cli.startMcpServer;
|
package/dist/index.d.cts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runMcpCli } from "./cli.cjs";
|
|
1
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
3
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
3
4
|
import { BambooContext } from "@bamboocss/node";
|
|
@@ -23,25 +24,4 @@ interface StartMcpServerOptions {
|
|
|
23
24
|
*/
|
|
24
25
|
declare function startMcpServer(options?: StartMcpServerOptions): Promise<McpServer>;
|
|
25
26
|
//#endregion
|
|
26
|
-
|
|
27
|
-
type McpClient = 'claude' | 'cursor' | 'vscode' | 'windsurf' | 'codex';
|
|
28
|
-
interface McpClientConfig {
|
|
29
|
-
name: string;
|
|
30
|
-
label: string;
|
|
31
|
-
configPath: string;
|
|
32
|
-
configKey: 'mcpServers' | 'servers';
|
|
33
|
-
}
|
|
34
|
-
declare const MCP_CLIENTS: Record<McpClient, McpClientConfig>;
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/init.d.ts
|
|
37
|
-
interface InitMcpConfigOptions {
|
|
38
|
-
cwd?: string;
|
|
39
|
-
clients?: McpClient[];
|
|
40
|
-
}
|
|
41
|
-
declare function initMcpConfig(options?: InitMcpConfigOptions): Promise<{
|
|
42
|
-
client: McpClient;
|
|
43
|
-
path: string;
|
|
44
|
-
created: boolean;
|
|
45
|
-
}[]>;
|
|
46
|
-
//#endregion
|
|
47
|
-
export { type CreateMcpServerOptions, type InitMcpConfigOptions, MCP_CLIENTS, type McpClient, type McpClientConfig, type StartMcpServerOptions, createMcpServer, initMcpConfig, startMcpServer };
|
|
27
|
+
export { type CreateMcpServerOptions, type StartMcpServerOptions, createMcpServer, runMcpCli, startMcpServer };
|
package/dist/index.d.mts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { runMcpCli } from "./cli.mjs";
|
|
1
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
3
|
import { BambooContext } from "@bamboocss/node";
|
|
3
4
|
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
|
|
@@ -23,25 +24,4 @@ interface StartMcpServerOptions {
|
|
|
23
24
|
*/
|
|
24
25
|
declare function startMcpServer(options?: StartMcpServerOptions): Promise<McpServer>;
|
|
25
26
|
//#endregion
|
|
26
|
-
|
|
27
|
-
type McpClient = 'claude' | 'cursor' | 'vscode' | 'windsurf' | 'codex';
|
|
28
|
-
interface McpClientConfig {
|
|
29
|
-
name: string;
|
|
30
|
-
label: string;
|
|
31
|
-
configPath: string;
|
|
32
|
-
configKey: 'mcpServers' | 'servers';
|
|
33
|
-
}
|
|
34
|
-
declare const MCP_CLIENTS: Record<McpClient, McpClientConfig>;
|
|
35
|
-
//#endregion
|
|
36
|
-
//#region src/init.d.ts
|
|
37
|
-
interface InitMcpConfigOptions {
|
|
38
|
-
cwd?: string;
|
|
39
|
-
clients?: McpClient[];
|
|
40
|
-
}
|
|
41
|
-
declare function initMcpConfig(options?: InitMcpConfigOptions): Promise<{
|
|
42
|
-
client: McpClient;
|
|
43
|
-
path: string;
|
|
44
|
-
created: boolean;
|
|
45
|
-
}[]>;
|
|
46
|
-
//#endregion
|
|
47
|
-
export { type CreateMcpServerOptions, type InitMcpConfigOptions, MCP_CLIENTS, type McpClient, type McpClientConfig, type StartMcpServerOptions, createMcpServer, initMcpConfig, startMcpServer };
|
|
27
|
+
export { type CreateMcpServerOptions, type StartMcpServerOptions, createMcpServer, runMcpCli, startMcpServer };
|
package/dist/index.mjs
CHANGED
|
@@ -1,230 +1,2 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
import { logger } from "@bamboocss/logger";
|
|
4
|
-
import { analyze, loadConfigAndCreateContext } from "@bamboocss/node";
|
|
5
|
-
import { TOKEN_CATEGORIES } from "@bamboocss/token-dictionary";
|
|
6
|
-
import { dirname, resolve } from "path";
|
|
7
|
-
import * as z from "zod/v4";
|
|
8
|
-
import * as p from "@clack/prompts";
|
|
9
|
-
import { existsSync, mkdirSync, readFileSync, writeFileSync } from "fs";
|
|
10
|
-
//#region src/server.ts
|
|
11
|
-
const tokenCategorySchema = z.enum(TOKEN_CATEGORIES).optional().describe("Filter by token category");
|
|
12
|
-
const json = (data) => ({ content: [{
|
|
13
|
-
type: "text",
|
|
14
|
-
text: JSON.stringify(data)
|
|
15
|
-
}] });
|
|
16
|
-
/**
|
|
17
|
-
* Create an MCP server with all tools registered.
|
|
18
|
-
* This is separated from `startMcpServer` to allow testing with custom transports.
|
|
19
|
-
*/
|
|
20
|
-
function createMcpServer(options) {
|
|
21
|
-
const { ctx } = options;
|
|
22
|
-
const server = new McpServer({
|
|
23
|
-
name: "@bamboocss/mcp",
|
|
24
|
-
version: "1.0.0"
|
|
25
|
-
});
|
|
26
|
-
const recipeNames = ctx.recipes.keys;
|
|
27
|
-
const patternNames = ctx.patterns.keys;
|
|
28
|
-
const recipeNameSchema = recipeNames.length ? z.enum(recipeNames).optional().describe("Filter by recipe name") : z.string().optional().describe("Filter by recipe name");
|
|
29
|
-
const patternNameSchema = patternNames.length ? z.enum(patternNames).optional().describe("Filter by pattern name") : z.string().optional().describe("Filter by pattern name");
|
|
30
|
-
server.registerTool("get_tokens", {
|
|
31
|
-
description: "Get all design tokens with their values, CSS variables, and usage examples",
|
|
32
|
-
inputSchema: { category: tokenCategorySchema }
|
|
33
|
-
}, async ({ category }) => {
|
|
34
|
-
const spec = ctx.getSpecOfType("tokens");
|
|
35
|
-
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
36
|
-
return json({
|
|
37
|
-
type: spec.type,
|
|
38
|
-
data
|
|
39
|
-
});
|
|
40
|
-
});
|
|
41
|
-
server.registerTool("get_semantic_tokens", {
|
|
42
|
-
description: "Get semantic tokens with their conditional values (responsive, color modes)",
|
|
43
|
-
inputSchema: { category: tokenCategorySchema }
|
|
44
|
-
}, async ({ category }) => {
|
|
45
|
-
const spec = ctx.getSpecOfType("semantic-tokens");
|
|
46
|
-
const data = category ? spec.data.filter((group) => group.type === category) : spec.data;
|
|
47
|
-
return json({
|
|
48
|
-
type: spec.type,
|
|
49
|
-
data
|
|
50
|
-
});
|
|
51
|
-
});
|
|
52
|
-
server.registerTool("get_recipes", {
|
|
53
|
-
description: "Get component recipes with their variants, default values, and usage examples",
|
|
54
|
-
inputSchema: { name: recipeNameSchema }
|
|
55
|
-
}, async ({ name }) => {
|
|
56
|
-
const spec = ctx.getSpecOfType("recipes");
|
|
57
|
-
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
58
|
-
return json({
|
|
59
|
-
type: spec.type,
|
|
60
|
-
data
|
|
61
|
-
});
|
|
62
|
-
});
|
|
63
|
-
server.registerTool("get_patterns", {
|
|
64
|
-
description: "Get layout patterns with their properties and usage examples",
|
|
65
|
-
inputSchema: { name: patternNameSchema }
|
|
66
|
-
}, async ({ name }) => {
|
|
67
|
-
const spec = ctx.getSpecOfType("patterns");
|
|
68
|
-
const data = name ? spec.data.filter((item) => item.name === name) : spec.data;
|
|
69
|
-
return json({
|
|
70
|
-
type: spec.type,
|
|
71
|
-
data
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
server.registerTool("get_conditions", { description: "Get all conditions (breakpoints, pseudo-classes, color modes) and their CSS values" }, async () => json(ctx.getSpecOfType("conditions")));
|
|
75
|
-
server.registerTool("get_keyframes", { description: "Get keyframe animations defined in the theme" }, async () => json(ctx.getSpecOfType("keyframes")));
|
|
76
|
-
server.registerTool("get_text_styles", { description: "Get text style compositions for typography" }, async () => json(ctx.getSpecOfType("text-styles")));
|
|
77
|
-
server.registerTool("get_layer_styles", { description: "Get layer style compositions for visual styling" }, async () => json(ctx.getSpecOfType("layer-styles")));
|
|
78
|
-
server.registerTool("get_animation_styles", { description: "Get animation style compositions" }, async () => json(ctx.getSpecOfType("animation-styles")));
|
|
79
|
-
server.registerTool("get_color_palette", { description: "Get the color palette with all color values" }, async () => json(ctx.getSpecOfType("color-palette")));
|
|
80
|
-
server.registerTool("get_config", { description: "Get the resolved Bamboo CSS configuration including paths, JSX settings, and output options" }, async () => json(ctx.config));
|
|
81
|
-
server.registerTool("get_usage_report", {
|
|
82
|
-
description: "Get a usage report of design tokens and recipes across the codebase. Shows which tokens/recipes are used, unused, or missing. Useful for auditing, cleanup, and identifying dead code.",
|
|
83
|
-
inputSchema: { scope: z.enum([
|
|
84
|
-
"all",
|
|
85
|
-
"token",
|
|
86
|
-
"recipe"
|
|
87
|
-
]).optional().describe("Analysis scope: token, recipe, or all (default)") }
|
|
88
|
-
}, async ({ scope }) => {
|
|
89
|
-
const result = analyze(ctx);
|
|
90
|
-
const includeTokens = !scope || scope === "all" || scope === "token";
|
|
91
|
-
const includeRecipes = !scope || scope === "all" || scope === "recipe";
|
|
92
|
-
const report = {};
|
|
93
|
-
if (includeTokens && !ctx.tokens.isEmpty) report.tokens = result.getTokenReport().report.getSummary();
|
|
94
|
-
if (includeRecipes && !ctx.recipes.isEmpty()) report.recipes = result.getRecipeReport().report;
|
|
95
|
-
return json(report);
|
|
96
|
-
});
|
|
97
|
-
return server;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Start the MCP server with the given options.
|
|
101
|
-
* By default, uses StdioServerTransport for CLI usage.
|
|
102
|
-
*/
|
|
103
|
-
async function startMcpServer(options = {}) {
|
|
104
|
-
const { cwd = process.cwd(), config: configPath, silent = false, transport } = options;
|
|
105
|
-
if (silent) logger.level = "silent";
|
|
106
|
-
const resolvedCwd = resolve(cwd);
|
|
107
|
-
const resolvedConfigPath = configPath ? resolve(configPath) : void 0;
|
|
108
|
-
const server = createMcpServer({ ctx: await loadConfigAndCreateContext({
|
|
109
|
-
cwd: resolvedCwd,
|
|
110
|
-
configPath: resolvedConfigPath
|
|
111
|
-
}) });
|
|
112
|
-
const serverTransport = transport ?? new StdioServerTransport();
|
|
113
|
-
await server.connect(serverTransport);
|
|
114
|
-
console.error("Bamboo CSS MCP server started");
|
|
115
|
-
console.error(`Working directory: ${resolvedCwd}`);
|
|
116
|
-
if (resolvedConfigPath) console.error(`Config path: ${resolvedConfigPath}`);
|
|
117
|
-
return server;
|
|
118
|
-
}
|
|
119
|
-
//#endregion
|
|
120
|
-
//#region src/clients.ts
|
|
121
|
-
const MCP_CLIENTS = {
|
|
122
|
-
claude: {
|
|
123
|
-
name: "claude",
|
|
124
|
-
label: "Claude (.mcp.json)",
|
|
125
|
-
configPath: ".mcp.json",
|
|
126
|
-
configKey: "mcpServers"
|
|
127
|
-
},
|
|
128
|
-
cursor: {
|
|
129
|
-
name: "cursor",
|
|
130
|
-
label: "Cursor (.cursor/mcp.json)",
|
|
131
|
-
configPath: ".cursor/mcp.json",
|
|
132
|
-
configKey: "mcpServers"
|
|
133
|
-
},
|
|
134
|
-
vscode: {
|
|
135
|
-
name: "vscode",
|
|
136
|
-
label: "VS Code (.vscode/mcp.json)",
|
|
137
|
-
configPath: ".vscode/mcp.json",
|
|
138
|
-
configKey: "servers"
|
|
139
|
-
},
|
|
140
|
-
windsurf: {
|
|
141
|
-
name: "windsurf",
|
|
142
|
-
label: "Windsurf (.windsurf/mcp.json)",
|
|
143
|
-
configPath: ".windsurf/mcp.json",
|
|
144
|
-
configKey: "mcpServers"
|
|
145
|
-
},
|
|
146
|
-
codex: {
|
|
147
|
-
name: "codex",
|
|
148
|
-
label: "Codex (.codex/mcp.json)",
|
|
149
|
-
configPath: ".codex/mcp.json",
|
|
150
|
-
configKey: "mcpServers"
|
|
151
|
-
}
|
|
152
|
-
};
|
|
153
|
-
const CLIENT_NAMES = Object.keys(MCP_CLIENTS);
|
|
154
|
-
function isValidClient(client) {
|
|
155
|
-
return CLIENT_NAMES.includes(client);
|
|
156
|
-
}
|
|
157
|
-
function getClientConfig(client) {
|
|
158
|
-
return MCP_CLIENTS[client];
|
|
159
|
-
}
|
|
160
|
-
function generateMcpConfig(clientConfig) {
|
|
161
|
-
const serverConfig = {
|
|
162
|
-
command: "npx",
|
|
163
|
-
args: ["bamboo", "mcp"]
|
|
164
|
-
};
|
|
165
|
-
return { [clientConfig.configKey]: { bamboo: serverConfig } };
|
|
166
|
-
}
|
|
167
|
-
//#endregion
|
|
168
|
-
//#region src/init.ts
|
|
169
|
-
async function initMcpConfig(options = {}) {
|
|
170
|
-
const { cwd = process.cwd() } = options;
|
|
171
|
-
let { clients } = options;
|
|
172
|
-
p.intro("Bamboo MCP Setup");
|
|
173
|
-
if (!clients || clients.length === 0) {
|
|
174
|
-
const selected = await p.multiselect({
|
|
175
|
-
message: "Select AI clients to configure:",
|
|
176
|
-
options: CLIENT_NAMES.map((client) => ({
|
|
177
|
-
value: client,
|
|
178
|
-
label: MCP_CLIENTS[client].label
|
|
179
|
-
})),
|
|
180
|
-
required: true
|
|
181
|
-
});
|
|
182
|
-
if (p.isCancel(selected)) {
|
|
183
|
-
p.cancel("Setup cancelled.");
|
|
184
|
-
process.exit(0);
|
|
185
|
-
}
|
|
186
|
-
clients = selected;
|
|
187
|
-
}
|
|
188
|
-
const validClients = clients.filter((client) => {
|
|
189
|
-
if (!isValidClient(client)) {
|
|
190
|
-
logger.warn("mcp:init", `Unknown client: ${client}`);
|
|
191
|
-
return false;
|
|
192
|
-
}
|
|
193
|
-
return true;
|
|
194
|
-
});
|
|
195
|
-
if (validClients.length === 0) {
|
|
196
|
-
p.cancel("No valid clients selected.");
|
|
197
|
-
process.exit(1);
|
|
198
|
-
}
|
|
199
|
-
const results = [];
|
|
200
|
-
for (const client of validClients) {
|
|
201
|
-
const clientConfig = getClientConfig(client);
|
|
202
|
-
const configPath = resolve(cwd, clientConfig.configPath);
|
|
203
|
-
const configDir = dirname(configPath);
|
|
204
|
-
if (!existsSync(configDir)) mkdirSync(configDir, { recursive: true });
|
|
205
|
-
const newConfig = generateMcpConfig(clientConfig);
|
|
206
|
-
let finalConfig = newConfig;
|
|
207
|
-
if (existsSync(configPath)) try {
|
|
208
|
-
const existingContent = readFileSync(configPath, "utf-8");
|
|
209
|
-
const existingConfig = JSON.parse(existingContent);
|
|
210
|
-
finalConfig = {
|
|
211
|
-
...existingConfig,
|
|
212
|
-
[clientConfig.configKey]: {
|
|
213
|
-
...existingConfig[clientConfig.configKey],
|
|
214
|
-
...newConfig[clientConfig.configKey]
|
|
215
|
-
}
|
|
216
|
-
};
|
|
217
|
-
} catch {}
|
|
218
|
-
writeFileSync(configPath, JSON.stringify(finalConfig, null, 2));
|
|
219
|
-
results.push({
|
|
220
|
-
client,
|
|
221
|
-
path: clientConfig.configPath,
|
|
222
|
-
created: true
|
|
223
|
-
});
|
|
224
|
-
}
|
|
225
|
-
p.note(results.map((r) => `${r.client}: ${r.path}`).join("\n"), "Created MCP configurations");
|
|
226
|
-
p.outro("MCP setup complete! Your AI assistants can now use Bamboo CSS tools.");
|
|
227
|
-
return results;
|
|
228
|
-
}
|
|
229
|
-
//#endregion
|
|
230
|
-
export { MCP_CLIENTS, createMcpServer, initMcpConfig, startMcpServer };
|
|
1
|
+
import { i as startMcpServer, n as runMcpCli, r as createMcpServer } from "./cli-Dg1YlnHA.mjs";
|
|
2
|
+
export { createMcpServer, runMcpCli, startMcpServer };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@bamboocss/mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.15.0",
|
|
4
4
|
"description": "MCP server for Bamboo CSS AI assistants",
|
|
5
5
|
"homepage": "https://bamboocss.com",
|
|
6
6
|
"license": "MIT",
|
|
@@ -10,8 +10,13 @@
|
|
|
10
10
|
"url": "git+https://github.com/bamboocss/bamboo.git",
|
|
11
11
|
"directory": "packages/mcp"
|
|
12
12
|
},
|
|
13
|
+
"bin": {
|
|
14
|
+
"bamboo-mcp": "bin.js"
|
|
15
|
+
},
|
|
13
16
|
"files": [
|
|
14
|
-
"dist"
|
|
17
|
+
"dist",
|
|
18
|
+
"bin.js",
|
|
19
|
+
"README.md"
|
|
15
20
|
],
|
|
16
21
|
"sideEffects": false,
|
|
17
22
|
"main": "dist/index.cjs",
|
|
@@ -33,17 +38,16 @@
|
|
|
33
38
|
"access": "public"
|
|
34
39
|
},
|
|
35
40
|
"dependencies": {
|
|
36
|
-
"@clack/prompts": "0.11.0",
|
|
37
41
|
"@modelcontextprotocol/sdk": "^1.29.0",
|
|
38
42
|
"zod": "^4.0.0",
|
|
39
|
-
"@bamboocss/logger": "1.
|
|
40
|
-
"@bamboocss/node": "1.
|
|
41
|
-
"@bamboocss/token-dictionary": "1.
|
|
42
|
-
"@bamboocss/types": "1.
|
|
43
|
+
"@bamboocss/logger": "1.15.0",
|
|
44
|
+
"@bamboocss/node": "1.15.0",
|
|
45
|
+
"@bamboocss/token-dictionary": "1.15.0",
|
|
46
|
+
"@bamboocss/types": "1.15.0"
|
|
43
47
|
},
|
|
44
48
|
"scripts": {
|
|
45
|
-
"build": "tsdown src/index.ts --format=esm,cjs",
|
|
46
|
-
"build-fast": "tsdown --dts=false src/index.ts --format=esm,cjs",
|
|
49
|
+
"build": "tsdown src/index.ts src/cli.ts --format=esm,cjs",
|
|
50
|
+
"build-fast": "tsdown --dts=false src/index.ts src/cli.ts --format=esm,cjs",
|
|
47
51
|
"dev": "pnpm build-fast --watch"
|
|
48
52
|
}
|
|
49
53
|
}
|