kleanmcp 1.0.1 → 1.0.3
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.cjs +554 -0
- package/dist/index.d.ts +24 -0
- package/dist/index.mjs +446 -0
- package/dist/types.cjs +460 -0
- package/dist/types.d.ts +71 -0
- package/dist/types.mjs +394 -0
- package/example/README.md +1 -1
- package/package.json +2 -2
- package/build.ts +0 -30
- package/bun.lock +0 -64
- package/example/bun.lock +0 -75
- package/example/index.ts +0 -125
- package/example/package.json +0 -19
- package/example/tsconfig.json +0 -29
- package/src/index.ts +0 -131
- package/src/types.ts +0 -165
- package/test/mcp.test.ts +0 -65
- package/test/testToolSet.ts +0 -67
- package/test/toolset.test.ts +0 -42
- package/tsconfig.dts.json +0 -12
- package/tsconfig.json +0 -36
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,446 @@
|
|
|
1
|
+
// ../elysia-jsonrpc/dist/mcp.types.js
|
|
2
|
+
import { z as b } from "zod/v4";
|
|
3
|
+
var P = Object.create;
|
|
4
|
+
var { getPrototypeOf: Q, defineProperty: m, getOwnPropertyNames: R } = Object;
|
|
5
|
+
var W = Object.prototype.hasOwnProperty;
|
|
6
|
+
function X(l) {
|
|
7
|
+
return this[l];
|
|
8
|
+
}
|
|
9
|
+
var Y;
|
|
10
|
+
var Z;
|
|
11
|
+
var $ = (l, u, U) => {
|
|
12
|
+
var j = l != null && typeof l === "object";
|
|
13
|
+
if (j) {
|
|
14
|
+
var A = u ? Y ??= new WeakMap : Z ??= new WeakMap, I = A.get(l);
|
|
15
|
+
if (I)
|
|
16
|
+
return I;
|
|
17
|
+
}
|
|
18
|
+
U = l != null ? P(Q(l)) : {};
|
|
19
|
+
let V = u || !l || !l.__esModule ? m(U, "default", { value: l, enumerable: true }) : U;
|
|
20
|
+
for (let F of R(l))
|
|
21
|
+
if (!W.call(V, F))
|
|
22
|
+
m(V, F, { get: X.bind(l, F), enumerable: true });
|
|
23
|
+
if (j)
|
|
24
|
+
A.set(l, V);
|
|
25
|
+
return V;
|
|
26
|
+
};
|
|
27
|
+
var B = (l, u) => () => (u || l((u = { exports: {} }).exports, u), u.exports);
|
|
28
|
+
var C = B((v) => {
|
|
29
|
+
Object.defineProperty(v, "__esModule", { value: true });
|
|
30
|
+
});
|
|
31
|
+
var G = B((D) => {
|
|
32
|
+
Object.defineProperty(D, "__esModule", { value: true });
|
|
33
|
+
var d = Symbol("inverted"), i = Symbol("expectNull"), o = Symbol("expectUndefined"), y = Symbol("expectNumber"), h = Symbol("expectString"), t = Symbol("expectBoolean"), k = Symbol("expectVoid"), a = Symbol("expectFunction"), O = Symbol("expectObject"), x = Symbol("expectArray"), r = Symbol("expectSymbol"), T = Symbol("expectAny"), s = Symbol("expectUnknown"), e = Symbol("expectNever"), f = Symbol("expectNullable"), p = Symbol("expectBigInt");
|
|
34
|
+
});
|
|
35
|
+
var J = B((H) => {
|
|
36
|
+
Object.defineProperty(H, "__esModule", { value: true });
|
|
37
|
+
});
|
|
38
|
+
var L = B((K) => {
|
|
39
|
+
Object.defineProperty(K, "__esModule", { value: true });
|
|
40
|
+
var lb = Symbol("secret"), Sb = Symbol("mismatch"), cb = Symbol("avalue");
|
|
41
|
+
});
|
|
42
|
+
var M = B((c) => {
|
|
43
|
+
var n = c && c.__createBinding || (Object.create ? function(l, u, U, j) {
|
|
44
|
+
if (j === undefined)
|
|
45
|
+
j = U;
|
|
46
|
+
var A = Object.getOwnPropertyDescriptor(u, U);
|
|
47
|
+
if (!A || ("get" in A ? !u.__esModule : A.writable || A.configurable))
|
|
48
|
+
A = { enumerable: true, get: function() {
|
|
49
|
+
return u[U];
|
|
50
|
+
} };
|
|
51
|
+
Object.defineProperty(l, j, A);
|
|
52
|
+
} : function(l, u, U, j) {
|
|
53
|
+
if (j === undefined)
|
|
54
|
+
j = U;
|
|
55
|
+
l[j] = u[U];
|
|
56
|
+
}), w = c && c.__exportStar || function(l, u) {
|
|
57
|
+
for (var U in l)
|
|
58
|
+
if (U !== "default" && !Object.prototype.hasOwnProperty.call(u, U))
|
|
59
|
+
n(u, l, U);
|
|
60
|
+
};
|
|
61
|
+
Object.defineProperty(c, "__esModule", { value: true });
|
|
62
|
+
c.expectTypeOf = undefined;
|
|
63
|
+
w(C(), c);
|
|
64
|
+
w(G(), c);
|
|
65
|
+
w(J(), c);
|
|
66
|
+
w(L(), c);
|
|
67
|
+
var N = () => true, q = (l) => {
|
|
68
|
+
let u = ["parameters", "returns", "resolves", "not", "items", "constructorParameters", "thisParameter", "instance", "guards", "asserts", "branded"], U = { toBeAny: N, toBeUnknown: N, toBeNever: N, toBeFunction: N, toBeObject: N, toBeArray: N, toBeString: N, toBeNumber: N, toBeBoolean: N, toBeVoid: N, toBeSymbol: N, toBeNull: N, toBeUndefined: N, toBeNullable: N, toBeBigInt: N, toMatchTypeOf: N, toEqualTypeOf: N, toBeConstructibleWith: N, toMatchObjectType: N, toExtend: N, map: c.expectTypeOf, toBeCallableWith: c.expectTypeOf, extract: c.expectTypeOf, exclude: c.expectTypeOf, pick: c.expectTypeOf, omit: c.expectTypeOf, toHaveProperty: c.expectTypeOf, parameter: c.expectTypeOf };
|
|
69
|
+
return u.forEach((A) => Object.defineProperty(U, A, { get: () => (0, c.expectTypeOf)({}) })), U;
|
|
70
|
+
};
|
|
71
|
+
c.expectTypeOf = q;
|
|
72
|
+
});
|
|
73
|
+
var S = $(M(), 1);
|
|
74
|
+
var jb = { initialize: { params: b.object({ protocolVersion: b.string(), capabilities: b.any(), clientInfo: b.any() }), result: b.object({ protocolVersion: b.string(), capabilities: b.any(), serverInfo: b.any() }) }, ping: { params: b.object({}), result: b.object({}) }, prompts: { list: { params: b.object({ cursor: b.string().optional() }), result: b.object({ prompts: b.array(b.object({ name: b.string(), description: b.string().optional(), arguments: b.array(b.object({ name: b.string(), description: b.string().optional(), required: b.boolean().optional() })).optional() })), nextCursor: b.string().optional() }), description: "" }, get: { params: b.object({ name: b.string(), arguments: b.record(b.string(), b.string()).optional() }), result: b.object({ description: b.string().optional(), messages: b.array(b.object({ role: b.enum(["user", "assistant"]), content: b.object({ type: b.literal("text"), text: b.string() }) })) }) } }, resources: { list: { params: b.object({ cursor: b.string().optional() }), result: b.object({ resources: b.array(b.object({ uri: b.string(), name: b.string(), description: b.string().optional(), mimeType: b.string().optional() })), nextCursor: b.string().optional() }) }, read: { params: b.object({ uri: b.string() }), result: b.object({ contents: b.array(b.object({ uri: b.string(), mimeType: b.string().optional(), text: b.string().optional(), blob: b.string().optional() })) }) }, subscribe: { params: b.object({ uri: b.string() }), result: b.object({}) }, templates: { list: { params: b.object({ cursor: b.string().optional() }), result: b.object({ resourceTemplates: b.array(b.object({ uriTemplate: b.string(), name: b.string(), description: b.string().optional(), mimeType: b.string().optional() })), nextCursor: b.string().optional() }) } } }, tools: { list: { params: b.object({ cursor: b.string().optional() }), result: b.object({ tools: b.array(b.object({ name: b.string(), description: b.string().optional(), inputSchema: b.object({ type: b.literal("object"), properties: b.record(b.string(), b.any()).optional(), required: b.array(b.string()).optional() }) })), nextCursor: b.string().optional() }) }, call: { params: b.object({ name: b.string(), arguments: b.record(b.string(), b.any()).optional() }), result: b.object({ content: b.array(b.object({ type: b.enum(["text", "image", "resource"]), text: b.string().optional(), data: b.string().optional(), mimeType: b.string().optional() })), isError: b.boolean().optional() }) } }, notifications: { "prompts/list_changed": null, "resources/list_changed": null, "resources/updated": null, "tools/list_changed": null, cancelled: null } };
|
|
75
|
+
|
|
76
|
+
class _ extends Error {
|
|
77
|
+
args;
|
|
78
|
+
constructor(l, u) {
|
|
79
|
+
super(`MCPError: ${l} with args ${u || {}}`);
|
|
80
|
+
this.args = u;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
84
|
+
S.expectTypeOf().not.toEqualTypeOf();
|
|
85
|
+
S.expectTypeOf().not.toEqualTypeOf();
|
|
86
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
87
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
88
|
+
S.expectTypeOf({ a: 1, b: 1 }).toMatchObjectType();
|
|
89
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
90
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
91
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
92
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
93
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
94
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
95
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
96
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
97
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
98
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
99
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
100
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
101
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
102
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
103
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
104
|
+
S.expectTypeOf().toEqualTypeOf();
|
|
105
|
+
// ../elysia-jsonrpc/dist/rpc.types.js
|
|
106
|
+
import k from "zod/v4";
|
|
107
|
+
var _2 = "2.0";
|
|
108
|
+
var q = "1.3.2";
|
|
109
|
+
var A = k.string();
|
|
110
|
+
var n = k.enum([_2]);
|
|
111
|
+
var m2 = k.enum([q]);
|
|
112
|
+
var G2 = k.union([k.string(), k.number(), k.null()]);
|
|
113
|
+
var U = k.union([k.array(k.unknown()), k.record(k.any(), k.unknown())]).optional();
|
|
114
|
+
var b2 = k.object({ code: k.number().int(), message: k.string(), data: k.unknown().optional() });
|
|
115
|
+
var W2 = k.object({ jsonrpc: A, method: k.string(), params: U, id: G2 });
|
|
116
|
+
var H = k.object({ jsonrpc: A, method: k.string(), params: U });
|
|
117
|
+
var f = k.unknown();
|
|
118
|
+
var j = k.object({ jsonrpc: A, result: f, id: G2 });
|
|
119
|
+
var D = k.object({ jsonrpc: A, error: b2, id: G2 });
|
|
120
|
+
var X2 = k.union([j, D]);
|
|
121
|
+
var P2 = k.union([W2, H, X2]);
|
|
122
|
+
var C2 = k.union([W2, H]);
|
|
123
|
+
var a = k.union([X2, H]);
|
|
124
|
+
var O = { ParseError: -32700, InvalidRequest: -32600, MethodNotFound: -32601, InvalidParams: -32602, InternalError: -32603 };
|
|
125
|
+
var u = k.object({ name: k.string().optional(), url: k.url().optional(), email: k.email().optional() });
|
|
126
|
+
var E = k.object({ name: k.string(), url: k.url().optional() });
|
|
127
|
+
var I = k.object({ title: k.string(), version: k.string(), description: k.string().optional(), termsOfService: k.string().optional(), contact: u.optional(), license: E.optional() });
|
|
128
|
+
var Y2 = k.object({ name: k.string(), url: k.string(), summary: k.string().optional(), description: k.string().optional(), variables: k.record(k.string(), k.any()).optional() });
|
|
129
|
+
var F = k.object({ name: k.string(), summary: k.string().optional(), description: k.string().optional(), required: k.boolean().optional(), schema: k.any(), deprecated: k.boolean().optional() });
|
|
130
|
+
var d = k.object({ name: k.string(), tags: k.array(k.object({ name: k.string(), description: k.string().optional() })).optional(), summary: k.string().optional(), description: k.string().optional(), externalDocs: k.object({ description: k.string().optional(), url: k.string() }).optional(), params: k.array(F).optional(), result: F, deprecated: k.boolean().optional(), servers: k.array(Y2).optional(), errors: k.array(k.any()).optional(), links: k.array(k.any()).optional(), examples: k.array(k.any()).optional(), paramStructure: k.enum(["by-name", "by-position", "either"]).optional() });
|
|
131
|
+
var p = k.object({ $ref: k.string() });
|
|
132
|
+
var r = k.object({ schemas: k.record(k.string(), k.any()).optional(), links: k.record(k.string(), k.any()).optional(), errors: k.record(k.string(), k.any()).optional(), examples: k.record(k.string(), k.any()).optional(), examplePairings: k.record(k.string(), k.any()).optional(), contentDescriptors: k.record(k.string(), F).optional(), tags: k.record(k.string(), k.any()).optional() });
|
|
133
|
+
var s = k.object({ description: k.string().optional(), url: k.string() });
|
|
134
|
+
var R2 = k.object({ openrpc: k.string(), info: I, servers: k.array(Y2).optional(), methods: k.array(k.union([d, p])), components: r.optional(), externalDocs: s.optional() });
|
|
135
|
+
|
|
136
|
+
class i extends Error {
|
|
137
|
+
code;
|
|
138
|
+
message;
|
|
139
|
+
originalError;
|
|
140
|
+
constructor(v, w, y) {
|
|
141
|
+
super(`JSONRPCException ${v}: ${w}`);
|
|
142
|
+
this.code = v;
|
|
143
|
+
this.message = w;
|
|
144
|
+
this.originalError = y;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
// ../elysia-jsonrpc/dist/index.js
|
|
148
|
+
import G3 from "zod/v4";
|
|
149
|
+
import g, { InvertedStatusMap as jG, sse as q2, StatusMap as DG } from "elysia";
|
|
150
|
+
var B2 = "2.0";
|
|
151
|
+
var I2 = "1.3.2";
|
|
152
|
+
var j2 = G3.string();
|
|
153
|
+
var b3 = G3.enum([B2]);
|
|
154
|
+
var AG = G3.enum([I2]);
|
|
155
|
+
var _3 = G3.union([G3.string(), G3.number(), G3.null()]);
|
|
156
|
+
var D2 = G3.union([G3.array(G3.unknown()), G3.record(G3.any(), G3.unknown())]).optional();
|
|
157
|
+
var n2 = G3.object({ code: G3.number().int(), message: G3.string(), data: G3.unknown().optional() });
|
|
158
|
+
var V = G3.object({ jsonrpc: j2, method: G3.string(), params: D2, id: _3 });
|
|
159
|
+
var M2 = G3.object({ jsonrpc: j2, method: G3.string(), params: D2 });
|
|
160
|
+
var i2 = G3.unknown();
|
|
161
|
+
var R3 = G3.object({ jsonrpc: j2, result: i2, id: _3 });
|
|
162
|
+
var S2 = G3.object({ jsonrpc: j2, error: n2, id: _3 });
|
|
163
|
+
var v = G3.union([R3, S2]);
|
|
164
|
+
var LG = G3.union([V, M2, v]);
|
|
165
|
+
var UG = G3.union([V, M2]);
|
|
166
|
+
var kG = G3.union([v, M2]);
|
|
167
|
+
var w = { ParseError: -32700, InvalidRequest: -32600, MethodNotFound: -32601, InvalidParams: -32602, InternalError: -32603 };
|
|
168
|
+
var c = G3.object({ name: G3.string().optional(), url: G3.url().optional(), email: G3.email().optional() });
|
|
169
|
+
var p2 = G3.object({ name: G3.string(), url: G3.url().optional() });
|
|
170
|
+
var d2 = G3.object({ title: G3.string(), version: G3.string(), description: G3.string().optional(), termsOfService: G3.string().optional(), contact: c.optional(), license: p2.optional() });
|
|
171
|
+
var l = G3.object({ name: G3.string(), url: G3.string(), summary: G3.string().optional(), description: G3.string().optional(), variables: G3.record(G3.string(), G3.any()).optional() });
|
|
172
|
+
var x = G3.object({ name: G3.string(), summary: G3.string().optional(), description: G3.string().optional(), required: G3.boolean().optional(), schema: G3.any(), deprecated: G3.boolean().optional() });
|
|
173
|
+
var a2 = G3.object({ name: G3.string(), tags: G3.array(G3.object({ name: G3.string(), description: G3.string().optional() })).optional(), summary: G3.string().optional(), description: G3.string().optional(), externalDocs: G3.object({ description: G3.string().optional(), url: G3.string() }).optional(), params: G3.array(x).optional(), result: x, deprecated: G3.boolean().optional(), servers: G3.array(l).optional(), errors: G3.array(G3.any()).optional(), links: G3.array(G3.any()).optional(), examples: G3.array(G3.any()).optional(), paramStructure: G3.enum(["by-name", "by-position", "either"]).optional() });
|
|
174
|
+
var s2 = G3.object({ $ref: G3.string() });
|
|
175
|
+
var o = G3.object({ schemas: G3.record(G3.string(), G3.any()).optional(), links: G3.record(G3.string(), G3.any()).optional(), errors: G3.record(G3.string(), G3.any()).optional(), examples: G3.record(G3.string(), G3.any()).optional(), examplePairings: G3.record(G3.string(), G3.any()).optional(), contentDescriptors: G3.record(G3.string(), x).optional(), tags: G3.record(G3.string(), G3.any()).optional() });
|
|
176
|
+
var t = G3.object({ description: G3.string().optional(), url: G3.string() });
|
|
177
|
+
var HG = G3.object({ openrpc: G3.string(), info: d2, servers: G3.array(l).optional(), methods: G3.array(G3.union([a2, s2])), components: o.optional(), externalDocs: t.optional() });
|
|
178
|
+
|
|
179
|
+
class z extends Error {
|
|
180
|
+
code;
|
|
181
|
+
message;
|
|
182
|
+
originalError;
|
|
183
|
+
constructor(Q2, K, Z2) {
|
|
184
|
+
super(`JSONRPCException ${Q2}: ${K}`);
|
|
185
|
+
this.code = Q2;
|
|
186
|
+
this.message = K;
|
|
187
|
+
this.originalError = Z2;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
var r2 = { version: B2, debug: false, dns_rebind_origin: undefined, rpcHandler: e, onError: undefined, onResponse: undefined, onRequest: undefined, service: null, cors: "*" };
|
|
191
|
+
async function e(Q2, K, Z2) {
|
|
192
|
+
let A2 = J2(Q2, Z2.method), L2 = GG(Z2.params), U2 = await A2.apply(Q2, [L2]);
|
|
193
|
+
return { id: K, jsonrpc: "2.0", result: U2 };
|
|
194
|
+
}
|
|
195
|
+
function J2(Q2, K) {
|
|
196
|
+
if (!Q2)
|
|
197
|
+
throw new z(w.MethodNotFound, "Invalid Method");
|
|
198
|
+
let Z2 = Q2[K];
|
|
199
|
+
if (!Z2) {
|
|
200
|
+
let A2 = K.split("/");
|
|
201
|
+
if (A2.length > 1)
|
|
202
|
+
return J2(Q2[A2[0]], A2.slice(1).join("/"));
|
|
203
|
+
throw new z(w.MethodNotFound, "Method not found");
|
|
204
|
+
}
|
|
205
|
+
return Z2;
|
|
206
|
+
}
|
|
207
|
+
function y(Q2) {
|
|
208
|
+
let K = b3.safeParse(Q2);
|
|
209
|
+
if (!K.success)
|
|
210
|
+
throw new z(w.InvalidRequest, "Invalid JSON RPC Version");
|
|
211
|
+
return K.success;
|
|
212
|
+
}
|
|
213
|
+
function GG(Q2) {
|
|
214
|
+
let K = D2.safeParse(Q2);
|
|
215
|
+
if (!K.success)
|
|
216
|
+
throw new z(w.InvalidParams, "Invalid Params");
|
|
217
|
+
return K.data;
|
|
218
|
+
}
|
|
219
|
+
function KG(Q2) {
|
|
220
|
+
try {
|
|
221
|
+
let K = typeof Q2 === "string" ? JSON.parse(Q2) : Q2;
|
|
222
|
+
if (typeof Q2 == "object")
|
|
223
|
+
return K;
|
|
224
|
+
throw new z(w.ParseError, "body is not an object");
|
|
225
|
+
} catch (K) {
|
|
226
|
+
throw new z(w.ParseError, "failed json parse", K);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
function E2(Q2, K, Z2 = false) {
|
|
230
|
+
return { id: Q2, jsonrpc: "2.0", error: { code: K?.code || w.InvalidRequest, message: K?.message || "InvalidRequest", data: Z2 && K ? K.originalError ?? {} : undefined } };
|
|
231
|
+
}
|
|
232
|
+
function QG(Q2) {
|
|
233
|
+
let K = { ...r2, ...Q2 }, Z2 = async function(X3) {
|
|
234
|
+
let $2 = null;
|
|
235
|
+
try {
|
|
236
|
+
let W3 = V.safeParse(X3), Y3 = M2.safeParse(X3 || {});
|
|
237
|
+
if (W3.success) {
|
|
238
|
+
y(W3.data.jsonrpc), $2 = W3.data?.id;
|
|
239
|
+
try {
|
|
240
|
+
if (K.onRequest)
|
|
241
|
+
K.onRequest(W3.data);
|
|
242
|
+
} catch (T) {}
|
|
243
|
+
return await K.rpcHandler(K.service, $2, W3.data);
|
|
244
|
+
} else if (Y3.success) {
|
|
245
|
+
y(Y3.data.jsonrpc);
|
|
246
|
+
try {
|
|
247
|
+
if (K.onRequest)
|
|
248
|
+
K.onRequest(Y3.data);
|
|
249
|
+
} catch (H2) {}
|
|
250
|
+
} else
|
|
251
|
+
throw new z(w.InvalidRequest, "Invalid Request", W3.error);
|
|
252
|
+
} catch (W3) {
|
|
253
|
+
let Y3 = E2($2, W3, K.debug);
|
|
254
|
+
try {
|
|
255
|
+
if (K.onError)
|
|
256
|
+
K.onError(Y3);
|
|
257
|
+
} catch (H2) {}
|
|
258
|
+
return Y3;
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
function A2() {
|
|
262
|
+
return function(X3) {
|
|
263
|
+
return X3;
|
|
264
|
+
};
|
|
265
|
+
}
|
|
266
|
+
let L2 = async function({ body: X3, set: $2 }) {
|
|
267
|
+
$2.headers["Content-Type"] = "application/json";
|
|
268
|
+
try {
|
|
269
|
+
let W3 = KG(X3);
|
|
270
|
+
if (Array.isArray(W3)) {
|
|
271
|
+
let Y3 = [];
|
|
272
|
+
if (W3.length == 0)
|
|
273
|
+
throw new z(w.InvalidRequest, "Batch empty");
|
|
274
|
+
for (let H2 of W3) {
|
|
275
|
+
let T = await Z2(H2);
|
|
276
|
+
try {
|
|
277
|
+
if (T && K.onResponse)
|
|
278
|
+
K.onResponse(T);
|
|
279
|
+
} catch (YG) {}
|
|
280
|
+
if (T)
|
|
281
|
+
Y3.push(T);
|
|
282
|
+
}
|
|
283
|
+
return Y3;
|
|
284
|
+
} else {
|
|
285
|
+
let Y3 = await Z2(W3);
|
|
286
|
+
try {
|
|
287
|
+
if (Y3 && K.onResponse)
|
|
288
|
+
K.onResponse(Y3);
|
|
289
|
+
} catch (H2) {}
|
|
290
|
+
return Y3;
|
|
291
|
+
}
|
|
292
|
+
} catch (W3) {
|
|
293
|
+
let Y3 = E2(null, W3, K.debug);
|
|
294
|
+
try {
|
|
295
|
+
if (K.onError)
|
|
296
|
+
K.onError(Y3);
|
|
297
|
+
} catch (H2) {}
|
|
298
|
+
return Y3;
|
|
299
|
+
}
|
|
300
|
+
}, U2 = new g().options("sse", async ({ set: X3 }) => {
|
|
301
|
+
X3.headers.Allow = ["GET", "POST", "OPTIONS"].join(",");
|
|
302
|
+
}).get("sse", async function* ({ set: X3 }) {
|
|
303
|
+
X3.headers["Content-Type"] = "text/event-stream";
|
|
304
|
+
for await (let $2 of [])
|
|
305
|
+
yield q2({ data: $2, event: "message" });
|
|
306
|
+
yield q2({ event: "done" });
|
|
307
|
+
}).post("sse", ({ body: X3 }) => {}), k2 = new g().options("stream", async ({ set: X3, status: $2 }) => {
|
|
308
|
+
X3.headers.Allow = ["POST", "OPTIONS"].join(",");
|
|
309
|
+
}).post("stream", L2, {}), F2 = new g().get("/openrpc.json", async ({}) => {
|
|
310
|
+
let X3 = Object.getPrototypeOf(K.service), $2 = Object.getOwnPropertyNames(X3).filter((W3) => W3 !== "constructor" && typeof K.service[W3] === "function");
|
|
311
|
+
return { openrpc: I2, info: { title: K.title || "JSON RPC Server", version: K.version }, methods: $2.map((W3) => {
|
|
312
|
+
return { name: W3, params: [], result: { name: "", schema: "" } };
|
|
313
|
+
}) };
|
|
314
|
+
});
|
|
315
|
+
return new g({ name: "jsonRPC" }).onRequest(({ request: X3, status: $2 }) => {
|
|
316
|
+
if (K.dns_rebind_origin !== undefined) {
|
|
317
|
+
if (X3.headers.get("Origin") != K.dns_rebind_origin)
|
|
318
|
+
return $2(400, "Wrong domain");
|
|
319
|
+
}
|
|
320
|
+
}).use(U2).use(k2).use(F2);
|
|
321
|
+
}
|
|
322
|
+
|
|
323
|
+
// src/types.ts
|
|
324
|
+
function InputSchemaFromParameters(params) {
|
|
325
|
+
return {
|
|
326
|
+
type: "object",
|
|
327
|
+
properties: Object.fromEntries(Object.entries(params).map(([k2, v2]) => [
|
|
328
|
+
v2.name,
|
|
329
|
+
{
|
|
330
|
+
description: v2.description,
|
|
331
|
+
type: v2.type,
|
|
332
|
+
default: v2.default
|
|
333
|
+
}
|
|
334
|
+
])),
|
|
335
|
+
required: Object.entries(params).map(([k2, v2]) => v2.required ? k2 : undefined).filter((v2) => v2 !== undefined)
|
|
336
|
+
};
|
|
337
|
+
}
|
|
338
|
+
function ToolArgsToParameterList(toolArgs, params) {
|
|
339
|
+
let res = [];
|
|
340
|
+
for (const param of params) {
|
|
341
|
+
res.push(toolArgs[param.name] ?? param.default ?? undefined);
|
|
342
|
+
}
|
|
343
|
+
return res;
|
|
344
|
+
}
|
|
345
|
+
function ToolDefinition(methodName, methodDescription, params) {
|
|
346
|
+
return (callback) => {
|
|
347
|
+
return {
|
|
348
|
+
name: methodName,
|
|
349
|
+
description: methodDescription,
|
|
350
|
+
params,
|
|
351
|
+
callback
|
|
352
|
+
};
|
|
353
|
+
};
|
|
354
|
+
}
|
|
355
|
+
|
|
356
|
+
// src/index.ts
|
|
357
|
+
class MCPServerService {
|
|
358
|
+
serverTitle;
|
|
359
|
+
serverVersion;
|
|
360
|
+
serverInstructions;
|
|
361
|
+
getReferenceInstanceForToolCall;
|
|
362
|
+
toolsets;
|
|
363
|
+
constructor(serverTitle, serverVersion, serverInstructions, getReferenceInstanceForToolCall, toolsets) {
|
|
364
|
+
this.serverTitle = serverTitle;
|
|
365
|
+
this.serverVersion = serverVersion;
|
|
366
|
+
this.serverInstructions = serverInstructions;
|
|
367
|
+
this.getReferenceInstanceForToolCall = getReferenceInstanceForToolCall;
|
|
368
|
+
this.toolsets = toolsets;
|
|
369
|
+
}
|
|
370
|
+
initialize(params) {
|
|
371
|
+
return Promise.resolve({
|
|
372
|
+
capabilities: {
|
|
373
|
+
tools: {}
|
|
374
|
+
},
|
|
375
|
+
serverInfo: {
|
|
376
|
+
name: this.serverTitle,
|
|
377
|
+
version: this.serverVersion
|
|
378
|
+
},
|
|
379
|
+
protocolVersion: "2025-11-25",
|
|
380
|
+
instructions: this.serverInstructions
|
|
381
|
+
});
|
|
382
|
+
}
|
|
383
|
+
ping(params) {
|
|
384
|
+
return Promise.resolve({});
|
|
385
|
+
}
|
|
386
|
+
"tools/list"(params) {
|
|
387
|
+
return Promise.resolve({
|
|
388
|
+
tools: this.toolsets.flatMap((toolset) => {
|
|
389
|
+
return toolset.getTools().map((tool) => {
|
|
390
|
+
return {
|
|
391
|
+
name: tool.name,
|
|
392
|
+
description: tool.description,
|
|
393
|
+
inputSchema: InputSchemaFromParameters(tool.params)
|
|
394
|
+
};
|
|
395
|
+
});
|
|
396
|
+
})
|
|
397
|
+
});
|
|
398
|
+
}
|
|
399
|
+
getTool(toolName) {
|
|
400
|
+
for (const toolset of this.toolsets) {
|
|
401
|
+
const maybeTool = toolset.getTool(toolName);
|
|
402
|
+
if (maybeTool)
|
|
403
|
+
return maybeTool;
|
|
404
|
+
}
|
|
405
|
+
return null;
|
|
406
|
+
}
|
|
407
|
+
async "tools/call"(params) {
|
|
408
|
+
const toolName = params.name;
|
|
409
|
+
const toolArgs = params.arguments || {};
|
|
410
|
+
const tool = this.getTool(toolName);
|
|
411
|
+
if (!tool)
|
|
412
|
+
throw new _("Tool not found!", { toolName });
|
|
413
|
+
const referenceInstance = this.getReferenceInstanceForToolCall(toolName);
|
|
414
|
+
const result = await tool.callback(referenceInstance, ...ToolArgsToParameterList(toolArgs, tool.params), {});
|
|
415
|
+
return ((result2) => {
|
|
416
|
+
return {
|
|
417
|
+
toolUseId: "",
|
|
418
|
+
content: result2.content,
|
|
419
|
+
type: "tool_result",
|
|
420
|
+
isError: result2.isError || false
|
|
421
|
+
};
|
|
422
|
+
})(result);
|
|
423
|
+
}
|
|
424
|
+
"prompts/list"(params) {
|
|
425
|
+
throw new Error("Method not implemented.");
|
|
426
|
+
}
|
|
427
|
+
"prompts/get"(params) {
|
|
428
|
+
throw new Error("Method not implemented.");
|
|
429
|
+
}
|
|
430
|
+
"resources/list"(params) {
|
|
431
|
+
throw new Error("Method not implemented.");
|
|
432
|
+
}
|
|
433
|
+
"resources/read"(params) {
|
|
434
|
+
throw new Error("Method not implemented.");
|
|
435
|
+
}
|
|
436
|
+
"resources/subscribe"(params) {
|
|
437
|
+
throw new Error("Method not implemented.");
|
|
438
|
+
}
|
|
439
|
+
"resources/templates/list"(params) {
|
|
440
|
+
throw new Error("Method not implemented.");
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
export {
|
|
444
|
+
QG as elysiaJsonRPC,
|
|
445
|
+
MCPServerService
|
|
446
|
+
};
|