@boldkit/mcp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bin.d.ts ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env node
2
+ export {};
package/dist/bin.js ADDED
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env node
2
+ import { startServer } from './server.js';
3
+ startServer().catch((err) => {
4
+ console.error('boldkit mcp failed to start:', err);
5
+ process.exit(1);
6
+ });
@@ -0,0 +1,26 @@
1
+ export type Framework = 'react' | 'vue';
2
+ export interface FrameworkEntry {
3
+ url: string;
4
+ dependencies: string[];
5
+ registryDependencies: string[];
6
+ files: string[];
7
+ }
8
+ export interface CatalogItem {
9
+ name: string;
10
+ type: string;
11
+ description: string;
12
+ frameworks: Framework[];
13
+ docsUrl?: string;
14
+ react?: FrameworkEntry;
15
+ vue?: FrameworkEntry;
16
+ }
17
+ export declare function loadCatalog(): CatalogItem[];
18
+ export declare function getItem(name: string): CatalogItem | undefined;
19
+ export interface SearchResult extends CatalogItem {
20
+ score: number;
21
+ }
22
+ /**
23
+ * Plain scored keyword search. The calling agent is the LLM — this only needs
24
+ * decent ranking over ~115 items, not semantics.
25
+ */
26
+ export declare function searchCatalog(query: string, framework?: Framework, limit?: number): SearchResult[];
@@ -0,0 +1,49 @@
1
+ import { readFileSync } from 'node:fs';
2
+ let cached = null;
3
+ export function loadCatalog() {
4
+ if (!cached) {
5
+ const raw = readFileSync(new URL('../catalog.json', import.meta.url), 'utf8');
6
+ cached = JSON.parse(raw).items;
7
+ }
8
+ return cached;
9
+ }
10
+ export function getItem(name) {
11
+ return loadCatalog().find((item) => item.name === name.toLowerCase());
12
+ }
13
+ /**
14
+ * Plain scored keyword search. The calling agent is the LLM — this only needs
15
+ * decent ranking over ~115 items, not semantics.
16
+ */
17
+ export function searchCatalog(query, framework, limit = 10) {
18
+ const tokens = query
19
+ .toLowerCase()
20
+ .split(/[^a-z0-9]+/)
21
+ .filter((t) => t.length > 1);
22
+ let items = loadCatalog();
23
+ if (framework)
24
+ items = items.filter((item) => item.frameworks.includes(framework));
25
+ if (tokens.length === 0)
26
+ return [];
27
+ const results = [];
28
+ for (const item of items) {
29
+ const name = item.name.toLowerCase();
30
+ const nameParts = name.split('-');
31
+ const description = item.description.toLowerCase();
32
+ let score = 0;
33
+ for (const token of tokens) {
34
+ if (name === token)
35
+ score += 100;
36
+ else if (nameParts.includes(token))
37
+ score += 40;
38
+ else if (name.includes(token))
39
+ score += 25;
40
+ if (description.includes(token))
41
+ score += 10;
42
+ if (item.type.includes(token))
43
+ score += 5;
44
+ }
45
+ if (score > 0)
46
+ results.push({ ...item, score });
47
+ }
48
+ return results.sort((a, b) => b.score - a.score || a.name.localeCompare(b.name)).slice(0, limit);
49
+ }
@@ -0,0 +1,14 @@
1
+ import { type CatalogItem, type Framework } from './catalog.js';
2
+ export interface InstallCommand {
3
+ framework: Framework;
4
+ /** Executable + args, e.g. ["npx", "shadcn@latest", "add", "<url>"] */
5
+ argv: string[];
6
+ /** Copy-pasteable command string */
7
+ display: string;
8
+ items: CatalogItem[];
9
+ /** Names not present in the catalog at all */
10
+ unknown: string[];
11
+ /** Names that exist but are not available for this framework */
12
+ unavailable: string[];
13
+ }
14
+ export declare function buildInstallCommand(names: string[], framework: Framework): InstallCommand;
@@ -0,0 +1,29 @@
1
+ import { getItem } from './catalog.js';
2
+ const CLI = {
3
+ react: 'shadcn@latest',
4
+ vue: 'shadcn-vue@latest',
5
+ };
6
+ export function buildInstallCommand(names, framework) {
7
+ const items = [];
8
+ const unknown = [];
9
+ const unavailable = [];
10
+ for (const name of names) {
11
+ const item = getItem(name);
12
+ if (!item)
13
+ unknown.push(name);
14
+ else if (!item[framework])
15
+ unavailable.push(name);
16
+ else
17
+ items.push(item);
18
+ }
19
+ const urls = items.map((item) => item[framework].url);
20
+ const argv = ['npx', CLI[framework], 'add', ...urls];
21
+ return {
22
+ framework,
23
+ argv,
24
+ display: ['npx', CLI[framework], 'add', ...urls.map((u) => `"${u}"`)].join(' '),
25
+ items,
26
+ unknown,
27
+ unavailable,
28
+ };
29
+ }
@@ -0,0 +1,9 @@
1
+ import type { Framework } from './catalog.js';
2
+ /**
3
+ * Detect whether a project is Vue or React by walking up from `cwd` to the
4
+ * nearest package.json and inspecting its dependencies. Defaults to react.
5
+ */
6
+ export declare function detectFramework(cwd: string): {
7
+ framework: Framework;
8
+ reason: string;
9
+ };
package/dist/detect.js ADDED
@@ -0,0 +1,37 @@
1
+ import { existsSync, readFileSync } from 'node:fs';
2
+ import { dirname, join } from 'node:path';
3
+ /**
4
+ * Detect whether a project is Vue or React by walking up from `cwd` to the
5
+ * nearest package.json and inspecting its dependencies. Defaults to react.
6
+ */
7
+ export function detectFramework(cwd) {
8
+ let dir = cwd;
9
+ for (;;) {
10
+ const pkgPath = join(dir, 'package.json');
11
+ if (existsSync(pkgPath)) {
12
+ try {
13
+ const pkg = JSON.parse(readFileSync(pkgPath, 'utf8'));
14
+ const deps = {
15
+ ...pkg.dependencies,
16
+ ...pkg.devDependencies,
17
+ };
18
+ for (const dep of ['nuxt', 'vue', 'reka-ui']) {
19
+ if (deps[dep])
20
+ return { framework: 'vue', reason: `found "${dep}" in ${pkgPath}` };
21
+ }
22
+ for (const dep of ['next', 'react']) {
23
+ if (deps[dep])
24
+ return { framework: 'react', reason: `found "${dep}" in ${pkgPath}` };
25
+ }
26
+ }
27
+ catch {
28
+ // unreadable package.json — keep walking up
29
+ }
30
+ }
31
+ const parent = dirname(dir);
32
+ if (parent === dir)
33
+ break;
34
+ dir = parent;
35
+ }
36
+ return { framework: 'react', reason: 'no framework dependency found, defaulting to react' };
37
+ }
@@ -0,0 +1,5 @@
1
+ export { loadCatalog, getItem, searchCatalog, type CatalogItem, type Framework, type FrameworkEntry, type SearchResult, } from './catalog.js';
2
+ export { detectFramework } from './detect.js';
3
+ export { buildInstallCommand, type InstallCommand } from './commands.js';
4
+ export { runInstall, type InstallResult } from './install.js';
5
+ export { createServer, startServer } from './server.js';
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ export { loadCatalog, getItem, searchCatalog, } from './catalog.js';
2
+ export { detectFramework } from './detect.js';
3
+ export { buildInstallCommand } from './commands.js';
4
+ export { runInstall } from './install.js';
5
+ export { createServer, startServer } from './server.js';
@@ -0,0 +1,11 @@
1
+ import type { InstallCommand } from './commands.js';
2
+ export interface InstallResult {
3
+ ok: boolean;
4
+ exitCode: number | null;
5
+ output: string;
6
+ }
7
+ /**
8
+ * Run the shadcn / shadcn-vue CLI for real. Non-interactive: passes --yes so
9
+ * the CLI never blocks on a confirmation prompt.
10
+ */
11
+ export declare function runInstall(command: InstallCommand, cwd: string, timeoutMs?: number): Promise<InstallResult>;
@@ -0,0 +1,21 @@
1
+ import { spawn } from 'node:child_process';
2
+ /**
3
+ * Run the shadcn / shadcn-vue CLI for real. Non-interactive: passes --yes so
4
+ * the CLI never blocks on a confirmation prompt.
5
+ */
6
+ export function runInstall(command, cwd, timeoutMs = 5 * 60000) {
7
+ const [bin, ...args] = command.argv;
8
+ return new Promise((resolve) => {
9
+ const child = spawn(bin, [...args, '--yes'], {
10
+ cwd,
11
+ env: { ...process.env, CI: 'true' },
12
+ timeout: timeoutMs,
13
+ shell: process.platform === 'win32',
14
+ });
15
+ let output = '';
16
+ child.stdout.on('data', (d) => (output += d.toString()));
17
+ child.stderr.on('data', (d) => (output += d.toString()));
18
+ child.on('error', (err) => resolve({ ok: false, exitCode: null, output: String(err) }));
19
+ child.on('close', (code) => resolve({ ok: code === 0, exitCode: code, output: output.trim() }));
20
+ });
21
+ }
@@ -0,0 +1,3 @@
1
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
2
+ export declare function createServer(): McpServer;
3
+ export declare function startServer(): Promise<void>;
package/dist/server.js ADDED
@@ -0,0 +1,108 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js';
3
+ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js';
4
+ import { z } from 'zod';
5
+ import { getItem, loadCatalog, searchCatalog } from './catalog.js';
6
+ import { buildInstallCommand } from './commands.js';
7
+ import { detectFramework } from './detect.js';
8
+ import { runInstall } from './install.js';
9
+ const VERSION = JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version;
10
+ const frameworkSchema = z
11
+ .enum(['react', 'vue'])
12
+ .optional()
13
+ .describe('Target framework. Omit to auto-detect from the project package.json.');
14
+ // server.tool()'s generic inference hits TS2589 (excessively deep instantiation)
15
+ // with zod 3.25 optional-enum shapes. This helper erases the generic; runtime
16
+ // zod validation by the SDK is unchanged, handlers type their args explicitly.
17
+ function registerTool(server, name, description, shape, handler) {
18
+ ;
19
+ server.tool(name, description, shape, handler);
20
+ }
21
+ function json(data) {
22
+ return { content: [{ type: 'text', text: JSON.stringify(data, null, 2) }] };
23
+ }
24
+ function summarize(item) {
25
+ return {
26
+ name: item.name,
27
+ type: item.type,
28
+ description: item.description,
29
+ frameworks: item.frameworks,
30
+ };
31
+ }
32
+ export function createServer() {
33
+ const server = new McpServer({ name: 'boldkit', version: VERSION });
34
+ registerTool(server, 'search_components', 'Search BoldKit neubrutalism UI components, charts, shapes, and blocks by natural-language description. Returns ranked matches with framework availability (react/vue).', {
35
+ query: z.string().describe('Natural-language description, e.g. "toast notification" or "chart showing proportions"'),
36
+ framework: frameworkSchema,
37
+ }, async ({ query, framework }) => {
38
+ const results = searchCatalog(query, framework);
39
+ if (results.length === 0) {
40
+ return json({ results: [], hint: 'No matches. Try broader keywords, or list_components.' });
41
+ }
42
+ return json({ results: results.map((r) => ({ ...summarize(r), score: r.score })) });
43
+ });
44
+ registerTool(server, 'get_component', 'Get full details for a BoldKit component: description, dependencies, registry URLs per framework, files, and docs link.', { name: z.string().describe('Component name, e.g. "button" or "date-range-picker"') }, async ({ name }) => {
45
+ const item = getItem(name);
46
+ if (!item) {
47
+ const near = searchCatalog(name).slice(0, 5).map((r) => r.name);
48
+ return json({ error: `Unknown component "${name}"`, didYouMean: near });
49
+ }
50
+ return json(item);
51
+ });
52
+ registerTool(server, 'get_install_command', 'Get the exact shadcn / shadcn-vue CLI command to install BoldKit components into a project. Auto-detects React vs Vue from the project directory unless framework is given.', {
53
+ names: z.array(z.string()).min(1).describe('Component names to install'),
54
+ framework: frameworkSchema,
55
+ projectDir: z.string().optional().describe('Project directory used for framework auto-detection. Defaults to the current working directory.'),
56
+ }, async ({ names, framework, projectDir }) => {
57
+ const detected = framework
58
+ ? { framework, reason: 'explicitly requested' }
59
+ : detectFramework(projectDir ?? process.cwd());
60
+ const cmd = buildInstallCommand(names, detected.framework);
61
+ return json({
62
+ framework: detected.framework,
63
+ frameworkReason: detected.reason,
64
+ command: cmd.display,
65
+ unknown: cmd.unknown,
66
+ unavailable: cmd.unavailable,
67
+ });
68
+ });
69
+ registerTool(server, 'install_components', 'Install BoldKit components into a project by running the shadcn / shadcn-vue CLI. Returns the CLI output.', {
70
+ names: z.array(z.string()).min(1).describe('Component names to install'),
71
+ framework: frameworkSchema,
72
+ projectDir: z.string().describe('Absolute path of the project to install into'),
73
+ }, async ({ names, framework, projectDir }) => {
74
+ const detected = framework
75
+ ? { framework, reason: 'explicitly requested' }
76
+ : detectFramework(projectDir);
77
+ const cmd = buildInstallCommand(names, detected.framework);
78
+ if (cmd.unknown.length > 0 || cmd.items.length === 0) {
79
+ return json({
80
+ error: 'Nothing installable',
81
+ unknown: cmd.unknown,
82
+ unavailable: cmd.unavailable,
83
+ });
84
+ }
85
+ const result = await runInstall(cmd, projectDir);
86
+ return json({
87
+ framework: detected.framework,
88
+ command: cmd.display,
89
+ installed: result.ok ? cmd.items.map((i) => i.name) : [],
90
+ skipped: { unknown: cmd.unknown, unavailable: cmd.unavailable },
91
+ ok: result.ok,
92
+ exitCode: result.exitCode,
93
+ output: result.output,
94
+ });
95
+ });
96
+ registerTool(server, 'list_components', 'List every item in the BoldKit registry (components, charts, shapes, blocks, templates), optionally filtered by framework.', { framework: frameworkSchema }, async ({ framework }) => {
97
+ let items = loadCatalog();
98
+ if (framework)
99
+ items = items.filter((item) => item.frameworks.includes(framework));
100
+ return json({ count: items.length, items: items.map(summarize) });
101
+ });
102
+ return server;
103
+ }
104
+ export async function startServer() {
105
+ const server = createServer();
106
+ await server.connect(new StdioServerTransport());
107
+ console.error(`boldkit mcp v${VERSION} — ${loadCatalog().length} registry items ready`);
108
+ }
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@boldkit/mcp",
3
+ "version": "0.1.0",
4
+ "description": "MCP server for BoldKit - search and install neubrutalism UI components (React & Vue) by natural-language description.",
5
+ "author": "BoldKit Team",
6
+ "license": "MIT",
7
+ "homepage": "https://boldkit.dev",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "https://github.com/ANIBIT14/boldkit.git",
11
+ "directory": "packages/mcp"
12
+ },
13
+ "keywords": [
14
+ "mcp",
15
+ "model-context-protocol",
16
+ "boldkit",
17
+ "neubrutalism",
18
+ "shadcn",
19
+ "shadcn-vue",
20
+ "ui",
21
+ "components"
22
+ ],
23
+ "type": "module",
24
+ "main": "dist/index.js",
25
+ "types": "dist/index.d.ts",
26
+ "exports": {
27
+ ".": "./dist/index.js"
28
+ },
29
+ "bin": {
30
+ "boldkit-mcp": "dist/bin.js"
31
+ },
32
+ "files": [
33
+ "dist",
34
+ "catalog.json",
35
+ "README.md"
36
+ ],
37
+ "scripts": {
38
+ "build": "tsc -p tsconfig.json",
39
+ "typecheck": "tsc -p tsconfig.json --noEmit",
40
+ "test": "vitest run",
41
+ "prepack": "tsc -p tsconfig.json"
42
+ },
43
+ "dependencies": {
44
+ "@modelcontextprotocol/sdk": "^1.12.0",
45
+ "zod": "^3.25.0"
46
+ },
47
+ "devDependencies": {
48
+ "@types/node": "^25.9.5",
49
+ "typescript": "~5.9.3",
50
+ "vitest": "^4.1.10"
51
+ },
52
+ "engines": {
53
+ "node": ">=18"
54
+ }
55
+ }