@fruit-labs/design-mcp 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +18 -2
- package/bin/fruit-design-mcp.js +25 -0
- package/package.json +38 -3
- package/src/core.js +77 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Fruit Labs
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,19 @@
|
|
|
1
|
-
#
|
|
1
|
+
# @fruit-labs/design-mcp
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Read-only MCP server for [Fruit Design](https://design.fruitlabs.online). It fetches the docs from that site, so it needs network access.
|
|
4
|
+
|
|
5
|
+
```json
|
|
6
|
+
{ "mcpServers": { "fruit-design": { "command": "npx", "args": ["-y", "@fruit-labs/design-mcp@latest"] } } }
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Or use the remote server: `https://design.fruitlabs.online/mcp`.
|
|
10
|
+
|
|
11
|
+
Tools: `get_guide`, `list_components`, `search_components`, `get_component`, `get_tokens`, `get_changelog`.
|
|
12
|
+
|
|
13
|
+
## Updates
|
|
14
|
+
|
|
15
|
+
- **Docs and components:** both servers read the live site, so new releases show up without any change on your side.
|
|
16
|
+
- **The server itself:** the remote server updates on deploy. With `@latest`, the local one picks up new versions the next time your agent starts it.
|
|
17
|
+
- Ask your agent to call `get_changelog` to compare with your installed `@fruit-labs/design`.
|
|
18
|
+
|
|
19
|
+
Designed and developed by [Vishwanath](https://github.com/ms-vishwanath), open-source contributor.
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Local (stdio) MCP server. Reads the same JSON the website publishes.
|
|
3
|
+
import { createInterface } from 'node:readline';
|
|
4
|
+
import { readFile } from 'node:fs/promises';
|
|
5
|
+
import { join } from 'node:path';
|
|
6
|
+
import { handle } from '../src/core.js';
|
|
7
|
+
|
|
8
|
+
const base = process.env.FRUIT_DESIGN_URL ?? 'https://design.fruitlabs.online/api/';
|
|
9
|
+
const load = async (path) => {
|
|
10
|
+
if (!/^https?:/.test(base)) return JSON.parse(await readFile(join(base, path), 'utf8'));
|
|
11
|
+
const res = await fetch(new URL(path, base));
|
|
12
|
+
if (!res.ok) throw new Error(`Could not load ${path}: HTTP ${res.status}`);
|
|
13
|
+
return res.json();
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
createInterface({ input: process.stdin }).on('line', async (text) => {
|
|
17
|
+
if (!text.trim()) return;
|
|
18
|
+
let res;
|
|
19
|
+
try {
|
|
20
|
+
res = await handle(JSON.parse(text), load);
|
|
21
|
+
} catch {
|
|
22
|
+
res = { jsonrpc: '2.0', id: null, error: { code: -32700, message: 'Parse error' } };
|
|
23
|
+
}
|
|
24
|
+
if (res) process.stdout.write(`${JSON.stringify(res)}\n`);
|
|
25
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,41 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fruit-labs/design-mcp",
|
|
3
|
-
"version": "0.
|
|
4
|
-
"
|
|
5
|
-
"
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for Fruit Design: search components, read props, examples and tokens.",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"author": "Fruit Labs",
|
|
7
|
+
"contributors": [
|
|
8
|
+
{
|
|
9
|
+
"name": "Vishwanath",
|
|
10
|
+
"url": "https://github.com/ms-vishwanath"
|
|
11
|
+
}
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://design.fruitlabs.online/docs/mcp/",
|
|
14
|
+
"repository": {
|
|
15
|
+
"type": "git",
|
|
16
|
+
"url": "git+https://github.com/fruit-labs-org/fruit-labs-design.git",
|
|
17
|
+
"directory": "packages/mcp"
|
|
18
|
+
},
|
|
19
|
+
"type": "module",
|
|
20
|
+
"bin": {
|
|
21
|
+
"design-mcp": "bin/fruit-design-mcp.js"
|
|
22
|
+
},
|
|
23
|
+
"files": [
|
|
24
|
+
"bin",
|
|
25
|
+
"src",
|
|
26
|
+
"README.md",
|
|
27
|
+
"LICENSE"
|
|
28
|
+
],
|
|
29
|
+
"engines": {
|
|
30
|
+
"node": ">=18"
|
|
31
|
+
},
|
|
32
|
+
"publishConfig": {
|
|
33
|
+
"access": "public"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"@modelcontextprotocol/sdk": "^1"
|
|
37
|
+
},
|
|
38
|
+
"scripts": {
|
|
39
|
+
"test": "node --test"
|
|
40
|
+
}
|
|
6
41
|
}
|
package/src/core.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// Minimal MCP (JSON-RPC 2.0) for read-only docs tools. `load(path)` returns the parsed JSON the site publishes.
|
|
2
|
+
export const VERSION = '0.1.0';
|
|
3
|
+
const PROTOCOLS = ['2025-11-25', '2025-06-18', '2025-03-26', '2024-11-05'];
|
|
4
|
+
const SITE = 'https://design.fruitlabs.online';
|
|
5
|
+
|
|
6
|
+
const str = (description) => ({ type: 'string', description });
|
|
7
|
+
const schema = (properties = {}, required = []) => ({ type: 'object', properties, required });
|
|
8
|
+
const readOnly = { readOnlyHint: true };
|
|
9
|
+
|
|
10
|
+
export const tools = [
|
|
11
|
+
{ name: 'list_components', description: 'List Fruit Design components, optionally filtered by group.', inputSchema: schema({ group: str('Group name, e.g. Forms or Agentic') }), annotations: readOnly },
|
|
12
|
+
{ name: 'search_components', description: 'Find Fruit Design components by name or purpose.', inputSchema: schema({ query: str('What you need, e.g. "date" or "chat input"') }, ['query']), annotations: readOnly },
|
|
13
|
+
{ name: 'get_component', description: 'Guidelines, props, example code and install command for one component.', inputSchema: schema({ name: str('Component name or slug, e.g. DatePicker') }, ['name']), annotations: readOnly },
|
|
14
|
+
{ name: 'get_tokens', description: 'Fruit Design colour, type, spacing and radius tokens as JSON.', inputSchema: schema(), annotations: readOnly },
|
|
15
|
+
{ name: 'get_changelog', description: 'Latest Fruit Design version and what changed. Compare with the installed version before updating.', inputSchema: schema(), annotations: readOnly },
|
|
16
|
+
{ name: 'get_guide', description: 'How to install Fruit Design and the rules for using it.', inputSchema: schema(), annotations: readOnly },
|
|
17
|
+
];
|
|
18
|
+
|
|
19
|
+
const line = (c) => `${c.name} (${c.group}): ${c.description}`;
|
|
20
|
+
const norm = (s) => String(s).toLowerCase().replace(/[^a-z0-9]/g, '');
|
|
21
|
+
|
|
22
|
+
async function call(name, args, load) {
|
|
23
|
+
if (name === 'get_guide') return (await load('guide.json')).guide;
|
|
24
|
+
if (name === 'get_changelog') {
|
|
25
|
+
const { version, changelog } = await load('version.json');
|
|
26
|
+
return `Latest version: ${version}\n\n${changelog}`;
|
|
27
|
+
}
|
|
28
|
+
if (name === 'get_tokens') return JSON.stringify(await load('tokens.json'));
|
|
29
|
+
const all = await load('components.json');
|
|
30
|
+
if (name === 'list_components') {
|
|
31
|
+
const hits = args.group ? all.filter((c) => norm(c.group) === norm(args.group)) : all;
|
|
32
|
+
return hits.length ? hits.map(line).join('\n') : `No group "${args.group}". Groups: ${[...new Set(all.map((c) => c.group))].join(', ')}`;
|
|
33
|
+
}
|
|
34
|
+
if (name === 'search_components') {
|
|
35
|
+
const words = String(args.query ?? '').toLowerCase().split(/\s+/).filter(Boolean);
|
|
36
|
+
const score = (c) => words.reduce((n, w) => n + (norm(c.name).includes(norm(w)) ? 3 : 0) + (`${c.group} ${c.description}`.toLowerCase().includes(w) ? 1 : 0), 0);
|
|
37
|
+
const hits = all.map((c) => [score(c), c]).filter(([s]) => s).sort((a, b) => b[0] - a[0]).slice(0, 12);
|
|
38
|
+
return hits.length ? hits.map(([, c]) => line(c)).join('\n') : `Nothing matched "${args.query}". Try list_components.`;
|
|
39
|
+
}
|
|
40
|
+
if (name === 'get_component') {
|
|
41
|
+
// Only slugs from the published list reach `load`, so a caller cannot choose the path.
|
|
42
|
+
const c = all.find((c) => norm(c.name) === norm(args.name) || c.slug === args.name);
|
|
43
|
+
if (!c) throw new Error(`No component "${args.name}". Use search_components.`);
|
|
44
|
+
return (await load(`components/${c.slug}.json`)).doc;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** Handle one JSON-RPC message. Returns the response object, or null for notifications. */
|
|
49
|
+
export async function handle(msg, load) {
|
|
50
|
+
const { id, method, params = {} } = msg ?? {};
|
|
51
|
+
const ok = (result) => ({ jsonrpc: '2.0', id, result });
|
|
52
|
+
const fail = (code, message) => ({ jsonrpc: '2.0', id: id ?? null, error: { code, message } });
|
|
53
|
+
if (msg?.jsonrpc !== '2.0' || typeof method !== 'string') return fail(-32600, 'Invalid request');
|
|
54
|
+
if (id === undefined) return null;
|
|
55
|
+
switch (method) {
|
|
56
|
+
case 'initialize':
|
|
57
|
+
return ok({
|
|
58
|
+
protocolVersion: PROTOCOLS.includes(params.protocolVersion) ? params.protocolVersion : PROTOCOLS[0],
|
|
59
|
+
capabilities: { tools: {} },
|
|
60
|
+
serverInfo: { name: 'fruit-design', version: VERSION },
|
|
61
|
+
instructions: `Fruit Design UI docs (${SITE}). Call get_guide before writing UI.`,
|
|
62
|
+
});
|
|
63
|
+
case 'ping': return ok({});
|
|
64
|
+
case 'tools/list': return ok({ tools });
|
|
65
|
+
case 'tools/call': {
|
|
66
|
+
const tool = tools.find((t) => t.name === params.name);
|
|
67
|
+
if (!tool) return fail(-32602, `Unknown tool: ${params.name}`);
|
|
68
|
+
try {
|
|
69
|
+
const text = await call(tool.name, params.arguments ?? {}, load);
|
|
70
|
+
return ok({ content: [{ type: 'text', text }] });
|
|
71
|
+
} catch (e) {
|
|
72
|
+
return ok({ content: [{ type: 'text', text: e.message }], isError: true });
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
default: return fail(-32601, `Unknown method: ${method}`);
|
|
76
|
+
}
|
|
77
|
+
}
|