@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.
Files changed (2) hide show
  1. package/dist/index.js +94 -62
  2. package/package.json +2 -1
package/dist/index.js CHANGED
@@ -1,112 +1,144 @@
1
1
  #!/usr/bin/env node
2
- import { McpServer as w } from "@modelcontextprotocol/sdk/server/mcp.js";
3
- import { StdioServerTransport as y } from "@modelcontextprotocol/sdk/server/stdio.js";
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 s from "path";
6
- import { fileURLToPath as p } from "url";
7
- import { ListPromptsRequestSchema as h, GetPromptRequestSchema as R, ListResourcesRequestSchema as v, ReadResourceRequestSchema as g, ListToolsRequestSchema as S, CallToolRequestSchema as q } from "@modelcontextprotocol/sdk/types.js";
8
- async function u(e) {
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 i.access(e), (await i.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 d(e, r) {
18
- return (await u(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 l(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 x(e) {
25
- const r = s.dirname(p(import.meta.url)), o = s.resolve(r, "../../../resources/command-prompts");
26
- e.server.setRequestHandler(h, async () => {
56
+ function $(r) {
57
+ const e = d();
58
+ r.server.setRequestHandler(R, async () => {
27
59
  try {
28
- return { prompts: (await u(o)).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
- } catch (t) {
33
- return console.error("Error listing prompts:", t), { prompts: [] };
64
+ } catch (o) {
65
+ return console.error("Error listing prompts:", o), { prompts: [] };
34
66
  }
35
- }), e.server.setRequestHandler(R, async (t) => {
36
- const a = t.params.name;
67
+ }), r.server.setRequestHandler(h, async (o) => {
68
+ const t = o.params.name;
37
69
  try {
38
- const n = await d(o, a);
70
+ const n = await f(e, t);
39
71
  if (!n)
40
- throw new Error(`Prompt not found: ${a}`);
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(s.join(o, n), "utf-8")
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 ${a}: ${n}`);
85
+ throw new Error(`Failed to load prompt ${t}: ${n}`);
54
86
  }
55
87
  });
56
88
  }
57
- function F(e) {
58
- const r = s.dirname(p(import.meta.url)), o = s.resolve(r, "../../../resources/command-prompts");
59
- e.server.setRequestHandler(v, async () => {
89
+ function C(r) {
90
+ const e = d();
91
+ r.server.setRequestHandler(S, async () => {
60
92
  try {
61
- return { resources: (await u(o)).map((n) => {
62
- const c = s.parse(n).name, m = l(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://${c}`,
65
- name: c,
66
- mimeType: m,
96
+ uri: `prompt://${s}`,
97
+ name: s,
98
+ mimeType: c,
67
99
  description: `Content of ${n}`
68
100
  };
69
101
  }) };
70
- } catch (t) {
71
- return console.error("Error listing resources:", t), { resources: [] };
102
+ } catch (o) {
103
+ return console.error("Error listing resources:", o), { resources: [] };
72
104
  }
73
- }), e.server.setRequestHandler(
74
- g,
75
- async (t) => {
76
- const a = t.params.uri, n = a.replace(/^prompt:\/\//, "");
105
+ }), r.server.setRequestHandler(
106
+ P,
107
+ async (o) => {
108
+ const t = o.params.uri, n = t.replace(/^prompt:\/\//, "");
77
109
  try {
78
- const c = await d(o, n);
79
- if (!c)
80
- throw new Error(`Resource not found: ${a}`);
81
- const m = await i.readFile(s.join(o, c), "utf-8"), f = l(c);
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: a,
86
- mimeType: f,
87
- text: m
117
+ uri: t,
118
+ mimeType: w,
119
+ text: c
88
120
  }
89
121
  ]
90
122
  };
91
- } catch (c) {
92
- throw new Error(`Failed to read resource ${a}: ${c}`);
123
+ } catch (s) {
124
+ throw new Error(`Failed to read resource ${t}: ${s}`);
93
125
  }
94
126
  }
95
127
  );
96
128
  }
97
- function $(e) {
98
- e.server.setRequestHandler(S, async () => ({ tools: [] })), e.server.setRequestHandler(q, 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 H() {
109
- const e = s.dirname(p(import.meta.url)), r = s.resolve(e, "../package.json"), o = JSON.parse(await i.readFile(r, "utf-8")), t = new w(
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 x(t), F(t), $(t), t;
154
+ return $(t), C(t), T(t), t;
123
155
  }
124
- async function P() {
156
+ async function M() {
125
157
  console.error("Starting MCP server serving...");
126
- const e = await H(), r = new y();
127
- await e.connect(r);
158
+ const r = await D(), e = new v();
159
+ await r.connect(e);
128
160
  }
129
- P().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.9",
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
  }