@reus-able/frontend-helper-mcp 1.0.10 → 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.
Files changed (2) hide show
  1. package/dist/index.js +84 -52
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -1,41 +1,73 @@
1
1
  #!/usr/bin/env node
2
- import { McpServer as d } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import { StdioServerTransport as f } from "@modelcontextprotocol/sdk/server/stdio.js";
4
- import c from "fs/promises";
5
- import s from "path";
6
- import { fileURLToPath as w } 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) {
2
+ import { McpServer as y } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { StdioServerTransport as v } from "@modelcontextprotocol/sdk/server/stdio.js";
4
+ import i from "fs/promises";
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 await c.access(e), (await c.readdir(e)).filter(
11
- (o) => [".txt", ".md", ".json"].includes(s.extname(o).toLowerCase())
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 (r) {
14
- return console.error(`Error accessing prompts directory ${e}:`, r), [];
45
+ } catch (e) {
46
+ return console.error(`Error accessing prompts directory ${r}:`, e), [];
15
47
  }
16
48
  }
17
- async function u(e, r) {
18
- return (await m(e)).find((t) => s.parse(t).name === r);
49
+ async function f(r, e) {
50
+ return (await m(r)).find((t) => a.parse(t).name === e);
19
51
  }
20
- function p(e) {
21
- const r = s.extname(e).toLowerCase();
22
- return r === ".md" ? "text/markdown" : r === ".json" ? "application/json" : "text/plain";
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 q(e) {
25
- const r = s.resolve(__dirname, "../../../resources/command-prompts");
26
- e.server.setRequestHandler(y, async () => {
56
+ function $(r) {
57
+ const e = d();
58
+ r.server.setRequestHandler(R, async () => {
27
59
  try {
28
- return { prompts: (await m(r)).map((n) => ({
29
- name: s.parse(n).name,
60
+ return { prompts: (await m(e)).map((n) => ({
61
+ name: a.parse(n).name,
30
62
  description: `Content of ${n}`
31
63
  })) };
32
64
  } catch (o) {
33
65
  return console.error("Error listing prompts:", o), { prompts: [] };
34
66
  }
35
- }), e.server.setRequestHandler(h, async (o) => {
67
+ }), r.server.setRequestHandler(h, async (o) => {
36
68
  const t = o.params.name;
37
69
  try {
38
- const n = await u(r, t);
70
+ const n = await f(e, t);
39
71
  if (!n)
40
72
  throw new Error(`Prompt not found: ${t}`);
41
73
  return {
@@ -44,7 +76,7 @@ function q(e) {
44
76
  role: "user",
45
77
  content: {
46
78
  type: "text",
47
- text: await c.readFile(s.join(r, n), "utf-8")
79
+ text: await i.readFile(a.join(e, n), "utf-8")
48
80
  }
49
81
  }
50
82
  ]
@@ -54,59 +86,59 @@ function q(e) {
54
86
  }
55
87
  });
56
88
  }
57
- function x(e) {
58
- const r = s.resolve(__dirname, "../../../resources/command-prompts");
59
- e.server.setRequestHandler(R, async () => {
89
+ function C(r) {
90
+ const e = d();
91
+ r.server.setRequestHandler(S, async () => {
60
92
  try {
61
- return { resources: (await m(r)).map((n) => {
62
- const a = s.parse(n).name, i = p(n);
93
+ return { resources: (await m(e)).map((n) => {
94
+ const s = a.parse(n).name, c = u(n);
63
95
  return {
64
- uri: `prompt://${a}`,
65
- name: a,
66
- mimeType: i,
96
+ uri: `prompt://${s}`,
97
+ name: s,
98
+ mimeType: c,
67
99
  description: `Content of ${n}`
68
100
  };
69
101
  }) };
70
102
  } catch (o) {
71
103
  return console.error("Error listing resources:", o), { resources: [] };
72
104
  }
73
- }), e.server.setRequestHandler(
74
- v,
105
+ }), r.server.setRequestHandler(
106
+ P,
75
107
  async (o) => {
76
108
  const t = o.params.uri, n = t.replace(/^prompt:\/\//, "");
77
109
  try {
78
- const a = await u(r, n);
79
- if (!a)
110
+ const s = await f(e, n);
111
+ if (!s)
80
112
  throw new Error(`Resource not found: ${t}`);
81
- const i = await c.readFile(s.join(r, a), "utf-8"), l = p(a);
113
+ const c = await i.readFile(a.join(e, s), "utf-8"), w = u(s);
82
114
  return {
83
115
  contents: [
84
116
  {
85
117
  uri: t,
86
- mimeType: l,
87
- text: i
118
+ mimeType: w,
119
+ text: c
88
120
  }
89
121
  ]
90
122
  };
91
- } catch (a) {
92
- throw new Error(`Failed to read resource ${t}: ${a}`);
123
+ } catch (s) {
124
+ throw new Error(`Failed to read resource ${t}: ${s}`);
93
125
  }
94
126
  }
95
127
  );
96
128
  }
97
- function F(e) {
98
- e.server.setRequestHandler(g, async () => ({ tools: [] })), e.server.setRequestHandler(S, async (r) => ({
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: ${r.params.name}`
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 e = s.dirname(w(import.meta.url)), r = s.resolve(e, "../package.json"), o = JSON.parse(await c.readFile(r, "utf-8")), t = new d(
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 $() {
119
151
  }
120
152
  }
121
153
  );
122
- return q(t), x(t), F(t), t;
154
+ return $(t), C(t), T(t), t;
123
155
  }
124
- async function H() {
156
+ async function M() {
125
157
  console.error("Starting MCP server serving...");
126
- const e = await $(), r = new f();
127
- await e.connect(r);
158
+ const r = await D(), e = new v();
159
+ await r.connect(e);
128
160
  }
129
- H().catch((e) => {
130
- console.error("Fatal error:", e), process.exit(1);
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.10",
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
  }