@automattic/mcp-wordpress-remote 0.5.1 → 0.5.2

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/lib.d.ts CHANGED
@@ -15,7 +15,7 @@ interface WordPressResponse {
15
15
  [key: string]: any;
16
16
  }
17
17
 
18
- declare const MCP_WORDPRESS_REMOTE_VERSION = "0.5.1";
18
+ declare const MCP_WORDPRESS_REMOTE_VERSION = "0.5.2";
19
19
  /**
20
20
  * Centralized configuration for MCP WordPress Remote
21
21
  * All default values are defined here and can be overridden via environment variables
package/dist/lib.js CHANGED
@@ -73824,10 +73824,9 @@ var ProgressTokenSchema = union([string2(), number2().int()]);
73824
73824
  var CursorSchema = string2();
73825
73825
  var TaskCreationParamsSchema = looseObject({
73826
73826
  /**
73827
- * Time in milliseconds to keep task results available after completion.
73828
- * If null, the task has unlimited lifetime until manually cleaned up.
73827
+ * Requested duration in milliseconds to retain task from creation.
73829
73828
  */
73830
- ttl: union([number2(), _null3()]).optional(),
73829
+ ttl: number2().optional(),
73831
73830
  /**
73832
73831
  * Time in milliseconds to wait between task status requests.
73833
73832
  */
@@ -74122,7 +74121,11 @@ var ClientCapabilitiesSchema = object({
74122
74121
  /**
74123
74122
  * Present if the client supports task creation.
74124
74123
  */
74125
- tasks: ClientTasksCapabilitySchema.optional()
74124
+ tasks: ClientTasksCapabilitySchema.optional(),
74125
+ /**
74126
+ * Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
74127
+ */
74128
+ extensions: record(string2(), AssertObjectSchema).optional()
74126
74129
  });
74127
74130
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
74128
74131
  /**
@@ -74183,7 +74186,11 @@ var ServerCapabilitiesSchema = object({
74183
74186
  /**
74184
74187
  * Present if the server supports task creation.
74185
74188
  */
74186
- tasks: ServerTasksCapabilitySchema.optional()
74189
+ tasks: ServerTasksCapabilitySchema.optional(),
74190
+ /**
74191
+ * Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
74192
+ */
74193
+ extensions: record(string2(), AssertObjectSchema).optional()
74187
74194
  });
74188
74195
  var InitializeResultSchema = ResultSchema.extend({
74189
74196
  /**
@@ -74375,6 +74382,12 @@ var ResourceSchema = object({
74375
74382
  * The MIME type of this resource, if known.
74376
74383
  */
74377
74384
  mimeType: optional(string2()),
74385
+ /**
74386
+ * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
74387
+ *
74388
+ * This can be used by Hosts to display file sizes and estimate context window usage.
74389
+ */
74390
+ size: optional(number2()),
74378
74391
  /**
74379
74392
  * Optional annotations for the client.
74380
74393
  */
@@ -75393,7 +75406,12 @@ var OAuthTokensSchema = object({
75393
75406
  token_type: string2(),
75394
75407
  expires_in: coerce_exports.number().optional(),
75395
75408
  scope: string2().optional(),
75396
- refresh_token: string2().optional()
75409
+ refresh_token: string2().optional(),
75410
+ /**
75411
+ * Not part of the wire format: the authorization server this value was obtained from, added by
75412
+ * the client's `auth()` before it is stored and compared when it is read back.
75413
+ */
75414
+ issuer: string2().optional().catch(void 0)
75397
75415
  }).strip();
75398
75416
  var OAuthErrorResponseSchema = object({
75399
75417
  error: string2(),
@@ -75423,7 +75441,12 @@ var OAuthClientInformationSchema = object({
75423
75441
  client_id: string2(),
75424
75442
  client_secret: string2().optional(),
75425
75443
  client_id_issued_at: number2().optional(),
75426
- client_secret_expires_at: number2().optional()
75444
+ client_secret_expires_at: number2().optional(),
75445
+ /**
75446
+ * Not part of the wire format: the authorization server this value was obtained from, added by
75447
+ * the client's `auth()` before it is stored and compared when it is read back.
75448
+ */
75449
+ issuer: string2().optional().catch(void 0)
75427
75450
  }).strip();
75428
75451
  var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
75429
75452
  var OAuthClientRegistrationErrorSchema = object({
@@ -75530,6 +75553,10 @@ var OAUTH_ERRORS = {
75530
75553
  [InvalidTargetError.errorCode]: InvalidTargetError
75531
75554
  };
75532
75555
 
75556
+ // node_modules/@modelcontextprotocol/sdk/dist/esm/client/auth.js
75557
+ var TokenResponseSchema = OAuthTokensSchema.omit({ issuer: true });
75558
+ var RegistrationResponseSchema = OAuthClientInformationFullSchema.omit({ issuer: true });
75559
+
75533
75560
  // src/lib/utils.ts
75534
75561
  import * as fs2 from "node:fs";
75535
75562
  import * as path3 from "node:path";
@@ -75774,7 +75801,7 @@ async function selectCallbackPort(serverUrl, specifiedPort, _unused) {
75774
75801
  }
75775
75802
 
75776
75803
  // src/lib/config.ts
75777
- var MCP_WORDPRESS_REMOTE_VERSION = "0.5.1";
75804
+ var MCP_WORDPRESS_REMOTE_VERSION = "0.5.2";
75778
75805
  function parsePositiveIntEnv(value, defaultValue) {
75779
75806
  if (!value) {
75780
75807
  return defaultValue;
@@ -77403,7 +77430,11 @@ var OAuthCallbackServer = class {
77403
77430
  async start() {
77404
77431
  return new Promise((resolve, reject) => {
77405
77432
  try {
77406
- this.server = this.app.listen(this.options.port, this.options.host, () => {
77433
+ this.server = this.app.listen(this.options.port, this.options.host, (error51) => {
77434
+ if (error51) {
77435
+ reject(error51);
77436
+ return;
77437
+ }
77407
77438
  logger.oauth(
77408
77439
  `OAuth callback server listening on http://${this.options.host}:${this.options.port}`
77409
77440
  );
package/dist/proxy.js CHANGED
@@ -4939,7 +4939,7 @@ async function toFormData(Body2, ct) {
4939
4939
  let headerValue2;
4940
4940
  let entryValue;
4941
4941
  let entryName;
4942
- let contentType;
4942
+ let contentType2;
4943
4943
  let filename;
4944
4944
  const entryChunks = [];
4945
4945
  const formData = new FormData();
@@ -4950,7 +4950,7 @@ async function toFormData(Body2, ct) {
4950
4950
  entryChunks.push(ui8a);
4951
4951
  };
4952
4952
  const appendFileToFormData = () => {
4953
- const file2 = new file_default(entryChunks, filename, { type: contentType });
4953
+ const file2 = new file_default(entryChunks, filename, { type: contentType2 });
4954
4954
  formData.append(entryName, file2);
4955
4955
  };
4956
4956
  const appendEntryToFormData = () => {
@@ -4965,7 +4965,7 @@ async function toFormData(Body2, ct) {
4965
4965
  headerValue2 = "";
4966
4966
  entryValue = "";
4967
4967
  entryName = "";
4968
- contentType = "";
4968
+ contentType2 = "";
4969
4969
  filename = null;
4970
4970
  entryChunks.length = 0;
4971
4971
  };
@@ -4989,7 +4989,7 @@ async function toFormData(Body2, ct) {
4989
4989
  parser.onPartEnd = appendFileToFormData;
4990
4990
  }
4991
4991
  } else if (headerField === "content-type") {
4992
- contentType = headerValue2;
4992
+ contentType2 = headerValue2;
4993
4993
  }
4994
4994
  headerValue2 = "";
4995
4995
  headerField = "";
@@ -5749,9 +5749,9 @@ var init_response = __esm({
5749
5749
  const status = options.status != null ? options.status : 200;
5750
5750
  const headers = new Headers2(options.headers);
5751
5751
  if (body !== null && !headers.has("Content-Type")) {
5752
- const contentType = extractContentType(body, this);
5753
- if (contentType) {
5754
- headers.append("Content-Type", contentType);
5752
+ const contentType2 = extractContentType(body, this);
5753
+ if (contentType2) {
5754
+ headers.append("Content-Type", contentType2);
5755
5755
  }
5756
5756
  }
5757
5757
  this[INTERNALS2] = {
@@ -6073,9 +6073,9 @@ var init_request = __esm({
6073
6073
  });
6074
6074
  const headers = new Headers2(init.headers || input.headers || {});
6075
6075
  if (inputBody !== null && !headers.has("Content-Type")) {
6076
- const contentType = extractContentType(inputBody, this);
6077
- if (contentType) {
6078
- headers.set("Content-Type", contentType);
6076
+ const contentType2 = extractContentType(inputBody, this);
6077
+ if (contentType2) {
6078
+ headers.set("Content-Type", contentType2);
6079
6079
  }
6080
6080
  }
6081
6081
  let signal = isRequest(input) ? input.signal : null;
@@ -6547,6 +6547,110 @@ var init_src = __esm({
6547
6547
  }
6548
6548
  });
6549
6549
 
6550
+ // node_modules/content-type/index.js
6551
+ var require_content_type = __commonJS({
6552
+ "node_modules/content-type/index.js"(exports) {
6553
+ "use strict";
6554
+ var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
6555
+ var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/;
6556
+ var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
6557
+ var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
6558
+ var QUOTE_REGEXP = /([\\"])/g;
6559
+ var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
6560
+ exports.format = format;
6561
+ exports.parse = parse3;
6562
+ function format(obj) {
6563
+ if (!obj || typeof obj !== "object") {
6564
+ throw new TypeError("argument obj is required");
6565
+ }
6566
+ var parameters = obj.parameters;
6567
+ var type = obj.type;
6568
+ if (!type || !TYPE_REGEXP.test(type)) {
6569
+ throw new TypeError("invalid type");
6570
+ }
6571
+ var string4 = type;
6572
+ if (parameters && typeof parameters === "object") {
6573
+ var param;
6574
+ var params = Object.keys(parameters).sort();
6575
+ for (var i2 = 0; i2 < params.length; i2++) {
6576
+ param = params[i2];
6577
+ if (!TOKEN_REGEXP.test(param)) {
6578
+ throw new TypeError("invalid parameter name");
6579
+ }
6580
+ string4 += "; " + param + "=" + qstring(parameters[param]);
6581
+ }
6582
+ }
6583
+ return string4;
6584
+ }
6585
+ function parse3(string4) {
6586
+ if (!string4) {
6587
+ throw new TypeError("argument string is required");
6588
+ }
6589
+ var header = typeof string4 === "object" ? getcontenttype(string4) : string4;
6590
+ if (typeof header !== "string") {
6591
+ throw new TypeError("argument string is required to be a string");
6592
+ }
6593
+ var index = header.indexOf(";");
6594
+ var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
6595
+ if (!TYPE_REGEXP.test(type)) {
6596
+ throw new TypeError("invalid media type");
6597
+ }
6598
+ var obj = new ContentType(type.toLowerCase());
6599
+ if (index !== -1) {
6600
+ var key;
6601
+ var match;
6602
+ var value;
6603
+ PARAM_REGEXP.lastIndex = index;
6604
+ while (match = PARAM_REGEXP.exec(header)) {
6605
+ if (match.index !== index) {
6606
+ throw new TypeError("invalid parameter format");
6607
+ }
6608
+ index += match[0].length;
6609
+ key = match[1].toLowerCase();
6610
+ value = match[2];
6611
+ if (value.charCodeAt(0) === 34) {
6612
+ value = value.slice(1, -1);
6613
+ if (value.indexOf("\\") !== -1) {
6614
+ value = value.replace(QESC_REGEXP, "$1");
6615
+ }
6616
+ }
6617
+ obj.parameters[key] = value;
6618
+ }
6619
+ if (index !== header.length) {
6620
+ throw new TypeError("invalid parameter format");
6621
+ }
6622
+ }
6623
+ return obj;
6624
+ }
6625
+ function getcontenttype(obj) {
6626
+ var header;
6627
+ if (typeof obj.getHeader === "function") {
6628
+ header = obj.getHeader("content-type");
6629
+ } else if (typeof obj.headers === "object") {
6630
+ header = obj.headers && obj.headers["content-type"];
6631
+ }
6632
+ if (typeof header !== "string") {
6633
+ throw new TypeError("content-type header is missing from object");
6634
+ }
6635
+ return header;
6636
+ }
6637
+ function qstring(val) {
6638
+ var str = String(val);
6639
+ if (TOKEN_REGEXP.test(str)) {
6640
+ return str;
6641
+ }
6642
+ if (str.length > 0 && !TEXT_REGEXP.test(str)) {
6643
+ throw new TypeError("invalid parameter value");
6644
+ }
6645
+ return '"' + str.replace(QUOTE_REGEXP, "\\$1") + '"';
6646
+ }
6647
+ function ContentType(type) {
6648
+ this.parameters = /* @__PURE__ */ Object.create(null);
6649
+ this.type = type;
6650
+ }
6651
+ }
6652
+ });
6653
+
6550
6654
  // node_modules/ms/index.js
6551
6655
  var require_ms = __commonJS({
6552
6656
  "node_modules/ms/index.js"(exports, module) {
@@ -21818,7 +21922,7 @@ var require_mime_types = __commonJS({
21818
21922
  var TEXT_TYPE_REGEXP = /^text\//i;
21819
21923
  exports.charset = charset;
21820
21924
  exports.charsets = { lookup: charset };
21821
- exports.contentType = contentType;
21925
+ exports.contentType = contentType2;
21822
21926
  exports.extension = extension;
21823
21927
  exports.extensions = /* @__PURE__ */ Object.create(null);
21824
21928
  exports.lookup = lookup;
@@ -21839,7 +21943,7 @@ var require_mime_types = __commonJS({
21839
21943
  }
21840
21944
  return false;
21841
21945
  }
21842
- function contentType(str) {
21946
+ function contentType2(str) {
21843
21947
  if (!str || typeof str !== "string") {
21844
21948
  return false;
21845
21949
  }
@@ -21981,7 +22085,7 @@ var require_media_typer = __commonJS({
21981
22085
  var require_type_is = __commonJS({
21982
22086
  "node_modules/type-is/index.js"(exports, module) {
21983
22087
  "use strict";
21984
- var contentType = require_dist();
22088
+ var contentType2 = require_dist();
21985
22089
  var mime = require_mime_types();
21986
22090
  var typer = require_media_typer();
21987
22091
  module.exports = typeofrequest;
@@ -22062,7 +22166,7 @@ var require_type_is = __commonJS({
22062
22166
  }
22063
22167
  function normalizeType(value) {
22064
22168
  if (!value) return null;
22065
- var type = contentType.parse(value, { parameters: false }).type;
22169
+ var type = contentType2.parse(value, { parameters: false }).type;
22066
22170
  return typer.test(type) ? type : null;
22067
22171
  }
22068
22172
  }
@@ -22212,7 +22316,7 @@ var require_utils = __commonJS({
22212
22316
  "node_modules/body-parser/lib/utils.js"(exports, module) {
22213
22317
  "use strict";
22214
22318
  var bytes = require_bytes();
22215
- var contentType = require_dist2();
22319
+ var contentType2 = require_dist2();
22216
22320
  var typeis = require_type_is();
22217
22321
  module.exports = {
22218
22322
  getCharset,
@@ -22222,7 +22326,7 @@ var require_utils = __commonJS({
22222
22326
  function getCharset(req) {
22223
22327
  const header = req.headers["content-type"];
22224
22328
  if (!header) return void 0;
22225
- return contentType.parse(header).parameters.charset?.toLowerCase();
22329
+ return contentType2.parse(header).parameters.charset?.toLowerCase();
22226
22330
  }
22227
22331
  function typeChecker(type) {
22228
22332
  return function checkType(req) {
@@ -25646,110 +25750,6 @@ var require_view = __commonJS({
25646
25750
  }
25647
25751
  });
25648
25752
 
25649
- // node_modules/content-type/index.js
25650
- var require_content_type = __commonJS({
25651
- "node_modules/content-type/index.js"(exports) {
25652
- "use strict";
25653
- var PARAM_REGEXP = /; *([!#$%&'*+.^_`|~0-9A-Za-z-]+) *= *("(?:[\u000b\u0020\u0021\u0023-\u005b\u005d-\u007e\u0080-\u00ff]|\\[\u000b\u0020-\u00ff])*"|[!#$%&'*+.^_`|~0-9A-Za-z-]+) */g;
25654
- var TEXT_REGEXP = /^[\u000b\u0020-\u007e\u0080-\u00ff]+$/;
25655
- var TOKEN_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
25656
- var QESC_REGEXP = /\\([\u000b\u0020-\u00ff])/g;
25657
- var QUOTE_REGEXP = /([\\"])/g;
25658
- var TYPE_REGEXP = /^[!#$%&'*+.^_`|~0-9A-Za-z-]+\/[!#$%&'*+.^_`|~0-9A-Za-z-]+$/;
25659
- exports.format = format;
25660
- exports.parse = parse3;
25661
- function format(obj) {
25662
- if (!obj || typeof obj !== "object") {
25663
- throw new TypeError("argument obj is required");
25664
- }
25665
- var parameters = obj.parameters;
25666
- var type = obj.type;
25667
- if (!type || !TYPE_REGEXP.test(type)) {
25668
- throw new TypeError("invalid type");
25669
- }
25670
- var string4 = type;
25671
- if (parameters && typeof parameters === "object") {
25672
- var param;
25673
- var params = Object.keys(parameters).sort();
25674
- for (var i2 = 0; i2 < params.length; i2++) {
25675
- param = params[i2];
25676
- if (!TOKEN_REGEXP.test(param)) {
25677
- throw new TypeError("invalid parameter name");
25678
- }
25679
- string4 += "; " + param + "=" + qstring(parameters[param]);
25680
- }
25681
- }
25682
- return string4;
25683
- }
25684
- function parse3(string4) {
25685
- if (!string4) {
25686
- throw new TypeError("argument string is required");
25687
- }
25688
- var header = typeof string4 === "object" ? getcontenttype(string4) : string4;
25689
- if (typeof header !== "string") {
25690
- throw new TypeError("argument string is required to be a string");
25691
- }
25692
- var index = header.indexOf(";");
25693
- var type = index !== -1 ? header.slice(0, index).trim() : header.trim();
25694
- if (!TYPE_REGEXP.test(type)) {
25695
- throw new TypeError("invalid media type");
25696
- }
25697
- var obj = new ContentType(type.toLowerCase());
25698
- if (index !== -1) {
25699
- var key;
25700
- var match;
25701
- var value;
25702
- PARAM_REGEXP.lastIndex = index;
25703
- while (match = PARAM_REGEXP.exec(header)) {
25704
- if (match.index !== index) {
25705
- throw new TypeError("invalid parameter format");
25706
- }
25707
- index += match[0].length;
25708
- key = match[1].toLowerCase();
25709
- value = match[2];
25710
- if (value.charCodeAt(0) === 34) {
25711
- value = value.slice(1, -1);
25712
- if (value.indexOf("\\") !== -1) {
25713
- value = value.replace(QESC_REGEXP, "$1");
25714
- }
25715
- }
25716
- obj.parameters[key] = value;
25717
- }
25718
- if (index !== header.length) {
25719
- throw new TypeError("invalid parameter format");
25720
- }
25721
- }
25722
- return obj;
25723
- }
25724
- function getcontenttype(obj) {
25725
- var header;
25726
- if (typeof obj.getHeader === "function") {
25727
- header = obj.getHeader("content-type");
25728
- } else if (typeof obj.headers === "object") {
25729
- header = obj.headers && obj.headers["content-type"];
25730
- }
25731
- if (typeof header !== "string") {
25732
- throw new TypeError("content-type header is missing from object");
25733
- }
25734
- return header;
25735
- }
25736
- function qstring(val) {
25737
- var str = String(val);
25738
- if (TOKEN_REGEXP.test(str)) {
25739
- return str;
25740
- }
25741
- if (str.length > 0 && !TEXT_REGEXP.test(str)) {
25742
- throw new TypeError("invalid parameter value");
25743
- }
25744
- return '"' + str.replace(QUOTE_REGEXP, "\\$1") + '"';
25745
- }
25746
- function ContentType(type) {
25747
- this.parameters = /* @__PURE__ */ Object.create(null);
25748
- this.type = type;
25749
- }
25750
- }
25751
- });
25752
-
25753
25753
  // node_modules/etag/index.js
25754
25754
  var require_etag = __commonJS({
25755
25755
  "node_modules/etag/index.js"(exports, module) {
@@ -35204,7 +35204,7 @@ var require_mime_types2 = __commonJS({
35204
35204
  var TEXT_TYPE_REGEXP = /^text\//i;
35205
35205
  exports.charset = charset;
35206
35206
  exports.charsets = { lookup: charset };
35207
- exports.contentType = contentType;
35207
+ exports.contentType = contentType2;
35208
35208
  exports.extension = extension;
35209
35209
  exports.extensions = /* @__PURE__ */ Object.create(null);
35210
35210
  exports.lookup = lookup;
@@ -35225,7 +35225,7 @@ var require_mime_types2 = __commonJS({
35225
35225
  }
35226
35226
  return false;
35227
35227
  }
35228
- function contentType(str) {
35228
+ function contentType2(str) {
35229
35229
  if (!str || typeof str !== "string") {
35230
35230
  return false;
35231
35231
  }
@@ -36149,7 +36149,7 @@ var require_utils3 = __commonJS({
36149
36149
  "node_modules/express/lib/utils.js"(exports) {
36150
36150
  "use strict";
36151
36151
  var { METHODS } = __require("node:http");
36152
- var contentType = require_content_type();
36152
+ var contentType2 = require_content_type();
36153
36153
  var etag = require_etag();
36154
36154
  var mime = require_mime_types2();
36155
36155
  var proxyaddr = require_proxy_addr();
@@ -36253,9 +36253,9 @@ var require_utils3 = __commonJS({
36253
36253
  if (!type || !charset) {
36254
36254
  return type;
36255
36255
  }
36256
- var parsed = contentType.parse(type);
36256
+ var parsed = contentType2.parse(type);
36257
36257
  parsed.parameters.charset = charset;
36258
- return contentType.format(parsed);
36258
+ return contentType2.format(parsed);
36259
36259
  };
36260
36260
  function createETagGenerator(options) {
36261
36261
  return function generateETag(body, encoding) {
@@ -37800,14 +37800,14 @@ var require_dist4 = __commonJS({
37800
37800
  var require_accept = __commonJS({
37801
37801
  "node_modules/negotiator/lib/accept.js"(exports, module) {
37802
37802
  "use strict";
37803
- var contentType = require_dist4();
37803
+ var contentType2 = require_dist4();
37804
37804
  module.exports = parseAccept;
37805
37805
  function parseAccept(header) {
37806
37806
  var values = [];
37807
37807
  var index = 0;
37808
37808
  while (index < header.length) {
37809
37809
  var start = skipOptionalWhitespace(header, index);
37810
- var parsed = contentType.parse(header, { comma: true, start });
37810
+ var parsed = contentType2.parse(header, { comma: true, start });
37811
37811
  parsed.type = header.slice(start, start + parsed.type.length);
37812
37812
  values.push(parsed);
37813
37813
  index = parsed.index + 1;
@@ -38000,7 +38000,7 @@ var require_encoding = __commonJS({
38000
38000
  var require_language = __commonJS({
38001
38001
  "node_modules/negotiator/lib/language.js"(exports, module) {
38002
38002
  "use strict";
38003
- var contentType = require_dist4();
38003
+ var contentType2 = require_dist4();
38004
38004
  var parseAccept = require_accept();
38005
38005
  module.exports = preferredLanguages;
38006
38006
  module.exports.preferredLanguages = preferredLanguages;
@@ -38037,7 +38037,7 @@ var require_language = __commonJS({
38037
38037
  return priority;
38038
38038
  }
38039
38039
  function specify(language, spec, index) {
38040
- var p = formatLanguage(contentType.parse(language), 0);
38040
+ var p = formatLanguage(contentType2.parse(language), 0);
38041
38041
  if (!p) return null;
38042
38042
  var s2 = 0;
38043
38043
  if (spec.full.toLowerCase() === p.full.toLowerCase()) {
@@ -38084,7 +38084,7 @@ var require_language = __commonJS({
38084
38084
  var require_mediaType = __commonJS({
38085
38085
  "node_modules/negotiator/lib/mediaType.js"(exports, module) {
38086
38086
  "use strict";
38087
- var contentType = require_dist4();
38087
+ var contentType2 = require_dist4();
38088
38088
  var parseAcceptHeader = require_accept();
38089
38089
  module.exports = preferredMediaTypes;
38090
38090
  module.exports.preferredMediaTypes = preferredMediaTypes;
@@ -38121,7 +38121,7 @@ var require_mediaType = __commonJS({
38121
38121
  return priority;
38122
38122
  }
38123
38123
  function specify(type, spec, index) {
38124
- var p = formatMediaType(contentType.parse(type), 0);
38124
+ var p = formatMediaType(contentType2.parse(type), 0);
38125
38125
  var s2 = 0;
38126
38126
  if (!p) {
38127
38127
  return null;
@@ -47645,7 +47645,7 @@ var require_mime_types3 = __commonJS({
47645
47645
  var TEXT_TYPE_REGEXP = /^text\//i;
47646
47646
  exports.charset = charset;
47647
47647
  exports.charsets = { lookup: charset };
47648
- exports.contentType = contentType;
47648
+ exports.contentType = contentType2;
47649
47649
  exports.extension = extension;
47650
47650
  exports.extensions = /* @__PURE__ */ Object.create(null);
47651
47651
  exports.lookup = lookup;
@@ -47666,7 +47666,7 @@ var require_mime_types3 = __commonJS({
47666
47666
  }
47667
47667
  return false;
47668
47668
  }
47669
- function contentType(str) {
47669
+ function contentType2(str) {
47670
47670
  if (!str || typeof str !== "string") {
47671
47671
  return false;
47672
47672
  }
@@ -57927,7 +57927,7 @@ var require_mime_types4 = __commonJS({
57927
57927
  var TEXT_TYPE_REGEXP = /^text\//i;
57928
57928
  exports.charset = charset;
57929
57929
  exports.charsets = { lookup: charset };
57930
- exports.contentType = contentType;
57930
+ exports.contentType = contentType2;
57931
57931
  exports.extension = extension;
57932
57932
  exports.extensions = /* @__PURE__ */ Object.create(null);
57933
57933
  exports.lookup = lookup;
@@ -57948,7 +57948,7 @@ var require_mime_types4 = __commonJS({
57948
57948
  }
57949
57949
  return false;
57950
57950
  }
57951
- function contentType(str) {
57951
+ function contentType2(str) {
57952
57952
  if (!str || typeof str !== "string") {
57953
57953
  return false;
57954
57954
  }
@@ -58809,7 +58809,7 @@ var require_response = __commonJS({
58809
58809
  var fullPath = !opts.root ? resolve(path7) : path7;
58810
58810
  return this.sendFile(fullPath, opts, done);
58811
58811
  };
58812
- res.contentType = res.type = function contentType(type) {
58812
+ res.contentType = res.type = function contentType2(type) {
58813
58813
  var ct = type.indexOf("/") === -1 ? mime.contentType(type) || "application/octet-stream" : type;
58814
58814
  return this.set("Content-Type", ct);
58815
58815
  };
@@ -73726,10 +73726,9 @@ var ProgressTokenSchema = union([string2(), number2().int()]);
73726
73726
  var CursorSchema = string2();
73727
73727
  var TaskCreationParamsSchema = looseObject({
73728
73728
  /**
73729
- * Time in milliseconds to keep task results available after completion.
73730
- * If null, the task has unlimited lifetime until manually cleaned up.
73729
+ * Requested duration in milliseconds to retain task from creation.
73731
73730
  */
73732
- ttl: union([number2(), _null3()]).optional(),
73731
+ ttl: number2().optional(),
73733
73732
  /**
73734
73733
  * Time in milliseconds to wait between task status requests.
73735
73734
  */
@@ -74026,7 +74025,11 @@ var ClientCapabilitiesSchema = object({
74026
74025
  /**
74027
74026
  * Present if the client supports task creation.
74028
74027
  */
74029
- tasks: ClientTasksCapabilitySchema.optional()
74028
+ tasks: ClientTasksCapabilitySchema.optional(),
74029
+ /**
74030
+ * Extensions that the client supports. Keys are extension identifiers (vendor-prefix/extension-name).
74031
+ */
74032
+ extensions: record(string2(), AssertObjectSchema).optional()
74030
74033
  });
74031
74034
  var InitializeRequestParamsSchema = BaseRequestParamsSchema.extend({
74032
74035
  /**
@@ -74087,7 +74090,11 @@ var ServerCapabilitiesSchema = object({
74087
74090
  /**
74088
74091
  * Present if the server supports task creation.
74089
74092
  */
74090
- tasks: ServerTasksCapabilitySchema.optional()
74093
+ tasks: ServerTasksCapabilitySchema.optional(),
74094
+ /**
74095
+ * Extensions that the server supports. Keys are extension identifiers (vendor-prefix/extension-name).
74096
+ */
74097
+ extensions: record(string2(), AssertObjectSchema).optional()
74091
74098
  });
74092
74099
  var InitializeResultSchema = ResultSchema.extend({
74093
74100
  /**
@@ -74280,6 +74287,12 @@ var ResourceSchema = object({
74280
74287
  * The MIME type of this resource, if known.
74281
74288
  */
74282
74289
  mimeType: optional(string2()),
74290
+ /**
74291
+ * The size of the raw resource content, in bytes (i.e., before base64 encoding or any tokenization), if known.
74292
+ *
74293
+ * This can be used by Hosts to display file sizes and estimate context window usage.
74294
+ */
74295
+ size: optional(number2()),
74283
74296
  /**
74284
74297
  * Optional annotations for the client.
74285
74298
  */
@@ -75221,8 +75234,17 @@ var UrlElicitationRequiredError = class extends McpError {
75221
75234
  };
75222
75235
 
75223
75236
  // node_modules/@modelcontextprotocol/sdk/dist/esm/shared/stdio.js
75237
+ var STDIO_DEFAULT_MAX_BUFFER_SIZE = 10 * 1024 * 1024;
75224
75238
  var ReadBuffer = class {
75239
+ constructor(options) {
75240
+ this._maxBufferSize = options?.maxBufferSize ?? STDIO_DEFAULT_MAX_BUFFER_SIZE;
75241
+ }
75225
75242
  append(chunk) {
75243
+ const newSize = (this._buffer?.length ?? 0) + chunk.length;
75244
+ if (newSize > this._maxBufferSize) {
75245
+ this.clear();
75246
+ throw new Error(`ReadBuffer exceeded maximum size of ${this._maxBufferSize} bytes`);
75247
+ }
75226
75248
  this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
75227
75249
  }
75228
75250
  readMessage() {
@@ -75250,18 +75272,24 @@ function serializeMessage(message) {
75250
75272
 
75251
75273
  // node_modules/@modelcontextprotocol/sdk/dist/esm/server/stdio.js
75252
75274
  var StdioServerTransport = class {
75253
- constructor(_stdin = process3.stdin, _stdout = process3.stdout) {
75275
+ constructor(_stdin = process3.stdin, _stdout = process3.stdout, options) {
75254
75276
  this._stdin = _stdin;
75255
75277
  this._stdout = _stdout;
75256
- this._readBuffer = new ReadBuffer();
75257
75278
  this._started = false;
75258
75279
  this._ondata = (chunk) => {
75259
- this._readBuffer.append(chunk);
75260
- this.processReadBuffer();
75280
+ try {
75281
+ this._readBuffer.append(chunk);
75282
+ this.processReadBuffer();
75283
+ } catch (error51) {
75284
+ this.onerror?.(error51);
75285
+ this.close().catch(() => {
75286
+ });
75287
+ }
75261
75288
  };
75262
75289
  this._onerror = (error51) => {
75263
75290
  this.onerror?.(error51);
75264
75291
  };
75292
+ this._readBuffer = new ReadBuffer({ maxBufferSize: options?.maxBufferSize });
75265
75293
  }
75266
75294
  /**
75267
75295
  * Starts listening for messages on stdin.
@@ -75580,7 +75608,12 @@ var OAuthTokensSchema = object({
75580
75608
  token_type: string2(),
75581
75609
  expires_in: coerce_exports.number().optional(),
75582
75610
  scope: string2().optional(),
75583
- refresh_token: string2().optional()
75611
+ refresh_token: string2().optional(),
75612
+ /**
75613
+ * Not part of the wire format: the authorization server this value was obtained from, added by
75614
+ * the client's `auth()` before it is stored and compared when it is read back.
75615
+ */
75616
+ issuer: string2().optional().catch(void 0)
75584
75617
  }).strip();
75585
75618
  var OAuthErrorResponseSchema = object({
75586
75619
  error: string2(),
@@ -75610,7 +75643,12 @@ var OAuthClientInformationSchema = object({
75610
75643
  client_id: string2(),
75611
75644
  client_secret: string2().optional(),
75612
75645
  client_id_issued_at: number2().optional(),
75613
- client_secret_expires_at: number2().optional()
75646
+ client_secret_expires_at: number2().optional(),
75647
+ /**
75648
+ * Not part of the wire format: the authorization server this value was obtained from, added by
75649
+ * the client's `auth()` before it is stored and compared when it is read back.
75650
+ */
75651
+ issuer: string2().optional().catch(void 0)
75614
75652
  }).strip();
75615
75653
  var OAuthClientInformationFullSchema = OAuthClientMetadataSchema.merge(OAuthClientInformationSchema);
75616
75654
  var OAuthClientRegistrationErrorSchema = object({
@@ -75750,12 +75788,12 @@ var AUTHORIZATION_CODE_RESPONSE_TYPE = "code";
75750
75788
  var AUTHORIZATION_CODE_CHALLENGE_METHOD = "S256";
75751
75789
  function selectClientAuthMethod(clientInformation, supportedMethods) {
75752
75790
  const hasClientSecret = clientInformation.client_secret !== void 0;
75753
- if (supportedMethods.length === 0) {
75754
- return hasClientSecret ? "client_secret_post" : "none";
75755
- }
75756
- if ("token_endpoint_auth_method" in clientInformation && clientInformation.token_endpoint_auth_method && isClientAuthMethod(clientInformation.token_endpoint_auth_method) && supportedMethods.includes(clientInformation.token_endpoint_auth_method)) {
75791
+ if ("token_endpoint_auth_method" in clientInformation && clientInformation.token_endpoint_auth_method && isClientAuthMethod(clientInformation.token_endpoint_auth_method) && (supportedMethods.length === 0 || supportedMethods.includes(clientInformation.token_endpoint_auth_method))) {
75757
75792
  return clientInformation.token_endpoint_auth_method;
75758
75793
  }
75794
+ if (supportedMethods.length === 0) {
75795
+ return hasClientSecret ? "client_secret_basic" : "none";
75796
+ }
75759
75797
  if (hasClientSecret && supportedMethods.includes("client_secret_basic")) {
75760
75798
  return "client_secret_basic";
75761
75799
  }
@@ -75812,6 +75850,26 @@ async function parseErrorResponse(input) {
75812
75850
  return new ServerError(errorMessage);
75813
75851
  }
75814
75852
  }
75853
+ function issuersMatch(a, b) {
75854
+ let [x2, y] = [a, b];
75855
+ try {
75856
+ [x2, y] = [new URL(a).href, new URL(b).href];
75857
+ } catch {
75858
+ }
75859
+ return x2 === y || x2.endsWith("/") && x2.slice(0, -1) === y || y.endsWith("/") && y.slice(0, -1) === x2;
75860
+ }
75861
+ function discardIfIssuerMismatch(stored, issuer) {
75862
+ if (!stored)
75863
+ return void 0;
75864
+ if (typeof stored.issuer !== "string")
75865
+ return stored.issuer == null ? stored : { ...stored, issuer: void 0 };
75866
+ return issuersMatch(stored.issuer, issuer) ? stored : void 0;
75867
+ }
75868
+ var TokenResponseSchema = OAuthTokensSchema.omit({ issuer: true });
75869
+ var RegistrationResponseSchema = OAuthClientInformationFullSchema.omit({ issuer: true });
75870
+ function boundElsewhereError(stored, issuer) {
75871
+ return new Error(`OAuth client information is bound to authorization server ${stored.issuer} and is not presented to ${issuer}. Clear the stored client information, or correct \`expectedIssuer\`, if the authorization server has moved.`);
75872
+ }
75815
75873
  async function auth(provider, options) {
75816
75874
  try {
75817
75875
  return await authInternal(provider, options);
@@ -75827,23 +75885,62 @@ async function auth(provider, options) {
75827
75885
  }
75828
75886
  }
75829
75887
  async function authInternal(provider, { serverUrl, authorizationCode, scope, resourceMetadataUrl, fetchFn }) {
75888
+ const cachedState = await provider.discoveryState?.();
75830
75889
  let resourceMetadata;
75831
75890
  let authorizationServerUrl;
75832
- try {
75833
- resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl }, fetchFn);
75834
- if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
75835
- authorizationServerUrl = resourceMetadata.authorization_servers[0];
75891
+ let metadata;
75892
+ let effectiveResourceMetadataUrl = resourceMetadataUrl;
75893
+ if (!effectiveResourceMetadataUrl && cachedState?.resourceMetadataUrl) {
75894
+ effectiveResourceMetadataUrl = new URL(cachedState.resourceMetadataUrl);
75895
+ }
75896
+ if (cachedState?.authorizationServerUrl) {
75897
+ authorizationServerUrl = cachedState.authorizationServerUrl;
75898
+ resourceMetadata = cachedState.resourceMetadata;
75899
+ metadata = cachedState.authorizationServerMetadata ?? await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn });
75900
+ if (!resourceMetadata) {
75901
+ try {
75902
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl }, fetchFn);
75903
+ } catch {
75904
+ }
75836
75905
  }
75837
- } catch {
75838
- }
75839
- if (!authorizationServerUrl) {
75840
- authorizationServerUrl = new URL("/", serverUrl);
75906
+ if (metadata !== cachedState.authorizationServerMetadata || resourceMetadata !== cachedState.resourceMetadata) {
75907
+ await provider.saveDiscoveryState?.({
75908
+ authorizationServerUrl: String(authorizationServerUrl),
75909
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
75910
+ resourceMetadata,
75911
+ authorizationServerMetadata: metadata
75912
+ });
75913
+ }
75914
+ } else {
75915
+ const serverInfo = await discoverOAuthServerInfo(serverUrl, { resourceMetadataUrl: effectiveResourceMetadataUrl, fetchFn });
75916
+ authorizationServerUrl = serverInfo.authorizationServerUrl;
75917
+ metadata = serverInfo.authorizationServerMetadata;
75918
+ resourceMetadata = serverInfo.resourceMetadata;
75919
+ await provider.saveDiscoveryState?.({
75920
+ authorizationServerUrl: String(authorizationServerUrl),
75921
+ resourceMetadataUrl: effectiveResourceMetadataUrl?.toString(),
75922
+ resourceMetadata,
75923
+ authorizationServerMetadata: metadata
75924
+ });
75841
75925
  }
75842
- const resource = await selectResourceURL(serverUrl, provider, resourceMetadata);
75843
- const metadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, {
75844
- fetchFn
75845
- });
75846
- let clientInformation = await Promise.resolve(provider.clientInformation());
75926
+ const issuer = String(authorizationServerUrl);
75927
+ const selectedResource = await selectResourceURL(serverUrl, provider, resourceMetadata);
75928
+ const resource = selectedResource && resourceMetadata && !provider.validateResourceURL ? resourceMetadata.resource : selectedResource;
75929
+ const resolvedScope = scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope;
75930
+ const storedClientInformation = await Promise.resolve(provider.clientInformation());
75931
+ let clientInformation = discardIfIssuerMismatch(storedClientInformation, issuer);
75932
+ const canRegisterAgain = provider.saveClientInformation !== void 0 && !!provider.redirectUrl;
75933
+ if (storedClientInformation && !clientInformation && !canRegisterAgain) {
75934
+ throw boundElsewhereError(storedClientInformation, issuer);
75935
+ }
75936
+ const unstampedClientInformation = clientInformation?.issuer == null ? clientInformation : void 0;
75937
+ const bindClientInformation = async () => {
75938
+ try {
75939
+ if (unstampedClientInformation)
75940
+ await provider.saveClientInformation?.({ ...unstampedClientInformation, issuer });
75941
+ } catch {
75942
+ }
75943
+ };
75847
75944
  if (!clientInformation) {
75848
75945
  if (authorizationCode !== void 0) {
75849
75946
  throw new Error("Existing OAuth client information is required when exchanging an authorization code");
@@ -75855,9 +75952,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
75855
75952
  }
75856
75953
  const shouldUseUrlBasedClientId = supportsUrlBasedClientId && clientMetadataUrl;
75857
75954
  if (shouldUseUrlBasedClientId) {
75858
- clientInformation = {
75859
- client_id: clientMetadataUrl
75860
- };
75955
+ clientInformation = { client_id: clientMetadataUrl, issuer };
75861
75956
  await provider.saveClientInformation?.(clientInformation);
75862
75957
  } else {
75863
75958
  if (!provider.saveClientInformation) {
@@ -75866,10 +75961,11 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
75866
75961
  const fullInformation = await registerClient(authorizationServerUrl, {
75867
75962
  metadata,
75868
75963
  clientMetadata: provider.clientMetadata,
75964
+ scope: resolvedScope,
75869
75965
  fetchFn
75870
75966
  });
75871
- await provider.saveClientInformation(fullInformation);
75872
- clientInformation = fullInformation;
75967
+ clientInformation = { ...fullInformation, issuer };
75968
+ await provider.saveClientInformation(clientInformation);
75873
75969
  }
75874
75970
  }
75875
75971
  const nonInteractiveFlow = !provider.redirectUrl;
@@ -75880,10 +75976,14 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
75880
75976
  authorizationCode,
75881
75977
  fetchFn
75882
75978
  });
75883
- await provider.saveTokens(tokens2);
75979
+ await bindClientInformation();
75980
+ await provider.saveTokens({ ...tokens2, issuer });
75884
75981
  return "AUTHORIZED";
75885
75982
  }
75886
- const tokens = await provider.tokens();
75983
+ const tokens = discardIfIssuerMismatch(await provider.tokens(), issuer);
75984
+ if (tokens?.refresh_token && tokens.issuer == null) {
75985
+ console.warn("[mcp-sdk] stored OAuth tokens have no 'issuer' property (saved by an earlier version, or by a provider that does not keep it) and are used as-is; make sure your OAuthClientProvider stores what saveTokens() and saveClientInformation() receive unchanged.");
75986
+ }
75887
75987
  if (tokens?.refresh_token) {
75888
75988
  try {
75889
75989
  const newTokens = await refreshAuthorization(authorizationServerUrl, {
@@ -75894,7 +75994,8 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
75894
75994
  addClientAuthentication: provider.addClientAuthentication,
75895
75995
  fetchFn
75896
75996
  });
75897
- await provider.saveTokens(newTokens);
75997
+ await bindClientInformation();
75998
+ await provider.saveTokens({ ...newTokens, issuer });
75898
75999
  return "AUTHORIZED";
75899
76000
  } catch (error51) {
75900
76001
  if (!(error51 instanceof OAuthError) || error51 instanceof ServerError) {
@@ -75909,7 +76010,7 @@ async function authInternal(provider, { serverUrl, authorizationCode, scope, res
75909
76010
  clientInformation,
75910
76011
  state,
75911
76012
  redirectUrl: provider.redirectUrl,
75912
- scope: scope || resourceMetadata?.scopes_supported?.join(" ") || provider.clientMetadata.scope,
76013
+ scope: resolvedScope,
75913
76014
  resource
75914
76015
  });
75915
76016
  await provider.saveCodeVerifier(codeVerifier);
@@ -76097,6 +76198,29 @@ async function discoverAuthorizationServerMetadata(authorizationServerUrl, { fet
76097
76198
  }
76098
76199
  return void 0;
76099
76200
  }
76201
+ async function discoverOAuthServerInfo(serverUrl, opts) {
76202
+ let resourceMetadata;
76203
+ let authorizationServerUrl;
76204
+ try {
76205
+ resourceMetadata = await discoverOAuthProtectedResourceMetadata(serverUrl, { resourceMetadataUrl: opts?.resourceMetadataUrl }, opts?.fetchFn);
76206
+ if (resourceMetadata.authorization_servers && resourceMetadata.authorization_servers.length > 0) {
76207
+ authorizationServerUrl = resourceMetadata.authorization_servers[0];
76208
+ }
76209
+ } catch {
76210
+ }
76211
+ if (!authorizationServerUrl) {
76212
+ authorizationServerUrl = String(new URL("/", serverUrl));
76213
+ }
76214
+ const authorizationServerMetadata = await discoverAuthorizationServerMetadata(authorizationServerUrl, { fetchFn: opts?.fetchFn });
76215
+ return {
76216
+ authorizationServerUrl,
76217
+ authorizationServerMetadata,
76218
+ resourceMetadata
76219
+ };
76220
+ }
76221
+ function resourceIndicatorToString(resource) {
76222
+ return typeof resource === "string" ? resource : resource.href;
76223
+ }
76100
76224
  async function startAuthorization(authorizationServerUrl, { metadata, clientInformation, redirectUrl, scope, state, resource }) {
76101
76225
  let authorizationUrl;
76102
76226
  if (metadata) {
@@ -76128,7 +76252,7 @@ async function startAuthorization(authorizationServerUrl, { metadata, clientInfo
76128
76252
  authorizationUrl.searchParams.append("prompt", "consent");
76129
76253
  }
76130
76254
  if (resource) {
76131
- authorizationUrl.searchParams.set("resource", resource.href);
76255
+ authorizationUrl.searchParams.set("resource", resourceIndicatorToString(resource));
76132
76256
  }
76133
76257
  return { authorizationUrl, codeVerifier };
76134
76258
  }
@@ -76147,7 +76271,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
76147
76271
  Accept: "application/json"
76148
76272
  });
76149
76273
  if (resource) {
76150
- tokenRequestParams.set("resource", resource.href);
76274
+ tokenRequestParams.set("resource", resourceIndicatorToString(resource));
76151
76275
  }
76152
76276
  if (addClientAuthentication) {
76153
76277
  await addClientAuthentication(headers, tokenRequestParams, tokenUrl, metadata);
@@ -76164,7 +76288,7 @@ async function executeTokenRequest(authorizationServerUrl, { metadata, tokenRequ
76164
76288
  if (!response.ok) {
76165
76289
  throw await parseErrorResponse(response);
76166
76290
  }
76167
- return OAuthTokensSchema.parse(await response.json());
76291
+ return TokenResponseSchema.parse(await response.json());
76168
76292
  }
76169
76293
  async function refreshAuthorization(authorizationServerUrl, { metadata, clientInformation, refreshToken, resource, addClientAuthentication, fetchFn }) {
76170
76294
  const tokenRequestParams = new URLSearchParams({
@@ -76182,6 +76306,15 @@ async function refreshAuthorization(authorizationServerUrl, { metadata, clientIn
76182
76306
  return { refresh_token: refreshToken, ...tokens };
76183
76307
  }
76184
76308
  async function fetchToken(provider, authorizationServerUrl, { metadata, resource, authorizationCode, fetchFn } = {}) {
76309
+ const readClientInformation = async () => {
76310
+ const storedClientInformation = await provider.clientInformation();
76311
+ const checked = discardIfIssuerMismatch(storedClientInformation, String(authorizationServerUrl));
76312
+ if (storedClientInformation && !checked) {
76313
+ throw boundElsewhereError(storedClientInformation, String(authorizationServerUrl));
76314
+ }
76315
+ return checked;
76316
+ };
76317
+ let clientInformation = await readClientInformation();
76185
76318
  const scope = provider.clientMetadata.scope;
76186
76319
  let tokenRequestParams;
76187
76320
  if (provider.prepareTokenRequest) {
@@ -76197,17 +76330,17 @@ async function fetchToken(provider, authorizationServerUrl, { metadata, resource
76197
76330
  const codeVerifier = await provider.codeVerifier();
76198
76331
  tokenRequestParams = prepareAuthorizationCodeRequest(authorizationCode, codeVerifier, provider.redirectUrl);
76199
76332
  }
76200
- const clientInformation = await provider.clientInformation();
76333
+ clientInformation ?? (clientInformation = await readClientInformation());
76201
76334
  return executeTokenRequest(authorizationServerUrl, {
76202
76335
  metadata,
76203
76336
  tokenRequestParams,
76204
- clientInformation: clientInformation ?? void 0,
76337
+ clientInformation,
76205
76338
  addClientAuthentication: provider.addClientAuthentication,
76206
76339
  resource,
76207
76340
  fetchFn
76208
76341
  });
76209
76342
  }
76210
- async function registerClient(authorizationServerUrl, { metadata, clientMetadata, fetchFn }) {
76343
+ async function registerClient(authorizationServerUrl, { metadata, clientMetadata, scope, fetchFn }) {
76211
76344
  let registrationUrl;
76212
76345
  if (metadata) {
76213
76346
  if (!metadata.registration_endpoint) {
@@ -76222,12 +76355,15 @@ async function registerClient(authorizationServerUrl, { metadata, clientMetadata
76222
76355
  headers: {
76223
76356
  "Content-Type": "application/json"
76224
76357
  },
76225
- body: JSON.stringify(clientMetadata)
76358
+ body: JSON.stringify({
76359
+ ...clientMetadata,
76360
+ ...scope !== void 0 ? { scope } : {}
76361
+ })
76226
76362
  });
76227
76363
  if (!response.ok) {
76228
76364
  throw await parseErrorResponse(response);
76229
76365
  }
76230
- return OAuthClientInformationFullSchema.parse(await response.json());
76366
+ return RegistrationResponseSchema.parse(await response.json());
76231
76367
  }
76232
76368
 
76233
76369
  // src/lib/utils.ts
@@ -76507,7 +76643,7 @@ async function selectCallbackPort(serverUrl, specifiedPort, _unused) {
76507
76643
  }
76508
76644
 
76509
76645
  // src/lib/config.ts
76510
- var MCP_WORDPRESS_REMOTE_VERSION = "0.5.1";
76646
+ var MCP_WORDPRESS_REMOTE_VERSION = "0.5.2";
76511
76647
  function parsePositiveIntEnv(value, defaultValue) {
76512
76648
  if (!value) {
76513
76649
  return defaultValue;
@@ -77080,6 +77216,23 @@ async function proxyFetch(url2, init) {
77080
77216
  // src/lib/wordpress-transport.ts
77081
77217
  import { Readable } from "node:stream";
77082
77218
 
77219
+ // node_modules/@modelcontextprotocol/sdk/dist/esm/shared/mediaType.js
77220
+ var import_content_type = __toESM(require_content_type(), 1);
77221
+ function mediaTypeEssence(header) {
77222
+ if (!header) {
77223
+ return void 0;
77224
+ }
77225
+ try {
77226
+ return import_content_type.default.parse(header).type;
77227
+ } catch {
77228
+ const essence = (header.split(";", 1)[0] ?? "").trim().toLowerCase();
77229
+ if (essence === "" || header.slice(essence.length).includes(",")) {
77230
+ return void 0;
77231
+ }
77232
+ return essence;
77233
+ }
77234
+ }
77235
+
77083
77236
  // node_modules/eventsource-parser/dist/stream.js
77084
77237
  var EventSourceParserStream = class extends TransformStream {
77085
77238
  constructor({ onError, onRetry, onComment } = {}) {
@@ -77420,11 +77573,12 @@ var StreamableHTTPClientTransport = class {
77420
77573
  }
77421
77574
  const messages = Array.isArray(message) ? message : [message];
77422
77575
  const hasRequests = messages.filter((msg) => "method" in msg && "id" in msg && msg.id !== void 0).length > 0;
77423
- const contentType = response.headers.get("content-type");
77576
+ const contentType2 = response.headers.get("content-type");
77577
+ const responseMediaType = mediaTypeEssence(contentType2);
77424
77578
  if (hasRequests) {
77425
- if (contentType?.includes("text/event-stream")) {
77579
+ if (responseMediaType === "text/event-stream") {
77426
77580
  this._handleSseStream(response.body, { onresumptiontoken }, false);
77427
- } else if (contentType?.includes("application/json")) {
77581
+ } else if (responseMediaType === "application/json") {
77428
77582
  const data = await response.json();
77429
77583
  const responseMessages = Array.isArray(data) ? data.map((msg) => JSONRPCMessageSchema.parse(msg)) : [JSONRPCMessageSchema.parse(data)];
77430
77584
  for (const msg of responseMessages) {
@@ -77432,7 +77586,7 @@ var StreamableHTTPClientTransport = class {
77432
77586
  }
77433
77587
  } else {
77434
77588
  await response.body?.cancel();
77435
- throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType}`);
77589
+ throw new StreamableHTTPError(-1, `Unexpected content type: ${contentType2}`);
77436
77590
  }
77437
77591
  } else {
77438
77592
  await response.body?.cancel();
@@ -78645,7 +78799,11 @@ var OAuthCallbackServer = class {
78645
78799
  async start() {
78646
78800
  return new Promise((resolve, reject) => {
78647
78801
  try {
78648
- this.server = this.app.listen(this.options.port, this.options.host, () => {
78802
+ this.server = this.app.listen(this.options.port, this.options.host, (error51) => {
78803
+ if (error51) {
78804
+ reject(error51);
78805
+ return;
78806
+ }
78649
78807
  logger.oauth(
78650
78808
  `OAuth callback server listening on http://${this.options.host}:${this.options.port}`
78651
78809
  );
@@ -79788,6 +79946,19 @@ async function getOAuthTokens() {
79788
79946
  return null;
79789
79947
  }
79790
79948
  }
79949
+ async function discardRejectedOAuthToken(authorization) {
79950
+ if (!CONFIG.OAUTH_ENABLED || CONFIG.JWT_TOKEN) {
79951
+ return false;
79952
+ }
79953
+ const serverUrlHash = generateServerUrlHash(CONFIG.WP_API_URL);
79954
+ const tokens = await readTokens(serverUrlHash);
79955
+ if (!tokens || authorization !== `Bearer ${tokens.access_token}`) {
79956
+ return false;
79957
+ }
79958
+ logger.warn("WordPress rejected the stored OAuth token; signing in again", "AUTH");
79959
+ await deleteTokens(serverUrlHash);
79960
+ return true;
79961
+ }
79791
79962
  function getCurrentApiUrl() {
79792
79963
  return process.env.WP_API_URL || CONFIG.WP_API_URL;
79793
79964
  }
@@ -79887,6 +80058,9 @@ function collectHeaderParams(schema, path6 = []) {
79887
80058
  return [...own, ...collectHeaderParams(child, [...path6, key])];
79888
80059
  });
79889
80060
  }
80061
+ function isBearerChallenge(challenge) {
80062
+ return challenge === null || /^Bearer\b/i.test(challenge);
80063
+ }
79890
80064
  function valueAtPath(value, path6) {
79891
80065
  return path6.reduce(
79892
80066
  (node, key) => node && typeof node === "object" ? node[key] : void 0,
@@ -79896,25 +80070,24 @@ function valueAtPath(value, path6) {
79896
80070
  function createWordPressTransport(onFailure) {
79897
80071
  const inflight = /* @__PURE__ */ new Map();
79898
80072
  const toolHeaders = /* @__PURE__ */ new Map();
79899
- const fetch3 = async (url2, init) => {
80073
+ const send = async (url2, init, retried) => {
79900
80074
  const message = typeof init?.body === "string" ? JSON.parse(init.body) : void 0;
79901
80075
  const request = message && "method" in message && "id" in message ? message : void 0;
79902
80076
  const controller = new AbortController();
79903
- const abort = () => controller.abort();
79904
80077
  let cancelled = false;
79905
80078
  const cancel = () => {
79906
80079
  cancelled = true;
79907
- abort();
80080
+ controller.abort();
79908
80081
  };
79909
80082
  if (request) inflight.set(request.id, cancel);
79910
- init?.signal?.addEventListener("abort", abort, { once: true });
79911
- if (init?.signal?.aborted) abort();
80083
+ init?.signal?.addEventListener("abort", cancel, { once: true });
80084
+ if (init?.signal?.aborted) cancel();
79912
80085
  const timeoutMs = message && "method" in message && message.method === "initialize" ? CONFIG.WP_API_INIT_TIMEOUT : CONFIG.WP_API_TIMEOUT;
79913
80086
  let timedOut = false;
79914
80087
  let timer;
79915
80088
  const cleanup = () => {
79916
80089
  clearTimeout(timer);
79917
- init?.signal?.removeEventListener("abort", abort);
80090
+ init?.signal?.removeEventListener("abort", cancel);
79918
80091
  if (request && inflight.get(request.id) === cancel) inflight.delete(request.id);
79919
80092
  };
79920
80093
  const failure = (error51) => {
@@ -79963,17 +80136,28 @@ function createWordPressTransport(onFailure) {
79963
80136
  headers,
79964
80137
  signal: controller.signal
79965
80138
  });
80139
+ if (response.status === 401 && !retried && isBearerChallenge(response.headers.get("WWW-Authenticate")) && await discardRejectedOAuthToken(headers.get("Authorization"))) {
80140
+ const unread = response.body;
80141
+ if (typeof unread?.cancel === "function") await unread.cancel();
80142
+ else unread?.destroy?.();
80143
+ cleanup();
80144
+ if (cancelled) return new Response(null, { status: 202 });
80145
+ return send(url2, init, true);
80146
+ }
79966
80147
  const body = response.body && typeof response.body.getReader !== "function" ? Readable.toWeb(response.body) : response.body;
79967
80148
  const reader = body?.getReader();
80149
+ let released = false;
79968
80150
  const stream = reader ? new ReadableStream({
79969
80151
  async pull(output) {
79970
80152
  try {
79971
80153
  const { value, done } = await reader.read();
80154
+ if (released) return;
79972
80155
  if (done) {
79973
80156
  cleanup();
79974
80157
  output.close();
79975
80158
  } else output.enqueue(value);
79976
80159
  } catch (error51) {
80160
+ if (released) return;
79977
80161
  if (cancelled) {
79978
80162
  cleanup();
79979
80163
  output.close();
@@ -79981,6 +80165,7 @@ function createWordPressTransport(onFailure) {
79981
80165
  }
79982
80166
  },
79983
80167
  async cancel(reason) {
80168
+ released = true;
79984
80169
  cleanup();
79985
80170
  await reader.cancel(reason);
79986
80171
  }
@@ -80019,6 +80204,7 @@ function createWordPressTransport(onFailure) {
80019
80204
  throw failure(error51);
80020
80205
  }
80021
80206
  };
80207
+ const fetch3 = (url2, init) => send(url2, init, false);
80022
80208
  return Object.assign(new StreamableHTTPClientTransport(new URL(getRequestUrl()), { fetch: fetch3 }), {
80023
80209
  cancelRequest(id) {
80024
80210
  inflight.get(id)?.();
@@ -80285,6 +80471,13 @@ formdata-polyfill/esm.min.js:
80285
80471
  node-domexception/index.js:
80286
80472
  (*! node-domexception. MIT License. Jimmy Wärting <https://jimmy.warting.se/opensource> *)
80287
80473
 
80474
+ content-type/index.js:
80475
+ (*!
80476
+ * content-type
80477
+ * Copyright(c) 2015 Douglas Christopher Wilson
80478
+ * MIT Licensed
80479
+ *)
80480
+
80288
80481
  depd/index.js:
80289
80482
  (*!
80290
80483
  * depd
@@ -80482,13 +80675,6 @@ express/lib/view.js:
80482
80675
  * MIT Licensed
80483
80676
  *)
80484
80677
 
80485
- content-type/index.js:
80486
- (*!
80487
- * content-type
80488
- * Copyright(c) 2015 Douglas Christopher Wilson
80489
- * MIT Licensed
80490
- *)
80491
-
80492
80678
  etag/index.js:
80493
80679
  (*!
80494
80680
  * etag
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@automattic/mcp-wordpress-remote",
3
- "version": "0.5.1",
3
+ "version": "0.5.2",
4
4
  "description": "MCP WordPress Remote proxy server",
5
5
  "engines": {
6
6
  "node": ">=18.0.0"