@m3e/mcp 0.0.0-stage → 2.12.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 +22 -0
- package/README.md +88 -3
- package/dist/cli.d.ts +3 -0
- package/dist/cli.d.ts.map +1 -0
- package/dist/cli.js +54 -0
- package/dist/cli.js.map +1 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -0
- package/dist/manifest.d.ts +80 -0
- package/dist/manifest.d.ts.map +1 -0
- package/dist/manifest.js +107 -0
- package/dist/manifest.js.map +1 -0
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -0
- package/dist/server.js +128 -0
- package/dist/server.js.map +1 -0
- package/package.json +45 -6
package/LICENSE
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025–2026 matraic
|
|
4
|
+
Contact: matraic@yahoo.com
|
|
5
|
+
|
|
6
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
7
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
8
|
+
in the Software without restriction, including without limitation the rights
|
|
9
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
10
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
11
|
+
furnished to do so, subject to the following conditions:
|
|
12
|
+
|
|
13
|
+
The above copyright notice and this permission notice shall be included in all
|
|
14
|
+
copies or substantial portions of the Software.
|
|
15
|
+
|
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
17
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
18
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
19
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
20
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
21
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
22
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,88 @@
|
|
|
1
|
-
#
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
# @m3e/mcp
|
|
2
|
+
|
|
3
|
+
The `@m3e/mcp` package provides an [MCP](https://modelcontextprotocol.io/) server that gives AI assistants access to the M3E Web Components catalog.
|
|
4
|
+
|
|
5
|
+
## Install
|
|
6
|
+
|
|
7
|
+
Requires Node.js 22 or later.
|
|
8
|
+
|
|
9
|
+
```sh
|
|
10
|
+
npm install @m3e/mcp
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Configure an MCP client
|
|
14
|
+
|
|
15
|
+
### Standard I/O (stdio)
|
|
16
|
+
|
|
17
|
+
The default transport is stdio. For example, add this server to `.mcp.json` in your workspace root:
|
|
18
|
+
|
|
19
|
+
```json
|
|
20
|
+
{
|
|
21
|
+
"mcpServers": {
|
|
22
|
+
"m3e": {
|
|
23
|
+
"type": "stdio",
|
|
24
|
+
"command": "npx",
|
|
25
|
+
"args": ["-y", "@m3e/mcp"]
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
In VS Code, the guided setup offers workspace-root configuration when the experimental `chat.mcp.workspaceRootConfig.enabled` setting is enabled. Alternatively, add the same configuration to `$COPILOT_HOME/mcp-config.json` (or `~/.copilot/mcp-config.json` when `COPILOT_HOME` is unset) for use across workspaces.
|
|
32
|
+
|
|
33
|
+
The legacy VS Code format uses `.vscode/mcp.json` with a top-level `servers` object instead; it remains available for compatibility. See the [VS Code MCP configuration reference](https://code.visualstudio.com/docs/agents/reference/mcp-configuration) for format and capability differences.
|
|
34
|
+
|
|
35
|
+
The server can also be started directly:
|
|
36
|
+
|
|
37
|
+
```sh
|
|
38
|
+
npx -y @m3e/mcp
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
### Streamable HTTP
|
|
42
|
+
|
|
43
|
+
Start the server in a terminal:
|
|
44
|
+
|
|
45
|
+
```sh
|
|
46
|
+
npx -y @m3e/mcp --http
|
|
47
|
+
```
|
|
48
|
+
|
|
49
|
+
It listens at `http://127.0.0.1:3333/mcp` by default. Configure an MCP client to connect to that URL. A portable workspace-root `.mcp.json` entry can be:
|
|
50
|
+
|
|
51
|
+
```json
|
|
52
|
+
{
|
|
53
|
+
"mcpServers": {
|
|
54
|
+
"m3e": {
|
|
55
|
+
"type": "http",
|
|
56
|
+
"url": "http://127.0.0.1:3333/mcp"
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
The HTTP transport is stateless and has no authentication. The default host is loopback (`127.0.0.1`); only bind it to a network interface you trust.
|
|
63
|
+
|
|
64
|
+
## Tools
|
|
65
|
+
|
|
66
|
+
| Tool | Purpose |
|
|
67
|
+
| --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
68
|
+
| `list_components` | List all custom elements and short descriptions. |
|
|
69
|
+
| `get_component` | Get a component's description, detailed remarks, attributes, properties, methods, slots, events, CSS parts, CSS states, and CSS custom properties. Accepts a tag name with or without the `m3e-` prefix. |
|
|
70
|
+
| `search_components` | Search component names, descriptions, attributes, slots, and events. |
|
|
71
|
+
| `get_usage_example` | Get the component's usage examples. |
|
|
72
|
+
| `get_react_wrapper` | Get the corresponding `@m3e/react` import, wrapper name, and event prop names. |
|
|
73
|
+
| `list_css_properties` | List CSS custom properties across components, optionally filtering by component or keyword. |
|
|
74
|
+
|
|
75
|
+
Unknown component names return suggestions when similar components are found. These tools provide catalog information and snippets; they do not execute or modify the user's project.
|
|
76
|
+
|
|
77
|
+
## CLI options
|
|
78
|
+
|
|
79
|
+
```text
|
|
80
|
+
m3e-mcp [--http] [--port 3333] [--host 127.0.0.1]
|
|
81
|
+
```
|
|
82
|
+
|
|
83
|
+
| Option | Description |
|
|
84
|
+
| ------------------ | ----------------------------------------------- |
|
|
85
|
+
| `--http` | Use stateless Streamable HTTP instead of stdio. |
|
|
86
|
+
| `--port <number>` | HTTP listening port. Default: `3333`. |
|
|
87
|
+
| `--host <address>` | HTTP listening address. Default: `127.0.0.1`. |
|
|
88
|
+
| `--help` | Show usage. |
|
package/dist/cli.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.d.ts","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":""}
|
package/dist/cli.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import { createServer as createHttpServer } from "node:http";
|
|
3
|
+
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
5
|
+
import { Catalog, loadManifest } from "./manifest.js";
|
|
6
|
+
import { createServer } from "./server.js";
|
|
7
|
+
const args = process.argv.slice(2);
|
|
8
|
+
const flag = (name) => {
|
|
9
|
+
const i = args.indexOf(name);
|
|
10
|
+
return i < 0 ? undefined : (args[i + 1] ?? "");
|
|
11
|
+
};
|
|
12
|
+
if (args.includes("--help")) {
|
|
13
|
+
console.log("Usage: m3e-mcp [--http] [--port 3333] [--host 127.0.0.1]\nDefaults to stdio.");
|
|
14
|
+
process.exit(0);
|
|
15
|
+
}
|
|
16
|
+
const catalog = new Catalog(loadManifest());
|
|
17
|
+
if (!args.includes("--http")) {
|
|
18
|
+
await createServer(catalog).connect(new StdioServerTransport());
|
|
19
|
+
}
|
|
20
|
+
else {
|
|
21
|
+
const port = Number(flag("--port") ?? 3333);
|
|
22
|
+
const host = flag("--host") ?? "127.0.0.1";
|
|
23
|
+
const http = createHttpServer(async (req, res) => {
|
|
24
|
+
if (!req.url?.startsWith("/mcp")) {
|
|
25
|
+
res.writeHead(404).end();
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
if (req.method !== "POST") {
|
|
29
|
+
res.writeHead(405, { Allow: "POST" }).end();
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
const chunks = [];
|
|
34
|
+
for await (const chunk of req)
|
|
35
|
+
chunks.push(chunk);
|
|
36
|
+
const body = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
37
|
+
const server = createServer(catalog);
|
|
38
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });
|
|
39
|
+
res.on("close", () => {
|
|
40
|
+
void transport.close();
|
|
41
|
+
void server.close();
|
|
42
|
+
});
|
|
43
|
+
await server.connect(transport);
|
|
44
|
+
await transport.handleRequest(req, res, body);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
if (!res.headersSent)
|
|
48
|
+
res.writeHead(400, { "Content-Type": "application/json" });
|
|
49
|
+
res.end(JSON.stringify({ jsonrpc: "2.0", error: { code: -32700, message: "Invalid request" }, id: null }));
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
http.listen(port, host, () => console.error(`m3e-mcp listening on http://${host}:${port}/mcp`));
|
|
53
|
+
}
|
|
54
|
+
//# sourceMappingURL=cli.js.map
|
package/dist/cli.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"cli.js","sourceRoot":"","sources":["../src/cli.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,YAAY,IAAI,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AACnG,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,MA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iBAAiB,EAAE,EAAE,EAAE,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC;QAC7G,CAAC;IACH,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE,CAAC,OAAO,CAAC,KAAK,CAAC,+BAA+B,IAAI,IAAI,IAAI,MAAM,CAAC,CAAC,CAAC;AAClG,CAAC","sourcesContent":["#!/usr/bin/env node\r\nimport { createServer as createHttpServer } from \"node:http\";\r\nimport { StdioServerTransport } from \"@modelcontextprotocol/sdk/server/stdio.js\";\r\nimport { StreamableHTTPServerTransport } from \"@modelcontextprotocol/sdk/server/streamableHttp.js\";\r\nimport { Catalog, loadManifest } from \"./manifest.js\";\r\nimport { createServer } from \"./server.js\";\r\n\r\nconst args = process.argv.slice(2);\r\nconst flag = (name: string) => {\r\n const i = args.indexOf(name);\r\n return i < 0 ? undefined : (args[i + 1] ?? \"\");\r\n};\r\n\r\nif (args.includes(\"--help\")) {\r\n console.log(\"Usage: m3e-mcp [--http] [--port 3333] [--host 127.0.0.1]\\nDefaults to stdio.\");\r\n process.exit(0);\r\n}\r\n\r\nconst catalog = new Catalog(loadManifest());\r\n\r\nif (!args.includes(\"--http\")) {\r\n await createServer(catalog).connect(new StdioServerTransport());\r\n} else {\r\n const port = Number(flag(\"--port\") ?? 3333);\r\n const host = flag(\"--host\") ?? \"127.0.0.1\";\r\n\r\n const http = createHttpServer(async (req, res) => {\r\n if (!req.url?.startsWith(\"/mcp\")) {\r\n res.writeHead(404).end();\r\n return;\r\n }\r\n if (req.method !== \"POST\") {\r\n res.writeHead(405, { Allow: \"POST\" }).end();\r\n return;\r\n }\r\n try {\r\n const chunks: Buffer[] = [];\r\n for await (const chunk of req) chunks.push(chunk as Buffer);\r\n const body = JSON.parse(Buffer.concat(chunks).toString(\"utf8\"));\r\n const server = createServer(catalog);\r\n const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined, enableJsonResponse: true });\r\n res.on(\"close\", () => {\r\n void transport.close();\r\n void server.close();\r\n });\r\n await server.connect(transport);\r\n await transport.handleRequest(req, res, body);\r\n } catch {\r\n if (!res.headersSent) res.writeHead(400, { \"Content-Type\": \"application/json\" });\r\n res.end(JSON.stringify({ jsonrpc: \"2.0\", error: { code: -32700, message: \"Invalid request\" }, id: null }));\r\n }\r\n });\r\n http.listen(port, host, () => console.error(`m3e-mcp listening on http://${host}:${port}/mcp`));\r\n}\r\n"]}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AACrE,YAAY,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAC/C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAErE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC","sourcesContent":["export { Catalog, loadManifest, parseManifest } from \"./manifest.js\";\r\nexport type { Component } from \"./manifest.js\";\r\nexport { createServer } from \"./server.js\";\r\n"]}
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
interface Described {
|
|
2
|
+
name: string;
|
|
3
|
+
description?: string;
|
|
4
|
+
}
|
|
5
|
+
interface Typed extends Described {
|
|
6
|
+
type?: {
|
|
7
|
+
text: string;
|
|
8
|
+
};
|
|
9
|
+
default?: string;
|
|
10
|
+
deprecated?: boolean | string;
|
|
11
|
+
}
|
|
12
|
+
interface RawMember extends Typed {
|
|
13
|
+
kind: "field" | "method";
|
|
14
|
+
privacy?: "public" | "private" | "protected";
|
|
15
|
+
static?: boolean;
|
|
16
|
+
readonly?: boolean;
|
|
17
|
+
attribute?: string;
|
|
18
|
+
parameters?: Typed[];
|
|
19
|
+
return?: {
|
|
20
|
+
type?: {
|
|
21
|
+
text: string;
|
|
22
|
+
};
|
|
23
|
+
description?: string;
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
interface RawDeclaration extends Described {
|
|
27
|
+
kind: string;
|
|
28
|
+
tagName?: string;
|
|
29
|
+
customElement?: boolean;
|
|
30
|
+
remarks?: string;
|
|
31
|
+
examples?: string[];
|
|
32
|
+
attributes?: Typed[];
|
|
33
|
+
members?: RawMember[];
|
|
34
|
+
slots?: Described[];
|
|
35
|
+
events?: Typed[];
|
|
36
|
+
cssParts?: Described[];
|
|
37
|
+
cssProperties?: Typed[];
|
|
38
|
+
cssStates?: Described[];
|
|
39
|
+
}
|
|
40
|
+
interface RawManifest {
|
|
41
|
+
modules: {
|
|
42
|
+
path: string;
|
|
43
|
+
declarations?: RawDeclaration[];
|
|
44
|
+
}[];
|
|
45
|
+
}
|
|
46
|
+
export interface Component {
|
|
47
|
+
tagName: string;
|
|
48
|
+
className: string;
|
|
49
|
+
description: string;
|
|
50
|
+
remarks: string;
|
|
51
|
+
examples: string[];
|
|
52
|
+
/** Folder under `src/`, which is the subpath of the `@m3e/web` and `@m3e/react` entry points. */
|
|
53
|
+
entryPoint: string;
|
|
54
|
+
attributes: Typed[];
|
|
55
|
+
properties: RawMember[];
|
|
56
|
+
methods: RawMember[];
|
|
57
|
+
slots: Described[];
|
|
58
|
+
events: Typed[];
|
|
59
|
+
cssParts: Described[];
|
|
60
|
+
cssProperties: Typed[];
|
|
61
|
+
cssStates: Described[];
|
|
62
|
+
}
|
|
63
|
+
export declare const reactName: (tagName: string) => string;
|
|
64
|
+
export declare const reactEventProp: (eventName: string) => string;
|
|
65
|
+
export declare function parseManifest(manifest: RawManifest): Component[];
|
|
66
|
+
export declare function loadManifest(): Component[];
|
|
67
|
+
export declare class Catalog {
|
|
68
|
+
readonly components: Component[];
|
|
69
|
+
constructor(components: Component[]);
|
|
70
|
+
get(tagName: string): Component | undefined;
|
|
71
|
+
search(query: string, limit?: number): Component[];
|
|
72
|
+
/** CSS custom properties across all components, optionally filtered by a substring of name/description. */
|
|
73
|
+
cssProperties(filter?: string, component?: string): {
|
|
74
|
+
component: string;
|
|
75
|
+
name: string;
|
|
76
|
+
description: string;
|
|
77
|
+
}[];
|
|
78
|
+
}
|
|
79
|
+
export {};
|
|
80
|
+
//# sourceMappingURL=manifest.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.d.ts","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAIA,UAAU,SAAS;IACjB,IAAI,EAAE,MAAM,CAAC;IACb,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB;AAED,UAAU,KAAM,SAAQ,SAAS;IAC/B,IAAI,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAA;KAAE,CAAC;IACxB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,UAAU,CAAC,EAAE,OAAO,GAAG,MAAM,CAAC;CAC/B;AAED,UAAU,SAAU,SAAQ,KAAK;IAC/B,IAAI,EAAE,OAAO,GAAG,QAAQ,CAAC;IACzB,OAAO,CAAC,EAAE,QAAQ,GAAG,SAAS,GAAG,WAAW,CAAC;IAC7C,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,KAAK,EAAE,CAAC;IACrB,MAAM,CAAC,EAAE;QAAE,IAAI,CAAC,EAAE;YAAE,IAAI,EAAE,MAAM,CAAA;SAAE,CAAC;QAAC,WAAW,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;CAC5D;AAED,UAAU,cAAe,SAAQ,SAAS;IACxC,IAAI,EAAE,MAAM,CAAC;IACb,OAAO,CAA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Q,EAAE,WAAW,GAAG,SAAS,EAAE,CAyBhE;AAED,wBAAgB,YAAY,IAAI,SAAS,EAAE,CAE1C;AAeD,qBAAa,OAAO;IACN,QAAQ,CAAC,UAAU,EAAE,SAAS,EAAE;gBAAvB,UAAU,EAAE,SAAS,EAAE;IAE5C,GAAG,CAAC,OAAO,EAAE,MAAM,GAAG,SAAS,GAAG,SAAS;IAK3C,MAAM,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,SAAK,GAAG,SAAS,EAAE;IA2B9C,2GAA2G;IAC3G,aAAa,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,MAAM;mBAEvB,MAAM;cAAQ,MAAM;qBAAe,MAAM;;CAUpE"}
|
package/dist/manifest.js
ADDED
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { createRequire } from "node:module";
|
|
3
|
+
import { dirname, resolve } from "node:path";
|
|
4
|
+
const toPascal = (value) => value
|
|
5
|
+
.split(/[-:_]/)
|
|
6
|
+
.filter(Boolean)
|
|
7
|
+
.map((x) => x[0].toUpperCase() + x.slice(1))
|
|
8
|
+
.join("");
|
|
9
|
+
export const reactName = (tagName) => toPascal(tagName);
|
|
10
|
+
export const reactEventProp = (eventName) => `on${toPascal(eventName.replace(/^before(?=[a-z])/, "before-"))}`;
|
|
11
|
+
const isPublic = (m) => m.privacy !== "private" && m.privacy !== "protected" && !m.name.startsWith("_");
|
|
12
|
+
export function parseManifest(manifest) {
|
|
13
|
+
const components = [];
|
|
14
|
+
for (const module of manifest.modules) {
|
|
15
|
+
for (const d of module.declarations ?? []) {
|
|
16
|
+
if (!d.customElement || !d.tagName)
|
|
17
|
+
continue;
|
|
18
|
+
const members = (d.members ?? []).filter(isPublic);
|
|
19
|
+
components.push({
|
|
20
|
+
tagName: d.tagName,
|
|
21
|
+
className: d.name,
|
|
22
|
+
description: d.description ?? "",
|
|
23
|
+
remarks: d.remarks ?? "",
|
|
24
|
+
examples: d.examples ?? [],
|
|
25
|
+
entryPoint: module.path.split("/")[1] ?? "",
|
|
26
|
+
attributes: d.attributes ?? [],
|
|
27
|
+
properties: members.filter((m) => m.kind === "field" && !m.static),
|
|
28
|
+
methods: members.filter((m) => m.kind === "method" && !m.static),
|
|
29
|
+
slots: d.slots ?? [],
|
|
30
|
+
events: d.events ?? [],
|
|
31
|
+
cssParts: d.cssParts ?? [],
|
|
32
|
+
cssProperties: d.cssProperties ?? [],
|
|
33
|
+
cssStates: d.cssStates ?? [],
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
return components.sort((a, b) => a.tagName.localeCompare(b.tagName));
|
|
38
|
+
}
|
|
39
|
+
export function loadManifest() {
|
|
40
|
+
return parseManifest(JSON.parse(readFileSync(resolveWebManifest(), "utf8")));
|
|
41
|
+
}
|
|
42
|
+
function resolveWebManifest() {
|
|
43
|
+
const require = createRequire(import.meta.url);
|
|
44
|
+
try {
|
|
45
|
+
return require.resolve("@m3e/web/custom-elements.json");
|
|
46
|
+
}
|
|
47
|
+
catch (error) {
|
|
48
|
+
if (!(error instanceof Error) || !("code" in error) || error.code !== "ERR_PACKAGE_PATH_NOT_EXPORTED") {
|
|
49
|
+
throw error;
|
|
50
|
+
}
|
|
51
|
+
// Some @m3e/web releases ship the manifest beside the "all" entry point without exporting it.
|
|
52
|
+
return resolve(dirname(require.resolve("@m3e/web/all")), "custom-elements.json");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
export class Catalog {
|
|
56
|
+
constructor(components) {
|
|
57
|
+
this.components = components;
|
|
58
|
+
}
|
|
59
|
+
get(tagName) {
|
|
60
|
+
const key = tagName.trim().toLowerCase();
|
|
61
|
+
return this.components.find((c) => c.tagName === key || c.tagName === `m3e-${key}` || c.className.toLowerCase() === key);
|
|
62
|
+
}
|
|
63
|
+
search(query, limit = 10) {
|
|
64
|
+
const terms = query.toLowerCase().split(/\s+/).filter(Boolean);
|
|
65
|
+
return this.components
|
|
66
|
+
.map((c) => {
|
|
67
|
+
const name = `${c.tagName} ${c.className}`.toLowerCase();
|
|
68
|
+
const body = [
|
|
69
|
+
c.description,
|
|
70
|
+
c.remarks,
|
|
71
|
+
...c.attributes.map((x) => `${x.name} ${x.description ?? ""}`),
|
|
72
|
+
...c.slots.map((x) => `${x.name} ${x.description ?? ""}`),
|
|
73
|
+
...c.events.map((x) => `${x.name} ${x.description ?? ""}`),
|
|
74
|
+
]
|
|
75
|
+
.join(" ")
|
|
76
|
+
.toLowerCase();
|
|
77
|
+
let score = 0;
|
|
78
|
+
for (const t of terms) {
|
|
79
|
+
if (name.includes(t))
|
|
80
|
+
score += 10;
|
|
81
|
+
if (body.includes(t))
|
|
82
|
+
score += 1;
|
|
83
|
+
}
|
|
84
|
+
return { c, score };
|
|
85
|
+
})
|
|
86
|
+
.filter((x) => x.score > 0)
|
|
87
|
+
.sort((a, b) => b.score - a.score || a.c.tagName.localeCompare(b.c.tagName))
|
|
88
|
+
.slice(0, limit)
|
|
89
|
+
.map((x) => x.c);
|
|
90
|
+
}
|
|
91
|
+
/** CSS custom properties across all components, optionally filtered by a substring of name/description. */
|
|
92
|
+
cssProperties(filter, component) {
|
|
93
|
+
const f = filter?.toLowerCase();
|
|
94
|
+
const out = [];
|
|
95
|
+
for (const c of this.components) {
|
|
96
|
+
if (component && c.tagName !== component)
|
|
97
|
+
continue;
|
|
98
|
+
for (const p of c.cssProperties) {
|
|
99
|
+
if (f && !`${p.name} ${p.description ?? ""}`.toLowerCase().includes(f))
|
|
100
|
+
continue;
|
|
101
|
+
out.push({ component: c.tagName, name: p.name, description: p.description ?? "" });
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
return out;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
//# sourceMappingURL=manifest.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest.js","sourceRoot":"","sources":["../src/manifest.ts"],"names":[],"mappings":"AAAA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KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;aAC3E,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC;aACf,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IACrB,CAAC;IAED,2GAA2G;IAC3G,aAAa,CAAC,MAAe,EAAE,SAAkB;QAC/C,MAAM,CAAC,GAAG,MAAM,EAAE,WAAW,EAAE,CAAC;QAChC,MAAM,GAAG,GAA+D,EAAE,CAAC;QAC3E,KAAK,MAAM,CAAC,IAAI,IAAI,CAAC,UAAU,EAAE,CAAC;YAChC,IAAI,SAAS,IAAI,CAAC,CAAC,OAAO,KAAK,SAAS;gBAAE,SAAS;YACnD,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;gBAChC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC,WAAW,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;oBAAE,SAAS;gBACjF,GAAG,CAAC,IAAI,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC,WAAW,IAAI,EAAE,EAAE,CAAC,CAAC;YACrF,CAAC;QACH,CAAC;QACD,OAAO,GAAG,CAAC;IACb,CAAC;CACF","sourcesContent":["import { readFileSync } from \"node:fs\";\r\nimport { createRequire } from \"node:module\";\r\nimport { dirname, resolve } from \"node:path\";\r\n\r\ninterface Described {\r\n name: string;\r\n description?: string;\r\n}\r\n\r\ninterface Typed extends Described {\r\n type?: { text: string };\r\n default?: string;\r\n deprecated?: boolean | string;\r\n}\r\n\r\ninterface RawMember extends Typed {\r\n kind: \"field\" | \"method\";\r\n privacy?: \"public\" | \"private\" | \"protected\";\r\n static?: boolean;\r\n readonly?: boolean;\r\n attribute?: string;\r\n parameters?: Typed[];\r\n return?: { type?: { text: string }; description?: string };\r\n}\r\n\r\ninterface RawDeclaration extends Described {\r\n kind: string;\r\n tagName?: string;\r\n customElement?: boolean;\r\n remarks?: string;\r\n examples?: string[];\r\n attributes?: Typed[];\r\n members?: RawMember[];\r\n slots?: Described[];\r\n events?: Typed[];\r\n cssParts?: Described[];\r\n cssProperties?: Typed[];\r\n cssStates?: Described[];\r\n}\r\n\r\ninterface RawManifest {\r\n modules: { path: string; declarations?: RawDeclaration[] }[];\r\n}\r\n\r\nexport interface Component {\r\n tagName: string;\r\n className: string;\r\n description: string;\r\n remarks: string;\r\n examples: string[];\r\n /** Folder under `src/`, which is the subpath of the `@m3e/web` and `@m3e/react` entry points. */\r\n entryPoint: string;\r\n attributes: Typed[];\r\n properties: RawMember[];\r\n methods: RawMember[];\r\n slots: Described[];\r\n events: Typed[];\r\n cssParts: Described[];\r\n cssProperties: Typed[];\r\n cssStates: Described[];\r\n}\r\n\r\nconst toPascal = (value: string) =>\r\n value\r\n .split(/[-:_]/)\r\n .filter(Boolean)\r\n .map((x) => x[0].toUpperCase() + x.slice(1))\r\n .join(\"\");\r\n\r\nexport const reactName = (tagName: string) => toPascal(tagName);\r\nexport const reactEventProp = (eventName: string) => `on${toPascal(eventName.replace(/^before(?=[a-z])/, \"before-\"))}`;\r\n\r\nconst isPublic = (m: RawMember) => m.privacy !== \"private\" && m.privacy !== \"protected\" && !m.name.startsWith(\"_\");\r\n\r\nexport function parseManifest(manifest: RawManifest): Component[] {\r\n const components: Component[] = [];\r\n for (const module of manifest.modules) {\r\n for (const d of module.declarations ?? []) {\r\n if (!d.customElement || !d.tagName) continue;\r\n const members = (d.members ?? []).filter(isPublic);\r\n components.push({\r\n tagName: d.tagName,\r\n className: d.name,\r\n description: d.description ?? \"\",\r\n remarks: d.remarks ?? \"\",\r\n examples: d.examples ?? [],\r\n entryPoint: module.path.split(\"/\")[1] ?? \"\",\r\n attributes: d.attributes ?? [],\r\n properties: members.filter((m) => m.kind === \"field\" && !m.static),\r\n methods: members.filter((m) => m.kind === \"method\" && !m.static),\r\n slots: d.slots ?? [],\r\n events: d.events ?? [],\r\n cssParts: d.cssParts ?? [],\r\n cssProperties: d.cssProperties ?? [],\r\n cssStates: d.cssStates ?? [],\r\n });\r\n }\r\n }\r\n return components.sort((a, b) => a.tagName.localeCompare(b.tagName));\r\n}\r\n\r\nexport function loadManifest(): Component[] {\r\n return parseManifest(JSON.parse(readFileSync(resolveWebManifest(), \"utf8\")) as RawManifest);\r\n}\r\n\r\nfunction resolveWebManifest(): string {\r\n const require = createRequire(import.meta.url);\r\n try {\r\n return require.resolve(\"@m3e/web/custom-elements.json\");\r\n } catch (error) {\r\n if (!(error instanceof Error) || !(\"code\" in error) || error.code !== \"ERR_PACKAGE_PATH_NOT_EXPORTED\") {\r\n throw error;\r\n }\r\n // Some @m3e/web releases ship the manifest beside the \"all\" entry point without exporting it.\r\n return resolve(dirname(require.resolve(\"@m3e/web/all\")), \"custom-elements.json\");\r\n }\r\n}\r\n\r\nexport class Catalog {\r\n constructor(readonly components: Component[]) {}\r\n\r\n get(tagName: string): Component | undefined {\r\n const key = tagName.trim().toLowerCase();\r\n return this.components.find((c) => c.tagName === key || c.tagName === `m3e-${key}` || c.className.toLowerCase() === key);\r\n }\r\n\r\n search(query: string, limit = 10): Component[] {\r\n const terms = query.toLowerCase().split(/\\s+/).filter(Boolean);\r\n return this.components\r\n .map((c) => {\r\n const name = `${c.tagName} ${c.className}`.toLowerCase();\r\n const body = [\r\n c.description,\r\n c.remarks,\r\n ...c.attributes.map((x) => `${x.name} ${x.description ?? \"\"}`),\r\n ...c.slots.map((x) => `${x.name} ${x.description ?? \"\"}`),\r\n ...c.events.map((x) => `${x.name} ${x.description ?? \"\"}`),\r\n ]\r\n .join(\" \")\r\n .toLowerCase();\r\n let score = 0;\r\n for (const t of terms) {\r\n if (name.includes(t)) score += 10;\r\n if (body.includes(t)) score += 1;\r\n }\r\n return { c, score };\r\n })\r\n .filter((x) => x.score > 0)\r\n .sort((a, b) => b.score - a.score || a.c.tagName.localeCompare(b.c.tagName))\r\n .slice(0, limit)\r\n .map((x) => x.c);\r\n }\r\n\r\n /** CSS custom properties across all components, optionally filtered by a substring of name/description. */\r\n cssProperties(filter?: string, component?: string) {\r\n const f = filter?.toLowerCase();\r\n const out: { component: string; name: string; description: string }[] = [];\r\n for (const c of this.components) {\r\n if (component && c.tagName !== component) continue;\r\n for (const p of c.cssProperties) {\r\n if (f && !`${p.name} ${p.description ?? \"\"}`.toLowerCase().includes(f)) continue;\r\n out.push({ component: c.tagName, name: p.name, description: p.description ?? \"\" });\r\n }\r\n }\r\n return out;\r\n }\r\n}\r\n"]}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { Catalog, Component } from "./manifest.js";
|
|
3
|
+
export declare function describe(c: Component): string;
|
|
4
|
+
export declare function createServer(catalog: Catalog): McpServer;
|
|
5
|
+
//# sourceMappingURL=server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAEpE,OAAO,EAAE,OAAO,EAAE,SAAS,EAA6B,MAAM,eAAe,CAAC;AAqB9E,wBAAgB,QAAQ,CAAC,CAAC,EAAE,SAAS,GAAG,MAAM,CAmC7C;AAsBD,wBAAgB,YAAY,CAAC,OAAO,EAAE,OAAO,GAAG,SAAS,CAqGxD"}
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
import { z } from "zod";
|
|
3
|
+
import { reactEventProp, reactName } from "./manifest.js";
|
|
4
|
+
const reply = (text, isError = false) => ({
|
|
5
|
+
content: [{ type: "text", text }],
|
|
6
|
+
...(isError ? { isError } : {}),
|
|
7
|
+
});
|
|
8
|
+
const oneLine = (s) => (s ?? "").replace(/\s+/g, " ").trim();
|
|
9
|
+
function notFound(catalog, name) {
|
|
10
|
+
const hints = catalog.search(name, 5).map((c) => c.tagName);
|
|
11
|
+
return reply(`Unknown component "${name}".${hints.length ? ` Did you mean: ${hints.join(", ")}?` : ""} Use list_components to see all.`, true);
|
|
12
|
+
}
|
|
13
|
+
function section(title, rows) {
|
|
14
|
+
return rows.length ? `\n## ${title}\n${rows.join("\n")}\n` : "";
|
|
15
|
+
}
|
|
16
|
+
export function describe(c) {
|
|
17
|
+
const attrs = c.attributes.map((a) => `- \`${a.name}\` (${a.type?.text ?? "unknown"}${a.default !== undefined ? `, default ${a.default}` : ""}): ${oneLine(a.description)}`);
|
|
18
|
+
const attrNames = new Set(c.attributes.map((a) => a.name));
|
|
19
|
+
const props = c.properties
|
|
20
|
+
.filter((p) => !attrNames.has(p.attribute ?? p.name))
|
|
21
|
+
.map((p) => `- \`${p.name}\` (${p.type?.text ?? "unknown"}${p.readonly ? ", readonly" : ""}): ${oneLine(p.description)}`);
|
|
22
|
+
const methods = c.methods.map((m) => `- \`${m.name}(${(m.parameters ?? []).map((p) => `${p.name}: ${p.type?.text ?? "any"}`).join(", ")})\`: ${oneLine(m.description)}`);
|
|
23
|
+
const slots = c.slots.map((s) => `- \`${s.name || "(default)"}\`: ${oneLine(s.description)}`);
|
|
24
|
+
const events = c.events.map((e) => `- \`${e.name}\` (${e.type?.text ?? "Event"}): ${oneLine(e.description)}`);
|
|
25
|
+
const parts = c.cssParts.map((p) => `- \`${p.name}\`: ${oneLine(p.description)}`);
|
|
26
|
+
const states = c.cssStates.map((p) => `- \`${p.name}\`: ${oneLine(p.description)}`);
|
|
27
|
+
const vars = c.cssProperties.map((p) => `- \`${p.name}\`: ${oneLine(p.description)}`);
|
|
28
|
+
return (`# <${c.tagName}> (${c.className})\n${c.description}\n` +
|
|
29
|
+
(c.remarks ? `\n${c.remarks}\n` : "") +
|
|
30
|
+
`\nImport: \`import "@m3e/web/${c.entryPoint}";\`\n` +
|
|
31
|
+
section("Attributes", attrs) +
|
|
32
|
+
section("Other properties", props) +
|
|
33
|
+
section("Methods", methods) +
|
|
34
|
+
section("Slots", slots) +
|
|
35
|
+
section("Events", events) +
|
|
36
|
+
section("CSS parts", parts) +
|
|
37
|
+
section("CSS states", states) +
|
|
38
|
+
section("CSS custom properties", vars));
|
|
39
|
+
}
|
|
40
|
+
function usage(c) {
|
|
41
|
+
return c.examples.length
|
|
42
|
+
? c.examples.map((example, i) => `## Example ${i + 1}\n\n${example}`).join("\n\n")
|
|
43
|
+
: `No usage examples are documented for <${c.tagName}>. See get_component for its API.`;
|
|
44
|
+
}
|
|
45
|
+
function reactUsage(c) {
|
|
46
|
+
const name = reactName(c.tagName);
|
|
47
|
+
const handlers = c.events.map((e) => `${reactEventProp(e.name)}`);
|
|
48
|
+
return [
|
|
49
|
+
"```tsx",
|
|
50
|
+
`import { ${name} } from "@m3e/react/${c.entryPoint}";`,
|
|
51
|
+
"",
|
|
52
|
+
`<${name}>Content</${name}>`,
|
|
53
|
+
"```",
|
|
54
|
+
`Event props (derived from the element's events): ${handlers.length ? handlers.map((h) => `\`${h}\``).join(", ") : "none"}.`,
|
|
55
|
+
"Properties map to React props by camelCase property name; the ref is forwarded to the element.",
|
|
56
|
+
].join("\n");
|
|
57
|
+
}
|
|
58
|
+
export function createServer(catalog) {
|
|
59
|
+
const server = new McpServer({ name: "m3e", version: "2.12.0" });
|
|
60
|
+
const readOnly = { readOnlyHint: true, openWorldHint: false };
|
|
61
|
+
server.registerTool("list_components", {
|
|
62
|
+
title: "List M3E components",
|
|
63
|
+
description: "Lists every M3E custom element with a one-line description.",
|
|
64
|
+
annotations: readOnly,
|
|
65
|
+
}, async () => reply(catalog.components.map((c) => `- ${c.tagName}: ${oneLine(c.description)}`).join("\n")));
|
|
66
|
+
server.registerTool("get_component", {
|
|
67
|
+
title: "Get component API",
|
|
68
|
+
description: "Returns the API of an M3E component: attributes, properties, methods, slots, events, CSS parts, states and custom properties.",
|
|
69
|
+
inputSchema: { name: z.string().describe('Tag name, e.g. "m3e-button" (the "m3e-" prefix is optional)') },
|
|
70
|
+
annotations: readOnly,
|
|
71
|
+
}, async ({ name }) => {
|
|
72
|
+
const c = catalog.get(name);
|
|
73
|
+
return c ? reply(describe(c)) : notFound(catalog, name);
|
|
74
|
+
});
|
|
75
|
+
server.registerTool("search_components", {
|
|
76
|
+
title: "Search components",
|
|
77
|
+
description: "Searches component names, descriptions, attributes, slots and events for the given keywords.",
|
|
78
|
+
inputSchema: {
|
|
79
|
+
query: z.string().min(1),
|
|
80
|
+
limit: z.number().int().min(1).max(50).optional().describe("Maximum results (default 10)"),
|
|
81
|
+
},
|
|
82
|
+
annotations: readOnly,
|
|
83
|
+
}, async ({ query, limit }) => {
|
|
84
|
+
const found = catalog.search(query, limit ?? 10);
|
|
85
|
+
return reply(found.length ? found.map((c) => `- ${c.tagName}: ${oneLine(c.description)}`).join("\n") : "No matches.");
|
|
86
|
+
});
|
|
87
|
+
server.registerTool("get_usage_example", {
|
|
88
|
+
title: "Get usage example",
|
|
89
|
+
description: "Returns the component's documented examples from the Custom Elements Manifest.",
|
|
90
|
+
inputSchema: { name: z.string() },
|
|
91
|
+
annotations: readOnly,
|
|
92
|
+
}, async ({ name }) => {
|
|
93
|
+
const c = catalog.get(name);
|
|
94
|
+
return c ? reply(usage(c)) : notFound(catalog, name);
|
|
95
|
+
});
|
|
96
|
+
server.registerTool("get_react_wrapper", {
|
|
97
|
+
title: "Get React wrapper info",
|
|
98
|
+
description: "Returns the @m3e/react import, component name and event props for a component.",
|
|
99
|
+
inputSchema: { name: z.string() },
|
|
100
|
+
annotations: readOnly,
|
|
101
|
+
}, async ({ name }) => {
|
|
102
|
+
const c = catalog.get(name);
|
|
103
|
+
return c ? reply(reactUsage(c)) : notFound(catalog, name);
|
|
104
|
+
});
|
|
105
|
+
server.registerTool("list_css_properties", {
|
|
106
|
+
title: "List design tokens / CSS custom properties",
|
|
107
|
+
description: "Lists CSS custom properties used to theme components, optionally filtered by component and/or keyword.",
|
|
108
|
+
inputSchema: {
|
|
109
|
+
component: z.string().optional().describe("Restrict to one component, e.g. m3e-button"),
|
|
110
|
+
filter: z.string().optional().describe("Case-insensitive substring matched against name and description"),
|
|
111
|
+
},
|
|
112
|
+
annotations: readOnly,
|
|
113
|
+
}, async ({ component, filter }) => {
|
|
114
|
+
const tag = component ? catalog.get(component)?.tagName : undefined;
|
|
115
|
+
if (component && !tag)
|
|
116
|
+
return notFound(catalog, component);
|
|
117
|
+
const rows = catalog.cssProperties(filter, tag);
|
|
118
|
+
if (!rows.length)
|
|
119
|
+
return reply("No matching CSS custom properties.");
|
|
120
|
+
const cap = 200;
|
|
121
|
+
const text = rows.slice(0, cap).map((r) => `- ${r.component} \`${r.name}\`: ${oneLine(r.description)}`);
|
|
122
|
+
if (rows.length > cap)
|
|
123
|
+
text.push(`… ${rows.length - cap} more; narrow with component or filter.`);
|
|
124
|
+
return reply(text.join("\n"));
|
|
125
|
+
});
|
|
126
|
+
return server;
|
|
127
|
+
}
|
|
128
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AACxB,OAAO,EAAsB,cAAc,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAE9E,MAAM,KAAK,GAAG,CAAC,IAAY,EAAE,OAAO,GAAG,KAAK,EAAE,EAAE,CAAC,CAAC;IAChD,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,CAAC;I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CAAC,MAAM,GAAG,GAAG;YAAE,IAAI,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC,MAAM,GAAG,GAAG,yCAAyC,CAAC,CAAC;QAClG,OAAO,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,CAAC;IAChC,CAAC,CACF,CAAC;IAEF,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\r\nimport { z } from \"zod\";\r\nimport { Catalog, Component, reactEventProp, reactName } from \"./manifest.js\";\r\n\r\nconst reply = (text: string, isError = false) => ({\r\n content: [{ type: \"text\" as const, text }],\r\n ...(isError ? { isError } : {}),\r\n});\r\n\r\nconst oneLine = (s?: string) => (s ?? \"\").replace(/\\s+/g, \" \").trim();\r\n\r\nfunction notFound(catalog: Catalog, name: string) {\r\n const hints = catalog.search(name, 5).map((c) => c.tagName);\r\n return reply(\r\n `Unknown component \"${name}\".${hints.length ? ` Did you mean: ${hints.join(\", \")}?` : \"\"} Use list_components to see all.`,\r\n true,\r\n );\r\n}\r\n\r\nfunction section(title: string, rows: string[]) {\r\n return rows.length ? `\\n## ${title}\\n${rows.join(\"\\n\")}\\n` : \"\";\r\n}\r\n\r\nexport function describe(c: Component): string {\r\n const attrs = c.attributes.map(\r\n (a) =>\r\n `- \\`${a.name}\\` (${a.type?.text ?? \"unknown\"}${a.default !== undefined ? `, default ${a.default}` : \"\"}): ${oneLine(a.description)}`,\r\n );\r\n const attrNames = new Set(c.attributes.map((a) => a.name));\r\n const props = c.properties\r\n .filter((p) => !attrNames.has(p.attribute ?? p.name))\r\n .map(\r\n (p) =>\r\n `- \\`${p.name}\\` (${p.type?.text ?? \"unknown\"}${p.readonly ? \", readonly\" : \"\"}): ${oneLine(p.description)}`,\r\n );\r\n const methods = c.methods.map(\r\n (m) =>\r\n `- \\`${m.name}(${(m.parameters ?? []).map((p) => `${p.name}: ${p.type?.text ?? \"any\"}`).join(\", \")})\\`: ${oneLine(m.description)}`,\r\n );\r\n const slots = c.slots.map((s) => `- \\`${s.name || \"(default)\"}\\`: ${oneLine(s.description)}`);\r\n const events = c.events.map((e) => `- \\`${e.name}\\` (${e.type?.text ?? \"Event\"}): ${oneLine(e.description)}`);\r\n const parts = c.cssParts.map((p) => `- \\`${p.name}\\`: ${oneLine(p.description)}`);\r\n const states = c.cssStates.map((p) => `- \\`${p.name}\\`: ${oneLine(p.description)}`);\r\n const vars = c.cssProperties.map((p) => `- \\`${p.name}\\`: ${oneLine(p.description)}`);\r\n\r\n return (\r\n `# <${c.tagName}> (${c.className})\\n${c.description}\\n` +\r\n (c.remarks ? `\\n${c.remarks}\\n` : \"\") +\r\n `\\nImport: \\`import \"@m3e/web/${c.entryPoint}\";\\`\\n` +\r\n section(\"Attributes\", attrs) +\r\n section(\"Other properties\", props) +\r\n section(\"Methods\", methods) +\r\n section(\"Slots\", slots) +\r\n section(\"Events\", events) +\r\n section(\"CSS parts\", parts) +\r\n section(\"CSS states\", states) +\r\n section(\"CSS custom properties\", vars)\r\n );\r\n}\r\n\r\nfunction usage(c: Component): string {\r\n return c.examples.length\r\n ? c.examples.map((example, i) => `## Example ${i + 1}\\n\\n${example}`).join(\"\\n\\n\")\r\n : `No usage examples are documented for <${c.tagName}>. See get_component for its API.`;\r\n}\r\n\r\nfunction reactUsage(c: Component): string {\r\n const name = reactName(c.tagName);\r\n const handlers = c.events.map((e) => `${reactEventProp(e.name)}`);\r\n return [\r\n \"```tsx\",\r\n `import { ${name} } from \"@m3e/react/${c.entryPoint}\";`,\r\n \"\",\r\n `<${name}>Content</${name}>`,\r\n \"```\",\r\n `Event props (derived from the element's events): ${handlers.length ? handlers.map((h) => `\\`${h}\\``).join(\", \") : \"none\"}.`,\r\n \"Properties map to React props by camelCase property name; the ref is forwarded to the element.\",\r\n ].join(\"\\n\");\r\n}\r\n\r\nexport function createServer(catalog: Catalog): McpServer {\r\n const server = new McpServer({ name: \"m3e\", version: \"2.12.0\" });\r\n const readOnly = { readOnlyHint: true, openWorldHint: false };\r\n\r\n server.registerTool(\r\n \"list_components\",\r\n {\r\n title: \"List M3E components\",\r\n description: \"Lists every M3E custom element with a one-line description.\",\r\n annotations: readOnly,\r\n },\r\n async () => reply(catalog.components.map((c) => `- ${c.tagName}: ${oneLine(c.description)}`).join(\"\\n\")),\r\n );\r\n\r\n server.registerTool(\r\n \"get_component\",\r\n {\r\n title: \"Get component API\",\r\n description:\r\n \"Returns the API of an M3E component: attributes, properties, methods, slots, events, CSS parts, states and custom properties.\",\r\n inputSchema: { name: z.string().describe('Tag name, e.g. \"m3e-button\" (the \"m3e-\" prefix is optional)') },\r\n annotations: readOnly,\r\n },\r\n async ({ name }) => {\r\n const c = catalog.get(name);\r\n return c ? reply(describe(c)) : notFound(catalog, name);\r\n },\r\n );\r\n\r\n server.registerTool(\r\n \"search_components\",\r\n {\r\n title: \"Search components\",\r\n description: \"Searches component names, descriptions, attributes, slots and events for the given keywords.\",\r\n inputSchema: {\r\n query: z.string().min(1),\r\n limit: z.number().int().min(1).max(50).optional().describe(\"Maximum results (default 10)\"),\r\n },\r\n annotations: readOnly,\r\n },\r\n async ({ query, limit }) => {\r\n const found = catalog.search(query, limit ?? 10);\r\n return reply(\r\n found.length ? found.map((c) => `- ${c.tagName}: ${oneLine(c.description)}`).join(\"\\n\") : \"No matches.\",\r\n );\r\n },\r\n );\r\n\r\n server.registerTool(\r\n \"get_usage_example\",\r\n {\r\n title: \"Get usage example\",\r\n description: \"Returns the component's documented examples from the Custom Elements Manifest.\",\r\n inputSchema: { name: z.string() },\r\n annotations: readOnly,\r\n },\r\n async ({ name }) => {\r\n const c = catalog.get(name);\r\n return c ? reply(usage(c)) : notFound(catalog, name);\r\n },\r\n );\r\n\r\n server.registerTool(\r\n \"get_react_wrapper\",\r\n {\r\n title: \"Get React wrapper info\",\r\n description: \"Returns the @m3e/react import, component name and event props for a component.\",\r\n inputSchema: { name: z.string() },\r\n annotations: readOnly,\r\n },\r\n async ({ name }) => {\r\n const c = catalog.get(name);\r\n return c ? reply(reactUsage(c)) : notFound(catalog, name);\r\n },\r\n );\r\n\r\n server.registerTool(\r\n \"list_css_properties\",\r\n {\r\n title: \"List design tokens / CSS custom properties\",\r\n description:\r\n \"Lists CSS custom properties used to theme components, optionally filtered by component and/or keyword.\",\r\n inputSchema: {\r\n component: z.string().optional().describe(\"Restrict to one component, e.g. m3e-button\"),\r\n filter: z.string().optional().describe(\"Case-insensitive substring matched against name and description\"),\r\n },\r\n annotations: readOnly,\r\n },\r\n async ({ component, filter }) => {\r\n const tag = component ? catalog.get(component)?.tagName : undefined;\r\n if (component && !tag) return notFound(catalog, component);\r\n const rows = catalog.cssProperties(filter, tag);\r\n if (!rows.length) return reply(\"No matching CSS custom properties.\");\r\n const cap = 200;\r\n const text = rows.slice(0, cap).map((r) => `- ${r.component} \\`${r.name}\\`: ${oneLine(r.description)}`);\r\n if (rows.length > cap) text.push(`… ${rows.length - cap} more; narrow with component or filter.`);\r\n return reply(text.join(\"\\n\"));\r\n },\r\n );\r\n\r\n return server;\r\n}\r\n"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,45 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@m3e/mcp",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
"
|
|
6
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "@m3e/mcp",
|
|
3
|
+
"version": "2.12.0",
|
|
4
|
+
"description": "Model Context Protocol server exposing the M3E component library to AI assistants",
|
|
5
|
+
"author": "matraic <matraic@yahoo.com>",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://matraic.github.io/m3e/#/getting-started/mcp.html",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/matraic/m3e.git"
|
|
11
|
+
},
|
|
12
|
+
"keywords": [
|
|
13
|
+
"material design",
|
|
14
|
+
"mcp",
|
|
15
|
+
"model context protocol",
|
|
16
|
+
"web components",
|
|
17
|
+
"custom elements manifest"
|
|
18
|
+
],
|
|
19
|
+
"type": "module",
|
|
20
|
+
"engines": {
|
|
21
|
+
"node": ">=22"
|
|
22
|
+
},
|
|
23
|
+
"main": "./dist/index.js",
|
|
24
|
+
"bin": {
|
|
25
|
+
"m3e-mcp": "./dist/cli.js"
|
|
26
|
+
},
|
|
27
|
+
"files": [
|
|
28
|
+
"dist"
|
|
29
|
+
],
|
|
30
|
+
"scripts": {
|
|
31
|
+
"build": "rimraf dist && tsc -p tsconfig.json",
|
|
32
|
+
"cem": "echo \"@m3e/mcp: using @m3e/web manifest\"",
|
|
33
|
+
"lint": "echo \"@m3e/mcp: skipping lint\"",
|
|
34
|
+
"test": "rimraf test-results && tsc -p test/tsconfig.json && node --test test-results/test/*.test.js",
|
|
35
|
+
"clean": "rimraf dist test-results"
|
|
36
|
+
},
|
|
37
|
+
"dependencies": {
|
|
38
|
+
"@m3e/web": "^2.12.0",
|
|
39
|
+
"@modelcontextprotocol/sdk": "^1.32.2",
|
|
40
|
+
"zod": "^4.6.7"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/node": "^22.0.0"
|
|
44
|
+
}
|
|
45
|
+
}
|