@vitemcp/server 1.8.8 → 1.9.1

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.
Files changed (41) hide show
  1. package/README.md +9 -3
  2. package/dist/{OAuthProvider-COBBSCMI.d.cts → OAuthProvider-BaPwgWny.d.cts} +23 -2
  3. package/dist/{OAuthProvider-COBBSCMI.d.ts → OAuthProvider-BaPwgWny.d.ts} +23 -2
  4. package/dist/ViteMCP.cjs +4 -3
  5. package/dist/ViteMCP.cjs.map +1 -1
  6. package/dist/ViteMCP.d.cts +5 -4
  7. package/dist/ViteMCP.d.ts +5 -4
  8. package/dist/ViteMCP.js +3 -2
  9. package/dist/auth/index.cjs +2 -2
  10. package/dist/auth/index.d.cts +2 -2
  11. package/dist/auth/index.d.ts +2 -2
  12. package/dist/auth/index.js +1 -1
  13. package/dist/chunk-4FH73ERY.js +64 -0
  14. package/dist/chunk-4FH73ERY.js.map +1 -0
  15. package/dist/chunk-FEM6LNS4.cjs +64 -0
  16. package/dist/chunk-FEM6LNS4.cjs.map +1 -0
  17. package/dist/{chunk-M22UTH2Z.js → chunk-IHX3AXKW.js} +204 -137
  18. package/dist/chunk-IHX3AXKW.js.map +1 -0
  19. package/dist/{chunk-5KNSU2F3.js → chunk-KKSDTVEW.js} +87 -18
  20. package/dist/chunk-KKSDTVEW.js.map +1 -0
  21. package/dist/{chunk-Y3GRHB77.cjs → chunk-SHPKRGNY.cjs} +101 -32
  22. package/dist/chunk-SHPKRGNY.cjs.map +1 -0
  23. package/dist/{chunk-7UCE3YTY.cjs → chunk-Y52P2PCS.cjs} +216 -149
  24. package/dist/chunk-Y52P2PCS.cjs.map +1 -0
  25. package/dist/edge/index.cjs +128 -21
  26. package/dist/edge/index.cjs.map +1 -1
  27. package/dist/edge/index.d.cts +6 -0
  28. package/dist/edge/index.d.ts +6 -0
  29. package/dist/edge/index.js +127 -20
  30. package/dist/edge/index.js.map +1 -1
  31. package/dist/openapi/index.cjs +36 -18
  32. package/dist/openapi/index.cjs.map +1 -1
  33. package/dist/openapi/index.d.cts +1 -1
  34. package/dist/openapi/index.d.ts +1 -1
  35. package/dist/openapi/index.js +28 -10
  36. package/dist/openapi/index.js.map +1 -1
  37. package/package.json +1 -1
  38. package/dist/chunk-5KNSU2F3.js.map +0 -1
  39. package/dist/chunk-7UCE3YTY.cjs.map +0 -1
  40. package/dist/chunk-M22UTH2Z.js.map +0 -1
  41. package/dist/chunk-Y3GRHB77.cjs.map +0 -1
@@ -1,4 +1,16 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }// src/ViteMCP.ts
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkSHPKRGNYcjs = require('./chunk-SHPKRGNY.cjs');
4
+
5
+
6
+
7
+
8
+ var _chunkFEM6LNS4cjs = require('./chunk-FEM6LNS4.cjs');
9
+
10
+ // src/ViteMCP.ts
11
+
12
+
13
+
2
14
 
3
15
 
4
16
 
@@ -460,6 +472,16 @@ var ServerState = /* @__PURE__ */ ((ServerState2) => {
460
472
  })(ServerState || {});
461
473
  var LATCH_NAME = "vitemcp.internal.capability-latch";
462
474
  var LATCH_URI = "vitemcp-internal:capability-latch";
475
+ var LOG_LEVELS = [
476
+ "debug",
477
+ "info",
478
+ "notice",
479
+ "warning",
480
+ "error",
481
+ "critical",
482
+ "alert",
483
+ "emergency"
484
+ ];
463
485
  var stderrLogger = {
464
486
  debug: (...args) => console.error(...args),
465
487
  error: (...args) => console.error(...args),
@@ -518,16 +540,16 @@ var ViteMCP = class {
518
540
  #logger;
519
541
  #options;
520
542
  #prompts = [];
521
- #resources = [];
522
- #resourceTemplates = [];
523
- #serverState = "stopped" /* Stopped */;
524
543
  /**
525
- * Whether this server publishes an RFC 9728 protected-resource document, and
526
- * so whether a 401 can point a client at it. Latched when the routes are
544
+ * The RFC 9728 protected-resource document this server publishes, if it
545
+ * publishes one — what a 401 points a client at. Latched when the routes are
527
546
  * mounted rather than read back from `auth` per rejection: the provider's
528
547
  * config getter builds its proxy on demand and refuses once destroyed.
529
548
  */
530
- #servesProtectedResourceMetadata = false;
549
+ #protectedResource;
550
+ #resources = [];
551
+ #resourceTemplates = [];
552
+ #serverState = "stopped" /* Stopped */;
531
553
  #stdioHandle = null;
532
554
  #tools = [];
533
555
  /** Each tool's schemas, as `#sdkSchemasFor` converted them. */
@@ -610,7 +632,11 @@ var ViteMCP = class {
610
632
  uri
611
633
  });
612
634
  }
613
- return { ...first, mimeType: _nullishCoalesce(first.mimeType, () => ( direct.mimeType)), uri };
635
+ return {
636
+ ...first,
637
+ mimeType: _nullishCoalesce(first.mimeType, () => ( direct.mimeType)),
638
+ uri: _nullishCoalesce(first.uri, () => ( uri))
639
+ };
614
640
  }
615
641
  for (const template of this.#resourceTemplates) {
616
642
  const params = _uritemplates2.default.call(void 0, template.uriTemplate).fromUri(uri);
@@ -628,7 +654,11 @@ var ViteMCP = class {
628
654
  { uri }
629
655
  );
630
656
  }
631
- return { ...first, mimeType: _nullishCoalesce(first.mimeType, () => ( template.mimeType)), uri };
657
+ return {
658
+ ...first,
659
+ mimeType: _nullishCoalesce(first.mimeType, () => ( template.mimeType)),
660
+ uri: _nullishCoalesce(first.uri, () => ( uri))
661
+ };
632
662
  }
633
663
  throw new UnexpectedStateError(`Resource not found: ${uri}`, { uri });
634
664
  }
@@ -638,7 +668,8 @@ var ViteMCP = class {
638
668
  }
639
669
  /**
640
670
  * Publishes `notifications/resources/updated` for a URI to any subscription
641
- * that opted in to it.
671
+ * that opted in to it and whose caller may read it. HTTP only: a stdio
672
+ * client is never reached.
642
673
  */
643
674
  notifyResourceUpdated(uri) {
644
675
  _optionalChain([this, 'access', _13 => _13.#handler, 'optionalAccess', _14 => _14.notify, 'access', _15 => _15.resourceUpdated, 'call', _16 => _16(uri)]);
@@ -684,7 +715,9 @@ var ViteMCP = class {
684
715
  try {
685
716
  if (options.transportType === "stdio") {
686
717
  this.#logger = _nullishCoalesce(this.#options.logger, () => ( stderrLogger));
687
- this.#stdioHandle = _stdio.serveStdio.call(void 0, () => this.#buildServer(void 0));
718
+ this.#stdioHandle = _stdio.serveStdio.call(void 0,
719
+ ({ era }) => this.#buildServer(void 0, { era })
720
+ );
688
721
  this.#logger.info(`[ViteMCP info] server is running on stdio`);
689
722
  } else {
690
723
  await this.#startHttp(options.httpStream);
@@ -747,7 +780,16 @@ var ViteMCP = class {
747
780
  }
748
781
  return { auth };
749
782
  }
750
- async #buildServer(auth) {
783
+ /**
784
+ * `era` is the protocol era the server will speak, where it is known: one
785
+ * built for `connect()` speaks whichever the client picks.
786
+ * `resourceSubscriptions` declares `resources.subscribe`. Set it only where
787
+ * `notifyResourceUpdated` delivers: to 2026-07-28 HTTP clients.
788
+ */
789
+ async #buildServer(auth, {
790
+ era,
791
+ resourceSubscriptions = false
792
+ } = {}) {
751
793
  const server = new (0, _server.McpServer)(
752
794
  {
753
795
  description: this.#options.description,
@@ -757,7 +799,15 @@ var ViteMCP = class {
757
799
  version: this.#options.version,
758
800
  websiteUrl: this.#options.websiteUrl
759
801
  },
760
- { instructions: this.#options.instructions }
802
+ {
803
+ // Without it the SDK refuses to send `notifications/message`, and
804
+ // `log.*` swallows the refusal, so every log line vanished silently.
805
+ // Left out for a 2025-era client: `log.*` answers only the 2026-07-28
806
+ // per-request opt-in, so the `logging/setLevel` it would promise that
807
+ // client could never take effect.
808
+ capabilities: era === "legacy" ? {} : { logging: {} },
809
+ instructions: this.#options.instructions
810
+ }
761
811
  );
762
812
  const visible = (all) => all.filter((entry) => !entry.canAccess || entry.canAccess(auth));
763
813
  const tools = (await Promise.all(
@@ -770,6 +820,29 @@ var ViteMCP = class {
770
820
  const resourceTemplates = visible(this.#resourceTemplates);
771
821
  const prompts = visible(this.#prompts);
772
822
  for (const { schemas, tool } of tools) {
823
+ const call = async (args, ctx) => {
824
+ const timeout = tool.timeoutMs ? { controller: new AbortController(), ms: tool.timeoutMs } : void 0;
825
+ const { context, release } = this.#makeContext(
826
+ auth,
827
+ ctx,
828
+ _optionalChain([timeout, 'optionalAccess', _23 => _23.controller, 'access', _24 => _24.signal])
829
+ );
830
+ try {
831
+ const result = await (timeout ? withTimeout(tool.execute(args, context), timeout, tool.name) : tool.execute(args, context));
832
+ return normalizeToolResult(result, tool.outputSchema !== void 0);
833
+ } catch (error) {
834
+ if (error instanceof UserError) {
835
+ return {
836
+ content: [{ text: error.message, type: "text" }],
837
+ isError: true,
838
+ ...error.extras ? { structuredContent: error.extras } : {}
839
+ };
840
+ }
841
+ throw error;
842
+ } finally {
843
+ release();
844
+ }
845
+ };
773
846
  server.registerTool(
774
847
  tool.name,
775
848
  {
@@ -779,29 +852,12 @@ var ViteMCP = class {
779
852
  inputSchema: schemas.inputSchema,
780
853
  outputSchema: schemas.outputSchema
781
854
  },
782
- (async (args, ctx) => {
783
- const timeout = tool.timeoutMs ? { controller: new AbortController(), ms: tool.timeoutMs } : void 0;
784
- const { context, release } = this.#makeContext(
785
- auth,
786
- ctx,
787
- _optionalChain([timeout, 'optionalAccess', _23 => _23.controller, 'access', _24 => _24.signal])
788
- );
789
- try {
790
- const result = await (timeout ? withTimeout(tool.execute(args, context), timeout, tool.name) : tool.execute(args, context));
791
- return normalizeToolResult(result, tool.outputSchema !== void 0);
792
- } catch (error) {
793
- if (error instanceof UserError) {
794
- return {
795
- content: [{ text: error.message, type: "text" }],
796
- isError: true,
797
- ...error.extras ? { structuredContent: error.extras } : {}
798
- };
799
- }
800
- throw error;
801
- } finally {
802
- release();
803
- }
804
- })
855
+ // The SDK passes arguments only to a tool that declares an input
856
+ // schema; one that does not is called with the request context alone.
857
+ // Registering `call` as it stands would take that context for `args`
858
+ // and leave the tool without one: no progress, no logs, no request id
859
+ // and a `signal` that never fires.
860
+ schemas.inputSchema ? call : (ctx) => call(void 0, ctx)
805
861
  );
806
862
  }
807
863
  for (const resource of resources) {
@@ -869,31 +925,32 @@ var ViteMCP = class {
869
925
  );
870
926
  }
871
927
  for (const prompt of prompts) {
928
+ const argsSchema = promptArgsSchema(prompt);
929
+ const load = async (args, ctx) => {
930
+ const { context, release } = this.#makeContext(auth, ctx);
931
+ try {
932
+ const loaded = await prompt.load(_nullishCoalesce(args, () => ( {})), context);
933
+ if (typeof loaded !== "string") {
934
+ return loaded;
935
+ }
936
+ return {
937
+ messages: [
938
+ {
939
+ content: { text: loaded, type: "text" },
940
+ role: "user"
941
+ }
942
+ ]
943
+ };
944
+ } finally {
945
+ release();
946
+ }
947
+ };
872
948
  server.registerPrompt(
873
949
  prompt.name,
874
- {
875
- argsSchema: promptArgsSchema(prompt),
876
- description: prompt.description
877
- },
878
- (async (args, ctx) => {
879
- const { context, release } = this.#makeContext(auth, ctx);
880
- try {
881
- const loaded = await prompt.load(_nullishCoalesce(args, () => ( {})), context);
882
- if (typeof loaded !== "string") {
883
- return loaded;
884
- }
885
- return {
886
- messages: [
887
- {
888
- content: { text: loaded, type: "text" },
889
- role: "user"
890
- }
891
- ]
892
- };
893
- } finally {
894
- release();
895
- }
896
- })
950
+ { argsSchema, description: prompt.description },
951
+ // As for tools: without `argsSchema` the SDK passes the request
952
+ // context alone.
953
+ argsSchema ? load : (ctx) => load(void 0, ctx)
897
954
  );
898
955
  }
899
956
  if (this.#tools.length > 0 && tools.length === 0) {
@@ -907,8 +964,48 @@ var ViteMCP = class {
907
964
  if (this.#prompts.length > 0 && prompts.length === 0) {
908
965
  server.registerPrompt(LATCH_NAME, {}, (() => ({ messages: [] }))).remove();
909
966
  }
967
+ if (resourceSubscriptions && server.server.getCapabilities().resources) {
968
+ server.server.registerCapabilities({ resources: { subscribe: true } });
969
+ }
910
970
  return server;
911
971
  }
972
+ /**
973
+ * Whether `resources/read` would serve `uri` to this caller: a resource of
974
+ * that URI, or a template matching it, that `canAccess` leaves visible.
975
+ */
976
+ #canRead(uri, auth) {
977
+ const visible = (entry) => !entry.canAccess || entry.canAccess(auth);
978
+ return this.#resources.some(
979
+ (resource) => resource.uri === uri && visible(resource)
980
+ ) || this.#resourceTemplates.some(
981
+ (template) => visible(template) && new (0, _server.UriTemplate)(template.uriTemplate).match(uri) !== null
982
+ );
983
+ }
984
+ /**
985
+ * The bus `notifyResourceUpdated` publishes to and `subscriptions/listen`
986
+ * streams read from, narrowed per stream to updates its caller could read.
987
+ *
988
+ * `canAccess` keeps a resource out of `resources/read`, so its updates must
989
+ * not reach that caller either, or subscribing to the URI would reveal what
990
+ * reading it cannot. The SDK subscribes a stream while serving its listen
991
+ * request, so that caller's auth is still in scope here.
992
+ */
993
+ #eventBus() {
994
+ const events = new (0, _server.InMemoryServerEventBus)(
995
+ (error) => this.#logger.error("[ViteMCP error]", error)
996
+ );
997
+ return {
998
+ publish: (event) => events.publish(event),
999
+ subscribe: (listener) => {
1000
+ const auth = _optionalChain([this, 'access', _25 => _25.#authStore, 'access', _26 => _26.getStore, 'call', _27 => _27(), 'optionalAccess', _28 => _28.auth]);
1001
+ return events.subscribe((event) => {
1002
+ if (event.kind !== "resource_updated" || this.#canRead(event.uri, auth)) {
1003
+ listener(event);
1004
+ }
1005
+ });
1006
+ }
1007
+ };
1008
+ }
912
1009
  /** Builds the Hono app with the CORS shim installed ahead of user routes. */
913
1010
  #freshApp() {
914
1011
  const app = new (0, _hono.Hono)();
@@ -927,19 +1024,19 @@ var ViteMCP = class {
927
1024
  */
928
1025
  #makeContext(auth, rawCtx, timeoutSignal) {
929
1026
  const ctx = rawCtx;
930
- const mcpReq = _optionalChain([ctx, 'optionalAccess', _25 => _25.mcpReq]);
931
- const requestedLevel = _optionalChain([mcpReq, 'optionalAccess', _26 => _26._meta, 'optionalAccess', _27 => _27["io.modelcontextprotocol/logLevel"]]);
1027
+ const mcpReq = _optionalChain([ctx, 'optionalAccess', _29 => _29.mcpReq]);
1028
+ const requestedLevel = _optionalChain([mcpReq, 'optionalAccess', _30 => _30.envelope, 'optionalAccess', _31 => _31[_server.LOG_LEVEL_META_KEY]]);
932
1029
  const emit = (level, message, data) => {
933
- if (!requestedLevel) {
1030
+ if (!requestedLevel || LOG_LEVELS.indexOf(level) < LOG_LEVELS.indexOf(requestedLevel)) {
934
1031
  return;
935
1032
  }
936
- void _optionalChain([mcpReq, 'optionalAccess', _28 => _28.notify, 'optionalCall', _29 => _29({
1033
+ void _optionalChain([mcpReq, 'optionalAccess', _32 => _32.notify, 'optionalCall', _33 => _33({
937
1034
  method: "notifications/message",
938
1035
  params: { data: { context: data, message }, level }
939
- }), 'optionalAccess', _30 => _30.catch, 'call', _31 => _31(() => {
1036
+ }), 'optionalAccess', _34 => _34.catch, 'call', _35 => _35(() => {
940
1037
  })]);
941
1038
  };
942
- const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _32 => _32.signal]), timeoutSignal);
1039
+ const scope = requestScope(_optionalChain([mcpReq, 'optionalAccess', _36 => _36.signal]), timeoutSignal);
943
1040
  return {
944
1041
  context: {
945
1042
  auth,
@@ -948,12 +1045,12 @@ var ViteMCP = class {
948
1045
  requestedSchema: params.requestedSchema
949
1046
  }),
950
1047
  input: (key, schema) => _server.acceptedContent.call(void 0,
951
- _optionalChain([mcpReq, 'optionalAccess', _33 => _33.inputResponses]),
1048
+ _optionalChain([mcpReq, 'optionalAccess', _37 => _37.inputResponses]),
952
1049
  key,
953
1050
  schema
954
1051
  ),
955
1052
  inputRequired: (inputRequests, requestState) => _server.inputRequired.call(void 0, { inputRequests, requestState }),
956
- inputResponses: _optionalChain([mcpReq, 'optionalAccess', _34 => _34.inputResponses]),
1053
+ inputResponses: _optionalChain([mcpReq, 'optionalAccess', _38 => _38.inputResponses]),
957
1054
  log: {
958
1055
  debug: (m, d) => emit("debug", m, d),
959
1056
  error: (m, d) => emit("error", m, d),
@@ -961,11 +1058,11 @@ var ViteMCP = class {
961
1058
  warn: (m, d) => emit("warning", m, d)
962
1059
  },
963
1060
  reportProgress: async (progress) => {
964
- const progressToken = _optionalChain([mcpReq, 'optionalAccess', _35 => _35._meta, 'optionalAccess', _36 => _36.progressToken]);
1061
+ const progressToken = _optionalChain([mcpReq, 'optionalAccess', _39 => _39._meta, 'optionalAccess', _40 => _40.progressToken]);
965
1062
  if (progressToken === void 0) {
966
1063
  return;
967
1064
  }
968
- await _optionalChain([mcpReq, 'optionalAccess', _37 => _37.notify, 'optionalCall', _38 => _38({
1065
+ await _optionalChain([mcpReq, 'optionalAccess', _41 => _41.notify, 'optionalCall', _42 => _42({
969
1066
  method: "notifications/progress",
970
1067
  params: {
971
1068
  message: progress.message,
@@ -975,10 +1072,10 @@ var ViteMCP = class {
975
1072
  }
976
1073
  })]);
977
1074
  },
978
- requestId: _optionalChain([mcpReq, 'optionalAccess', _39 => _39.id]),
1075
+ requestId: _optionalChain([mcpReq, 'optionalAccess', _43 => _43.id]),
979
1076
  // The SDK exposes this as an accessor; call it so callers get the
980
1077
  // value.
981
- requestState: _optionalChain([mcpReq, 'optionalAccess', _40 => _40.requestState, 'optionalCall', _41 => _41()]),
1078
+ requestState: _optionalChain([mcpReq, 'optionalAccess', _44 => _44.requestState, 'optionalCall', _45 => _45()]),
982
1079
  signal: scope.signal
983
1080
  },
984
1081
  release: scope.release
@@ -990,7 +1087,7 @@ var ViteMCP = class {
990
1087
  * no addressee on a stateless transport.
991
1088
  */
992
1089
  #notifyListChanged(kind) {
993
- const notifier = _optionalChain([this, 'access', _42 => _42.#handler, 'optionalAccess', _43 => _43.notify]);
1090
+ const notifier = _optionalChain([this, 'access', _46 => _46.#handler, 'optionalAccess', _47 => _47.notify]);
994
1091
  if (!notifier) {
995
1092
  return;
996
1093
  }
@@ -1038,8 +1135,14 @@ var ViteMCP = class {
1038
1135
  // Authentication has already run in the route below, which is the only
1039
1136
  // place that can turn a refusal into an HTTP status. What reaches here
1040
1137
  // is either an authenticated session or a deliberately anonymous one.
1041
- async () => this.#buildServer(_optionalChain([this, 'access', _44 => _44.#authStore, 'access', _45 => _45.getStore, 'call', _46 => _46(), 'optionalAccess', _47 => _47.auth])),
1138
+ async ({ era }) => this.#buildServer(_optionalChain([this, 'access', _48 => _48.#authStore, 'access', _49 => _49.getStore, 'call', _50 => _50(), 'optionalAccess', _51 => _51.auth]), {
1139
+ era,
1140
+ // A 2025-era client reads `resources.subscribe` as a promise of
1141
+ // `resources/subscribe`, which is not served.
1142
+ resourceSubscriptions: era === "modern"
1143
+ }),
1042
1144
  {
1145
+ bus: this.#eventBus(),
1043
1146
  // Tradeoff: `server/discover` advertises only 2026-07-28, so legacy
1044
1147
  // requests are answered unadvertised and skip Mcp-* validation.
1045
1148
  legacy: _nullishCoalesce(config.legacy, () => ( "stateless")),
@@ -1048,7 +1151,11 @@ var ViteMCP = class {
1048
1151
  }
1049
1152
  );
1050
1153
  this.#corsMiddleware = config.cors === false ? null : _cors.cors.call(void 0, config.cors);
1051
- const oauth = _nullishCoalesce(this.#options.oauth, () => ( _optionalChain([this, 'access', _48 => _48.#options, 'access', _49 => _49.auth, 'optionalAccess', _50 => _50.getOAuthConfig, 'call', _51 => _51()])));
1154
+ const provider = this.#options.auth;
1155
+ const oauth = _nullishCoalesce(this.#options.oauth, () => ( (provider && withEndpointAsResource(
1156
+ provider.getOAuthConfig(),
1157
+ _nullishCoalesce(config.endpoint, () => ( "/mcp"))
1158
+ ))));
1052
1159
  if (_optionalChain([oauth, 'optionalAccess', _52 => _52.enabled]) !== false && (_nullishCoalesce(_nullishCoalesce(_optionalChain([oauth, 'optionalAccess', _53 => _53.proxy]), () => ( _optionalChain([oauth, 'optionalAccess', _54 => _54.authorizationServer]))), () => ( _optionalChain([oauth, 'optionalAccess', _55 => _55.protectedResource]))))) {
1053
1160
  this.#honoApp.route(
1054
1161
  "/",
@@ -1060,7 +1167,7 @@ var ViteMCP = class {
1060
1167
  proxy: oauth.proxy
1061
1168
  })
1062
1169
  );
1063
- this.#servesProtectedResourceMetadata = Boolean(oauth.protectedResource);
1170
+ this.#protectedResource = oauth.protectedResource;
1064
1171
  }
1065
1172
  const health = this.#options.health;
1066
1173
  if (_optionalChain([health, 'optionalAccess', _56 => _56.enabled]) !== false) {
@@ -1107,7 +1214,7 @@ var ViteMCP = class {
1107
1214
  res.end(
1108
1215
  JSON.stringify({
1109
1216
  error: "invalid_request",
1110
- error_description: `Request body exceeds ${formatBytes(maxBodySize)}`
1217
+ error_description: `Request body exceeds ${_chunkFEM6LNS4cjs.formatBytes.call(void 0, maxBodySize)}`
1111
1218
  })
1112
1219
  );
1113
1220
  return;
@@ -1119,7 +1226,7 @@ var ViteMCP = class {
1119
1226
  outgoing: res
1120
1227
  }
1121
1228
  );
1122
- res.writeHead(response.status, Object.fromEntries(response.headers));
1229
+ res.writeHead(response.status, toNodeHeaders(response.headers));
1123
1230
  if (!response.body) {
1124
1231
  res.end();
1125
1232
  return;
@@ -1177,43 +1284,18 @@ var ViteMCP = class {
1177
1284
  );
1178
1285
  }
1179
1286
  /**
1180
- * Gives the SDK a JSON Schema for a schema that has none of its own. Zod v4
1181
- * and ArkType emit JSON Schema natively and pass through; anything else
1182
- * (Valibot, say) is converted, and the conversion is only what `tools/list`
1183
- * advertises. Validation stays with the library the schema was written in:
1184
- * the conversion drops what JSON Schema cannot say — a transform, a
1185
- * `check()` — so validating against it instead would pass `execute`
1186
- * arguments the schema never produced.
1187
- *
1188
- * Advertised inputs are closed with `strictInputSchema`. Outputs are left as
1189
- * converted, since closing them would misdescribe results the schema allows.
1287
+ * A tool schema in the form the SDK registers it — see `toSdkSchema` — with
1288
+ * a failed conversion reported under the tool's own name.
1190
1289
  */
1191
1290
  async #toSdkSchema(schema, label, io) {
1192
- if (!schema) {
1193
- return void 0;
1194
- }
1195
- const standard = schema["~standard"];
1196
- if (standard.jsonSchema) {
1197
- return schema;
1198
- }
1199
- let json;
1200
1291
  try {
1201
- json = await convertToJsonSchema(schema, io);
1292
+ return await _chunkFEM6LNS4cjs.toSdkSchema.call(void 0, schema, io, convertToJsonSchema);
1202
1293
  } catch (error) {
1203
1294
  throw new UnexpectedStateError(
1204
1295
  `${label} is not a supported Standard Schema: ${error instanceof Error ? error.message : String(error)}`,
1205
1296
  { label }
1206
1297
  );
1207
1298
  }
1208
- const advertised = io === "input" ? strictInputSchema(json) : json;
1209
- return {
1210
- "~standard": {
1211
- jsonSchema: { input: () => advertised, output: () => advertised },
1212
- validate: (value) => standard.validate(value),
1213
- vendor: standard.vendor,
1214
- version: standard.version
1215
- }
1216
- };
1217
1299
  }
1218
1300
  /**
1219
1301
  * The RFC 6750 §3 challenge sent when `authenticate` refuses a request.
@@ -1221,21 +1303,36 @@ var ViteMCP = class {
1221
1303
  * `resource_metadata` (RFC 9728 §5.1) is the parameter that turns a bare
1222
1304
  * rejection into a login: it points the client at this server's
1223
1305
  * protected-resource document, from which it discovers the authorization
1224
- * server and starts the flow. It is derived from the URL the request
1225
- * arrived on, which is exactly where `createOAuthRouter` mounts that
1226
- * document, and is omitted when this server publishes no such document.
1306
+ * server and starts the flow. It is omitted when this server publishes no
1307
+ * such document.
1308
+ *
1309
+ * The URL is formed from the resource that document names: the address the
1310
+ * server was configured as, which is the one a client can reach. The
1311
+ * request's own URL is not that address behind a proxy that terminates TLS —
1312
+ * it carries the listener's scheme and whatever Host was forwarded, so a
1313
+ * challenge built from it sent clients to `http://`, or to an internal host.
1314
+ * It is the fallback only, for a document that names no resource.
1227
1315
  */
1228
1316
  #unauthorized(request) {
1317
+ const published = this.#protectedResource;
1229
1318
  return _server.bearerAuthChallengeResponse.call(void 0,
1230
1319
  new (0, _server.OAuthError)(_server.OAuthErrorCode.InvalidToken, "Authentication required"),
1231
- this.#servesProtectedResourceMetadata ? {
1320
+ published ? {
1232
1321
  resourceMetadataUrl: _server.getOAuthProtectedResourceMetadataUrl.call(void 0,
1233
- new URL(request.url)
1322
+ _nullishCoalesce(toUrl(published.resource), () => ( new URL(request.url)))
1234
1323
  )
1235
1324
  } : {}
1236
1325
  );
1237
1326
  }
1238
1327
  };
1328
+ var toUrl = (value) => typeof value === "string" && URL.canParse(value) ? new URL(value) : void 0;
1329
+ var withEndpointAsResource = (config, endpoint) => ({
1330
+ ...config,
1331
+ protectedResource: {
1332
+ ...config.protectedResource,
1333
+ resource: `${_chunkSHPKRGNYcjs.withoutTrailingSlash.call(void 0, config.protectedResource.resource)}${endpoint}`
1334
+ }
1335
+ });
1239
1336
  var nodeToWebRequest = (req, body, secure, signal) => {
1240
1337
  const host = _nullishCoalesce(req.headers.host, () => ( "localhost"));
1241
1338
  const url = `${secure ? "https" : "http"}://${host}${_nullishCoalesce(req.url, () => ( "/"))}`;
@@ -1261,6 +1358,13 @@ var nodeToWebRequest = (req, body, secure, signal) => {
1261
1358
  ...hasBody ? { body } : {}
1262
1359
  });
1263
1360
  };
1361
+ var toNodeHeaders = (headers) => {
1362
+ const cookies = headers.getSetCookie();
1363
+ return {
1364
+ ...Object.fromEntries(headers),
1365
+ ...cookies.length > 0 ? { "set-cookie": cookies } : {}
1366
+ };
1367
+ };
1264
1368
  var clientDisconnectSignal = (res) => {
1265
1369
  const controller = new AbortController();
1266
1370
  const abortIfPremature = () => {
@@ -1304,15 +1408,6 @@ var requestScope = (...sources) => {
1304
1408
  }
1305
1409
  return { release: () => detach.abort(), signal: controller.signal };
1306
1410
  };
1307
- var formatBytes = (bytes) => {
1308
- if (bytes >= 1024 * 1024 && bytes % (1024 * 1024) === 0) {
1309
- return `${bytes / (1024 * 1024)} MiB`;
1310
- }
1311
- if (bytes >= 1024 && bytes % 1024 === 0) {
1312
- return `${bytes / 1024} KiB`;
1313
- }
1314
- return `${bytes} bytes`;
1315
- };
1316
1411
  var OVERSIZE = /* @__PURE__ */ Symbol("oversize");
1317
1412
  var readCappedNodeBody = async (req, maxBytes) => {
1318
1413
  const declared = Number(_nullishCoalesce(req.headers["content-length"], () => ( 0)));
@@ -1331,35 +1426,7 @@ var readCappedNodeBody = async (req, maxBytes) => {
1331
1426
  }
1332
1427
  return Buffer.concat(chunks);
1333
1428
  };
1334
- var convertToJsonSchema = async (schema, io) => {
1335
- if (schema["~standard"].vendor !== "valibot") {
1336
- return _xsschema.toJsonSchema.call(void 0, schema);
1337
- }
1338
- let converter;
1339
- try {
1340
- converter = await Promise.resolve().then(() => _interopRequireWildcard(require("@valibot/to-json-schema")));
1341
- } catch (e7) {
1342
- throw new Error(
1343
- 'The "@valibot/to-json-schema" package is required to describe Valibot schemas. Install it with: npm install @valibot/to-json-schema'
1344
- );
1345
- }
1346
- return converter.toJsonSchema(schema, {
1347
- errorMode: "ignore",
1348
- typeMode: io
1349
- });
1350
- };
1351
- var strictInputSchema = (schema) => ({
1352
- ...schema,
1353
- additionalProperties: typeof schema.additionalProperties === "object" ? schema.additionalProperties : false,
1354
- ...schema.properties && {
1355
- properties: Object.fromEntries(
1356
- Object.entries(schema.properties).map(([key, value]) => [
1357
- key,
1358
- typeof value === "object" && value.type === "object" ? strictInputSchema(value) : value
1359
- ])
1360
- )
1361
- }
1362
- });
1429
+ var convertToJsonSchema = async (schema, io) => schema["~standard"].vendor === "valibot" ? _chunkFEM6LNS4cjs.valibotToJsonSchema.call(void 0, schema, io) : _xsschema.toJsonSchema.call(void 0, schema);
1363
1430
  var assertStandardSchema = (schema, toolName, field) => {
1364
1431
  if (schema === void 0) {
1365
1432
  return;
@@ -1465,4 +1532,4 @@ var normalizeToolResult = (result, hasOutputSchema) => {
1465
1532
 
1466
1533
 
1467
1534
  exports.cancelResponseBody = cancelResponseBody; exports.DiscoveryDocumentCache = DiscoveryDocumentCache; exports.jsonSchemaAdapter = jsonSchemaAdapter; exports.delay = _promises5.setTimeout; exports.MEDIA_FETCH_TIMEOUT_MS = MEDIA_FETCH_TIMEOUT_MS; exports.ViteMCPError = ViteMCPError; exports.UnexpectedStateError = UnexpectedStateError; exports.UserError = UserError; exports.imageContent = imageContent; exports.audioContent = audioContent; exports.ServerState = ServerState; exports.ViteMCP = ViteMCP;
1468
- //# sourceMappingURL=chunk-7UCE3YTY.cjs.map
1535
+ //# sourceMappingURL=chunk-Y52P2PCS.cjs.map