mcp-remote 0.0.4 → 0.0.5-0
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/README.md +2 -2
- package/dist/chunk-66WA4K4A.js +547 -0
- package/dist/chunk-QD25LZNI.js +5575 -0
- package/dist/{chunk-GEWYQKIG.js → chunk-SJP4QJO2.js} +6 -72
- package/dist/{client.js → cli/client.js} +11 -6
- package/dist/cli/proxy.js +218 -0
- package/dist/react/index.js +571 -0
- package/package.json +12 -3
- package/dist/client.d.ts +0 -1
- package/dist/proxy.d.ts +0 -1
- package/dist/proxy.js +0 -54
package/README.md
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# `mcp-remote`
|
|
2
2
|
|
|
3
|
-
**EXPERIMENTAL PROOF OF CONCEPT**
|
|
4
|
-
|
|
5
3
|
Connect an MCP Client that only supports local (stdio) servers to a Remote MCP Server, with auth support:
|
|
6
4
|
|
|
5
|
+
**Note: this is a working proof-of-concept** but should be considered **experimental**
|
|
6
|
+
|
|
7
7
|
E.g: Claude Desktop or Windsurf
|
|
8
8
|
|
|
9
9
|
```json
|
|
@@ -0,0 +1,547 @@
|
|
|
1
|
+
import {
|
|
2
|
+
CallToolResultSchema,
|
|
3
|
+
CancelledNotificationSchema,
|
|
4
|
+
CompleteResultSchema,
|
|
5
|
+
EmptyResultSchema,
|
|
6
|
+
ErrorCode,
|
|
7
|
+
GetPromptResultSchema,
|
|
8
|
+
InitializeResultSchema,
|
|
9
|
+
LATEST_PROTOCOL_VERSION,
|
|
10
|
+
ListPromptsResultSchema,
|
|
11
|
+
ListResourceTemplatesResultSchema,
|
|
12
|
+
ListResourcesResultSchema,
|
|
13
|
+
ListToolsResultSchema,
|
|
14
|
+
McpError,
|
|
15
|
+
PingRequestSchema,
|
|
16
|
+
ProgressNotificationSchema,
|
|
17
|
+
ReadResourceResultSchema,
|
|
18
|
+
SUPPORTED_PROTOCOL_VERSIONS
|
|
19
|
+
} from "./chunk-QD25LZNI.js";
|
|
20
|
+
|
|
21
|
+
// ../../hax/mcp/typescript-sdk/dist/esm/shared/protocol.js
|
|
22
|
+
var DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4;
|
|
23
|
+
var Protocol = class {
|
|
24
|
+
constructor(_options) {
|
|
25
|
+
this._options = _options;
|
|
26
|
+
this._requestMessageId = 0;
|
|
27
|
+
this._requestHandlers = /* @__PURE__ */ new Map();
|
|
28
|
+
this._requestHandlerAbortControllers = /* @__PURE__ */ new Map();
|
|
29
|
+
this._notificationHandlers = /* @__PURE__ */ new Map();
|
|
30
|
+
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
31
|
+
this._progressHandlers = /* @__PURE__ */ new Map();
|
|
32
|
+
this._timeoutInfo = /* @__PURE__ */ new Map();
|
|
33
|
+
this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
|
|
34
|
+
const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
|
|
35
|
+
controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
|
|
36
|
+
});
|
|
37
|
+
this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
|
|
38
|
+
this._onprogress(notification);
|
|
39
|
+
});
|
|
40
|
+
this.setRequestHandler(
|
|
41
|
+
PingRequestSchema,
|
|
42
|
+
// Automatic pong by default.
|
|
43
|
+
(_request) => ({})
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
_setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout) {
|
|
47
|
+
this._timeoutInfo.set(messageId, {
|
|
48
|
+
timeoutId: setTimeout(onTimeout, timeout),
|
|
49
|
+
startTime: Date.now(),
|
|
50
|
+
timeout,
|
|
51
|
+
maxTotalTimeout,
|
|
52
|
+
onTimeout
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
_resetTimeout(messageId) {
|
|
56
|
+
const info = this._timeoutInfo.get(messageId);
|
|
57
|
+
if (!info)
|
|
58
|
+
return false;
|
|
59
|
+
const totalElapsed = Date.now() - info.startTime;
|
|
60
|
+
if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
|
|
61
|
+
this._timeoutInfo.delete(messageId);
|
|
62
|
+
throw new McpError(ErrorCode.RequestTimeout, "Maximum total timeout exceeded", { maxTotalTimeout: info.maxTotalTimeout, totalElapsed });
|
|
63
|
+
}
|
|
64
|
+
clearTimeout(info.timeoutId);
|
|
65
|
+
info.timeoutId = setTimeout(info.onTimeout, info.timeout);
|
|
66
|
+
return true;
|
|
67
|
+
}
|
|
68
|
+
_cleanupTimeout(messageId) {
|
|
69
|
+
const info = this._timeoutInfo.get(messageId);
|
|
70
|
+
if (info) {
|
|
71
|
+
clearTimeout(info.timeoutId);
|
|
72
|
+
this._timeoutInfo.delete(messageId);
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Attaches to the given transport, starts it, and starts listening for messages.
|
|
77
|
+
*
|
|
78
|
+
* The Protocol object assumes ownership of the Transport, replacing any callbacks that have already been set, and expects that it is the only user of the Transport instance going forward.
|
|
79
|
+
*/
|
|
80
|
+
async connect(transport) {
|
|
81
|
+
this._transport = transport;
|
|
82
|
+
this._transport.onclose = () => {
|
|
83
|
+
this._onclose();
|
|
84
|
+
};
|
|
85
|
+
this._transport.onerror = (error) => {
|
|
86
|
+
this._onerror(error);
|
|
87
|
+
};
|
|
88
|
+
this._transport.onmessage = (message) => {
|
|
89
|
+
if (!("method" in message)) {
|
|
90
|
+
this._onresponse(message);
|
|
91
|
+
} else if ("id" in message) {
|
|
92
|
+
this._onrequest(message);
|
|
93
|
+
} else {
|
|
94
|
+
this._onnotification(message);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
await this._transport.start();
|
|
98
|
+
}
|
|
99
|
+
_onclose() {
|
|
100
|
+
var _a;
|
|
101
|
+
const responseHandlers = this._responseHandlers;
|
|
102
|
+
this._responseHandlers = /* @__PURE__ */ new Map();
|
|
103
|
+
this._progressHandlers.clear();
|
|
104
|
+
this._transport = void 0;
|
|
105
|
+
(_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
|
|
106
|
+
const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
|
|
107
|
+
for (const handler of responseHandlers.values()) {
|
|
108
|
+
handler(error);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
_onerror(error) {
|
|
112
|
+
var _a;
|
|
113
|
+
(_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
|
|
114
|
+
}
|
|
115
|
+
_onnotification(notification) {
|
|
116
|
+
var _a;
|
|
117
|
+
const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler;
|
|
118
|
+
if (handler === void 0) {
|
|
119
|
+
return;
|
|
120
|
+
}
|
|
121
|
+
Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
|
|
122
|
+
}
|
|
123
|
+
_onrequest(request) {
|
|
124
|
+
var _a, _b, _c;
|
|
125
|
+
const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
|
|
126
|
+
if (handler === void 0) {
|
|
127
|
+
(_b = this._transport) === null || _b === void 0 ? void 0 : _b.send({
|
|
128
|
+
jsonrpc: "2.0",
|
|
129
|
+
id: request.id,
|
|
130
|
+
error: {
|
|
131
|
+
code: ErrorCode.MethodNotFound,
|
|
132
|
+
message: "Method not found"
|
|
133
|
+
}
|
|
134
|
+
}).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
const abortController = new AbortController();
|
|
138
|
+
this._requestHandlerAbortControllers.set(request.id, abortController);
|
|
139
|
+
const extra = {
|
|
140
|
+
signal: abortController.signal,
|
|
141
|
+
sessionId: (_c = this._transport) === null || _c === void 0 ? void 0 : _c.sessionId
|
|
142
|
+
};
|
|
143
|
+
Promise.resolve().then(() => handler(request, extra)).then((result) => {
|
|
144
|
+
var _a2;
|
|
145
|
+
if (abortController.signal.aborted) {
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
|
|
149
|
+
result,
|
|
150
|
+
jsonrpc: "2.0",
|
|
151
|
+
id: request.id
|
|
152
|
+
});
|
|
153
|
+
}, (error) => {
|
|
154
|
+
var _a2, _b2;
|
|
155
|
+
if (abortController.signal.aborted) {
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
|
|
159
|
+
jsonrpc: "2.0",
|
|
160
|
+
id: request.id,
|
|
161
|
+
error: {
|
|
162
|
+
code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
|
|
163
|
+
message: (_b2 = error.message) !== null && _b2 !== void 0 ? _b2 : "Internal error"
|
|
164
|
+
}
|
|
165
|
+
});
|
|
166
|
+
}).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
|
|
167
|
+
this._requestHandlerAbortControllers.delete(request.id);
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
_onprogress(notification) {
|
|
171
|
+
const { progressToken, ...params } = notification.params;
|
|
172
|
+
const messageId = Number(progressToken);
|
|
173
|
+
const handler = this._progressHandlers.get(messageId);
|
|
174
|
+
if (!handler) {
|
|
175
|
+
this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
|
|
176
|
+
return;
|
|
177
|
+
}
|
|
178
|
+
const responseHandler = this._responseHandlers.get(messageId);
|
|
179
|
+
if (this._timeoutInfo.has(messageId) && responseHandler) {
|
|
180
|
+
try {
|
|
181
|
+
this._resetTimeout(messageId);
|
|
182
|
+
} catch (error) {
|
|
183
|
+
responseHandler(error);
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
handler(params);
|
|
188
|
+
}
|
|
189
|
+
_onresponse(response) {
|
|
190
|
+
const messageId = Number(response.id);
|
|
191
|
+
const handler = this._responseHandlers.get(messageId);
|
|
192
|
+
if (handler === void 0) {
|
|
193
|
+
this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
this._responseHandlers.delete(messageId);
|
|
197
|
+
this._progressHandlers.delete(messageId);
|
|
198
|
+
this._cleanupTimeout(messageId);
|
|
199
|
+
if ("result" in response) {
|
|
200
|
+
handler(response);
|
|
201
|
+
} else {
|
|
202
|
+
const error = new McpError(response.error.code, response.error.message, response.error.data);
|
|
203
|
+
handler(error);
|
|
204
|
+
}
|
|
205
|
+
}
|
|
206
|
+
get transport() {
|
|
207
|
+
return this._transport;
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
210
|
+
* Closes the connection.
|
|
211
|
+
*/
|
|
212
|
+
async close() {
|
|
213
|
+
var _a;
|
|
214
|
+
await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
|
|
215
|
+
}
|
|
216
|
+
/**
|
|
217
|
+
* Sends a request and wait for a response.
|
|
218
|
+
*
|
|
219
|
+
* Do not use this method to emit notifications! Use notification() instead.
|
|
220
|
+
*/
|
|
221
|
+
request(request, resultSchema, options) {
|
|
222
|
+
return new Promise((resolve, reject) => {
|
|
223
|
+
var _a, _b, _c, _d;
|
|
224
|
+
if (!this._transport) {
|
|
225
|
+
reject(new Error("Not connected"));
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) {
|
|
229
|
+
this.assertCapabilityForMethod(request.method);
|
|
230
|
+
}
|
|
231
|
+
(_b = options === null || options === void 0 ? void 0 : options.signal) === null || _b === void 0 ? void 0 : _b.throwIfAborted();
|
|
232
|
+
const messageId = this._requestMessageId++;
|
|
233
|
+
const jsonrpcRequest = {
|
|
234
|
+
...request,
|
|
235
|
+
jsonrpc: "2.0",
|
|
236
|
+
id: messageId
|
|
237
|
+
};
|
|
238
|
+
if (options === null || options === void 0 ? void 0 : options.onprogress) {
|
|
239
|
+
this._progressHandlers.set(messageId, options.onprogress);
|
|
240
|
+
jsonrpcRequest.params = {
|
|
241
|
+
...request.params,
|
|
242
|
+
_meta: { progressToken: messageId }
|
|
243
|
+
};
|
|
244
|
+
}
|
|
245
|
+
const cancel = (reason) => {
|
|
246
|
+
var _a2;
|
|
247
|
+
this._responseHandlers.delete(messageId);
|
|
248
|
+
this._progressHandlers.delete(messageId);
|
|
249
|
+
this._cleanupTimeout(messageId);
|
|
250
|
+
(_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
|
|
251
|
+
jsonrpc: "2.0",
|
|
252
|
+
method: "notifications/cancelled",
|
|
253
|
+
params: {
|
|
254
|
+
requestId: messageId,
|
|
255
|
+
reason: String(reason)
|
|
256
|
+
}
|
|
257
|
+
}).catch((error) => this._onerror(new Error(`Failed to send cancellation: ${error}`)));
|
|
258
|
+
reject(reason);
|
|
259
|
+
};
|
|
260
|
+
this._responseHandlers.set(messageId, (response) => {
|
|
261
|
+
var _a2;
|
|
262
|
+
if ((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.aborted) {
|
|
263
|
+
return;
|
|
264
|
+
}
|
|
265
|
+
if (response instanceof Error) {
|
|
266
|
+
return reject(response);
|
|
267
|
+
}
|
|
268
|
+
try {
|
|
269
|
+
console.log("VENGABUG");
|
|
270
|
+
console.log({ resultSchema, response, jsonrpcRequest });
|
|
271
|
+
const result = resultSchema.parse(response.result);
|
|
272
|
+
console.log("COMING");
|
|
273
|
+
resolve(result);
|
|
274
|
+
} catch (error) {
|
|
275
|
+
reject(error);
|
|
276
|
+
}
|
|
277
|
+
});
|
|
278
|
+
(_c = options === null || options === void 0 ? void 0 : options.signal) === null || _c === void 0 ? void 0 : _c.addEventListener("abort", () => {
|
|
279
|
+
var _a2;
|
|
280
|
+
cancel((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.reason);
|
|
281
|
+
});
|
|
282
|
+
const timeout = (_d = options === null || options === void 0 ? void 0 : options.timeout) !== null && _d !== void 0 ? _d : DEFAULT_REQUEST_TIMEOUT_MSEC;
|
|
283
|
+
const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
|
|
284
|
+
this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler);
|
|
285
|
+
this._transport.send(jsonrpcRequest).catch((error) => {
|
|
286
|
+
this._cleanupTimeout(messageId);
|
|
287
|
+
reject(error);
|
|
288
|
+
});
|
|
289
|
+
});
|
|
290
|
+
}
|
|
291
|
+
/**
|
|
292
|
+
* Emits a notification, which is a one-way message that does not expect a response.
|
|
293
|
+
*/
|
|
294
|
+
async notification(notification) {
|
|
295
|
+
if (!this._transport) {
|
|
296
|
+
throw new Error("Not connected");
|
|
297
|
+
}
|
|
298
|
+
this.assertNotificationCapability(notification.method);
|
|
299
|
+
const jsonrpcNotification = {
|
|
300
|
+
...notification,
|
|
301
|
+
jsonrpc: "2.0"
|
|
302
|
+
};
|
|
303
|
+
await this._transport.send(jsonrpcNotification);
|
|
304
|
+
}
|
|
305
|
+
/**
|
|
306
|
+
* Registers a handler to invoke when this protocol object receives a request with the given method.
|
|
307
|
+
*
|
|
308
|
+
* Note that this will replace any previous request handler for the same method.
|
|
309
|
+
*/
|
|
310
|
+
setRequestHandler(requestSchema, handler) {
|
|
311
|
+
const method = requestSchema.shape.method.value;
|
|
312
|
+
this.assertRequestHandlerCapability(method);
|
|
313
|
+
this._requestHandlers.set(method, (request, extra) => Promise.resolve(handler(requestSchema.parse(request), extra)));
|
|
314
|
+
}
|
|
315
|
+
/**
|
|
316
|
+
* Removes the request handler for the given method.
|
|
317
|
+
*/
|
|
318
|
+
removeRequestHandler(method) {
|
|
319
|
+
this._requestHandlers.delete(method);
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
|
|
323
|
+
*/
|
|
324
|
+
assertCanSetRequestHandler(method) {
|
|
325
|
+
if (this._requestHandlers.has(method)) {
|
|
326
|
+
throw new Error(`A request handler for ${method} already exists, which would be overridden`);
|
|
327
|
+
}
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Registers a handler to invoke when this protocol object receives a notification with the given method.
|
|
331
|
+
*
|
|
332
|
+
* Note that this will replace any previous notification handler for the same method.
|
|
333
|
+
*/
|
|
334
|
+
setNotificationHandler(notificationSchema, handler) {
|
|
335
|
+
this._notificationHandlers.set(notificationSchema.shape.method.value, (notification) => Promise.resolve(handler(notificationSchema.parse(notification))));
|
|
336
|
+
}
|
|
337
|
+
/**
|
|
338
|
+
* Removes the notification handler for the given method.
|
|
339
|
+
*/
|
|
340
|
+
removeNotificationHandler(method) {
|
|
341
|
+
this._notificationHandlers.delete(method);
|
|
342
|
+
}
|
|
343
|
+
};
|
|
344
|
+
function mergeCapabilities(base, additional) {
|
|
345
|
+
return Object.entries(additional).reduce((acc, [key, value]) => {
|
|
346
|
+
if (value && typeof value === "object") {
|
|
347
|
+
acc[key] = acc[key] ? { ...acc[key], ...value } : value;
|
|
348
|
+
} else {
|
|
349
|
+
acc[key] = value;
|
|
350
|
+
}
|
|
351
|
+
return acc;
|
|
352
|
+
}, { ...base });
|
|
353
|
+
}
|
|
354
|
+
|
|
355
|
+
// ../../hax/mcp/typescript-sdk/dist/esm/client/index.js
|
|
356
|
+
var Client = class extends Protocol {
|
|
357
|
+
/**
|
|
358
|
+
* Initializes this client with the given name and version information.
|
|
359
|
+
*/
|
|
360
|
+
constructor(_clientInfo, options) {
|
|
361
|
+
var _a;
|
|
362
|
+
super(options);
|
|
363
|
+
this._clientInfo = _clientInfo;
|
|
364
|
+
this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
|
|
365
|
+
}
|
|
366
|
+
/**
|
|
367
|
+
* Registers new capabilities. This can only be called before connecting to a transport.
|
|
368
|
+
*
|
|
369
|
+
* The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
|
|
370
|
+
*/
|
|
371
|
+
registerCapabilities(capabilities) {
|
|
372
|
+
if (this.transport) {
|
|
373
|
+
throw new Error("Cannot register capabilities after connecting to transport");
|
|
374
|
+
}
|
|
375
|
+
this._capabilities = mergeCapabilities(this._capabilities, capabilities);
|
|
376
|
+
}
|
|
377
|
+
assertCapability(capability, method) {
|
|
378
|
+
var _a;
|
|
379
|
+
if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a[capability])) {
|
|
380
|
+
throw new Error(`Server does not support ${capability} (required for ${method})`);
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
async connect(transport) {
|
|
384
|
+
await super.connect(transport);
|
|
385
|
+
try {
|
|
386
|
+
const result = await this.request({
|
|
387
|
+
method: "initialize",
|
|
388
|
+
params: {
|
|
389
|
+
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
390
|
+
capabilities: this._capabilities,
|
|
391
|
+
clientInfo: this._clientInfo
|
|
392
|
+
}
|
|
393
|
+
}, InitializeResultSchema);
|
|
394
|
+
if (result === void 0) {
|
|
395
|
+
throw new Error(`Server sent invalid initialize result: ${result}`);
|
|
396
|
+
}
|
|
397
|
+
if (!SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion)) {
|
|
398
|
+
throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`);
|
|
399
|
+
}
|
|
400
|
+
this._serverCapabilities = result.capabilities;
|
|
401
|
+
this._serverVersion = result.serverInfo;
|
|
402
|
+
this._instructions = result.instructions;
|
|
403
|
+
await this.notification({
|
|
404
|
+
method: "notifications/initialized"
|
|
405
|
+
});
|
|
406
|
+
} catch (error) {
|
|
407
|
+
void this.close();
|
|
408
|
+
throw error;
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* After initialization has completed, this will be populated with the server's reported capabilities.
|
|
413
|
+
*/
|
|
414
|
+
getServerCapabilities() {
|
|
415
|
+
return this._serverCapabilities;
|
|
416
|
+
}
|
|
417
|
+
/**
|
|
418
|
+
* After initialization has completed, this will be populated with information about the server's name and version.
|
|
419
|
+
*/
|
|
420
|
+
getServerVersion() {
|
|
421
|
+
return this._serverVersion;
|
|
422
|
+
}
|
|
423
|
+
/**
|
|
424
|
+
* After initialization has completed, this may be populated with information about the server's instructions.
|
|
425
|
+
*/
|
|
426
|
+
getInstructions() {
|
|
427
|
+
return this._instructions;
|
|
428
|
+
}
|
|
429
|
+
assertCapabilityForMethod(method) {
|
|
430
|
+
var _a, _b, _c, _d, _e;
|
|
431
|
+
switch (method) {
|
|
432
|
+
case "logging/setLevel":
|
|
433
|
+
if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.logging)) {
|
|
434
|
+
throw new Error(`Server does not support logging (required for ${method})`);
|
|
435
|
+
}
|
|
436
|
+
break;
|
|
437
|
+
case "prompts/get":
|
|
438
|
+
case "prompts/list":
|
|
439
|
+
if (!((_b = this._serverCapabilities) === null || _b === void 0 ? void 0 : _b.prompts)) {
|
|
440
|
+
throw new Error(`Server does not support prompts (required for ${method})`);
|
|
441
|
+
}
|
|
442
|
+
break;
|
|
443
|
+
case "resources/list":
|
|
444
|
+
case "resources/templates/list":
|
|
445
|
+
case "resources/read":
|
|
446
|
+
case "resources/subscribe":
|
|
447
|
+
case "resources/unsubscribe":
|
|
448
|
+
if (!((_c = this._serverCapabilities) === null || _c === void 0 ? void 0 : _c.resources)) {
|
|
449
|
+
throw new Error(`Server does not support resources (required for ${method})`);
|
|
450
|
+
}
|
|
451
|
+
if (method === "resources/subscribe" && !this._serverCapabilities.resources.subscribe) {
|
|
452
|
+
throw new Error(`Server does not support resource subscriptions (required for ${method})`);
|
|
453
|
+
}
|
|
454
|
+
break;
|
|
455
|
+
case "tools/call":
|
|
456
|
+
case "tools/list":
|
|
457
|
+
if (!((_d = this._serverCapabilities) === null || _d === void 0 ? void 0 : _d.tools)) {
|
|
458
|
+
throw new Error(`Server does not support tools (required for ${method})`);
|
|
459
|
+
}
|
|
460
|
+
break;
|
|
461
|
+
case "completion/complete":
|
|
462
|
+
if (!((_e = this._serverCapabilities) === null || _e === void 0 ? void 0 : _e.prompts)) {
|
|
463
|
+
throw new Error(`Server does not support prompts (required for ${method})`);
|
|
464
|
+
}
|
|
465
|
+
break;
|
|
466
|
+
case "initialize":
|
|
467
|
+
break;
|
|
468
|
+
case "ping":
|
|
469
|
+
break;
|
|
470
|
+
}
|
|
471
|
+
}
|
|
472
|
+
assertNotificationCapability(method) {
|
|
473
|
+
var _a;
|
|
474
|
+
switch (method) {
|
|
475
|
+
case "notifications/roots/list_changed":
|
|
476
|
+
if (!((_a = this._capabilities.roots) === null || _a === void 0 ? void 0 : _a.listChanged)) {
|
|
477
|
+
throw new Error(`Client does not support roots list changed notifications (required for ${method})`);
|
|
478
|
+
}
|
|
479
|
+
break;
|
|
480
|
+
case "notifications/initialized":
|
|
481
|
+
break;
|
|
482
|
+
case "notifications/cancelled":
|
|
483
|
+
break;
|
|
484
|
+
case "notifications/progress":
|
|
485
|
+
break;
|
|
486
|
+
}
|
|
487
|
+
}
|
|
488
|
+
assertRequestHandlerCapability(method) {
|
|
489
|
+
switch (method) {
|
|
490
|
+
case "sampling/createMessage":
|
|
491
|
+
if (!this._capabilities.sampling) {
|
|
492
|
+
throw new Error(`Client does not support sampling capability (required for ${method})`);
|
|
493
|
+
}
|
|
494
|
+
break;
|
|
495
|
+
case "roots/list":
|
|
496
|
+
if (!this._capabilities.roots) {
|
|
497
|
+
throw new Error(`Client does not support roots capability (required for ${method})`);
|
|
498
|
+
}
|
|
499
|
+
break;
|
|
500
|
+
case "ping":
|
|
501
|
+
break;
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
async ping(options) {
|
|
505
|
+
return this.request({ method: "ping" }, EmptyResultSchema, options);
|
|
506
|
+
}
|
|
507
|
+
async complete(params, options) {
|
|
508
|
+
return this.request({ method: "completion/complete", params }, CompleteResultSchema, options);
|
|
509
|
+
}
|
|
510
|
+
async setLoggingLevel(level, options) {
|
|
511
|
+
return this.request({ method: "logging/setLevel", params: { level } }, EmptyResultSchema, options);
|
|
512
|
+
}
|
|
513
|
+
async getPrompt(params, options) {
|
|
514
|
+
return this.request({ method: "prompts/get", params }, GetPromptResultSchema, options);
|
|
515
|
+
}
|
|
516
|
+
async listPrompts(params, options) {
|
|
517
|
+
return this.request({ method: "prompts/list", params }, ListPromptsResultSchema, options);
|
|
518
|
+
}
|
|
519
|
+
async listResources(params, options) {
|
|
520
|
+
return this.request({ method: "resources/list", params }, ListResourcesResultSchema, options);
|
|
521
|
+
}
|
|
522
|
+
async listResourceTemplates(params, options) {
|
|
523
|
+
return this.request({ method: "resources/templates/list", params }, ListResourceTemplatesResultSchema, options);
|
|
524
|
+
}
|
|
525
|
+
async readResource(params, options) {
|
|
526
|
+
return this.request({ method: "resources/read", params }, ReadResourceResultSchema, options);
|
|
527
|
+
}
|
|
528
|
+
async subscribeResource(params, options) {
|
|
529
|
+
return this.request({ method: "resources/subscribe", params }, EmptyResultSchema, options);
|
|
530
|
+
}
|
|
531
|
+
async unsubscribeResource(params, options) {
|
|
532
|
+
return this.request({ method: "resources/unsubscribe", params }, EmptyResultSchema, options);
|
|
533
|
+
}
|
|
534
|
+
async callTool(params, resultSchema = CallToolResultSchema, options) {
|
|
535
|
+
return this.request({ method: "tools/call", params }, resultSchema, options);
|
|
536
|
+
}
|
|
537
|
+
async listTools(params, options) {
|
|
538
|
+
return this.request({ method: "tools/list", params }, ListToolsResultSchema, options);
|
|
539
|
+
}
|
|
540
|
+
async sendRootsListChanged() {
|
|
541
|
+
return this.notification({ method: "notifications/roots/list_changed" });
|
|
542
|
+
}
|
|
543
|
+
};
|
|
544
|
+
|
|
545
|
+
export {
|
|
546
|
+
Client
|
|
547
|
+
};
|