@reus-able/frontend-helper-mcp 1.0.9 → 1.0.11
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 +94 -62
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,112 +1,144 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import { McpServer as
|
|
3
|
-
import { StdioServerTransport as
|
|
2
|
+
import { McpServer as y } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import { StdioServerTransport as v } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
4
4
|
import i from "fs/promises";
|
|
5
|
-
import
|
|
6
|
-
import { fileURLToPath as
|
|
7
|
-
import { ListPromptsRequestSchema as
|
|
8
|
-
|
|
5
|
+
import a from "path";
|
|
6
|
+
import { fileURLToPath as l } from "url";
|
|
7
|
+
import { ListPromptsRequestSchema as R, GetPromptRequestSchema as h, ListResourcesRequestSchema as S, ReadResourceRequestSchema as P, ListToolsRequestSchema as g, CallToolRequestSchema as F } from "@modelcontextprotocol/sdk/types.js";
|
|
8
|
+
import q from "fs";
|
|
9
|
+
function x(r) {
|
|
9
10
|
try {
|
|
10
|
-
return
|
|
11
|
-
|
|
11
|
+
return q.statSync(r).isDirectory();
|
|
12
|
+
} catch {
|
|
13
|
+
return !1;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function p(r, e, o = 8) {
|
|
17
|
+
let t = r;
|
|
18
|
+
for (let n = 0; n <= o; n++) {
|
|
19
|
+
const s = a.resolve(t, e);
|
|
20
|
+
if (x(s)) return s;
|
|
21
|
+
const c = a.dirname(t);
|
|
22
|
+
if (c === t) break;
|
|
23
|
+
t = c;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function d() {
|
|
27
|
+
const r = process.env.MCP_COMMAND_PROMPTS_DIR ?? process.env.MCP_PROMPTS_DIR;
|
|
28
|
+
if (r) return r;
|
|
29
|
+
const e = a.dirname(l(import.meta.url)), o = p(
|
|
30
|
+
e,
|
|
31
|
+
"resources/command-prompts"
|
|
32
|
+
);
|
|
33
|
+
if (o) return o;
|
|
34
|
+
const t = p(
|
|
35
|
+
process.cwd(),
|
|
36
|
+
"resources/command-prompts"
|
|
37
|
+
);
|
|
38
|
+
return t || a.resolve(process.cwd(), "resources/command-prompts");
|
|
39
|
+
}
|
|
40
|
+
async function m(r) {
|
|
41
|
+
try {
|
|
42
|
+
return await i.access(r), (await i.readdir(r)).filter(
|
|
43
|
+
(o) => [".txt", ".md", ".json"].includes(a.extname(o).toLowerCase())
|
|
12
44
|
);
|
|
13
|
-
} catch (
|
|
14
|
-
return console.error(`Error accessing prompts directory ${
|
|
45
|
+
} catch (e) {
|
|
46
|
+
return console.error(`Error accessing prompts directory ${r}:`, e), [];
|
|
15
47
|
}
|
|
16
48
|
}
|
|
17
|
-
async function
|
|
18
|
-
return (await
|
|
49
|
+
async function f(r, e) {
|
|
50
|
+
return (await m(r)).find((t) => a.parse(t).name === e);
|
|
19
51
|
}
|
|
20
|
-
function
|
|
21
|
-
const
|
|
22
|
-
return
|
|
52
|
+
function u(r) {
|
|
53
|
+
const e = a.extname(r).toLowerCase();
|
|
54
|
+
return e === ".md" ? "text/markdown" : e === ".json" ? "application/json" : "text/plain";
|
|
23
55
|
}
|
|
24
|
-
function
|
|
25
|
-
const
|
|
26
|
-
|
|
56
|
+
function $(r) {
|
|
57
|
+
const e = d();
|
|
58
|
+
r.server.setRequestHandler(R, async () => {
|
|
27
59
|
try {
|
|
28
|
-
return { prompts: (await
|
|
29
|
-
name:
|
|
60
|
+
return { prompts: (await m(e)).map((n) => ({
|
|
61
|
+
name: a.parse(n).name,
|
|
30
62
|
description: `Content of ${n}`
|
|
31
63
|
})) };
|
|
32
|
-
} catch (
|
|
33
|
-
return console.error("Error listing prompts:",
|
|
64
|
+
} catch (o) {
|
|
65
|
+
return console.error("Error listing prompts:", o), { prompts: [] };
|
|
34
66
|
}
|
|
35
|
-
}),
|
|
36
|
-
const
|
|
67
|
+
}), r.server.setRequestHandler(h, async (o) => {
|
|
68
|
+
const t = o.params.name;
|
|
37
69
|
try {
|
|
38
|
-
const n = await
|
|
70
|
+
const n = await f(e, t);
|
|
39
71
|
if (!n)
|
|
40
|
-
throw new Error(`Prompt not found: ${
|
|
72
|
+
throw new Error(`Prompt not found: ${t}`);
|
|
41
73
|
return {
|
|
42
74
|
messages: [
|
|
43
75
|
{
|
|
44
76
|
role: "user",
|
|
45
77
|
content: {
|
|
46
78
|
type: "text",
|
|
47
|
-
text: await i.readFile(
|
|
79
|
+
text: await i.readFile(a.join(e, n), "utf-8")
|
|
48
80
|
}
|
|
49
81
|
}
|
|
50
82
|
]
|
|
51
83
|
};
|
|
52
84
|
} catch (n) {
|
|
53
|
-
throw new Error(`Failed to load prompt ${
|
|
85
|
+
throw new Error(`Failed to load prompt ${t}: ${n}`);
|
|
54
86
|
}
|
|
55
87
|
});
|
|
56
88
|
}
|
|
57
|
-
function
|
|
58
|
-
const
|
|
59
|
-
|
|
89
|
+
function C(r) {
|
|
90
|
+
const e = d();
|
|
91
|
+
r.server.setRequestHandler(S, async () => {
|
|
60
92
|
try {
|
|
61
|
-
return { resources: (await
|
|
62
|
-
const
|
|
93
|
+
return { resources: (await m(e)).map((n) => {
|
|
94
|
+
const s = a.parse(n).name, c = u(n);
|
|
63
95
|
return {
|
|
64
|
-
uri: `prompt://${
|
|
65
|
-
name:
|
|
66
|
-
mimeType:
|
|
96
|
+
uri: `prompt://${s}`,
|
|
97
|
+
name: s,
|
|
98
|
+
mimeType: c,
|
|
67
99
|
description: `Content of ${n}`
|
|
68
100
|
};
|
|
69
101
|
}) };
|
|
70
|
-
} catch (
|
|
71
|
-
return console.error("Error listing resources:",
|
|
102
|
+
} catch (o) {
|
|
103
|
+
return console.error("Error listing resources:", o), { resources: [] };
|
|
72
104
|
}
|
|
73
|
-
}),
|
|
74
|
-
|
|
75
|
-
async (
|
|
76
|
-
const
|
|
105
|
+
}), r.server.setRequestHandler(
|
|
106
|
+
P,
|
|
107
|
+
async (o) => {
|
|
108
|
+
const t = o.params.uri, n = t.replace(/^prompt:\/\//, "");
|
|
77
109
|
try {
|
|
78
|
-
const
|
|
79
|
-
if (!
|
|
80
|
-
throw new Error(`Resource not found: ${
|
|
81
|
-
const
|
|
110
|
+
const s = await f(e, n);
|
|
111
|
+
if (!s)
|
|
112
|
+
throw new Error(`Resource not found: ${t}`);
|
|
113
|
+
const c = await i.readFile(a.join(e, s), "utf-8"), w = u(s);
|
|
82
114
|
return {
|
|
83
115
|
contents: [
|
|
84
116
|
{
|
|
85
|
-
uri:
|
|
86
|
-
mimeType:
|
|
87
|
-
text:
|
|
117
|
+
uri: t,
|
|
118
|
+
mimeType: w,
|
|
119
|
+
text: c
|
|
88
120
|
}
|
|
89
121
|
]
|
|
90
122
|
};
|
|
91
|
-
} catch (
|
|
92
|
-
throw new Error(`Failed to read resource ${
|
|
123
|
+
} catch (s) {
|
|
124
|
+
throw new Error(`Failed to read resource ${t}: ${s}`);
|
|
93
125
|
}
|
|
94
126
|
}
|
|
95
127
|
);
|
|
96
128
|
}
|
|
97
|
-
function
|
|
98
|
-
|
|
129
|
+
function T(r) {
|
|
130
|
+
r.server.setRequestHandler(g, async () => ({ tools: [] })), r.server.setRequestHandler(F, async (e) => ({
|
|
99
131
|
content: [
|
|
100
132
|
{
|
|
101
133
|
type: "text",
|
|
102
|
-
text: `Tool not found: ${
|
|
134
|
+
text: `Tool not found: ${e.params.name}`
|
|
103
135
|
}
|
|
104
136
|
],
|
|
105
137
|
isError: !0
|
|
106
138
|
}));
|
|
107
139
|
}
|
|
108
|
-
async function
|
|
109
|
-
const
|
|
140
|
+
async function D() {
|
|
141
|
+
const r = a.dirname(l(import.meta.url)), e = a.resolve(r, "../package.json"), o = JSON.parse(await i.readFile(e, "utf-8")), t = new y(
|
|
110
142
|
{
|
|
111
143
|
name: o.name,
|
|
112
144
|
version: o.version
|
|
@@ -119,13 +151,13 @@ async function H() {
|
|
|
119
151
|
}
|
|
120
152
|
}
|
|
121
153
|
);
|
|
122
|
-
return
|
|
154
|
+
return $(t), C(t), T(t), t;
|
|
123
155
|
}
|
|
124
|
-
async function
|
|
156
|
+
async function M() {
|
|
125
157
|
console.error("Starting MCP server serving...");
|
|
126
|
-
const
|
|
127
|
-
await
|
|
158
|
+
const r = await D(), e = new v();
|
|
159
|
+
await r.connect(e);
|
|
128
160
|
}
|
|
129
|
-
|
|
130
|
-
console.error("Fatal error:",
|
|
161
|
+
M().catch((r) => {
|
|
162
|
+
console.error("Fatal error:", r), process.exit(1);
|
|
131
163
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"description": "前端开发的一些cursor mcp工具集",
|
|
3
3
|
"name": "@reus-able/frontend-helper-mcp",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.11",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
7
7
|
},
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
"scripts": {
|
|
30
30
|
"build": "vite build && node -e \"require('fs').chmodSync('dist/index.js',0o755)\"",
|
|
31
31
|
"typecheck": "tsc -p tsconfig.json --noEmit",
|
|
32
|
+
"verify:prompts": "node scripts/verify-command-prompts-path.mjs",
|
|
32
33
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
33
34
|
}
|
|
34
35
|
}
|