@cyanheads/mcp-ts-core 0.13.12 → 0.13.13

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 (93) hide show
  1. package/AGENTS.md +7 -6
  2. package/CLAUDE.md +7 -6
  3. package/README.md +1 -1
  4. package/changelog/0.13.x/0.13.13.md +93 -0
  5. package/dist/core/context.d.ts +12 -0
  6. package/dist/core/context.d.ts.map +1 -1
  7. package/dist/core/context.js +59 -14
  8. package/dist/core/context.js.map +1 -1
  9. package/dist/core/worker.d.ts.map +1 -1
  10. package/dist/core/worker.js +21 -8
  11. package/dist/core/worker.js.map +1 -1
  12. package/dist/mcp-server/inputRequired.d.ts +18 -9
  13. package/dist/mcp-server/inputRequired.d.ts.map +1 -1
  14. package/dist/mcp-server/inputRequired.js +29 -15
  15. package/dist/mcp-server/inputRequired.js.map +1 -1
  16. package/dist/mcp-server/prompts/prompt-registration.d.ts.map +1 -1
  17. package/dist/mcp-server/prompts/prompt-registration.js +10 -7
  18. package/dist/mcp-server/prompts/prompt-registration.js.map +1 -1
  19. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -1
  20. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +22 -9
  21. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -1
  22. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +7 -1
  23. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
  24. package/dist/mcp-server/tools/utils/toolHandlerFactory.js +34 -19
  25. package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
  26. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts +3 -1
  27. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts.map +1 -1
  28. package/dist/mcp-server/transports/auth/lib/authUtils.js +4 -2
  29. package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -1
  30. package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts.map +1 -1
  31. package/dist/storage/providers/fileSystem/fileSystemProvider.js +48 -21
  32. package/dist/storage/providers/fileSystem/fileSystemProvider.js.map +1 -1
  33. package/dist/types-global/errors.d.ts.map +1 -1
  34. package/dist/types-global/errors.js +31 -16
  35. package/dist/types-global/errors.js.map +1 -1
  36. package/dist/utils/internal/error-handler/errorHandler.d.ts +29 -12
  37. package/dist/utils/internal/error-handler/errorHandler.d.ts.map +1 -1
  38. package/dist/utils/internal/error-handler/errorHandler.js +198 -100
  39. package/dist/utils/internal/error-handler/errorHandler.js.map +1 -1
  40. package/dist/utils/internal/error-handler/helpers.d.ts +75 -4
  41. package/dist/utils/internal/error-handler/helpers.d.ts.map +1 -1
  42. package/dist/utils/internal/error-handler/helpers.js +232 -33
  43. package/dist/utils/internal/error-handler/helpers.js.map +1 -1
  44. package/dist/utils/internal/error-handler/types.d.ts +17 -7
  45. package/dist/utils/internal/error-handler/types.d.ts.map +1 -1
  46. package/dist/utils/internal/logValue.d.ts +33 -0
  47. package/dist/utils/internal/logValue.d.ts.map +1 -0
  48. package/dist/utils/internal/logValue.js +539 -0
  49. package/dist/utils/internal/logValue.js.map +1 -0
  50. package/dist/utils/internal/logger.d.ts +38 -9
  51. package/dist/utils/internal/logger.d.ts.map +1 -1
  52. package/dist/utils/internal/logger.js +228 -118
  53. package/dist/utils/internal/logger.js.map +1 -1
  54. package/dist/utils/internal/performance.d.ts.map +1 -1
  55. package/dist/utils/internal/performance.js +9 -11
  56. package/dist/utils/internal/performance.js.map +1 -1
  57. package/dist/utils/internal/requestContext.d.ts +3 -3
  58. package/dist/utils/internal/requestContext.js +1 -1
  59. package/dist/utils/network/fetchWithTimeout.d.ts +18 -10
  60. package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -1
  61. package/dist/utils/network/fetchWithTimeout.js +48 -20
  62. package/dist/utils/network/fetchWithTimeout.js.map +1 -1
  63. package/dist/utils/network/httpError.d.ts +8 -6
  64. package/dist/utils/network/httpError.d.ts.map +1 -1
  65. package/dist/utils/network/httpError.js +23 -7
  66. package/dist/utils/network/httpError.js.map +1 -1
  67. package/dist/utils/network/retry.d.ts +7 -4
  68. package/dist/utils/network/retry.d.ts.map +1 -1
  69. package/dist/utils/network/retry.js +24 -10
  70. package/dist/utils/network/retry.js.map +1 -1
  71. package/dist/utils/security/sanitization.d.ts +24 -28
  72. package/dist/utils/security/sanitization.d.ts.map +1 -1
  73. package/dist/utils/security/sanitization.js +25 -84
  74. package/dist/utils/security/sanitization.js.map +1 -1
  75. package/dist/utils/security/sensitiveFields.d.ts +32 -4
  76. package/dist/utils/security/sensitiveFields.d.ts.map +1 -1
  77. package/dist/utils/security/sensitiveFields.js +85 -4
  78. package/dist/utils/security/sensitiveFields.js.map +1 -1
  79. package/dist/utils/telemetry/trace.d.ts +3 -1
  80. package/dist/utils/telemetry/trace.d.ts.map +1 -1
  81. package/dist/utils/telemetry/trace.js +6 -6
  82. package/dist/utils/telemetry/trace.js.map +1 -1
  83. package/framework-skills/api-config/SKILL.md +2 -1
  84. package/framework-skills/api-context/SKILL.md +3 -3
  85. package/framework-skills/api-errors/SKILL.md +17 -15
  86. package/framework-skills/api-linter/SKILL.md +11 -10
  87. package/framework-skills/api-telemetry/SKILL.md +6 -4
  88. package/framework-skills/api-utils/SKILL.md +6 -6
  89. package/framework-skills/api-utils/references/security.md +4 -2
  90. package/package.json +6 -5
  91. package/scripts/check-framework-antipatterns.ts +3 -2
  92. package/templates/.env.example +2 -0
  93. package/templates/tests/tools/echo.tool.test.ts +19 -1
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../src/utils/internal/error-handler/helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAK/B;;;;;;;;;;;;;;;;;GAiBG;AACH,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,QAAQ,GAAG,MAAM,CAQ3D;AAED;;;;;;;;;;;;;;;;;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;IACb,+BAA+B;IAC/B,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAcD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,SAAK,GAAG,cAAc,EAAE,CA+EtF"}
@@ -3,9 +3,168 @@
3
3
  * Enhanced with cause chain extraction and circular reference detection.
4
4
  * @module src/utils/internal/error-handler/helpers
5
5
  */
6
+ import { SpanStatusCode } from '@opentelemetry/api';
6
7
  import { ZodError } from 'zod';
7
8
  import { McpError } from '../../../types-global/errors.js';
8
9
  import { isAggregateError } from '../../types/guards.js';
10
+ /**
11
+ * What the error path writes for a field whose read throws — a getter, a
12
+ * `Proxy` trap, a revoked `Proxy` — as the log-data walk does.
13
+ */
14
+ export const UNREADABLE = '[Unreadable]';
15
+ /** `value[key]`, or {@link UNREADABLE} when reading it throws. */
16
+ export function readField(value, key) {
17
+ try {
18
+ return value[key];
19
+ }
20
+ catch {
21
+ return UNREADABLE;
22
+ }
23
+ }
24
+ /**
25
+ * An error's `message` or `name`, as read, written as text: a string as it is;
26
+ * any other primitive as `String` converts it, which runs no caller code and
27
+ * never throws, a `Symbol` included (`'Symbol(description)'`), so a `message`
28
+ * set to `404` reads `'404'`; and an object or function as {@link UNREADABLE},
29
+ * since converting one runs its own `toString`, which can throw or return
30
+ * anything.
31
+ */
32
+ export function errorText(value) {
33
+ if (typeof value === 'string')
34
+ return value;
35
+ return value === null || (typeof value !== 'object' && typeof value !== 'function')
36
+ ? String(value)
37
+ : UNREADABLE;
38
+ }
39
+ /**
40
+ * `value instanceof type`, or `false` when the check throws — a revoked
41
+ * `Proxy`, a `getPrototypeOf` trap — so such a value is handled as the
42
+ * non-instance it cannot be shown not to be.
43
+ */
44
+ export function isInstance(value, type) {
45
+ try {
46
+ return value instanceof type;
47
+ }
48
+ catch {
49
+ return false;
50
+ }
51
+ }
52
+ /**
53
+ * A copy of `value`'s own enumerable fields, as a spread makes it (`{}` for
54
+ * `undefined`), or `undefined` when making it throws — a getter that throws, a
55
+ * `Proxy` whose trap throws.
56
+ */
57
+ export function copyFields(value) {
58
+ try {
59
+ return { ...value };
60
+ }
61
+ catch {
62
+ return;
63
+ }
64
+ }
65
+ /**
66
+ * A shallow copy of the `data` a thrown `McpError` carries, so the error path
67
+ * reads plain fields rather than the thrown value's. Nothing is serialized: the
68
+ * log record writes the copy through the bounded log walk, and the wire
69
+ * boundaries check it with {@link readWireErrorData}. `undefined` when `error`
70
+ * is not an `McpError`, carries no object `data`, or its `data` cannot be read
71
+ * or copied — a getter, a revoked `Proxy`, a throwing `ownKeys` trap.
72
+ */
73
+ export function readErrorData(error) {
74
+ if (!isInstance(error, McpError))
75
+ return;
76
+ const data = readField(error, 'data');
77
+ return typeof data === 'object' && data !== null
78
+ ? copyFields(data)
79
+ : undefined;
80
+ }
81
+ /**
82
+ * JSON values one `data` field may take to write before the wire check gives it
83
+ * up: about 6 MB of JSON, checked in tens of milliseconds. `JSON.stringify`
84
+ * writes a shared object once per reference, so 17 objects that each refer to
85
+ * the next three times write 43 million values: seconds and gigabytes to
86
+ * serialize, and a response a stdio client cannot read.
87
+ */
88
+ const WIRE_VALUES = 1_000_000;
89
+ /** Thrown by the wire check's replacer once a field passes {@link WIRE_VALUES}. */
90
+ const OVER_WIRE_BUDGET = Symbol('over wire budget');
91
+ /**
92
+ * `value` when `JSON.stringify` writes it within {@link WIRE_VALUES} values;
93
+ * `'[Truncated]'` when it would take more, and {@link UNREADABLE} when it
94
+ * cannot be written at all — a getter or a revoked `Proxy` that throws on read
95
+ * at any depth, a `BigInt`, a cycle, a `toJSON` that throws.
96
+ */
97
+ function wireField(value) {
98
+ let values = 0;
99
+ try {
100
+ JSON.stringify(value, (_key, field) => {
101
+ if (++values > WIRE_VALUES)
102
+ throw OVER_WIRE_BUDGET;
103
+ return field;
104
+ });
105
+ return value;
106
+ }
107
+ catch (error) {
108
+ return error === OVER_WIRE_BUDGET ? '[Truncated]' : UNREADABLE;
109
+ }
110
+ }
111
+ /**
112
+ * {@link readErrorData} for a response: every field is one the wire carries.
113
+ * A field `JSON.stringify` cannot write is {@link UNREADABLE}, since a response
114
+ * holding one is never sent and the client waits for it, and a field that takes
115
+ * more than {@link WIRE_VALUES} JSON values to write is `'[Truncated]'`. Every
116
+ * other field is the thrown value itself, so readable `data` is sent byte for
117
+ * byte as thrown.
118
+ */
119
+ export function readWireErrorData(error) {
120
+ const copy = readErrorData(error);
121
+ if (copy === undefined)
122
+ return;
123
+ for (const key of Object.keys(copy))
124
+ copy[key] = wireField(copy[key]);
125
+ return copy;
126
+ }
127
+ /**
128
+ * `value` when it is an `Error`, else an `Error` whose message is `String(value)`
129
+ * — or {@link UNREADABLE} when the value can be neither checked nor converted
130
+ * (a revoked `Proxy`, a null-prototype object).
131
+ */
132
+ export function asError(value) {
133
+ try {
134
+ return value instanceof Error ? value : new Error(String(value));
135
+ }
136
+ catch {
137
+ return new Error(UNREADABLE);
138
+ }
139
+ }
140
+ /**
141
+ * Marks `span` failed with `error`: records an `Error` as the span's exception,
142
+ * then sets the `ERROR` status with its `message` (any other value as `String`
143
+ * converts it). Never throws: an exception the span cannot read — a field
144
+ * whose getter throws, which the SDK's `recordException` reads unguarded — is
145
+ * left unrecorded, and a message that cannot be read is {@link UNREADABLE}.
146
+ */
147
+ export function recordSpanFailure(span, error) {
148
+ let message;
149
+ try {
150
+ if (error instanceof Error) {
151
+ try {
152
+ span.recordException(error);
153
+ }
154
+ catch {
155
+ // The span could not read it; the status below still marks the failure.
156
+ }
157
+ message = String(error.message);
158
+ }
159
+ else {
160
+ message = String(error);
161
+ }
162
+ }
163
+ catch {
164
+ message = UNREADABLE;
165
+ }
166
+ span.setStatus({ code: SpanStatusCode.ERROR, message });
167
+ }
9
168
  /**
10
169
  * Formats a ZodError as a single readable line: `<dotted.path>: <message>`.
11
170
  *
@@ -37,11 +196,13 @@ export function formatZodErrorMessage(err) {
37
196
  /**
38
197
  * Retrieves a descriptive name for an error object or value.
39
198
  *
40
- * - `Error` instances → `error.name` (e.g. `'TypeError'`), falling back to `'Error'`.
199
+ * - `Error` instances → `error.name` (e.g. `'TypeError'`), falling back to `'Error'`;
200
+ * a `name` that is not a string is written as {@link errorText} writes it.
41
201
  * - `null` → `'NullValueEncountered'`
42
202
  * - `undefined` → `'UndefinedValueEncountered'`
43
203
  * - Non-plain objects with a named constructor → `'<ConstructorName>Encountered'`
44
204
  * - Everything else → `'<typeof value>Encountered'` (e.g. `'stringEncountered'`)
205
+ * - A value whose inspection throws (a `name` getter, a revoked `Proxy`) → `'[Unreadable]'`
45
206
  *
46
207
  * @param error - The error object or value.
47
208
  * @returns A stable, human-readable string identifying the error's type.
@@ -54,35 +215,43 @@ export function formatZodErrorMessage(err) {
54
215
  * ```
55
216
  */
56
217
  export function getErrorName(error) {
57
- if (error instanceof Error) {
58
- return error.name || 'Error';
59
- }
60
- if (error === null) {
61
- return 'NullValueEncountered';
62
- }
63
- if (error === undefined) {
64
- return 'UndefinedValueEncountered';
218
+ try {
219
+ if (error instanceof Error) {
220
+ const name = readField(error, 'name');
221
+ return name ? errorText(name) : 'Error';
222
+ }
223
+ if (error === null) {
224
+ return 'NullValueEncountered';
225
+ }
226
+ if (error === undefined) {
227
+ return 'UndefinedValueEncountered';
228
+ }
229
+ if (typeof error === 'object' &&
230
+ error.constructor &&
231
+ typeof error.constructor.name === 'string' &&
232
+ error.constructor.name !== 'Object') {
233
+ return `${error.constructor.name}Encountered`;
234
+ }
235
+ return `${typeof error}Encountered`;
65
236
  }
66
- if (typeof error === 'object' &&
67
- error !== null &&
68
- error.constructor &&
69
- typeof error.constructor.name === 'string' &&
70
- error.constructor.name !== 'Object') {
71
- return `${error.constructor.name}Encountered`;
237
+ catch {
238
+ return UNREADABLE;
72
239
  }
73
- return `${typeof error}Encountered`;
74
240
  }
75
241
  /**
76
242
  * Extracts a human-readable message string from any thrown value.
77
243
  *
78
244
  * Handles every JavaScript type so that `catch (e)` blocks never produce `[object Object]`:
79
- * - `AggregateError` → combines up to 3 inner error messages after the outer message.
80
- * - `Error` → `error.message`
245
+ * - `AggregateError` → combines up to 3 inner error messages after the outer message,
246
+ * each one that cannot be read as `'[Unreadable]'`.
247
+ * - `Error` → `error.message`, or `'[Unreadable]'` when reading it throws (a getter);
248
+ * a `message` that is not a string, the outer's or a member's, as {@link errorText} writes it.
81
249
  * - `null` / `undefined` → descriptive literal strings.
82
250
  * - Primitives (`string`, `number`, `boolean`, `bigint`, `symbol`) → string-coerced value.
83
251
  * - Functions → `[function <name>]`
84
252
  * - Objects → JSON-serialized if possible; otherwise constructor name fallback.
85
- * - If conversion itself throws, returns a safe fallback describing the conversion error.
253
+ * - A value whose inspection throws (a getter, a `Proxy` trap, a revoked `Proxy`) →
254
+ * `'[Unreadable]'`, never the text of what the read threw.
86
255
  *
87
256
  * @param error - The thrown value to extract a message from.
88
257
  * @returns A non-empty string describing the error.
@@ -103,16 +272,17 @@ export function getErrorMessage(error) {
103
272
  return formatZodErrorMessage(error);
104
273
  }
105
274
  if (error instanceof Error) {
275
+ const message = errorText(readField(error, 'message'));
106
276
  // AggregateError should surface combined messages succinctly
107
277
  if (isAggregateError(error)) {
108
278
  const inner = error.errors
109
- .map((e) => (e instanceof Error ? e.message : String(e)))
279
+ .map((e) => errorText(readField(asError(e), 'message')))
110
280
  .filter(Boolean)
111
281
  .slice(0, 3)
112
282
  .join('; ');
113
- return inner ? `${error.message}: ${inner}` : error.message;
283
+ return inner ? `${message}: ${inner}` : message;
114
284
  }
115
- return error.message;
285
+ return message;
116
286
  }
117
287
  if (error === null) {
118
288
  return 'Null value encountered as error';
@@ -150,8 +320,19 @@ export function getErrorMessage(error) {
150
320
  // c8 ignore next
151
321
  return '[unrepresentable error]';
152
322
  }
153
- catch (conversionError) {
154
- return `Error converting error to string: ${conversionError instanceof Error ? conversionError.message : 'Unknown conversion error'}`;
323
+ catch {
324
+ return UNREADABLE;
325
+ }
326
+ }
327
+ /** Stands in, inside {@link extractErrorCauseChain}, for a `cause` whose read threw. */
328
+ const UNREADABLE_CAUSE = Symbol('unreadable cause');
329
+ /** `value instanceof Error`, or `undefined` when the check throws: a revoked `Proxy`, a `getPrototypeOf` trap. */
330
+ function errorCheck(value) {
331
+ try {
332
+ return value instanceof Error;
333
+ }
334
+ catch {
335
+ return;
155
336
  }
156
337
  }
157
338
  /**
@@ -166,6 +347,11 @@ export function getErrorMessage(error) {
166
347
  * `McpError` nodes include the `data` property when present, and any `Error`
167
348
  * node carrying a string `code` includes it.
168
349
  * Circular references are detected via `WeakSet` identity tracking.
350
+ * Every read is guarded: a `name`, `message`, or `stack` whose read throws is
351
+ * `'[Unreadable]'` on its node, an unreadable `code` or `data` is left out, and
352
+ * a cause that cannot be read or inspected — a throwing `cause` getter, a
353
+ * revoked `Proxy` — ends the chain as a node whose `name` and `message` are
354
+ * both `'[Unreadable]'`.
169
355
  *
170
356
  * @param error - The outermost error to start traversal from.
171
357
  * @param maxDepth - Maximum number of nodes to traverse before stopping. Defaults to `20`.
@@ -201,22 +387,35 @@ export function extractErrorCauseChain(error, maxDepth = 20) {
201
387
  }
202
388
  seen.add(current);
203
389
  }
204
- if (current instanceof Error) {
390
+ const isError = current === UNREADABLE_CAUSE ? undefined : errorCheck(current);
391
+ if (isError === undefined) {
392
+ chain.push({ name: UNREADABLE, message: UNREADABLE, depth });
393
+ break;
394
+ }
395
+ if (isError) {
396
+ const err = current;
397
+ const code = readField(err, 'code');
398
+ const stack = readField(err, 'stack');
205
399
  const node = {
206
- name: current.name,
207
- message: current.message,
400
+ name: errorText(readField(err, 'name')),
401
+ message: errorText(readField(err, 'message')),
208
402
  depth,
209
- ...('code' in current && typeof current.code === 'string' ? { code: current.code } : {}),
403
+ ...(typeof code === 'string' && code !== UNREADABLE ? { code } : {}),
210
404
  // Only include stack if it exists (exact optional property types)
211
- ...(current.stack !== undefined ? { stack: current.stack } : {}),
405
+ ...(stack !== undefined ? { stack: stack } : {}),
212
406
  };
213
407
  // Extract data from McpError instances
214
- if (current instanceof McpError && current.data) {
215
- node.data = current.data;
216
- }
408
+ const data = err instanceof McpError ? readField(err, 'data') : undefined;
409
+ if (data && data !== UNREADABLE)
410
+ node.data = data;
217
411
  chain.push(node);
218
412
  // Continue traversing cause chain
219
- current = current.cause;
413
+ try {
414
+ current = err.cause;
415
+ }
416
+ catch {
417
+ current = UNREADABLE_CAUSE;
418
+ }
220
419
  }
221
420
  else if (typeof current === 'string') {
222
421
  chain.push({
@@ -1 +1 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/utils/internal/error-handler/helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAE,QAAQ,EAAE,MAAM,KAAK,CAAC;AAE/B,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,yBAAyB,CAAC;AAE3D;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,UAAU,qBAAqB,CAAC,GAAa;IACjD,MAAM,MAAM,GAAG,GAAG,CAAC,MAAM,CAAC;IAC1B,MAAM,KAAK,GAAG,MAAM,CAAC,CAAC,CAAC,CAAC;IACxB,IAAI,CAAC,KAAK;QAAE,OAAO,mBAAmB,CAAC;IACvC,MAAM,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,IAAI,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC;IAClF,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC;IAC/B,MAAM,IAAI,GAAG,IAAI,GAAG,CAAC,CAAC,CAAC,CAAC,MAAM,IAAI,QAAQ,CAAC,CAAC,CAAC,EAAE,CAAC;IAChD,OAAO,GAAG,IAAI,GAAG,KAAK,CAAC,OAAO,GAAG,IAAI,EAAE,CAAC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,CAAC,EAAE,IAAI,EAAE,OAAO,CAAC,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACxF,kEAAkE;gBAClE,GAAG,CAAC,OAAO,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,OAAO,CAAC,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aACjE,CAAC;YAEF,uCAAuC;YACvC,IAAI,OAAO,YAAY,QAAQ,IAAI,OAAO,CAAC,IAAI,EAAE,CAAC;gBAChD,IAAI,CAAC,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;YAC3B,CAAC;YAED,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEjB,kCAAkC;YAClC,OAAO,GAAG,OAAO,CAAC,KAAK,CAAC;QAC1B,CAAC;aAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YACvC,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,OAAO;gBAChB,KAAK;aACN,CAAC,CAAC;YACH,MAAM;QACR,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC;gBAC3B,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC;gBACjC,KAAK;aACN,CAAC,CAAC;YACH,MAAM;QACR,CAAC;QAED,KAAK,EAAE,CAAC;IACV,CAAC;IAED,IAAI,KAAK,IAAI,QAAQ,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,kBAAkB;YACxB,OAAO,EAAE,+CAA+C,QAAQ,EAAE;YAClE,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
1
+ {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../../../src/utils/internal/error-handler/helpers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,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,KAAe,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;aAC3D,CAAC;YAEF,uCAAuC;YACvC,MAAM,IAAI,GAAG,GAAG,YAAY,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,SAAS,CAAC;YAC1E,IAAI,IAAI,IAAI,IAAI,KAAK,UAAU;gBAAE,IAAI,CAAC,IAAI,GAAG,IAA+B,CAAC;YAE7E,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;YAEjB,kCAAkC;YAClC,IAAI,CAAC;gBACH,OAAO,GAAG,GAAG,CAAC,KAAK,CAAC;YACtB,CAAC;YAAC,MAAM,CAAC;gBACP,OAAO,GAAG,gBAAgB,CAAC;YAC7B,CAAC;QACH,CAAC;aAAM,IAAI,OAAO,OAAO,KAAK,QAAQ,EAAE,CAAC;YACvC,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,aAAa;gBACnB,OAAO,EAAE,OAAO;gBAChB,KAAK;aACN,CAAC,CAAC;YACH,MAAM;QACR,CAAC;aAAM,CAAC;YACN,KAAK,CAAC,IAAI,CAAC;gBACT,IAAI,EAAE,YAAY,CAAC,OAAO,CAAC;gBAC3B,OAAO,EAAE,eAAe,CAAC,OAAO,CAAC;gBACjC,KAAK;aACN,CAAC,CAAC;YACH,MAAM;QACR,CAAC;QAED,KAAK,EAAE,CAAC;IACV,CAAC;IAED,IAAI,KAAK,IAAI,QAAQ,EAAE,CAAC;QACtB,KAAK,CAAC,IAAI,CAAC;YACT,IAAI,EAAE,kBAAkB;YACxB,OAAO,EAAE,+CAA+C,QAAQ,EAAE;YAClE,KAAK;SACN,CAAC,CAAC;IACL,CAAC;IAED,OAAO,KAAK,CAAC;AACf,CAAC"}
@@ -52,6 +52,9 @@ export interface ErrorHandlerOptions {
52
52
  * This can include `requestId` and other relevant debugging information.
53
53
  * It reaches the log record only, never the returned error's client-visible
54
54
  * `data`; put caller-actionable fields in the thrown `McpError`'s `data`.
55
+ * A context, or its `extra`, whose fields throw when copied — an own getter,
56
+ * a `Proxy` trap — is written as `'[Unreadable]'` under `context` or `extra`
57
+ * rather than failing the call.
55
58
  */
56
59
  context?: ErrorContext;
57
60
  /**
@@ -73,14 +76,21 @@ export interface ErrorHandlerOptions {
73
76
  */
74
77
  errorMapper?: (error: unknown) => Error;
75
78
  /**
76
- * Whether the log record carries stack traces. Defaults to `true`.
79
+ * Whether the log record carries stack traces. Defaults to `true`: the
80
+ * record's `extra.stack` is then the throw site's stack — never a context's
81
+ * `extra.stack` — and each stack is written once: a `causeChain` node
82
+ * carrying the record's stack, or the same stack as the node before it, is
83
+ * written without it.
77
84
  *
78
- * `false` removes every stack from the record: `extra.stack`,
79
- * `extra.errorData.originalStack` (including one carried in a thrown
80
- * `McpError`'s own `data`, or a cause's), and the `stack` of each
81
- * `extra.errorData.causeChain` node. The chain itself stays, each node
82
- * keeping its other fields. The returned error and the exception recorded
83
- * on the active span are the same either way.
85
+ * `false` makes the record stack-free, as a `RequestCancelled` always is: no
86
+ * `extra.stack`, no `extra.errorData.originalStack`, no `stack` on any
87
+ * `extra.errorData.causeChain` node nor `originalStack` in a node's `data`,
88
+ * and every `Error` in the record — in `errorData`, `input`, or the
89
+ * context's `extra` — written without its `stack`, whether this handler, the
90
+ * thrown `McpError`'s own `data`, or the caller supplied the field. Any other
91
+ * key named `stack` is the caller's data and is written as given. The chain
92
+ * itself stays, each node keeping its other fields. The returned error and
93
+ * the exception recorded on the active span are the same either way.
84
94
  */
85
95
  includeStack?: boolean;
86
96
  /**
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../src/utils/internal/error-handler/types.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAC;AACxF,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oCAAoC,CAAC;AAEzE;;;;;;;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MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAE5C;;;;;OAKG;IACH,OAAO,EAAE,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC;CACnE"}
@@ -0,0 +1,33 @@
1
+ /**
2
+ * The JSON-safe form a log record writes for `value`, as the walk pino runs on
3
+ * every record produces it. With `includeStack: false`, every `Error` in it is
4
+ * written without its `stack`: a stack-free record passes its fields through
5
+ * this first, since the walk pino runs keeps stacks. A key of `value` itself
6
+ * for which `exemptRootKey` returns true is never redacted; the same key deeper
7
+ * down is.
8
+ *
9
+ * @internal Exported for the logger, stack-free log records, `ctx.log` data a spread cannot
10
+ * read, and unit testing. Not part of the public API.
11
+ */
12
+ export declare function toLogValue(value: unknown, options?: {
13
+ exemptRootKey?: ((key: string) => boolean) | undefined;
14
+ includeStack?: boolean;
15
+ }): unknown;
16
+ /**
17
+ * The copy of a `ctx.log` call's data the client mirror sends: what
18
+ * `JSON.stringify` reads from it (an object's `toJSON()` result, else its own
19
+ * enumerable fields), with every sensitive field masked as `'[REDACTED]'` and
20
+ * every `Error` written as `{ type, message }` — no stack, cause, or own
21
+ * property such as a request URL. The process log's bounds and markers apply:
22
+ * `'[Circular]'`, `'[MaxDepth]'` (the data's own fields sit at depth 1, as they
23
+ * do in the log record), `'[Truncated]'` where the ceiling on reads, the ceiling
24
+ * on characters written, or the bound on repeated content stops it — a `toJSON()`
25
+ * result reached again from another object included — and `'[Unreadable]'`,
26
+ * with data that has no readable keys at all as `{ data: '[Unreadable]' }`, as
27
+ * the process log writes it. Nothing passes through `structuredClone`, which
28
+ * rejects a `URL` or a function, and the input is never modified.
29
+ *
30
+ * @internal Masks the `ctx.log` mirror to the client. Not part of the public API.
31
+ */
32
+ export declare function toMirrorValue(fields: Record<string, unknown>): Record<string, unknown>;
33
+ //# sourceMappingURL=logValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logValue.d.ts","sourceRoot":"","sources":["../../../src/utils/internal/logValue.ts"],"names":[],"mappings":"AAyiBA;;;;;;;;;;GAUG;AACH,wBAAgB,UAAU,CACxB,KAAK,EAAE,OAAO,EACd,OAAO,GAAE;IAAE,aAAa,CAAC,EAAE,CAAC,CAAC,GAAG,EAAE,MAAM,KAAK,OAAO,CAAC,GAAG,SAAS,CAAC;IAAC,YAAY,CAAC,EAAE,OAAO,CAAA;CAAO,GAC/F,OAAO,CAOT;AAED;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,aAAa,CAAC,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAWtF"}