mcp-remote 0.1.0-2 → 0.1.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 CHANGED
@@ -10,7 +10,7 @@ So far, the majority of MCP servers in the wild are installed locally, using the
10
10
 
11
11
  But there's a reason most software that _could_ be moved to the web _did_ get moved to the web: it's so much easier to find and fix bugs & iterate on new features when you can push updates to all your users with a single deploy.
12
12
 
13
- With the MCP [Authorization specification](https://spec.modelcontextprotocol.io/specification/draft/basic/authorization/) nearing completion, we now have a secure way of sharing our MCP servers with the world _without_ running code on user's laptops. Or at least, you would, if all the popular MCP _clients_ supported it yet. Most are stdio-only, and those that _do_ support HTTP+SSE don't yet support the OAuth flows required.
13
+ With the latest MCP [Authorization specification](https://modelcontextprotocol.io/specification/2025-03-26/basic/authorization), we now have a secure way of sharing our MCP servers with the world _without_ running code on user's laptops. Or at least, you would, if all the popular MCP _clients_ supported it yet. Most are stdio-only, and those that _do_ support HTTP+SSE don't yet support the OAuth flows required.
14
14
 
15
15
  That's where `mcp-remote` comes in. As soon as your chosen MCP client supports remote, authorized servers, you can remove it. Until that time, drop in this one liner and dress for the MCP clients you want!
16
16
 
@@ -14,7 +14,7 @@ var require_package = __commonJS({
14
14
  "package.json"(exports, module) {
15
15
  module.exports = {
16
16
  name: "mcp-remote",
17
- version: "0.1.0-2",
17
+ version: "0.1.0",
18
18
  description: "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth",
19
19
  keywords: [
20
20
  "mcp",
@@ -4870,6 +4870,540 @@ var McpError = class extends Error {
4870
4870
  }
4871
4871
  };
4872
4872
 
4873
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.10.2/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
4874
+ var DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4;
4875
+ var Protocol = class {
4876
+ constructor(_options) {
4877
+ this._options = _options;
4878
+ this._requestMessageId = 0;
4879
+ this._requestHandlers = /* @__PURE__ */ new Map();
4880
+ this._requestHandlerAbortControllers = /* @__PURE__ */ new Map();
4881
+ this._notificationHandlers = /* @__PURE__ */ new Map();
4882
+ this._responseHandlers = /* @__PURE__ */ new Map();
4883
+ this._progressHandlers = /* @__PURE__ */ new Map();
4884
+ this._timeoutInfo = /* @__PURE__ */ new Map();
4885
+ this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
4886
+ const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
4887
+ controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
4888
+ });
4889
+ this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
4890
+ this._onprogress(notification);
4891
+ });
4892
+ this.setRequestHandler(
4893
+ PingRequestSchema,
4894
+ // Automatic pong by default.
4895
+ (_request) => ({})
4896
+ );
4897
+ }
4898
+ _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
4899
+ this._timeoutInfo.set(messageId, {
4900
+ timeoutId: setTimeout(onTimeout, timeout),
4901
+ startTime: Date.now(),
4902
+ timeout,
4903
+ maxTotalTimeout,
4904
+ resetTimeoutOnProgress,
4905
+ onTimeout
4906
+ });
4907
+ }
4908
+ _resetTimeout(messageId) {
4909
+ const info = this._timeoutInfo.get(messageId);
4910
+ if (!info)
4911
+ return false;
4912
+ const totalElapsed = Date.now() - info.startTime;
4913
+ if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
4914
+ this._timeoutInfo.delete(messageId);
4915
+ throw new McpError(ErrorCode.RequestTimeout, "Maximum total timeout exceeded", { maxTotalTimeout: info.maxTotalTimeout, totalElapsed });
4916
+ }
4917
+ clearTimeout(info.timeoutId);
4918
+ info.timeoutId = setTimeout(info.onTimeout, info.timeout);
4919
+ return true;
4920
+ }
4921
+ _cleanupTimeout(messageId) {
4922
+ const info = this._timeoutInfo.get(messageId);
4923
+ if (info) {
4924
+ clearTimeout(info.timeoutId);
4925
+ this._timeoutInfo.delete(messageId);
4926
+ }
4927
+ }
4928
+ /**
4929
+ * Attaches to the given transport, starts it, and starts listening for messages.
4930
+ *
4931
+ * 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.
4932
+ */
4933
+ async connect(transport) {
4934
+ this._transport = transport;
4935
+ this._transport.onclose = () => {
4936
+ this._onclose();
4937
+ };
4938
+ this._transport.onerror = (error) => {
4939
+ this._onerror(error);
4940
+ };
4941
+ this._transport.onmessage = (message, extra) => {
4942
+ if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
4943
+ this._onresponse(message);
4944
+ } else if (isJSONRPCRequest(message)) {
4945
+ this._onrequest(message, extra);
4946
+ } else if (isJSONRPCNotification(message)) {
4947
+ this._onnotification(message);
4948
+ } else {
4949
+ this._onerror(new Error(`Unknown message type: ${JSON.stringify(message)}`));
4950
+ }
4951
+ };
4952
+ await this._transport.start();
4953
+ }
4954
+ _onclose() {
4955
+ var _a;
4956
+ const responseHandlers = this._responseHandlers;
4957
+ this._responseHandlers = /* @__PURE__ */ new Map();
4958
+ this._progressHandlers.clear();
4959
+ this._transport = void 0;
4960
+ (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
4961
+ const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
4962
+ for (const handler of responseHandlers.values()) {
4963
+ handler(error);
4964
+ }
4965
+ }
4966
+ _onerror(error) {
4967
+ var _a;
4968
+ (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
4969
+ }
4970
+ _onnotification(notification) {
4971
+ var _a;
4972
+ const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler;
4973
+ if (handler === void 0) {
4974
+ return;
4975
+ }
4976
+ Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
4977
+ }
4978
+ _onrequest(request, extra) {
4979
+ var _a, _b, _c;
4980
+ const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
4981
+ if (handler === void 0) {
4982
+ (_b = this._transport) === null || _b === void 0 ? void 0 : _b.send({
4983
+ jsonrpc: "2.0",
4984
+ id: request.id,
4985
+ error: {
4986
+ code: ErrorCode.MethodNotFound,
4987
+ message: "Method not found"
4988
+ }
4989
+ }).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
4990
+ return;
4991
+ }
4992
+ const abortController = new AbortController();
4993
+ this._requestHandlerAbortControllers.set(request.id, abortController);
4994
+ const fullExtra = {
4995
+ signal: abortController.signal,
4996
+ sessionId: (_c = this._transport) === null || _c === void 0 ? void 0 : _c.sessionId,
4997
+ sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
4998
+ sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
4999
+ authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo
5000
+ };
5001
+ Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
5002
+ var _a2;
5003
+ if (abortController.signal.aborted) {
5004
+ return;
5005
+ }
5006
+ return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
5007
+ result,
5008
+ jsonrpc: "2.0",
5009
+ id: request.id
5010
+ });
5011
+ }, (error) => {
5012
+ var _a2, _b2;
5013
+ if (abortController.signal.aborted) {
5014
+ return;
5015
+ }
5016
+ return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
5017
+ jsonrpc: "2.0",
5018
+ id: request.id,
5019
+ error: {
5020
+ code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
5021
+ message: (_b2 = error.message) !== null && _b2 !== void 0 ? _b2 : "Internal error"
5022
+ }
5023
+ });
5024
+ }).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
5025
+ this._requestHandlerAbortControllers.delete(request.id);
5026
+ });
5027
+ }
5028
+ _onprogress(notification) {
5029
+ const { progressToken, ...params } = notification.params;
5030
+ const messageId = Number(progressToken);
5031
+ const handler = this._progressHandlers.get(messageId);
5032
+ if (!handler) {
5033
+ this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
5034
+ return;
5035
+ }
5036
+ const responseHandler = this._responseHandlers.get(messageId);
5037
+ const timeoutInfo = this._timeoutInfo.get(messageId);
5038
+ if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) {
5039
+ try {
5040
+ this._resetTimeout(messageId);
5041
+ } catch (error) {
5042
+ responseHandler(error);
5043
+ return;
5044
+ }
5045
+ }
5046
+ handler(params);
5047
+ }
5048
+ _onresponse(response) {
5049
+ const messageId = Number(response.id);
5050
+ const handler = this._responseHandlers.get(messageId);
5051
+ if (handler === void 0) {
5052
+ this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
5053
+ return;
5054
+ }
5055
+ this._responseHandlers.delete(messageId);
5056
+ this._progressHandlers.delete(messageId);
5057
+ this._cleanupTimeout(messageId);
5058
+ if (isJSONRPCResponse(response)) {
5059
+ handler(response);
5060
+ } else {
5061
+ const error = new McpError(response.error.code, response.error.message, response.error.data);
5062
+ handler(error);
5063
+ }
5064
+ }
5065
+ get transport() {
5066
+ return this._transport;
5067
+ }
5068
+ /**
5069
+ * Closes the connection.
5070
+ */
5071
+ async close() {
5072
+ var _a;
5073
+ await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
5074
+ }
5075
+ /**
5076
+ * Sends a request and wait for a response.
5077
+ *
5078
+ * Do not use this method to emit notifications! Use notification() instead.
5079
+ */
5080
+ request(request, resultSchema, options) {
5081
+ const { relatedRequestId, resumptionToken, onresumptiontoken } = options !== null && options !== void 0 ? options : {};
5082
+ return new Promise((resolve, reject) => {
5083
+ var _a, _b, _c, _d, _e;
5084
+ if (!this._transport) {
5085
+ reject(new Error("Not connected"));
5086
+ return;
5087
+ }
5088
+ if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) {
5089
+ this.assertCapabilityForMethod(request.method);
5090
+ }
5091
+ (_b = options === null || options === void 0 ? void 0 : options.signal) === null || _b === void 0 ? void 0 : _b.throwIfAborted();
5092
+ const messageId = this._requestMessageId++;
5093
+ const jsonrpcRequest = {
5094
+ ...request,
5095
+ jsonrpc: "2.0",
5096
+ id: messageId
5097
+ };
5098
+ if (options === null || options === void 0 ? void 0 : options.onprogress) {
5099
+ this._progressHandlers.set(messageId, options.onprogress);
5100
+ jsonrpcRequest.params = {
5101
+ ...request.params,
5102
+ _meta: { progressToken: messageId }
5103
+ };
5104
+ }
5105
+ const cancel = (reason) => {
5106
+ var _a2;
5107
+ this._responseHandlers.delete(messageId);
5108
+ this._progressHandlers.delete(messageId);
5109
+ this._cleanupTimeout(messageId);
5110
+ (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
5111
+ jsonrpc: "2.0",
5112
+ method: "notifications/cancelled",
5113
+ params: {
5114
+ requestId: messageId,
5115
+ reason: String(reason)
5116
+ }
5117
+ }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => this._onerror(new Error(`Failed to send cancellation: ${error}`)));
5118
+ reject(reason);
5119
+ };
5120
+ this._responseHandlers.set(messageId, (response) => {
5121
+ var _a2;
5122
+ if ((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.aborted) {
5123
+ return;
5124
+ }
5125
+ if (response instanceof Error) {
5126
+ return reject(response);
5127
+ }
5128
+ try {
5129
+ const result = resultSchema.parse(response.result);
5130
+ resolve(result);
5131
+ } catch (error) {
5132
+ reject(error);
5133
+ }
5134
+ });
5135
+ (_c = options === null || options === void 0 ? void 0 : options.signal) === null || _c === void 0 ? void 0 : _c.addEventListener("abort", () => {
5136
+ var _a2;
5137
+ cancel((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.reason);
5138
+ });
5139
+ const timeout = (_d = options === null || options === void 0 ? void 0 : options.timeout) !== null && _d !== void 0 ? _d : DEFAULT_REQUEST_TIMEOUT_MSEC;
5140
+ const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
5141
+ this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler, (_e = options === null || options === void 0 ? void 0 : options.resetTimeoutOnProgress) !== null && _e !== void 0 ? _e : false);
5142
+ this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => {
5143
+ this._cleanupTimeout(messageId);
5144
+ reject(error);
5145
+ });
5146
+ });
5147
+ }
5148
+ /**
5149
+ * Emits a notification, which is a one-way message that does not expect a response.
5150
+ */
5151
+ async notification(notification, options) {
5152
+ if (!this._transport) {
5153
+ throw new Error("Not connected");
5154
+ }
5155
+ this.assertNotificationCapability(notification.method);
5156
+ const jsonrpcNotification = {
5157
+ ...notification,
5158
+ jsonrpc: "2.0"
5159
+ };
5160
+ await this._transport.send(jsonrpcNotification, options);
5161
+ }
5162
+ /**
5163
+ * Registers a handler to invoke when this protocol object receives a request with the given method.
5164
+ *
5165
+ * Note that this will replace any previous request handler for the same method.
5166
+ */
5167
+ setRequestHandler(requestSchema, handler) {
5168
+ const method = requestSchema.shape.method.value;
5169
+ this.assertRequestHandlerCapability(method);
5170
+ this._requestHandlers.set(method, (request, extra) => {
5171
+ return Promise.resolve(handler(requestSchema.parse(request), extra));
5172
+ });
5173
+ }
5174
+ /**
5175
+ * Removes the request handler for the given method.
5176
+ */
5177
+ removeRequestHandler(method) {
5178
+ this._requestHandlers.delete(method);
5179
+ }
5180
+ /**
5181
+ * Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
5182
+ */
5183
+ assertCanSetRequestHandler(method) {
5184
+ if (this._requestHandlers.has(method)) {
5185
+ throw new Error(`A request handler for ${method} already exists, which would be overridden`);
5186
+ }
5187
+ }
5188
+ /**
5189
+ * Registers a handler to invoke when this protocol object receives a notification with the given method.
5190
+ *
5191
+ * Note that this will replace any previous notification handler for the same method.
5192
+ */
5193
+ setNotificationHandler(notificationSchema, handler) {
5194
+ this._notificationHandlers.set(notificationSchema.shape.method.value, (notification) => Promise.resolve(handler(notificationSchema.parse(notification))));
5195
+ }
5196
+ /**
5197
+ * Removes the notification handler for the given method.
5198
+ */
5199
+ removeNotificationHandler(method) {
5200
+ this._notificationHandlers.delete(method);
5201
+ }
5202
+ };
5203
+ function mergeCapabilities(base, additional) {
5204
+ return Object.entries(additional).reduce((acc, [key, value]) => {
5205
+ if (value && typeof value === "object") {
5206
+ acc[key] = acc[key] ? { ...acc[key], ...value } : value;
5207
+ } else {
5208
+ acc[key] = value;
5209
+ }
5210
+ return acc;
5211
+ }, { ...base });
5212
+ }
5213
+
5214
+ // node_modules/.pnpm/@modelcontextprotocol+sdk@1.10.2/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
5215
+ var Client = class extends Protocol {
5216
+ /**
5217
+ * Initializes this client with the given name and version information.
5218
+ */
5219
+ constructor(_clientInfo, options) {
5220
+ var _a;
5221
+ super(options);
5222
+ this._clientInfo = _clientInfo;
5223
+ this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
5224
+ }
5225
+ /**
5226
+ * Registers new capabilities. This can only be called before connecting to a transport.
5227
+ *
5228
+ * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
5229
+ */
5230
+ registerCapabilities(capabilities) {
5231
+ if (this.transport) {
5232
+ throw new Error("Cannot register capabilities after connecting to transport");
5233
+ }
5234
+ this._capabilities = mergeCapabilities(this._capabilities, capabilities);
5235
+ }
5236
+ assertCapability(capability, method) {
5237
+ var _a;
5238
+ if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a[capability])) {
5239
+ throw new Error(`Server does not support ${capability} (required for ${method})`);
5240
+ }
5241
+ }
5242
+ async connect(transport, options) {
5243
+ await super.connect(transport);
5244
+ if (transport.sessionId !== void 0) {
5245
+ return;
5246
+ }
5247
+ try {
5248
+ const result = await this.request({
5249
+ method: "initialize",
5250
+ params: {
5251
+ protocolVersion: LATEST_PROTOCOL_VERSION,
5252
+ capabilities: this._capabilities,
5253
+ clientInfo: this._clientInfo
5254
+ }
5255
+ }, InitializeResultSchema, options);
5256
+ if (result === void 0) {
5257
+ throw new Error(`Server sent invalid initialize result: ${result}`);
5258
+ }
5259
+ if (!SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion)) {
5260
+ throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`);
5261
+ }
5262
+ this._serverCapabilities = result.capabilities;
5263
+ this._serverVersion = result.serverInfo;
5264
+ this._instructions = result.instructions;
5265
+ await this.notification({
5266
+ method: "notifications/initialized"
5267
+ });
5268
+ } catch (error) {
5269
+ void this.close();
5270
+ throw error;
5271
+ }
5272
+ }
5273
+ /**
5274
+ * After initialization has completed, this will be populated with the server's reported capabilities.
5275
+ */
5276
+ getServerCapabilities() {
5277
+ return this._serverCapabilities;
5278
+ }
5279
+ /**
5280
+ * After initialization has completed, this will be populated with information about the server's name and version.
5281
+ */
5282
+ getServerVersion() {
5283
+ return this._serverVersion;
5284
+ }
5285
+ /**
5286
+ * After initialization has completed, this may be populated with information about the server's instructions.
5287
+ */
5288
+ getInstructions() {
5289
+ return this._instructions;
5290
+ }
5291
+ assertCapabilityForMethod(method) {
5292
+ var _a, _b, _c, _d, _e;
5293
+ switch (method) {
5294
+ case "logging/setLevel":
5295
+ if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.logging)) {
5296
+ throw new Error(`Server does not support logging (required for ${method})`);
5297
+ }
5298
+ break;
5299
+ case "prompts/get":
5300
+ case "prompts/list":
5301
+ if (!((_b = this._serverCapabilities) === null || _b === void 0 ? void 0 : _b.prompts)) {
5302
+ throw new Error(`Server does not support prompts (required for ${method})`);
5303
+ }
5304
+ break;
5305
+ case "resources/list":
5306
+ case "resources/templates/list":
5307
+ case "resources/read":
5308
+ case "resources/subscribe":
5309
+ case "resources/unsubscribe":
5310
+ if (!((_c = this._serverCapabilities) === null || _c === void 0 ? void 0 : _c.resources)) {
5311
+ throw new Error(`Server does not support resources (required for ${method})`);
5312
+ }
5313
+ if (method === "resources/subscribe" && !this._serverCapabilities.resources.subscribe) {
5314
+ throw new Error(`Server does not support resource subscriptions (required for ${method})`);
5315
+ }
5316
+ break;
5317
+ case "tools/call":
5318
+ case "tools/list":
5319
+ if (!((_d = this._serverCapabilities) === null || _d === void 0 ? void 0 : _d.tools)) {
5320
+ throw new Error(`Server does not support tools (required for ${method})`);
5321
+ }
5322
+ break;
5323
+ case "completion/complete":
5324
+ if (!((_e = this._serverCapabilities) === null || _e === void 0 ? void 0 : _e.completions)) {
5325
+ throw new Error(`Server does not support completions (required for ${method})`);
5326
+ }
5327
+ break;
5328
+ case "initialize":
5329
+ break;
5330
+ case "ping":
5331
+ break;
5332
+ }
5333
+ }
5334
+ assertNotificationCapability(method) {
5335
+ var _a;
5336
+ switch (method) {
5337
+ case "notifications/roots/list_changed":
5338
+ if (!((_a = this._capabilities.roots) === null || _a === void 0 ? void 0 : _a.listChanged)) {
5339
+ throw new Error(`Client does not support roots list changed notifications (required for ${method})`);
5340
+ }
5341
+ break;
5342
+ case "notifications/initialized":
5343
+ break;
5344
+ case "notifications/cancelled":
5345
+ break;
5346
+ case "notifications/progress":
5347
+ break;
5348
+ }
5349
+ }
5350
+ assertRequestHandlerCapability(method) {
5351
+ switch (method) {
5352
+ case "sampling/createMessage":
5353
+ if (!this._capabilities.sampling) {
5354
+ throw new Error(`Client does not support sampling capability (required for ${method})`);
5355
+ }
5356
+ break;
5357
+ case "roots/list":
5358
+ if (!this._capabilities.roots) {
5359
+ throw new Error(`Client does not support roots capability (required for ${method})`);
5360
+ }
5361
+ break;
5362
+ case "ping":
5363
+ break;
5364
+ }
5365
+ }
5366
+ async ping(options) {
5367
+ return this.request({ method: "ping" }, EmptyResultSchema, options);
5368
+ }
5369
+ async complete(params, options) {
5370
+ return this.request({ method: "completion/complete", params }, CompleteResultSchema, options);
5371
+ }
5372
+ async setLoggingLevel(level, options) {
5373
+ return this.request({ method: "logging/setLevel", params: { level } }, EmptyResultSchema, options);
5374
+ }
5375
+ async getPrompt(params, options) {
5376
+ return this.request({ method: "prompts/get", params }, GetPromptResultSchema, options);
5377
+ }
5378
+ async listPrompts(params, options) {
5379
+ return this.request({ method: "prompts/list", params }, ListPromptsResultSchema, options);
5380
+ }
5381
+ async listResources(params, options) {
5382
+ return this.request({ method: "resources/list", params }, ListResourcesResultSchema, options);
5383
+ }
5384
+ async listResourceTemplates(params, options) {
5385
+ return this.request({ method: "resources/templates/list", params }, ListResourceTemplatesResultSchema, options);
5386
+ }
5387
+ async readResource(params, options) {
5388
+ return this.request({ method: "resources/read", params }, ReadResourceResultSchema, options);
5389
+ }
5390
+ async subscribeResource(params, options) {
5391
+ return this.request({ method: "resources/subscribe", params }, EmptyResultSchema, options);
5392
+ }
5393
+ async unsubscribeResource(params, options) {
5394
+ return this.request({ method: "resources/unsubscribe", params }, EmptyResultSchema, options);
5395
+ }
5396
+ async callTool(params, resultSchema = CallToolResultSchema, options) {
5397
+ return this.request({ method: "tools/call", params }, resultSchema, options);
5398
+ }
5399
+ async listTools(params, options) {
5400
+ return this.request({ method: "tools/list", params }, ListToolsResultSchema, options);
5401
+ }
5402
+ async sendRootsListChanged() {
5403
+ return this.notification({ method: "notifications/roots/list_changed" });
5404
+ }
5405
+ };
5406
+
4873
5407
  // node_modules/.pnpm/pkce-challenge@5.0.0/node_modules/pkce-challenge/dist/index.node.js
4874
5408
  var crypto;
4875
5409
  crypto = globalThis.crypto?.webcrypto ?? // Node.js [18-16] REPL
@@ -6090,7 +6624,7 @@ function mcpProxy({ transportToClient, transportToServer }) {
6090
6624
  log("Error from remote server:", error);
6091
6625
  }
6092
6626
  }
6093
- async function connectToRemoteServer(client, serverUrl, authProvider, headers, authInitializer, transportStrategy = "sse-first", recursionReasons = /* @__PURE__ */ new Set()) {
6627
+ async function connectToRemoteServer(client, serverUrl, authProvider, headers, authInitializer, transportStrategy = "http-first", recursionReasons = /* @__PURE__ */ new Set()) {
6094
6628
  log(`[${pid}] Connecting to remote server: ${serverUrl}`);
6095
6629
  const url = new URL(serverUrl);
6096
6630
  const eventSourceInit = {
@@ -6124,6 +6658,11 @@ async function connectToRemoteServer(client, serverUrl, authProvider, headers, a
6124
6658
  await client.connect(transport);
6125
6659
  } else {
6126
6660
  await transport.start();
6661
+ if (!sseTransport) {
6662
+ const testTransport = new StreamableHTTPClientTransport(url, { authProvider, requestInit: { headers } });
6663
+ const testClient = new Client({ name: "mcp-remote-fallback-test", version: "0.0.0" }, { capabilities: {} });
6664
+ await testClient.connect(testTransport);
6665
+ }
6127
6666
  }
6128
6667
  log(`Connected to remote server using ${transport.constructor.name}`);
6129
6668
  return transport;
@@ -6276,7 +6815,7 @@ async function parseCommandLineArgs(args, defaultPort, usage) {
6276
6815
  const serverUrl = args[0];
6277
6816
  const specifiedPort = args[1] ? parseInt(args[1]) : void 0;
6278
6817
  const allowHttp = args.includes("--allow-http");
6279
- let transportStrategy = "sse-first";
6818
+ let transportStrategy = "http-first";
6280
6819
  const transportIndex = args.indexOf("--transport");
6281
6820
  if (transportIndex !== -1 && transportIndex < args.length - 1) {
6282
6821
  const strategy = args[transportIndex + 1];
@@ -6669,28 +7208,10 @@ async function coordinateAuth(serverUrlHash, callbackPort, events) {
6669
7208
  }
6670
7209
 
6671
7210
  export {
6672
- LATEST_PROTOCOL_VERSION,
6673
- SUPPORTED_PROTOCOL_VERSIONS,
6674
- isJSONRPCRequest,
6675
- isJSONRPCNotification,
6676
- isJSONRPCResponse,
6677
- ErrorCode,
6678
- isJSONRPCError,
6679
7211
  JSONRPCMessageSchema,
6680
- EmptyResultSchema,
6681
- CancelledNotificationSchema,
6682
- InitializeResultSchema,
6683
- PingRequestSchema,
6684
- ProgressNotificationSchema,
6685
7212
  ListResourcesResultSchema,
6686
- ListResourceTemplatesResultSchema,
6687
- ReadResourceResultSchema,
6688
- ListPromptsResultSchema,
6689
- GetPromptResultSchema,
6690
7213
  ListToolsResultSchema,
6691
- CallToolResultSchema,
6692
- CompleteResultSchema,
6693
- McpError,
7214
+ Client,
6694
7215
  MCP_REMOTE_VERSION,
6695
7216
  log,
6696
7217
  mcpProxy,
package/dist/client.js CHANGED
@@ -1,575 +1,21 @@
1
1
  #!/usr/bin/env node
2
2
  import {
3
- CallToolResultSchema,
4
- CancelledNotificationSchema,
5
- CompleteResultSchema,
6
- EmptyResultSchema,
7
- ErrorCode,
8
- GetPromptResultSchema,
9
- InitializeResultSchema,
10
- LATEST_PROTOCOL_VERSION,
11
- ListPromptsResultSchema,
12
- ListResourceTemplatesResultSchema,
3
+ Client,
13
4
  ListResourcesResultSchema,
14
5
  ListToolsResultSchema,
15
6
  MCP_REMOTE_VERSION,
16
- McpError,
17
7
  NodeOAuthClientProvider,
18
- PingRequestSchema,
19
- ProgressNotificationSchema,
20
- ReadResourceResultSchema,
21
- SUPPORTED_PROTOCOL_VERSIONS,
22
8
  connectToRemoteServer,
23
9
  createLazyAuthCoordinator,
24
10
  getServerUrlHash,
25
- isJSONRPCError,
26
- isJSONRPCNotification,
27
- isJSONRPCRequest,
28
- isJSONRPCResponse,
29
11
  log,
30
12
  parseCommandLineArgs,
31
13
  setupSignalHandlers
32
- } from "./chunk-A3EI5AAW.js";
14
+ } from "./chunk-H6WV3ZQP.js";
33
15
 
34
16
  // src/client.ts
35
17
  import { EventEmitter } from "events";
36
-
37
- // node_modules/.pnpm/@modelcontextprotocol+sdk@1.10.2/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/protocol.js
38
- var DEFAULT_REQUEST_TIMEOUT_MSEC = 6e4;
39
- var Protocol = class {
40
- constructor(_options) {
41
- this._options = _options;
42
- this._requestMessageId = 0;
43
- this._requestHandlers = /* @__PURE__ */ new Map();
44
- this._requestHandlerAbortControllers = /* @__PURE__ */ new Map();
45
- this._notificationHandlers = /* @__PURE__ */ new Map();
46
- this._responseHandlers = /* @__PURE__ */ new Map();
47
- this._progressHandlers = /* @__PURE__ */ new Map();
48
- this._timeoutInfo = /* @__PURE__ */ new Map();
49
- this.setNotificationHandler(CancelledNotificationSchema, (notification) => {
50
- const controller = this._requestHandlerAbortControllers.get(notification.params.requestId);
51
- controller === null || controller === void 0 ? void 0 : controller.abort(notification.params.reason);
52
- });
53
- this.setNotificationHandler(ProgressNotificationSchema, (notification) => {
54
- this._onprogress(notification);
55
- });
56
- this.setRequestHandler(
57
- PingRequestSchema,
58
- // Automatic pong by default.
59
- (_request) => ({})
60
- );
61
- }
62
- _setupTimeout(messageId, timeout, maxTotalTimeout, onTimeout, resetTimeoutOnProgress = false) {
63
- this._timeoutInfo.set(messageId, {
64
- timeoutId: setTimeout(onTimeout, timeout),
65
- startTime: Date.now(),
66
- timeout,
67
- maxTotalTimeout,
68
- resetTimeoutOnProgress,
69
- onTimeout
70
- });
71
- }
72
- _resetTimeout(messageId) {
73
- const info = this._timeoutInfo.get(messageId);
74
- if (!info)
75
- return false;
76
- const totalElapsed = Date.now() - info.startTime;
77
- if (info.maxTotalTimeout && totalElapsed >= info.maxTotalTimeout) {
78
- this._timeoutInfo.delete(messageId);
79
- throw new McpError(ErrorCode.RequestTimeout, "Maximum total timeout exceeded", { maxTotalTimeout: info.maxTotalTimeout, totalElapsed });
80
- }
81
- clearTimeout(info.timeoutId);
82
- info.timeoutId = setTimeout(info.onTimeout, info.timeout);
83
- return true;
84
- }
85
- _cleanupTimeout(messageId) {
86
- const info = this._timeoutInfo.get(messageId);
87
- if (info) {
88
- clearTimeout(info.timeoutId);
89
- this._timeoutInfo.delete(messageId);
90
- }
91
- }
92
- /**
93
- * Attaches to the given transport, starts it, and starts listening for messages.
94
- *
95
- * 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.
96
- */
97
- async connect(transport) {
98
- this._transport = transport;
99
- this._transport.onclose = () => {
100
- this._onclose();
101
- };
102
- this._transport.onerror = (error) => {
103
- this._onerror(error);
104
- };
105
- this._transport.onmessage = (message, extra) => {
106
- if (isJSONRPCResponse(message) || isJSONRPCError(message)) {
107
- this._onresponse(message);
108
- } else if (isJSONRPCRequest(message)) {
109
- this._onrequest(message, extra);
110
- } else if (isJSONRPCNotification(message)) {
111
- this._onnotification(message);
112
- } else {
113
- this._onerror(new Error(`Unknown message type: ${JSON.stringify(message)}`));
114
- }
115
- };
116
- await this._transport.start();
117
- }
118
- _onclose() {
119
- var _a;
120
- const responseHandlers = this._responseHandlers;
121
- this._responseHandlers = /* @__PURE__ */ new Map();
122
- this._progressHandlers.clear();
123
- this._transport = void 0;
124
- (_a = this.onclose) === null || _a === void 0 ? void 0 : _a.call(this);
125
- const error = new McpError(ErrorCode.ConnectionClosed, "Connection closed");
126
- for (const handler of responseHandlers.values()) {
127
- handler(error);
128
- }
129
- }
130
- _onerror(error) {
131
- var _a;
132
- (_a = this.onerror) === null || _a === void 0 ? void 0 : _a.call(this, error);
133
- }
134
- _onnotification(notification) {
135
- var _a;
136
- const handler = (_a = this._notificationHandlers.get(notification.method)) !== null && _a !== void 0 ? _a : this.fallbackNotificationHandler;
137
- if (handler === void 0) {
138
- return;
139
- }
140
- Promise.resolve().then(() => handler(notification)).catch((error) => this._onerror(new Error(`Uncaught error in notification handler: ${error}`)));
141
- }
142
- _onrequest(request, extra) {
143
- var _a, _b, _c;
144
- const handler = (_a = this._requestHandlers.get(request.method)) !== null && _a !== void 0 ? _a : this.fallbackRequestHandler;
145
- if (handler === void 0) {
146
- (_b = this._transport) === null || _b === void 0 ? void 0 : _b.send({
147
- jsonrpc: "2.0",
148
- id: request.id,
149
- error: {
150
- code: ErrorCode.MethodNotFound,
151
- message: "Method not found"
152
- }
153
- }).catch((error) => this._onerror(new Error(`Failed to send an error response: ${error}`)));
154
- return;
155
- }
156
- const abortController = new AbortController();
157
- this._requestHandlerAbortControllers.set(request.id, abortController);
158
- const fullExtra = {
159
- signal: abortController.signal,
160
- sessionId: (_c = this._transport) === null || _c === void 0 ? void 0 : _c.sessionId,
161
- sendNotification: (notification) => this.notification(notification, { relatedRequestId: request.id }),
162
- sendRequest: (r, resultSchema, options) => this.request(r, resultSchema, { ...options, relatedRequestId: request.id }),
163
- authInfo: extra === null || extra === void 0 ? void 0 : extra.authInfo
164
- };
165
- Promise.resolve().then(() => handler(request, fullExtra)).then((result) => {
166
- var _a2;
167
- if (abortController.signal.aborted) {
168
- return;
169
- }
170
- return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
171
- result,
172
- jsonrpc: "2.0",
173
- id: request.id
174
- });
175
- }, (error) => {
176
- var _a2, _b2;
177
- if (abortController.signal.aborted) {
178
- return;
179
- }
180
- return (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
181
- jsonrpc: "2.0",
182
- id: request.id,
183
- error: {
184
- code: Number.isSafeInteger(error["code"]) ? error["code"] : ErrorCode.InternalError,
185
- message: (_b2 = error.message) !== null && _b2 !== void 0 ? _b2 : "Internal error"
186
- }
187
- });
188
- }).catch((error) => this._onerror(new Error(`Failed to send response: ${error}`))).finally(() => {
189
- this._requestHandlerAbortControllers.delete(request.id);
190
- });
191
- }
192
- _onprogress(notification) {
193
- const { progressToken, ...params } = notification.params;
194
- const messageId = Number(progressToken);
195
- const handler = this._progressHandlers.get(messageId);
196
- if (!handler) {
197
- this._onerror(new Error(`Received a progress notification for an unknown token: ${JSON.stringify(notification)}`));
198
- return;
199
- }
200
- const responseHandler = this._responseHandlers.get(messageId);
201
- const timeoutInfo = this._timeoutInfo.get(messageId);
202
- if (timeoutInfo && responseHandler && timeoutInfo.resetTimeoutOnProgress) {
203
- try {
204
- this._resetTimeout(messageId);
205
- } catch (error) {
206
- responseHandler(error);
207
- return;
208
- }
209
- }
210
- handler(params);
211
- }
212
- _onresponse(response) {
213
- const messageId = Number(response.id);
214
- const handler = this._responseHandlers.get(messageId);
215
- if (handler === void 0) {
216
- this._onerror(new Error(`Received a response for an unknown message ID: ${JSON.stringify(response)}`));
217
- return;
218
- }
219
- this._responseHandlers.delete(messageId);
220
- this._progressHandlers.delete(messageId);
221
- this._cleanupTimeout(messageId);
222
- if (isJSONRPCResponse(response)) {
223
- handler(response);
224
- } else {
225
- const error = new McpError(response.error.code, response.error.message, response.error.data);
226
- handler(error);
227
- }
228
- }
229
- get transport() {
230
- return this._transport;
231
- }
232
- /**
233
- * Closes the connection.
234
- */
235
- async close() {
236
- var _a;
237
- await ((_a = this._transport) === null || _a === void 0 ? void 0 : _a.close());
238
- }
239
- /**
240
- * Sends a request and wait for a response.
241
- *
242
- * Do not use this method to emit notifications! Use notification() instead.
243
- */
244
- request(request, resultSchema, options) {
245
- const { relatedRequestId, resumptionToken, onresumptiontoken } = options !== null && options !== void 0 ? options : {};
246
- return new Promise((resolve, reject) => {
247
- var _a, _b, _c, _d, _e;
248
- if (!this._transport) {
249
- reject(new Error("Not connected"));
250
- return;
251
- }
252
- if (((_a = this._options) === null || _a === void 0 ? void 0 : _a.enforceStrictCapabilities) === true) {
253
- this.assertCapabilityForMethod(request.method);
254
- }
255
- (_b = options === null || options === void 0 ? void 0 : options.signal) === null || _b === void 0 ? void 0 : _b.throwIfAborted();
256
- const messageId = this._requestMessageId++;
257
- const jsonrpcRequest = {
258
- ...request,
259
- jsonrpc: "2.0",
260
- id: messageId
261
- };
262
- if (options === null || options === void 0 ? void 0 : options.onprogress) {
263
- this._progressHandlers.set(messageId, options.onprogress);
264
- jsonrpcRequest.params = {
265
- ...request.params,
266
- _meta: { progressToken: messageId }
267
- };
268
- }
269
- const cancel = (reason) => {
270
- var _a2;
271
- this._responseHandlers.delete(messageId);
272
- this._progressHandlers.delete(messageId);
273
- this._cleanupTimeout(messageId);
274
- (_a2 = this._transport) === null || _a2 === void 0 ? void 0 : _a2.send({
275
- jsonrpc: "2.0",
276
- method: "notifications/cancelled",
277
- params: {
278
- requestId: messageId,
279
- reason: String(reason)
280
- }
281
- }, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => this._onerror(new Error(`Failed to send cancellation: ${error}`)));
282
- reject(reason);
283
- };
284
- this._responseHandlers.set(messageId, (response) => {
285
- var _a2;
286
- if ((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.aborted) {
287
- return;
288
- }
289
- if (response instanceof Error) {
290
- return reject(response);
291
- }
292
- try {
293
- const result = resultSchema.parse(response.result);
294
- resolve(result);
295
- } catch (error) {
296
- reject(error);
297
- }
298
- });
299
- (_c = options === null || options === void 0 ? void 0 : options.signal) === null || _c === void 0 ? void 0 : _c.addEventListener("abort", () => {
300
- var _a2;
301
- cancel((_a2 = options === null || options === void 0 ? void 0 : options.signal) === null || _a2 === void 0 ? void 0 : _a2.reason);
302
- });
303
- const timeout = (_d = options === null || options === void 0 ? void 0 : options.timeout) !== null && _d !== void 0 ? _d : DEFAULT_REQUEST_TIMEOUT_MSEC;
304
- const timeoutHandler = () => cancel(new McpError(ErrorCode.RequestTimeout, "Request timed out", { timeout }));
305
- this._setupTimeout(messageId, timeout, options === null || options === void 0 ? void 0 : options.maxTotalTimeout, timeoutHandler, (_e = options === null || options === void 0 ? void 0 : options.resetTimeoutOnProgress) !== null && _e !== void 0 ? _e : false);
306
- this._transport.send(jsonrpcRequest, { relatedRequestId, resumptionToken, onresumptiontoken }).catch((error) => {
307
- this._cleanupTimeout(messageId);
308
- reject(error);
309
- });
310
- });
311
- }
312
- /**
313
- * Emits a notification, which is a one-way message that does not expect a response.
314
- */
315
- async notification(notification, options) {
316
- if (!this._transport) {
317
- throw new Error("Not connected");
318
- }
319
- this.assertNotificationCapability(notification.method);
320
- const jsonrpcNotification = {
321
- ...notification,
322
- jsonrpc: "2.0"
323
- };
324
- await this._transport.send(jsonrpcNotification, options);
325
- }
326
- /**
327
- * Registers a handler to invoke when this protocol object receives a request with the given method.
328
- *
329
- * Note that this will replace any previous request handler for the same method.
330
- */
331
- setRequestHandler(requestSchema, handler) {
332
- const method = requestSchema.shape.method.value;
333
- this.assertRequestHandlerCapability(method);
334
- this._requestHandlers.set(method, (request, extra) => {
335
- return Promise.resolve(handler(requestSchema.parse(request), extra));
336
- });
337
- }
338
- /**
339
- * Removes the request handler for the given method.
340
- */
341
- removeRequestHandler(method) {
342
- this._requestHandlers.delete(method);
343
- }
344
- /**
345
- * Asserts that a request handler has not already been set for the given method, in preparation for a new one being automatically installed.
346
- */
347
- assertCanSetRequestHandler(method) {
348
- if (this._requestHandlers.has(method)) {
349
- throw new Error(`A request handler for ${method} already exists, which would be overridden`);
350
- }
351
- }
352
- /**
353
- * Registers a handler to invoke when this protocol object receives a notification with the given method.
354
- *
355
- * Note that this will replace any previous notification handler for the same method.
356
- */
357
- setNotificationHandler(notificationSchema, handler) {
358
- this._notificationHandlers.set(notificationSchema.shape.method.value, (notification) => Promise.resolve(handler(notificationSchema.parse(notification))));
359
- }
360
- /**
361
- * Removes the notification handler for the given method.
362
- */
363
- removeNotificationHandler(method) {
364
- this._notificationHandlers.delete(method);
365
- }
366
- };
367
- function mergeCapabilities(base, additional) {
368
- return Object.entries(additional).reduce((acc, [key, value]) => {
369
- if (value && typeof value === "object") {
370
- acc[key] = acc[key] ? { ...acc[key], ...value } : value;
371
- } else {
372
- acc[key] = value;
373
- }
374
- return acc;
375
- }, { ...base });
376
- }
377
-
378
- // node_modules/.pnpm/@modelcontextprotocol+sdk@1.10.2/node_modules/@modelcontextprotocol/sdk/dist/esm/client/index.js
379
- var Client = class extends Protocol {
380
- /**
381
- * Initializes this client with the given name and version information.
382
- */
383
- constructor(_clientInfo, options) {
384
- var _a;
385
- super(options);
386
- this._clientInfo = _clientInfo;
387
- this._capabilities = (_a = options === null || options === void 0 ? void 0 : options.capabilities) !== null && _a !== void 0 ? _a : {};
388
- }
389
- /**
390
- * Registers new capabilities. This can only be called before connecting to a transport.
391
- *
392
- * The new capabilities will be merged with any existing capabilities previously given (e.g., at initialization).
393
- */
394
- registerCapabilities(capabilities) {
395
- if (this.transport) {
396
- throw new Error("Cannot register capabilities after connecting to transport");
397
- }
398
- this._capabilities = mergeCapabilities(this._capabilities, capabilities);
399
- }
400
- assertCapability(capability, method) {
401
- var _a;
402
- if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a[capability])) {
403
- throw new Error(`Server does not support ${capability} (required for ${method})`);
404
- }
405
- }
406
- async connect(transport, options) {
407
- await super.connect(transport);
408
- if (transport.sessionId !== void 0) {
409
- return;
410
- }
411
- try {
412
- const result = await this.request({
413
- method: "initialize",
414
- params: {
415
- protocolVersion: LATEST_PROTOCOL_VERSION,
416
- capabilities: this._capabilities,
417
- clientInfo: this._clientInfo
418
- }
419
- }, InitializeResultSchema, options);
420
- if (result === void 0) {
421
- throw new Error(`Server sent invalid initialize result: ${result}`);
422
- }
423
- if (!SUPPORTED_PROTOCOL_VERSIONS.includes(result.protocolVersion)) {
424
- throw new Error(`Server's protocol version is not supported: ${result.protocolVersion}`);
425
- }
426
- this._serverCapabilities = result.capabilities;
427
- this._serverVersion = result.serverInfo;
428
- this._instructions = result.instructions;
429
- await this.notification({
430
- method: "notifications/initialized"
431
- });
432
- } catch (error) {
433
- void this.close();
434
- throw error;
435
- }
436
- }
437
- /**
438
- * After initialization has completed, this will be populated with the server's reported capabilities.
439
- */
440
- getServerCapabilities() {
441
- return this._serverCapabilities;
442
- }
443
- /**
444
- * After initialization has completed, this will be populated with information about the server's name and version.
445
- */
446
- getServerVersion() {
447
- return this._serverVersion;
448
- }
449
- /**
450
- * After initialization has completed, this may be populated with information about the server's instructions.
451
- */
452
- getInstructions() {
453
- return this._instructions;
454
- }
455
- assertCapabilityForMethod(method) {
456
- var _a, _b, _c, _d, _e;
457
- switch (method) {
458
- case "logging/setLevel":
459
- if (!((_a = this._serverCapabilities) === null || _a === void 0 ? void 0 : _a.logging)) {
460
- throw new Error(`Server does not support logging (required for ${method})`);
461
- }
462
- break;
463
- case "prompts/get":
464
- case "prompts/list":
465
- if (!((_b = this._serverCapabilities) === null || _b === void 0 ? void 0 : _b.prompts)) {
466
- throw new Error(`Server does not support prompts (required for ${method})`);
467
- }
468
- break;
469
- case "resources/list":
470
- case "resources/templates/list":
471
- case "resources/read":
472
- case "resources/subscribe":
473
- case "resources/unsubscribe":
474
- if (!((_c = this._serverCapabilities) === null || _c === void 0 ? void 0 : _c.resources)) {
475
- throw new Error(`Server does not support resources (required for ${method})`);
476
- }
477
- if (method === "resources/subscribe" && !this._serverCapabilities.resources.subscribe) {
478
- throw new Error(`Server does not support resource subscriptions (required for ${method})`);
479
- }
480
- break;
481
- case "tools/call":
482
- case "tools/list":
483
- if (!((_d = this._serverCapabilities) === null || _d === void 0 ? void 0 : _d.tools)) {
484
- throw new Error(`Server does not support tools (required for ${method})`);
485
- }
486
- break;
487
- case "completion/complete":
488
- if (!((_e = this._serverCapabilities) === null || _e === void 0 ? void 0 : _e.completions)) {
489
- throw new Error(`Server does not support completions (required for ${method})`);
490
- }
491
- break;
492
- case "initialize":
493
- break;
494
- case "ping":
495
- break;
496
- }
497
- }
498
- assertNotificationCapability(method) {
499
- var _a;
500
- switch (method) {
501
- case "notifications/roots/list_changed":
502
- if (!((_a = this._capabilities.roots) === null || _a === void 0 ? void 0 : _a.listChanged)) {
503
- throw new Error(`Client does not support roots list changed notifications (required for ${method})`);
504
- }
505
- break;
506
- case "notifications/initialized":
507
- break;
508
- case "notifications/cancelled":
509
- break;
510
- case "notifications/progress":
511
- break;
512
- }
513
- }
514
- assertRequestHandlerCapability(method) {
515
- switch (method) {
516
- case "sampling/createMessage":
517
- if (!this._capabilities.sampling) {
518
- throw new Error(`Client does not support sampling capability (required for ${method})`);
519
- }
520
- break;
521
- case "roots/list":
522
- if (!this._capabilities.roots) {
523
- throw new Error(`Client does not support roots capability (required for ${method})`);
524
- }
525
- break;
526
- case "ping":
527
- break;
528
- }
529
- }
530
- async ping(options) {
531
- return this.request({ method: "ping" }, EmptyResultSchema, options);
532
- }
533
- async complete(params, options) {
534
- return this.request({ method: "completion/complete", params }, CompleteResultSchema, options);
535
- }
536
- async setLoggingLevel(level, options) {
537
- return this.request({ method: "logging/setLevel", params: { level } }, EmptyResultSchema, options);
538
- }
539
- async getPrompt(params, options) {
540
- return this.request({ method: "prompts/get", params }, GetPromptResultSchema, options);
541
- }
542
- async listPrompts(params, options) {
543
- return this.request({ method: "prompts/list", params }, ListPromptsResultSchema, options);
544
- }
545
- async listResources(params, options) {
546
- return this.request({ method: "resources/list", params }, ListResourcesResultSchema, options);
547
- }
548
- async listResourceTemplates(params, options) {
549
- return this.request({ method: "resources/templates/list", params }, ListResourceTemplatesResultSchema, options);
550
- }
551
- async readResource(params, options) {
552
- return this.request({ method: "resources/read", params }, ReadResourceResultSchema, options);
553
- }
554
- async subscribeResource(params, options) {
555
- return this.request({ method: "resources/subscribe", params }, EmptyResultSchema, options);
556
- }
557
- async unsubscribeResource(params, options) {
558
- return this.request({ method: "resources/unsubscribe", params }, EmptyResultSchema, options);
559
- }
560
- async callTool(params, resultSchema = CallToolResultSchema, options) {
561
- return this.request({ method: "tools/call", params }, resultSchema, options);
562
- }
563
- async listTools(params, options) {
564
- return this.request({ method: "tools/list", params }, ListToolsResultSchema, options);
565
- }
566
- async sendRootsListChanged() {
567
- return this.notification({ method: "notifications/roots/list_changed" });
568
- }
569
- };
570
-
571
- // src/client.ts
572
- async function runClient(serverUrl, callbackPort, headers, transportStrategy = "sse-first") {
18
+ async function runClient(serverUrl, callbackPort, headers, transportStrategy = "http-first") {
573
19
  const events = new EventEmitter();
574
20
  const serverUrlHash = getServerUrlHash(serverUrl);
575
21
  const authCoordinator = createLazyAuthCoordinator(serverUrlHash, callbackPort, events);
package/dist/proxy.js CHANGED
@@ -9,7 +9,7 @@ import {
9
9
  mcpProxy,
10
10
  parseCommandLineArgs,
11
11
  setupSignalHandlers
12
- } from "./chunk-A3EI5AAW.js";
12
+ } from "./chunk-H6WV3ZQP.js";
13
13
 
14
14
  // src/proxy.ts
15
15
  import { EventEmitter } from "events";
@@ -110,7 +110,7 @@ var StdioServerTransport = class {
110
110
  };
111
111
 
112
112
  // src/proxy.ts
113
- async function runProxy(serverUrl, callbackPort, headers, transportStrategy = "sse-first") {
113
+ async function runProxy(serverUrl, callbackPort, headers, transportStrategy = "http-first") {
114
114
  const events = new EventEmitter();
115
115
  const serverUrlHash = getServerUrlHash(serverUrl);
116
116
  const authCoordinator = createLazyAuthCoordinator(serverUrlHash, callbackPort, events);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-remote",
3
- "version": "0.1.0-2",
3
+ "version": "0.1.0",
4
4
  "description": "Remote proxy for Model Context Protocol, allowing local-only clients to connect to remote servers using oAuth",
5
5
  "keywords": [
6
6
  "mcp",