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