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