mcp-proxy 5.6.0 → 5.7.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/dist/index.d.ts CHANGED
@@ -43,10 +43,12 @@ declare class InMemoryEventStore implements EventStore {
43
43
  //#region src/proxyServer.d.ts
44
44
  declare const proxyServer: ({
45
45
  client,
46
+ requestTimeout,
46
47
  server,
47
48
  serverCapabilities
48
49
  }: {
49
50
  client: Client;
51
+ requestTimeout?: number;
50
52
  server: Server;
51
53
  serverCapabilities: ServerCapabilities;
52
54
  }) => Promise<void>;
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
- import { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, ReadBuffer, Server, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType } from "./stdio-Cm2W-uxV.js";
1
+ import { Client, InMemoryEventStore, JSONRPCMessageSchema, LATEST_PROTOCOL_VERSION, NEVER, ReadBuffer, Server, ZodIssueCode, anyType, arrayType, booleanType, isInitializedNotification, isJSONRPCRequest, isJSONRPCResponse, numberType, objectType, proxyServer, serializeMessage, startHTTPServer, stringType } from "./stdio-AohZZTMh.js";
2
2
  import process from "node:process";
3
3
 
4
- //#region node_modules/.pnpm/eventsource-parser@3.0.3/node_modules/eventsource-parser/dist/index.js
4
+ //#region node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/index.js
5
5
  var ParseError = class extends Error {
6
6
  constructor(message, options) {
7
7
  super(message), this.name = "ParseError", this.type = options.type, this.field = options.field, this.value = options.value, this.line = options.line;
@@ -86,7 +86,7 @@ function splitLines(chunk) {
86
86
  const crIndex = chunk.indexOf("\r", searchIndex), lfIndex = chunk.indexOf(`
87
87
  `, searchIndex);
88
88
  let lineEnd = -1;
89
- if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
89
+ if (crIndex !== -1 && lfIndex !== -1 ? lineEnd = Math.min(crIndex, lfIndex) : crIndex !== -1 ? crIndex === chunk.length - 1 ? lineEnd = -1 : lineEnd = crIndex : lfIndex !== -1 && (lineEnd = lfIndex), lineEnd === -1) {
90
90
  incompleteLine = chunk.slice(searchIndex);
91
91
  break;
92
92
  } else {
@@ -387,13 +387,29 @@ async function pkceChallenge(length) {
387
387
  }
388
388
 
389
389
  //#endregion
390
- //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
390
+ //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.18.1/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth.js
391
+ /**
392
+ * Reusable URL validation that disallows javascript: scheme
393
+ */
394
+ const SafeUrlSchema = stringType().url().superRefine((val, ctx) => {
395
+ if (!URL.canParse(val)) {
396
+ ctx.addIssue({
397
+ code: ZodIssueCode.custom,
398
+ message: "URL must be parseable",
399
+ fatal: true
400
+ });
401
+ return NEVER;
402
+ }
403
+ }).refine((url) => {
404
+ const u = new URL(url);
405
+ return u.protocol !== "javascript:" && u.protocol !== "data:" && u.protocol !== "vbscript:";
406
+ }, { message: "URL cannot use javascript:, data:, or vbscript: scheme" });
391
407
  /**
392
408
  * RFC 9728 OAuth Protected Resource Metadata
393
409
  */
394
410
  const OAuthProtectedResourceMetadataSchema = objectType({
395
411
  resource: stringType().url(),
396
- authorization_servers: arrayType(stringType().url()).optional(),
412
+ authorization_servers: arrayType(SafeUrlSchema).optional(),
397
413
  jwks_uri: stringType().url().optional(),
398
414
  scopes_supported: arrayType(stringType()).optional(),
399
415
  bearer_methods_supported: arrayType(stringType()).optional(),
@@ -412,17 +428,17 @@ const OAuthProtectedResourceMetadataSchema = objectType({
412
428
  */
413
429
  const OAuthMetadataSchema = objectType({
414
430
  issuer: stringType(),
415
- authorization_endpoint: stringType(),
416
- token_endpoint: stringType(),
417
- registration_endpoint: stringType().optional(),
431
+ authorization_endpoint: SafeUrlSchema,
432
+ token_endpoint: SafeUrlSchema,
433
+ registration_endpoint: SafeUrlSchema.optional(),
418
434
  scopes_supported: arrayType(stringType()).optional(),
419
435
  response_types_supported: arrayType(stringType()),
420
436
  response_modes_supported: arrayType(stringType()).optional(),
421
437
  grant_types_supported: arrayType(stringType()).optional(),
422
438
  token_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
423
439
  token_endpoint_auth_signing_alg_values_supported: arrayType(stringType()).optional(),
424
- service_documentation: stringType().optional(),
425
- revocation_endpoint: stringType().optional(),
440
+ service_documentation: SafeUrlSchema.optional(),
441
+ revocation_endpoint: SafeUrlSchema.optional(),
426
442
  revocation_endpoint_auth_methods_supported: arrayType(stringType()).optional(),
427
443
  revocation_endpoint_auth_signing_alg_values_supported: arrayType(stringType()).optional(),
428
444
  introspection_endpoint: stringType().optional(),
@@ -436,11 +452,11 @@ const OAuthMetadataSchema = objectType({
436
452
  */
437
453
  const OpenIdProviderMetadataSchema = objectType({
438
454
  issuer: stringType(),
439
- authorization_endpoint: stringType(),
440
- token_endpoint: stringType(),
441
- userinfo_endpoint: stringType().optional(),
442
- jwks_uri: stringType(),
443
- registration_endpoint: stringType().optional(),
455
+ authorization_endpoint: SafeUrlSchema,
456
+ token_endpoint: SafeUrlSchema,
457
+ userinfo_endpoint: SafeUrlSchema.optional(),
458
+ jwks_uri: SafeUrlSchema,
459
+ registration_endpoint: SafeUrlSchema.optional(),
444
460
  scopes_supported: arrayType(stringType()).optional(),
445
461
  response_types_supported: arrayType(stringType()),
446
462
  response_modes_supported: arrayType(stringType()).optional(),
@@ -468,8 +484,8 @@ const OpenIdProviderMetadataSchema = objectType({
468
484
  request_parameter_supported: booleanType().optional(),
469
485
  request_uri_parameter_supported: booleanType().optional(),
470
486
  require_request_uri_registration: booleanType().optional(),
471
- op_policy_uri: stringType().optional(),
472
- op_tos_uri: stringType().optional()
487
+ op_policy_uri: SafeUrlSchema.optional(),
488
+ op_tos_uri: SafeUrlSchema.optional()
473
489
  }).passthrough();
474
490
  /**
475
491
  * OpenID Connect Discovery metadata that may include OAuth 2.0 fields
@@ -500,18 +516,18 @@ const OAuthErrorResponseSchema = objectType({
500
516
  * RFC 7591 OAuth 2.0 Dynamic Client Registration metadata
501
517
  */
502
518
  const OAuthClientMetadataSchema = objectType({
503
- redirect_uris: arrayType(stringType()).refine((uris) => uris.every((uri) => URL.canParse(uri)), { message: "redirect_uris must contain valid URLs" }),
519
+ redirect_uris: arrayType(SafeUrlSchema),
504
520
  token_endpoint_auth_method: stringType().optional(),
505
521
  grant_types: arrayType(stringType()).optional(),
506
522
  response_types: arrayType(stringType()).optional(),
507
523
  client_name: stringType().optional(),
508
- client_uri: stringType().optional(),
509
- logo_uri: stringType().optional(),
524
+ client_uri: SafeUrlSchema.optional(),
525
+ logo_uri: SafeUrlSchema.optional(),
510
526
  scope: stringType().optional(),
511
527
  contacts: arrayType(stringType()).optional(),
512
- tos_uri: stringType().optional(),
528
+ tos_uri: SafeUrlSchema.optional(),
513
529
  policy_uri: stringType().optional(),
514
- jwks_uri: stringType().optional(),
530
+ jwks_uri: SafeUrlSchema.optional(),
515
531
  jwks: anyType().optional(),
516
532
  software_id: stringType().optional(),
517
533
  software_version: stringType().optional(),
@@ -546,7 +562,7 @@ const OAuthTokenRevocationRequestSchema = objectType({
546
562
  }).strip();
547
563
 
548
564
  //#endregion
549
- //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.3/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js
565
+ //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.18.1/node_modules/@modelcontextprotocol/sdk/dist/esm/shared/auth-utils.js
550
566
  /**
551
567
  * Utilities for handling OAuth resource URIs.
552
568
  */
@@ -580,7 +596,7 @@ function checkResourceAllowed({ requestedResource, configuredResource }) {
580
596
  }
581
597
 
582
598
  //#endregion
583
- //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
599
+ //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.18.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/auth/errors.js
584
600
  /**
585
601
  * Base class for all OAuth errors
586
602
  */
@@ -724,7 +740,7 @@ const OAUTH_ERRORS = {
724
740
  };
725
741
 
726
742
  //#endregion
727
- //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.3/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
743
+ //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.18.1/node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
728
744
  var UnauthorizedError = class extends Error {
729
745
  constructor(message) {
730
746
  super(message !== null && message !== void 0 ? message : "Unauthorized");
@@ -815,10 +831,8 @@ async function parseErrorResponse(input) {
815
831
  const statusCode = input instanceof Response ? input.status : void 0;
816
832
  const body = input instanceof Response ? await input.text() : input;
817
833
  try {
818
- const result = OAuthErrorResponseSchema.parse(JSON.parse(body));
819
- const { error, error_description, error_uri } = result;
820
- const errorClass = OAUTH_ERRORS[error] || ServerError;
821
- return new errorClass(error_description || "", error_uri);
834
+ const { error, error_description, error_uri } = OAuthErrorResponseSchema.parse(JSON.parse(body));
835
+ return new (OAUTH_ERRORS[error] || ServerError)(error_description || "", error_uri);
822
836
  } catch (error) {
823
837
  const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}Invalid OAuth error response: ${error}. Raw body: ${body}`;
824
838
  return new ServerError(errorMessage);
@@ -917,7 +931,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
917
931
  async function selectResourceURL(serverUrl, provider, resourceMetadata) {
918
932
  const defaultResource = resourceUrlFromServerUrl(serverUrl);
919
933
  if (provider.validateResourceURL) return await provider.validateResourceURL(defaultResource, resourceMetadata === null || resourceMetadata === void 0 ? void 0 : resourceMetadata.resource);
920
- if (!resourceMetadata) return void 0;
934
+ if (!resourceMetadata) return;
921
935
  if (!checkResourceAllowed({
922
936
  requestedResource: defaultResource,
923
937
  configuredResource: resourceMetadata.resource
@@ -929,16 +943,15 @@ async function selectResourceURL(serverUrl, provider, resourceMetadata) {
929
943
  */
930
944
  function extractResourceMetadataUrl(res) {
931
945
  const authenticateHeader = res.headers.get("WWW-Authenticate");
932
- if (!authenticateHeader) return void 0;
946
+ if (!authenticateHeader) return;
933
947
  const [type, scheme] = authenticateHeader.split(" ");
934
- if (type.toLowerCase() !== "bearer" || !scheme) return void 0;
935
- const regex = /resource_metadata="([^"]*)"/;
936
- const match = regex.exec(authenticateHeader);
937
- if (!match) return void 0;
948
+ if (type.toLowerCase() !== "bearer" || !scheme) return;
949
+ const match = /resource_metadata="([^"]*)"/.exec(authenticateHeader);
950
+ if (!match) return;
938
951
  try {
939
952
  return new URL(match[1]);
940
953
  } catch (_a) {
941
- return void 0;
954
+ return;
942
955
  }
943
956
  }
944
957
  /**
@@ -964,7 +977,7 @@ async function fetchWithCorsRetry(url, headers, fetchFn = fetch) {
964
977
  return await fetchFn(url, { headers });
965
978
  } catch (error) {
966
979
  if (error instanceof TypeError) if (headers) return fetchWithCorsRetry(url, void 0, fetchFn);
967
- else return void 0;
980
+ else return;
968
981
  throw error;
969
982
  }
970
983
  }
@@ -979,14 +992,13 @@ function buildWellKnownPath(wellKnownPrefix, pathname = "", options = {}) {
979
992
  * Tries to discover OAuth metadata at a specific URL
980
993
  */
981
994
  async function tryMetadataDiscovery(url, protocolVersion, fetchFn = fetch) {
982
- const headers = { "MCP-Protocol-Version": protocolVersion };
983
- return await fetchWithCorsRetry(url, headers, fetchFn);
995
+ return await fetchWithCorsRetry(url, { "MCP-Protocol-Version": protocolVersion }, fetchFn);
984
996
  }
985
997
  /**
986
998
  * Determines if fallback to root discovery should be attempted
987
999
  */
988
1000
  function shouldAttemptFallback(response, pathname) {
989
- return !response || response.status === 404 && pathname !== "/";
1001
+ return !response || response.status >= 400 && response.status < 500 && pathname !== "/";
990
1002
  }
991
1003
  /**
992
1004
  * Generic function for discovering OAuth metadata with fallback support
@@ -1090,7 +1102,6 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
1090
1102
  return metadata;
1091
1103
  }
1092
1104
  }
1093
- return void 0;
1094
1105
  }
1095
1106
  /**
1096
1107
  * Begins the authorization flow with the given server, by generating a PKCE challenge and constructing the authorization URL.
@@ -1225,7 +1236,7 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
1225
1236
  }
1226
1237
 
1227
1238
  //#endregion
1228
- //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.3/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
1239
+ //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.18.1/node_modules/@modelcontextprotocol/sdk/dist/esm/client/sse.js
1229
1240
  var SseError = class extends Error {
1230
1241
  constructor(code, message, event) {
1231
1242
  super(`SSE error: ${message}`);
@@ -1342,13 +1353,12 @@ var SSEClientTransport = class {
1342
1353
  */
1343
1354
  async finishAuth(authorizationCode) {
1344
1355
  if (!this._authProvider) throw new UnauthorizedError("No auth provider");
1345
- const result = await auth(this._authProvider, {
1356
+ if (await auth(this._authProvider, {
1346
1357
  serverUrl: this._url,
1347
1358
  authorizationCode,
1348
1359
  resourceMetadataUrl: this._resourceMetadataUrl,
1349
1360
  fetchFn: this._fetch
1350
- });
1351
- if (result !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
1361
+ }) !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
1352
1362
  }
1353
1363
  async close() {
1354
1364
  var _a, _b, _c;
@@ -1373,12 +1383,11 @@ var SSEClientTransport = class {
1373
1383
  if (!response.ok) {
1374
1384
  if (response.status === 401 && this._authProvider) {
1375
1385
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
1376
- const result = await auth(this._authProvider, {
1386
+ if (await auth(this._authProvider, {
1377
1387
  serverUrl: this._url,
1378
1388
  resourceMetadataUrl: this._resourceMetadataUrl,
1379
1389
  fetchFn: this._fetch
1380
- });
1381
- if (result !== "AUTHORIZED") throw new UnauthorizedError();
1390
+ }) !== "AUTHORIZED") throw new UnauthorizedError();
1382
1391
  return this.send(message);
1383
1392
  }
1384
1393
  const text = await response.text().catch(() => null);
@@ -1395,7 +1404,7 @@ var SSEClientTransport = class {
1395
1404
  };
1396
1405
 
1397
1406
  //#endregion
1398
- //#region node_modules/.pnpm/eventsource-parser@3.0.3/node_modules/eventsource-parser/dist/stream.js
1407
+ //#region node_modules/.pnpm/eventsource-parser@3.0.6/node_modules/eventsource-parser/dist/stream.js
1399
1408
  var EventSourceParserStream = class extends TransformStream {
1400
1409
  constructor({ onError, onRetry, onComment } = {}) {
1401
1410
  let parser;
@@ -1420,7 +1429,7 @@ var EventSourceParserStream = class extends TransformStream {
1420
1429
  };
1421
1430
 
1422
1431
  //#endregion
1423
- //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.3/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
1432
+ //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.18.1/node_modules/@modelcontextprotocol/sdk/dist/esm/client/streamableHttp.js
1424
1433
  const DEFAULT_STREAMABLE_HTTP_RECONNECTION_OPTIONS = {
1425
1434
  initialReconnectionDelay: 1e3,
1426
1435
  maxReconnectionDelay: 3e4,
@@ -1591,13 +1600,12 @@ var StreamableHTTPClientTransport = class {
1591
1600
  */
1592
1601
  async finishAuth(authorizationCode) {
1593
1602
  if (!this._authProvider) throw new UnauthorizedError("No auth provider");
1594
- const result = await auth(this._authProvider, {
1603
+ if (await auth(this._authProvider, {
1595
1604
  serverUrl: this._url,
1596
1605
  authorizationCode,
1597
1606
  resourceMetadataUrl: this._resourceMetadataUrl,
1598
1607
  fetchFn: this._fetch
1599
- });
1600
- if (result !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
1608
+ }) !== "AUTHORIZED") throw new UnauthorizedError("Failed to authorize");
1601
1609
  }
1602
1610
  async close() {
1603
1611
  var _a, _b;
@@ -1634,12 +1642,11 @@ var StreamableHTTPClientTransport = class {
1634
1642
  if (!response.ok) {
1635
1643
  if (response.status === 401 && this._authProvider) {
1636
1644
  this._resourceMetadataUrl = extractResourceMetadataUrl(response);
1637
- const result = await auth(this._authProvider, {
1645
+ if (await auth(this._authProvider, {
1638
1646
  serverUrl: this._url,
1639
1647
  resourceMetadataUrl: this._resourceMetadataUrl,
1640
1648
  fetchFn: this._fetch
1641
- });
1642
- if (result !== "AUTHORIZED") throw new UnauthorizedError();
1649
+ }) !== "AUTHORIZED") throw new UnauthorizedError();
1643
1650
  return this.send(message);
1644
1651
  }
1645
1652
  const text = await response.text().catch(() => null);
@@ -1652,8 +1659,7 @@ var StreamableHTTPClientTransport = class {
1652
1659
  });
1653
1660
  return;
1654
1661
  }
1655
- const messages = Array.isArray(message) ? message : [message];
1656
- const hasRequests = messages.filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
1662
+ const hasRequests = (Array.isArray(message) ? message : [message]).filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
1657
1663
  const contentType = response.headers.get("content-type");
1658
1664
  if (hasRequests) if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("text/event-stream")) this._handleSseStream(response.body, { onresumptiontoken }, false);
1659
1665
  else if (contentType === null || contentType === void 0 ? void 0 : contentType.includes("application/json")) {
@@ -1708,7 +1714,7 @@ var StreamableHTTPClientTransport = class {
1708
1714
  };
1709
1715
 
1710
1716
  //#endregion
1711
- //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.17.3/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
1717
+ //#region node_modules/.pnpm/@modelcontextprotocol+sdk@1.18.1/node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
1712
1718
  /**
1713
1719
  * Server transport for stdio: this communicates with a MCP client by reading from the current process' stdin and writing to stdout.
1714
1720
  *
@@ -1752,8 +1758,7 @@ var StdioServerTransport = class {
1752
1758
  var _a;
1753
1759
  this._stdin.off("data", this._ondata);
1754
1760
  this._stdin.off("error", this._onerror);
1755
- const remainingDataListeners = this._stdin.listenerCount("data");
1756
- if (remainingDataListeners === 0) this._stdin.pause();
1761
+ if (this._stdin.listenerCount("data") === 0) this._stdin.pause();
1757
1762
  this._readBuffer.clear();
1758
1763
  (_a = this.onclose) === null || _a === void 0 || _a.call(this);
1759
1764
  }