elij-ui-library-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/index.js +74 -0
- package/dist/registry.js +37 -0
- package/package.json +24 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { McpServer } from "@modelcontextprotocol/server";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/server/stdio";
|
|
4
|
+
import { z } from "zod";
|
|
5
|
+
import { getComponent, listComponents, registry, searchComponents, } from "./registry.js";
|
|
6
|
+
const server = new McpServer({
|
|
7
|
+
name: "elij-ui-library",
|
|
8
|
+
version: "0.1.0",
|
|
9
|
+
});
|
|
10
|
+
function textResult(value) {
|
|
11
|
+
return {
|
|
12
|
+
content: [
|
|
13
|
+
{
|
|
14
|
+
type: "text",
|
|
15
|
+
text: JSON.stringify(value, null, 2),
|
|
16
|
+
},
|
|
17
|
+
],
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
server.registerTool("list_components", {
|
|
21
|
+
description: "List Elij UI components from the published registry.",
|
|
22
|
+
inputSchema: z.object({
|
|
23
|
+
category: z.string().optional(),
|
|
24
|
+
}),
|
|
25
|
+
}, async ({ category }) => {
|
|
26
|
+
return textResult(listComponents(category));
|
|
27
|
+
});
|
|
28
|
+
server.registerTool("search_components", {
|
|
29
|
+
description: "Search Elij UI components by name, category, or description.",
|
|
30
|
+
inputSchema: z.object({
|
|
31
|
+
query: z.string().trim().min(1).max(100),
|
|
32
|
+
category: z.string().optional(),
|
|
33
|
+
limit: z.number().int().min(1).max(50).default(20),
|
|
34
|
+
}),
|
|
35
|
+
}, async ({ query, category, limit }) => {
|
|
36
|
+
const result = searchComponents(query, category);
|
|
37
|
+
return textResult({
|
|
38
|
+
...result,
|
|
39
|
+
components: result.components.slice(0, limit),
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
server.registerTool("get_component", {
|
|
43
|
+
description: "Get import path, props, category, description, and Storybook story for one Elij UI component.",
|
|
44
|
+
inputSchema: z.object({
|
|
45
|
+
name: z.string().trim().min(1).max(100),
|
|
46
|
+
}),
|
|
47
|
+
}, async ({ name }) => {
|
|
48
|
+
const component = getComponent(name);
|
|
49
|
+
if (!component) {
|
|
50
|
+
return {
|
|
51
|
+
isError: true,
|
|
52
|
+
content: [
|
|
53
|
+
{
|
|
54
|
+
type: "text",
|
|
55
|
+
text: `Component not found: ${name}`,
|
|
56
|
+
},
|
|
57
|
+
],
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
return textResult({
|
|
61
|
+
registryVersion: registry.version,
|
|
62
|
+
component,
|
|
63
|
+
});
|
|
64
|
+
});
|
|
65
|
+
async function main() {
|
|
66
|
+
const transport = new StdioServerTransport();
|
|
67
|
+
await server.connect(transport);
|
|
68
|
+
// stdio MCP server 不要使用 console.log
|
|
69
|
+
console.error("Elij UI MCP Server running on stdio");
|
|
70
|
+
}
|
|
71
|
+
main().catch((error) => {
|
|
72
|
+
console.error("Fatal error in Elij UI MCP Server:", error);
|
|
73
|
+
process.exit(1);
|
|
74
|
+
});
|
package/dist/registry.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
const require = createRequire(import.meta.url);
|
|
3
|
+
export const registry = require("elij-ui-library/registry");
|
|
4
|
+
export function listComponents(category) {
|
|
5
|
+
const components = category
|
|
6
|
+
? registry.components.filter((component) => component.category === category)
|
|
7
|
+
: registry.components;
|
|
8
|
+
return {
|
|
9
|
+
registryVersion: registry.version,
|
|
10
|
+
count: components.length,
|
|
11
|
+
components,
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
export function searchComponents(query, category) {
|
|
15
|
+
const normalizedQuery = query.trim().toLowerCase();
|
|
16
|
+
const components = registry.components.filter((component) => {
|
|
17
|
+
const matchesCategory = category
|
|
18
|
+
? component.category === category
|
|
19
|
+
: true;
|
|
20
|
+
const searchableText = [
|
|
21
|
+
component.name,
|
|
22
|
+
component.category,
|
|
23
|
+
component.description,
|
|
24
|
+
]
|
|
25
|
+
.join(" ")
|
|
26
|
+
.toLowerCase();
|
|
27
|
+
return matchesCategory && searchableText.includes(normalizedQuery);
|
|
28
|
+
});
|
|
29
|
+
return {
|
|
30
|
+
registryVersion: registry.version,
|
|
31
|
+
count: components.length,
|
|
32
|
+
components,
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function getComponent(name) {
|
|
36
|
+
return registry.components.find((component) => component.name.toLowerCase() === name.toLowerCase());
|
|
37
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "elij-ui-library-mcp",
|
|
3
|
+
"version": "0.1.0",
|
|
4
|
+
"description": "MCP server for discovering Elij UI components",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"bin": "./dist/index.js",
|
|
7
|
+
"files": [
|
|
8
|
+
"dist",
|
|
9
|
+
"README.md"
|
|
10
|
+
],
|
|
11
|
+
"scripts": {
|
|
12
|
+
"build": "tsc -p tsconfig.json && chmod 755 dist/index.js",
|
|
13
|
+
"test": "yarn build && node --test test/*.test.mjs"
|
|
14
|
+
},
|
|
15
|
+
"dependencies": {
|
|
16
|
+
"@modelcontextprotocol/server": "^2.0.0",
|
|
17
|
+
"elij-ui-library": "^0.2.1",
|
|
18
|
+
"zod": "^4.2.0"
|
|
19
|
+
},
|
|
20
|
+
"devDependencies": {
|
|
21
|
+
"@types/node": "^22.18.0",
|
|
22
|
+
"typescript": "^5.8.3"
|
|
23
|
+
}
|
|
24
|
+
}
|