fastmcp 4.27.0 → 4.28.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 (43) hide show
  1. package/dist/FastMCP.cjs +4 -4
  2. package/dist/FastMCP.d.cts +2 -2
  3. package/dist/FastMCP.d.ts +2 -2
  4. package/dist/FastMCP.js +3 -3
  5. package/dist/{OAuthProvider-CUfrAKTR.d.cts → OAuthProvider-DvIxa9N1.d.cts} +8 -5
  6. package/dist/{OAuthProvider-CUfrAKTR.d.ts → OAuthProvider-DvIxa9N1.d.ts} +8 -5
  7. package/dist/auth/index.cjs +2 -2
  8. package/dist/auth/index.d.cts +2 -2
  9. package/dist/auth/index.d.ts +2 -2
  10. package/dist/auth/index.js +1 -1
  11. package/dist/{chunk-SQ5JIDOQ.cjs → chunk-2ABBQFJB.cjs} +28 -13
  12. package/dist/chunk-2ABBQFJB.cjs.map +1 -0
  13. package/dist/chunk-2NZFMD6I.cjs +120 -0
  14. package/dist/chunk-2NZFMD6I.cjs.map +1 -0
  15. package/dist/{chunk-PKJVR5H3.cjs → chunk-3FM67CFK.cjs} +58 -49
  16. package/dist/chunk-3FM67CFK.cjs.map +1 -0
  17. package/dist/chunk-AM3HVK4Z.js +120 -0
  18. package/dist/chunk-AM3HVK4Z.js.map +1 -0
  19. package/dist/{chunk-TCXNF2SR.js → chunk-NRATQX66.js} +22 -7
  20. package/dist/chunk-NRATQX66.js.map +1 -0
  21. package/dist/{chunk-6L7ORLPC.js → chunk-PWSYODM5.js} +49 -40
  22. package/dist/chunk-PWSYODM5.js.map +1 -0
  23. package/dist/edge/index.cjs +114 -65
  24. package/dist/edge/index.cjs.map +1 -1
  25. package/dist/edge/index.js +90 -41
  26. package/dist/edge/index.js.map +1 -1
  27. package/dist/examples/custom-routes.cjs +4 -4
  28. package/dist/examples/custom-routes.js +3 -3
  29. package/dist/openapi/index.cjs +26 -15
  30. package/dist/openapi/index.cjs.map +1 -1
  31. package/dist/openapi/index.d.cts +4 -4
  32. package/dist/openapi/index.d.ts +4 -4
  33. package/dist/openapi/index.js +20 -9
  34. package/dist/openapi/index.js.map +1 -1
  35. package/package.json +1 -1
  36. package/dist/chunk-6L7ORLPC.js.map +0 -1
  37. package/dist/chunk-6TDYSPLC.cjs +0 -44
  38. package/dist/chunk-6TDYSPLC.cjs.map +0 -1
  39. package/dist/chunk-OKKFL2M4.js +0 -44
  40. package/dist/chunk-OKKFL2M4.js.map +0 -1
  41. package/dist/chunk-PKJVR5H3.cjs.map +0 -1
  42. package/dist/chunk-SQ5JIDOQ.cjs.map +0 -1
  43. package/dist/chunk-TCXNF2SR.js.map +0 -1
@@ -1,7 +1,7 @@
1
1
  "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; } var _class;
2
2
 
3
3
 
4
- var _chunk6TDYSPLCcjs = require('../chunk-6TDYSPLC.cjs');
4
+ var _chunk2NZFMD6Icjs = require('../chunk-2NZFMD6I.cjs');
5
5
 
6
6
  // src/edge/index.ts
7
7
 
@@ -9,6 +9,7 @@ var _chunk6TDYSPLCcjs = require('../chunk-6TDYSPLC.cjs');
9
9
 
10
10
 
11
11
 
12
+
12
13
  var _typesjs = require('@modelcontextprotocol/sdk/types.js');
13
14
  var _hono = require('hono');
14
15
  var _route = require('hono/route');
@@ -32,6 +33,39 @@ var unsupportedProtocolVersion = (request) => {
32
33
  }
33
34
  return `Bad Request: Unsupported protocol version: ${protocolVersion} (supported versions: ${_typesjs.SUPPORTED_PROTOCOL_VERSIONS.join(", ")})`;
34
35
  };
36
+ var createSSEStream = () => {
37
+ const { readable, writable } = new TransformStream();
38
+ const reader = readable.getReader();
39
+ const writer = writable.getWriter();
40
+ let cancelled = false;
41
+ let forwarding;
42
+ const body = new ReadableStream(
43
+ {
44
+ cancel(reason) {
45
+ cancelled = true;
46
+ return reader.cancel(reason);
47
+ },
48
+ pull(controller) {
49
+ forwarding = reader.read().then(({ done, value }) => {
50
+ if (!done && !cancelled) controller.enqueue(value);
51
+ });
52
+ return forwarding;
53
+ },
54
+ start(controller) {
55
+ void reader.closed.then(async () => {
56
+ await forwarding;
57
+ if (!cancelled) controller.close();
58
+ }).catch((error) => controller.error(error));
59
+ }
60
+ },
61
+ { highWaterMark: 0 }
62
+ );
63
+ return {
64
+ readable: body,
65
+ terminate: () => reader.cancel(new Error("SSE stream ended")),
66
+ writer
67
+ };
68
+ };
35
69
  var MAXIMUM_MESSAGE_SIZE = 4 * 1024 * 1024;
36
70
  var readBodyWithLimit = async (request) => {
37
71
  if (!request.body) {
@@ -81,7 +115,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
81
115
  * send during that window has nothing to test against; persist rather than
82
116
  * drop, since over-storing for the length of a replay beats losing an event.
83
117
  */
84
- __init4() {this._replaysInFlight = 0}
118
+ __init4() {this._replaysInFlight = /* @__PURE__ */ new Set()}
85
119
  __init5() {this._requestToStreamMapping = /* @__PURE__ */ new Map()}
86
120
  __init6() {this._sessionClosing = false}
87
121
  /**
@@ -179,7 +213,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
179
213
  }
180
214
  return;
181
215
  }
182
- const writer = this._streamMapping.get(streamId);
216
+ const writer = _optionalChain([this, 'access', _4 => _4._streamMapping, 'access', _5 => _5.get, 'call', _6 => _6(streamId), 'optionalAccess', _7 => _7.writer]);
183
217
  const store = this.shouldPersist(streamId, writer) ? this._eventStore : void 0;
184
218
  if (writer || store) {
185
219
  try {
@@ -195,25 +229,22 @@ var WebStreamableHTTPServerTransport = (_class = class {
195
229
  }
196
230
  }
197
231
  } catch (error) {
198
- _optionalChain([this, 'access', _4 => _4.onerror, 'optionalCall', _5 => _5(
232
+ _optionalChain([this, 'access', _8 => _8.onerror, 'optionalCall', _9 => _9(
199
233
  error instanceof Error ? error : new Error(String(error))
200
234
  )]);
201
235
  }
202
- if (requestId !== void 0 && isResponse) {
236
+ if (requestId !== void 0 && isResponse && this._requestToStreamMapping.get(requestId) === streamId) {
203
237
  this._requestToStreamMapping.delete(requestId);
204
238
  const streamInUse = Array.from(
205
239
  this._requestToStreamMapping.values()
206
240
  ).includes(streamId);
207
- if (!streamInUse) {
208
- this._streamMapping.delete(streamId);
209
- if (writer) {
210
- try {
211
- await writer.close();
212
- } catch (error) {
213
- _optionalChain([this, 'access', _6 => _6.onerror, 'optionalCall', _7 => _7(
214
- error instanceof Error ? error : new Error(String(error))
215
- )]);
216
- }
241
+ if (writer && !streamInUse) {
242
+ try {
243
+ await writer.close();
244
+ } catch (error) {
245
+ _optionalChain([this, 'access', _10 => _10.onerror, 'optionalCall', _11 => _11(
246
+ error instanceof Error ? error : new Error(String(error))
247
+ )]);
217
248
  }
218
249
  }
219
250
  }
@@ -298,7 +329,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
298
329
  this.sessionId = void 0;
299
330
  try {
300
331
  await this.teardownStreams();
301
- await _optionalChain([this, 'access', _8 => _8._onsessionclosed, 'optionalCall', _9 => _9(closedSessionId)]);
332
+ await _optionalChain([this, 'access', _12 => _12._onsessionclosed, 'optionalCall', _13 => _13(closedSessionId)]);
302
333
  } finally {
303
334
  this._sessionClosing = false;
304
335
  }
@@ -312,7 +343,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
312
343
  */
313
344
  async handleGetRequest(request) {
314
345
  const acceptHeader = request.headers.get("accept");
315
- if (!_optionalChain([acceptHeader, 'optionalAccess', _10 => _10.includes, 'call', _11 => _11("text/event-stream")])) {
346
+ if (!_optionalChain([acceptHeader, 'optionalAccess', _14 => _14.includes, 'call', _15 => _15("text/event-stream")])) {
316
347
  return this.createErrorResponse(
317
348
  406,
318
349
  -32e3,
@@ -347,10 +378,9 @@ var WebStreamableHTTPServerTransport = (_class = class {
347
378
  "Conflict: SSE stream already exists for this session"
348
379
  );
349
380
  }
350
- const { readable, writable } = new TransformStream();
351
- const writer = writable.getWriter();
352
- this.trackStream(this._standaloneSseStreamId, writer);
353
- return new Response(readable, {
381
+ const stream = createSSEStream();
382
+ this.trackStream(this._standaloneSseStreamId, stream);
383
+ return new Response(stream.readable, {
354
384
  headers: {
355
385
  ...this.getResponseHeaders(),
356
386
  "Cache-Control": "no-cache, no-transform",
@@ -365,7 +395,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
365
395
  */
366
396
  async handlePostRequest(request, parsedBody) {
367
397
  const acceptHeader = request.headers.get("accept");
368
- if (!_optionalChain([acceptHeader, 'optionalAccess', _12 => _12.includes, 'call', _13 => _13("application/json")]) && !_optionalChain([acceptHeader, 'optionalAccess', _14 => _14.includes, 'call', _15 => _15("text/event-stream")])) {
398
+ if (!_optionalChain([acceptHeader, 'optionalAccess', _16 => _16.includes, 'call', _17 => _17("application/json")]) && !_optionalChain([acceptHeader, 'optionalAccess', _18 => _18.includes, 'call', _19 => _19("text/event-stream")])) {
369
399
  return this.createErrorResponse(
370
400
  406,
371
401
  -32e3,
@@ -373,7 +403,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
373
403
  );
374
404
  }
375
405
  const contentType = request.headers.get("content-type");
376
- if (!_optionalChain([contentType, 'optionalAccess', _16 => _16.includes, 'call', _17 => _17("application/json")])) {
406
+ if (!_optionalChain([contentType, 'optionalAccess', _20 => _20.includes, 'call', _21 => _21("application/json")])) {
377
407
  return this.createErrorResponse(
378
408
  415,
379
409
  -32e3,
@@ -472,7 +502,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
472
502
  const sessionGeneration = ++this._sessionGeneration;
473
503
  this.sessionId = generatedSessionId;
474
504
  try {
475
- await _optionalChain([this, 'access', _18 => _18._onsessioninitialized, 'optionalCall', _19 => _19(generatedSessionId)]);
505
+ await _optionalChain([this, 'access', _22 => _22._onsessioninitialized, 'optionalCall', _23 => _23(generatedSessionId)]);
476
506
  if (this._sessionGeneration !== sessionGeneration || this.activeSessionId !== generatedSessionId) {
477
507
  throw new Error("Session initialization was superseded");
478
508
  }
@@ -492,7 +522,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
492
522
  return this.createErrorResponse(400, -32e3, unsupported);
493
523
  }
494
524
  const requestIds = messages.filter((msg) => _typesjs.isJSONRPCRequest.call(void 0, msg)).map((msg) => msg.id);
495
- const useJsonResponse = this._enableJsonResponse && Boolean(_optionalChain([acceptHeader, 'optionalAccess', _20 => _20.includes, 'call', _21 => _21("application/json")]));
525
+ const useJsonResponse = this._enableJsonResponse && Boolean(_optionalChain([acceptHeader, 'optionalAccess', _24 => _24.includes, 'call', _25 => _25("application/json")]));
496
526
  let jsonResponses;
497
527
  let sseReadable;
498
528
  if (requestIds.length > 0) {
@@ -509,9 +539,9 @@ var WebStreamableHTTPServerTransport = (_class = class {
509
539
  });
510
540
  });
511
541
  } else {
512
- const { readable, writable } = new TransformStream();
513
- this.trackStream(streamId, writable.getWriter());
514
- sseReadable = readable;
542
+ const stream = createSSEStream();
543
+ this.trackStream(streamId, stream);
544
+ sseReadable = stream.readable;
515
545
  }
516
546
  }
517
547
  for (const message of messages) {
@@ -522,7 +552,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
522
552
  }
523
553
  const requestInfo = { headers: Object.fromEntries(request.headers) };
524
554
  for (const message of messages) {
525
- _optionalChain([this, 'access', _22 => _22.onmessage, 'optionalCall', _23 => _23(message, {
555
+ _optionalChain([this, 'access', _26 => _26.onmessage, 'optionalCall', _27 => _27(message, {
526
556
  authInfo: void 0,
527
557
  requestInfo
528
558
  })]);
@@ -571,8 +601,12 @@ var WebStreamableHTTPServerTransport = (_class = class {
571
601
  "Resumability not supported"
572
602
  );
573
603
  }
604
+ const generation = this._streamGeneration;
574
605
  if (this._eventStore.getStreamIdForEventId) {
575
606
  const existingStreamId = await this._eventStore.getStreamIdForEventId(lastEventId);
607
+ if (this._streamGeneration !== generation) {
608
+ return this.createErrorResponse(404, -32001, "Session not found");
609
+ }
576
610
  if (existingStreamId !== void 0 && this._streamMapping.has(existingStreamId)) {
577
611
  return this.createErrorResponse(
578
612
  409,
@@ -582,10 +616,9 @@ var WebStreamableHTTPServerTransport = (_class = class {
582
616
  }
583
617
  }
584
618
  const eventStore = this._eventStore;
585
- const generation = this._streamGeneration;
586
- const { readable, writable } = new TransformStream();
587
- const writer = writable.getWriter();
588
- this._replaysInFlight += 1;
619
+ const stream = createSSEStream();
620
+ const { readable, writer } = stream;
621
+ this._replaysInFlight.add(stream);
589
622
  void (async () => {
590
623
  try {
591
624
  const streamId = await eventStore.replayEventsAfter(lastEventId, {
@@ -594,11 +627,10 @@ var WebStreamableHTTPServerTransport = (_class = class {
594
627
  }
595
628
  });
596
629
  if (this._streamGeneration !== generation) {
597
- await this.closeQuietly(writer);
598
630
  return;
599
631
  }
600
632
  if (this._streamMapping.has(streamId)) {
601
- _optionalChain([this, 'access', _24 => _24.onerror, 'optionalCall', _25 => _25(
633
+ _optionalChain([this, 'access', _28 => _28.onerror, 'optionalCall', _29 => _29(
602
634
  new Error(
603
635
  `Conflict: SSE stream already exists for replayed stream ${streamId}`
604
636
  )
@@ -606,14 +638,14 @@ var WebStreamableHTTPServerTransport = (_class = class {
606
638
  await this.closeQuietly(writer);
607
639
  return;
608
640
  }
609
- this.trackStream(streamId, writer);
641
+ this.trackStream(streamId, stream);
610
642
  } catch (error) {
611
- _optionalChain([this, 'access', _26 => _26.onerror, 'optionalCall', _27 => _27(
643
+ _optionalChain([this, 'access', _30 => _30.onerror, 'optionalCall', _31 => _31(
612
644
  error instanceof Error ? error : new Error(String(error))
613
645
  )]);
614
646
  await this.closeQuietly(writer);
615
647
  } finally {
616
- this._replaysInFlight -= 1;
648
+ this._replaysInFlight.delete(stream);
617
649
  }
618
650
  })().catch(() => {
619
651
  });
@@ -660,13 +692,13 @@ var WebStreamableHTTPServerTransport = (_class = class {
660
692
  if (streamInUse) {
661
693
  return;
662
694
  }
663
- const writer = this._streamMapping.get(streamId);
695
+ const stream = this._streamMapping.get(streamId);
664
696
  this._streamMapping.delete(streamId);
665
- if (writer) {
697
+ if (stream) {
666
698
  try {
667
- await writer.close();
699
+ await stream.terminate();
668
700
  } catch (error) {
669
- _optionalChain([this, 'access', _28 => _28.onerror, 'optionalCall', _29 => _29(
701
+ _optionalChain([this, 'access', _32 => _32.onerror, 'optionalCall', _33 => _33(
670
702
  error instanceof Error ? error : new Error(String(error))
671
703
  )]);
672
704
  }
@@ -737,7 +769,7 @@ var WebStreamableHTTPServerTransport = (_class = class {
737
769
  return this._standaloneStreamOpened || // A live writer means the stream is open now, which is stronger evidence
738
770
  // than the latch. Belt and braces: it keeps a writer reaching this point
739
771
  // without `trackStream` from producing an SSE event with no `id:`.
740
- writer !== void 0 || this._replaysInFlight > 0;
772
+ writer !== void 0 || this._replaysInFlight.size > 0;
741
773
  }
742
774
  /**
743
775
  * Close and forget every stream of the current session and release whatever
@@ -747,24 +779,25 @@ var WebStreamableHTTPServerTransport = (_class = class {
747
779
  */
748
780
  async teardownStreams() {
749
781
  this._streamGeneration += 1;
750
- const writers = [...this._streamMapping.values()];
782
+ const streams = [...this._streamMapping.values(), ...this._replaysInFlight];
783
+ this._replaysInFlight.clear();
751
784
  this._streamMapping.clear();
752
785
  this._standaloneStreamOpened = false;
753
786
  this.releasePendingRequests();
754
- for (const writer of writers) {
787
+ for (const stream of streams) {
755
788
  try {
756
- await writer.close();
789
+ await stream.terminate();
757
790
  } catch (e3) {
758
791
  }
759
792
  }
760
793
  }
761
- trackStream(streamId, writer) {
794
+ trackStream(streamId, stream) {
762
795
  if (streamId === this._standaloneSseStreamId) {
763
796
  this._standaloneStreamOpened = true;
764
797
  }
765
- this._streamMapping.set(streamId, writer);
798
+ this._streamMapping.set(streamId, stream);
766
799
  const removeStreamIfCurrent = () => {
767
- if (this._streamMapping.get(streamId) !== writer) {
800
+ if (this._streamMapping.get(streamId) !== stream) {
768
801
  return;
769
802
  }
770
803
  this._streamMapping.delete(streamId);
@@ -777,7 +810,10 @@ var WebStreamableHTTPServerTransport = (_class = class {
777
810
  }
778
811
  }
779
812
  };
780
- void writer.closed.then(removeStreamIfCurrent, removeStreamIfCurrent);
813
+ void stream.writer.closed.then(
814
+ removeStreamIfCurrent,
815
+ removeStreamIfCurrent
816
+ );
781
817
  }
782
818
  /**
783
819
  * Write an SSE event to the stream
@@ -932,7 +968,7 @@ var EdgeFastMCP = class {
932
968
  * Handle initialize request
933
969
  */
934
970
  #handleInitialize(id, params) {
935
- const requestedVersion = _optionalChain([params, 'optionalAccess', _30 => _30.protocolVersion]);
971
+ const requestedVersion = _optionalChain([params, 'optionalAccess', _34 => _34.protocolVersion]);
936
972
  const protocolVersion = typeof requestedVersion === "string" && _typesjs.SUPPORTED_PROTOCOL_VERSIONS.includes(requestedVersion) ? requestedVersion : _typesjs.LATEST_PROTOCOL_VERSION;
937
973
  return {
938
974
  id,
@@ -956,7 +992,7 @@ var EdgeFastMCP = class {
956
992
  */
957
993
  async #handleMcpRequest(request) {
958
994
  const acceptHeader = request.headers.get("accept");
959
- if (!_optionalChain([acceptHeader, 'optionalAccess', _31 => _31.includes, 'call', _32 => _32("application/json")]) && !_optionalChain([acceptHeader, 'optionalAccess', _33 => _33.includes, 'call', _34 => _34("text/event-stream")])) {
995
+ if (!_optionalChain([acceptHeader, 'optionalAccess', _35 => _35.includes, 'call', _36 => _36("application/json")]) && !_optionalChain([acceptHeader, 'optionalAccess', _37 => _37.includes, 'call', _38 => _38("text/event-stream")])) {
960
996
  return this.#errorResponse(
961
997
  406,
962
998
  -32e3,
@@ -964,7 +1000,7 @@ var EdgeFastMCP = class {
964
1000
  );
965
1001
  }
966
1002
  const contentType = request.headers.get("content-type");
967
- if (!_optionalChain([contentType, 'optionalAccess', _35 => _35.includes, 'call', _36 => _36("application/json")])) {
1003
+ if (!_optionalChain([contentType, 'optionalAccess', _39 => _39.includes, 'call', _40 => _40("application/json")])) {
968
1004
  return this.#errorResponse(
969
1005
  415,
970
1006
  -32e3,
@@ -1022,7 +1058,7 @@ var EdgeFastMCP = class {
1022
1058
  */
1023
1059
  async #handleMcpSseRequest(request) {
1024
1060
  const acceptHeader = request.headers.get("accept");
1025
- if (!_optionalChain([acceptHeader, 'optionalAccess', _37 => _37.includes, 'call', _38 => _38("text/event-stream")])) {
1061
+ if (!_optionalChain([acceptHeader, 'optionalAccess', _41 => _41.includes, 'call', _42 => _42("text/event-stream")])) {
1026
1062
  return this.#errorResponse(
1027
1063
  406,
1028
1064
  -32e3,
@@ -1100,8 +1136,15 @@ var EdgeFastMCP = class {
1100
1136
  * Handle prompts/get request
1101
1137
  */
1102
1138
  async #handlePromptsGet(id, params) {
1103
- const promptName = _optionalChain([params, 'optionalAccess', _39 => _39.name]);
1104
- const promptArgs = _optionalChain([params, 'optionalAccess', _40 => _40.arguments]);
1139
+ const promptName = _optionalChain([params, 'optionalAccess', _43 => _43.name]);
1140
+ const promptArgs = _optionalChain([params, 'optionalAccess', _44 => _44.arguments]);
1141
+ if (promptArgs !== void 0 && (promptArgs === null || typeof promptArgs !== "object" || Array.isArray(promptArgs) || Object.values(promptArgs).some((value) => typeof value !== "string"))) {
1142
+ return this.#rpcError(
1143
+ id,
1144
+ _typesjs.ErrorCode.InvalidParams,
1145
+ "Prompt arguments must be an object with string values"
1146
+ );
1147
+ }
1105
1148
  const prompt = this.#prompts.find((p) => p.name === promptName);
1106
1149
  if (!prompt) {
1107
1150
  return this.#rpcError(
@@ -1128,6 +1171,9 @@ var EdgeFastMCP = class {
1128
1171
  result: { messages }
1129
1172
  };
1130
1173
  } catch (error) {
1174
+ if (error instanceof _typesjs.McpError) {
1175
+ return this.#rpcError(id, error.code, error.message, error.data);
1176
+ }
1131
1177
  return this.#rpcError(
1132
1178
  id,
1133
1179
  _typesjs.ErrorCode.InternalError,
@@ -1172,7 +1218,7 @@ var EdgeFastMCP = class {
1172
1218
  * Handle resources/read request
1173
1219
  */
1174
1220
  async #handleResourcesRead(id, params) {
1175
- const uri = _optionalChain([params, 'optionalAccess', _41 => _41.uri]);
1221
+ const uri = _optionalChain([params, 'optionalAccess', _45 => _45.uri]);
1176
1222
  const resource = this.#resources.find((r) => r.uri === uri);
1177
1223
  if (!resource) {
1178
1224
  return this.#rpcError(
@@ -1194,6 +1240,9 @@ var EdgeFastMCP = class {
1194
1240
  result: { contents: [content] }
1195
1241
  };
1196
1242
  } catch (error) {
1243
+ if (error instanceof _typesjs.McpError) {
1244
+ return this.#rpcError(id, error.code, error.message, error.data);
1245
+ }
1197
1246
  return this.#rpcError(
1198
1247
  id,
1199
1248
  _typesjs.ErrorCode.InternalError,
@@ -1205,8 +1254,8 @@ var EdgeFastMCP = class {
1205
1254
  * Handle tools/call request
1206
1255
  */
1207
1256
  async #handleToolsCall(id, params) {
1208
- const toolName = _optionalChain([params, 'optionalAccess', _42 => _42.name]);
1209
- const toolArgs = _optionalChain([params, 'optionalAccess', _43 => _43.arguments]);
1257
+ const toolName = _optionalChain([params, 'optionalAccess', _46 => _46.name]);
1258
+ const toolArgs = _optionalChain([params, 'optionalAccess', _47 => _47.arguments]);
1210
1259
  const tool = this.#tools.find((t) => t.name === toolName);
1211
1260
  if (!tool) {
1212
1261
  return this.#rpcError(
@@ -1229,11 +1278,11 @@ var EdgeFastMCP = class {
1229
1278
  }
1230
1279
  if (parsed.issues) {
1231
1280
  const friendlyErrors = parsed.issues.map((issue) => {
1232
- const path = _optionalChain([issue, 'access', _44 => _44.path, 'optionalAccess', _45 => _45.map, 'call', _46 => _46(
1281
+ const path = _optionalChain([issue, 'access', _48 => _48.path, 'optionalAccess', _49 => _49.map, 'call', _50 => _50(
1233
1282
  (segment) => String(
1234
1283
  typeof segment === "object" && segment !== null ? segment.key : segment
1235
1284
  )
1236
- ), 'access', _47 => _47.join, 'call', _48 => _48(".")]) || "root";
1285
+ ), 'access', _51 => _51.join, 'call', _52 => _52(".")]) || "root";
1237
1286
  return `${path}: ${issue.message}`;
1238
1287
  }).join(", ");
1239
1288
  return {
@@ -1300,9 +1349,9 @@ var EdgeFastMCP = class {
1300
1349
  /**
1301
1350
  * Create an RPC error message
1302
1351
  */
1303
- #rpcError(id, code, message) {
1352
+ #rpcError(id, code, message, data) {
1304
1353
  return {
1305
- error: { code, message },
1354
+ error: { code, ...data !== void 0 && { data }, message },
1306
1355
  id,
1307
1356
  jsonrpc: "2.0"
1308
1357
  };
@@ -1313,8 +1362,8 @@ var EdgeFastMCP = class {
1313
1362
  #schemaToJsonSchema(schema) {
1314
1363
  try {
1315
1364
  if (schema["~standard"].vendor === "zod") {
1316
- const jsonSchema = "_zod" in schema ? _chunk6TDYSPLCcjs.zodInputSchema.call(void 0, schema) : _zodtojsonschema.zodToJsonSchema.call(void 0, schema);
1317
- return _chunk6TDYSPLCcjs.strictInputSchema.call(void 0, jsonSchema);
1365
+ const jsonSchema = "_zod" in schema ? _chunk2NZFMD6Icjs.zodInputSchema.call(void 0, schema) : _zodtojsonschema.zodToJsonSchema.call(void 0, schema);
1366
+ return _chunk2NZFMD6Icjs.strictInputSchema.call(void 0, jsonSchema);
1318
1367
  }
1319
1368
  return { type: "object" };
1320
1369
  } catch (e5) {