@cyanheads/mcp-ts-core 0.13.11 → 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 (125) hide show
  1. package/AGENTS.md +9 -8
  2. package/CLAUDE.md +9 -8
  3. package/README.md +1 -1
  4. package/changelog/0.13.x/0.13.12.md +50 -0
  5. package/changelog/0.13.x/0.13.13.md +93 -0
  6. package/dist/core/context.d.ts +12 -0
  7. package/dist/core/context.d.ts.map +1 -1
  8. package/dist/core/context.js +59 -14
  9. package/dist/core/context.js.map +1 -1
  10. package/dist/core/worker.d.ts.map +1 -1
  11. package/dist/core/worker.js +21 -8
  12. package/dist/core/worker.js.map +1 -1
  13. package/dist/mcp-server/handlerContext.d.ts +14 -8
  14. package/dist/mcp-server/handlerContext.d.ts.map +1 -1
  15. package/dist/mcp-server/handlerContext.js +16 -9
  16. package/dist/mcp-server/handlerContext.js.map +1 -1
  17. package/dist/mcp-server/inputRequired.d.ts +18 -9
  18. package/dist/mcp-server/inputRequired.d.ts.map +1 -1
  19. package/dist/mcp-server/inputRequired.js +29 -15
  20. package/dist/mcp-server/inputRequired.js.map +1 -1
  21. package/dist/mcp-server/prompts/prompt-registration.d.ts.map +1 -1
  22. package/dist/mcp-server/prompts/prompt-registration.js +10 -7
  23. package/dist/mcp-server/prompts/prompt-registration.js.map +1 -1
  24. package/dist/mcp-server/resources/utils/resourceHandlerFactory.d.ts.map +1 -1
  25. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js +29 -19
  26. package/dist/mcp-server/resources/utils/resourceHandlerFactory.js.map +1 -1
  27. package/dist/mcp-server/tools/utils/inputPrevalidation.d.ts +8 -2
  28. package/dist/mcp-server/tools/utils/inputPrevalidation.d.ts.map +1 -1
  29. package/dist/mcp-server/tools/utils/inputPrevalidation.js +18 -7
  30. package/dist/mcp-server/tools/utils/inputPrevalidation.js.map +1 -1
  31. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts +7 -1
  32. package/dist/mcp-server/tools/utils/toolHandlerFactory.d.ts.map +1 -1
  33. package/dist/mcp-server/tools/utils/toolHandlerFactory.js +107 -21
  34. package/dist/mcp-server/tools/utils/toolHandlerFactory.js.map +1 -1
  35. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts +22 -0
  36. package/dist/mcp-server/transports/auth/lib/authUtils.d.ts.map +1 -1
  37. package/dist/mcp-server/transports/auth/lib/authUtils.js +29 -1
  38. package/dist/mcp-server/transports/auth/lib/authUtils.js.map +1 -1
  39. package/dist/mcp-server/transports/auth/lib/checkScopes.d.ts.map +1 -1
  40. package/dist/mcp-server/transports/auth/lib/checkScopes.js +2 -1
  41. package/dist/mcp-server/transports/auth/lib/checkScopes.js.map +1 -1
  42. package/dist/mcp-server/transports/http/httpErrorHandler.d.ts.map +1 -1
  43. package/dist/mcp-server/transports/http/httpErrorHandler.js +4 -2
  44. package/dist/mcp-server/transports/http/httpErrorHandler.js.map +1 -1
  45. package/dist/services/mirror/sqlite/handle.d.ts +13 -2
  46. package/dist/services/mirror/sqlite/handle.d.ts.map +1 -1
  47. package/dist/services/mirror/sqlite/handle.js +17 -6
  48. package/dist/services/mirror/sqlite/handle.js.map +1 -1
  49. package/dist/services/mirror/sqlite/sqliteMirrorStore.d.ts.map +1 -1
  50. package/dist/services/mirror/sqlite/sqliteMirrorStore.js +3 -2
  51. package/dist/services/mirror/sqlite/sqliteMirrorStore.js.map +1 -1
  52. package/dist/storage/providers/fileSystem/fileSystemProvider.d.ts.map +1 -1
  53. package/dist/storage/providers/fileSystem/fileSystemProvider.js +48 -21
  54. package/dist/storage/providers/fileSystem/fileSystemProvider.js.map +1 -1
  55. package/dist/types-global/errors.d.ts.map +1 -1
  56. package/dist/types-global/errors.js +31 -16
  57. package/dist/types-global/errors.js.map +1 -1
  58. package/dist/utils/internal/error-handler/errorHandler.d.ts +29 -11
  59. package/dist/utils/internal/error-handler/errorHandler.d.ts.map +1 -1
  60. package/dist/utils/internal/error-handler/errorHandler.js +204 -95
  61. package/dist/utils/internal/error-handler/errorHandler.js.map +1 -1
  62. package/dist/utils/internal/error-handler/helpers.d.ts +91 -9
  63. package/dist/utils/internal/error-handler/helpers.d.ts.map +1 -1
  64. package/dist/utils/internal/error-handler/helpers.js +243 -39
  65. package/dist/utils/internal/error-handler/helpers.js.map +1 -1
  66. package/dist/utils/internal/error-handler/types.d.ts +21 -4
  67. package/dist/utils/internal/error-handler/types.d.ts.map +1 -1
  68. package/dist/utils/internal/logValue.d.ts +33 -0
  69. package/dist/utils/internal/logValue.d.ts.map +1 -0
  70. package/dist/utils/internal/logValue.js +539 -0
  71. package/dist/utils/internal/logValue.js.map +1 -0
  72. package/dist/utils/internal/logger.d.ts +38 -9
  73. package/dist/utils/internal/logger.d.ts.map +1 -1
  74. package/dist/utils/internal/logger.js +228 -118
  75. package/dist/utils/internal/logger.js.map +1 -1
  76. package/dist/utils/internal/observabilityCap.d.ts +35 -0
  77. package/dist/utils/internal/observabilityCap.d.ts.map +1 -0
  78. package/dist/utils/internal/observabilityCap.js +43 -0
  79. package/dist/utils/internal/observabilityCap.js.map +1 -0
  80. package/dist/utils/internal/performance.d.ts.map +1 -1
  81. package/dist/utils/internal/performance.js +9 -11
  82. package/dist/utils/internal/performance.js.map +1 -1
  83. package/dist/utils/internal/requestContext.d.ts +3 -3
  84. package/dist/utils/internal/requestContext.js +1 -1
  85. package/dist/utils/network/fetchWithTimeout.d.ts +20 -10
  86. package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -1
  87. package/dist/utils/network/fetchWithTimeout.js +112 -30
  88. package/dist/utils/network/fetchWithTimeout.js.map +1 -1
  89. package/dist/utils/network/httpError.d.ts +8 -6
  90. package/dist/utils/network/httpError.d.ts.map +1 -1
  91. package/dist/utils/network/httpError.js +23 -7
  92. package/dist/utils/network/httpError.js.map +1 -1
  93. package/dist/utils/network/retry.d.ts +25 -2
  94. package/dist/utils/network/retry.d.ts.map +1 -1
  95. package/dist/utils/network/retry.js +47 -5
  96. package/dist/utils/network/retry.js.map +1 -1
  97. package/dist/utils/security/sanitization.d.ts +24 -28
  98. package/dist/utils/security/sanitization.d.ts.map +1 -1
  99. package/dist/utils/security/sanitization.js +25 -84
  100. package/dist/utils/security/sanitization.js.map +1 -1
  101. package/dist/utils/security/sensitiveFields.d.ts +32 -4
  102. package/dist/utils/security/sensitiveFields.d.ts.map +1 -1
  103. package/dist/utils/security/sensitiveFields.js +85 -4
  104. package/dist/utils/security/sensitiveFields.js.map +1 -1
  105. package/dist/utils/telemetry/trace.d.ts +3 -1
  106. package/dist/utils/telemetry/trace.d.ts.map +1 -1
  107. package/dist/utils/telemetry/trace.js +6 -6
  108. package/dist/utils/telemetry/trace.js.map +1 -1
  109. package/framework-skills/api-auth/SKILL.md +3 -1
  110. package/framework-skills/api-canvas/SKILL.md +2 -2
  111. package/framework-skills/api-config/SKILL.md +2 -1
  112. package/framework-skills/api-context/SKILL.md +6 -6
  113. package/framework-skills/api-errors/SKILL.md +19 -17
  114. package/framework-skills/api-linter/SKILL.md +11 -10
  115. package/framework-skills/api-mirror/SKILL.md +3 -1
  116. package/framework-skills/api-telemetry/SKILL.md +14 -8
  117. package/framework-skills/api-utils/SKILL.md +6 -6
  118. package/framework-skills/api-utils/references/security.md +4 -2
  119. package/framework-skills/field-test/SKILL.md +2 -2
  120. package/framework-skills/git-wrapup/SKILL.md +3 -3
  121. package/framework-skills/tool-defs-analysis/SKILL.md +2 -2
  122. package/package.json +10 -9
  123. package/scripts/check-framework-antipatterns.ts +3 -2
  124. package/templates/.env.example +2 -0
  125. package/templates/tests/tools/echo.tool.test.ts +19 -1
@@ -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"}
@@ -0,0 +1,539 @@
1
+ /**
2
+ * @fileoverview The walk every log sink runs over log data before writing it:
3
+ * pino's `formatters.log` for the process log and `interactions.log`, the OTLP
4
+ * export's attributes, and the `ctx.log` client mirror. One walk, so every sink
5
+ * shares one depth bound, one ceiling on reads, one ceiling on the characters
6
+ * written, one bound on repeated content, one cycle rule, one key matcher, and
7
+ * one answer for a value whose read throws.
8
+ * A leaf module, so the logger and the mirror use it without importing each other.
9
+ * @module src/utils/internal/logValue
10
+ */
11
+ import { McpError } from '../../types-global/errors.js';
12
+ import { isSensitiveKey } from '../security/sensitiveFields.js';
13
+ /**
14
+ * Depth bound, counted from the record root: objects through depth 15 are
15
+ * written, and an object at depth 16 is written as `'[MaxDepth]'`. Above the
16
+ * deepest framework record — a union argument rejection's
17
+ * `errorData.issues[i].errors[j][k].path`, at 7 — with margin, and far below
18
+ * the depth at which a recursive copy overflows the stack (10,000 levels on
19
+ * Node), which is why the walk keeps a bound at all.
20
+ */
21
+ const MAX_DEPTH = 16;
22
+ /**
23
+ * Reads one walk makes: one for each object it reaches, fresh or repeated, and
24
+ * for each field and array element that is not an object, a redacted field
25
+ * included; {@link DEPTH_BOUND_READS} for an object at {@link MAX_DEPTH}. The
26
+ * read past the last is written as `'[Truncated]'` and the walk stops there. A
27
+ * getter, a Proxy, or a mirror's `toJSON()` can build new data on every read,
28
+ * which neither the cycle check nor the bound on repeated content ever sees
29
+ * twice: an object whose three getters each build another like it is 43
30
+ * million objects down to the depth bound, a 308 MB line written in 3–35 s.
31
+ * Bounded, it writes 0.8 MB in 14–38 ms on Bun and Node, and 3.7 MB in
32
+ * 75–115 ms when each built object also carries 200 numeric fields. Distinct
33
+ * data takes a read for each object and each field: a record of 100,000
34
+ * distinct one-field objects takes half the reads and is written whole.
35
+ */
36
+ const MAX_READS = 400_000;
37
+ /**
38
+ * Reads an object at {@link MAX_DEPTH} counts. Data built on every read nests
39
+ * as deep as the walk goes, so most of what it reaches sits at the depth bound;
40
+ * held data rarely reaches it more than a few times.
41
+ */
42
+ const DEPTH_BOUND_READS = 10;
43
+ /**
44
+ * Characters of repeated content one walk writes. Content is repeated when the
45
+ * walk already wrote it: an object reached again on another path, and everything
46
+ * beneath it, and a string or field name of {@link LONG_TEXT} characters or more
47
+ * written before. Each repeated value is charged about the characters it writes,
48
+ * quotes, braces, and separators included, so 20,000 rows sharing one `tags: []`
49
+ * are written whole. Bounds what sharing multiplies: a 100 KB string shared
50
+ * 6,000 times writes 600 MB uncharged and 1.1 MB charged, as does one held by
51
+ * 2,000 distinct objects. Content written once is bounded only by
52
+ * {@link MAX_WRITTEN_CHARS}.
53
+ */
54
+ const MAX_REPEATED_CHARS = 1_000_000;
55
+ /**
56
+ * Characters one walk writes: every string, field name, and primitive, repeated
57
+ * or not, charged about the characters it writes — a string with its quotes, a
58
+ * field name with its quotes, colon, and comma. The value past it is written as
59
+ * `'[Truncated]'`, a field name past it as `'[Truncated]': '[Truncated]'`, and
60
+ * the walk stops there. Bounds what neither the read ceiling nor the bound on
61
+ * repeated content sees: data a getter builds on every read, each object it
62
+ * builds carrying 50 fields of one 1,000-character string, wrote 284 MB within
63
+ * {@link MAX_READS}. A 10 MB string is written whole; a 20 MB one is cut.
64
+ */
65
+ const MAX_WRITTEN_CHARS = 16 * 1024 * 1024;
66
+ /**
67
+ * Length from which the walk remembers a string or field name by its value, so
68
+ * that writing it again from another object is repeated content. Shorter text is
69
+ * written on every reference: remembering it would cost every record.
70
+ */
71
+ const LONG_TEXT = 1_024;
72
+ /**
73
+ * Longest text the walk remembers under its own value. V8 hashes a longer
74
+ * string by its length alone, so a set of same-length long strings compares
75
+ * each lookup with every one of them up to the first character that differs:
76
+ * 2,000 distinct strings of 20,000 characters took 1.3 s on Node, 4,000 took
77
+ * 5.4 s. Longer text is remembered under {@link longKey}'s sample.
78
+ */
79
+ const HASHED_TEXT = 16_383;
80
+ /**
81
+ * Distinct texts sharing one {@link longKey} sample that a lookup compares one
82
+ * by one. Past this many, they are kept by {@link contentHash}, so text that
83
+ * matches at every sampled window stays linear: 2,000 texts of 20,000
84
+ * characters differing 3,000 characters in take 60–160 ms on Bun and Node,
85
+ * where comparing them one by one took 210–330 ms, growing with the square.
86
+ */
87
+ const SAMPLE_BUCKET = 8;
88
+ /** What {@link read} returns for a property whose read threw; written as `'[Unreadable]'`. */
89
+ const UNREADABLE = Symbol('unreadable');
90
+ /** What {@link walkValue} returns for a value a bound stopped; written as `'[Truncated]'`. */
91
+ const CUT = Symbol('cut');
92
+ /** `object[key]`, or {@link UNREADABLE} when the read throws: a getter, a Proxy trap, a revoked Proxy. */
93
+ function read(object, key) {
94
+ try {
95
+ return object[key];
96
+ }
97
+ catch {
98
+ return UNREADABLE;
99
+ }
100
+ }
101
+ /**
102
+ * Copies a value into the JSON-safe form a sink writes, or returns `undefined`
103
+ * to drop it. Keeps primitives and drops functions; every key {@link isSensitiveKey}
104
+ * matches is written as `'[REDACTED]'`. A reference back to an object the walk is
105
+ * inside is written as `'[Circular]'`, an object at {@link MAX_DEPTH} as
106
+ * `'[MaxDepth]'`, and a value whose read throws as `'[Unreadable]'`. Returns
107
+ * {@link CUT} — written as `'[Truncated]'` — for the read past {@link MAX_READS}
108
+ * and the value past {@link MAX_WRITTEN_CHARS}, after which the walk stops, and
109
+ * for repeated content that does not fit in what is left of
110
+ * {@link MAX_REPEATED_CHARS}, after which the repeated array or object it sits in
111
+ * ends; a later repeat that still fits is written.
112
+ *
113
+ * Log mode writes a `Date` as its ISO string (`null` when invalid, as
114
+ * `JSON.stringify` does), a `URL` as its string, and an `Error` through
115
+ * {@link walkError}; copies arrays and plain objects; and drops any other object
116
+ * without reading it — `AbortSignal`, `Map`, `Set`, `Promise`, storage handles —
117
+ * since their prototype getters enforce receiver checks and throw (#32).
118
+ */
119
+ function walkValue(value, depth, walk) {
120
+ if (value === UNREADABLE)
121
+ return marker('[Unreadable]', walk);
122
+ const t = typeof value;
123
+ if (t === 'string') {
124
+ const text = value;
125
+ const repeated = walk.repeating || (text.length >= LONG_TEXT && seenLong(text, walk));
126
+ return write(text, text.length + 2, repeated, walk);
127
+ }
128
+ if (t === 'undefined' || t === 'function')
129
+ return;
130
+ if (value === null || t !== 'object') {
131
+ return write(value, primitiveChars(value), walk.repeating, walk);
132
+ }
133
+ if (--walk.reads < 0)
134
+ return stop(walk);
135
+ // The object a reference names: what the cycle check and the repeat check track, even when
136
+ // mirror mode writes its `toJSON()` result, which can be a fresh object on every call.
137
+ const original = value;
138
+ let object = original;
139
+ let shape;
140
+ let keys;
141
+ let length = 0;
142
+ try {
143
+ if (Array.isArray(object)) {
144
+ shape = 'array';
145
+ }
146
+ else if (walk.mode === 'log') {
147
+ // A plain object, the common case, is settled before any `instanceof` walk of its prototype chain.
148
+ const proto = Object.getPrototypeOf(object);
149
+ if (proto === Object.prototype || proto === null) {
150
+ shape = 'record';
151
+ }
152
+ else if (object instanceof Error) {
153
+ shape = errorShape(object);
154
+ }
155
+ else if (object instanceof Date) {
156
+ return walkValue(Number.isNaN(object.getTime()) ? null : object.toISOString(), depth, walk);
157
+ }
158
+ else if (object instanceof URL) {
159
+ return walkValue(object.toString(), depth, walk);
160
+ }
161
+ else {
162
+ return;
163
+ }
164
+ }
165
+ else if (object instanceof Error) {
166
+ shape = errorShape(object);
167
+ }
168
+ else {
169
+ const { toJSON } = object;
170
+ if (typeof toJSON === 'function') {
171
+ const json = toJSON.call(object);
172
+ if (json === null || typeof json !== 'object')
173
+ return walkValue(json, depth, walk);
174
+ object = json;
175
+ }
176
+ shape = Array.isArray(object) ? 'array' : 'record';
177
+ }
178
+ if (walk.ancestors.includes(original) ||
179
+ (object !== original && walk.ancestors.includes(object))) {
180
+ return marker('[Circular]', walk);
181
+ }
182
+ if (depth >= MAX_DEPTH) {
183
+ walk.reads -= DEPTH_BOUND_READS - 1;
184
+ return walk.reads < 0 ? stop(walk) : marker('[MaxDepth]', walk);
185
+ }
186
+ // Enumerated only now, so an object past the depth bound is never enumerated.
187
+ if (shape === 'record')
188
+ keys = Object.keys(object);
189
+ else if (shape === 'array')
190
+ length = object.length;
191
+ }
192
+ catch {
193
+ return marker('[Unreadable]', walk);
194
+ }
195
+ const repeated = walk.repeating || walk.seen.has(original) || (object !== original && walk.seen.has(object));
196
+ if (repeated) {
197
+ if (!charge(keys ? 2 + nameChars(keys) : 2 + length, walk))
198
+ return CUT;
199
+ }
200
+ else {
201
+ walk.seen.add(original);
202
+ if (object !== original)
203
+ walk.seen.add(object);
204
+ if (keys && walk.long && !chargeLongNames(keys, walk.long, walk))
205
+ return CUT;
206
+ }
207
+ const outside = walk.repeating;
208
+ walk.repeating = repeated;
209
+ // No `finally`: every read below is guarded, so nothing throws between the push and the pop.
210
+ walk.ancestors.push(original);
211
+ const out = shape === 'array'
212
+ ? walkArray(object, length, depth, walk)
213
+ : shape === 'record'
214
+ ? walkRecord(object, keys, depth, walk)
215
+ : walkError(object, shape, depth, walk);
216
+ walk.ancestors.pop();
217
+ walk.repeating = outside;
218
+ return out;
219
+ }
220
+ /**
221
+ * Walks one field or array element one level down: an object pays its read in
222
+ * {@link walkValue}, any other value pays one here.
223
+ */
224
+ function walkField(value, depth, walk) {
225
+ return (value === null || typeof value !== 'object') && --walk.reads < 0
226
+ ? stop(walk)
227
+ : walkValue(value, depth, walk);
228
+ }
229
+ /** Ends the walk: the read past {@link MAX_READS}, or the value past {@link MAX_WRITTEN_CHARS}. */
230
+ function stop(walk) {
231
+ walk.stopped = true;
232
+ return CUT;
233
+ }
234
+ /**
235
+ * `value`, which writes `cost` characters: {@link CUT} when it is repeated
236
+ * content that does not fit in the bound on repeats, and the end of the walk when
237
+ * it does not fit in what is left of {@link MAX_WRITTEN_CHARS}.
238
+ */
239
+ function write(value, cost, repeated, walk) {
240
+ if (repeated && !charge(cost, walk))
241
+ return CUT;
242
+ walk.room -= cost;
243
+ return walk.room < 0 ? stop(walk) : value;
244
+ }
245
+ /**
246
+ * The characters a primitive other than a string writes. A safe integer's
247
+ * digits are counted rather than converted: converting each number of a record
248
+ * of 100,000 one-field objects made its walk a third slower on Bun.
249
+ */
250
+ function primitiveChars(value) {
251
+ if (!Number.isSafeInteger(value))
252
+ return String(value).length;
253
+ const n = value;
254
+ const abs = n < 0 ? -n : n;
255
+ let chars = n < 0 ? 2 : 1;
256
+ for (let power = 10; abs >= power; power *= 10)
257
+ chars++;
258
+ return chars;
259
+ }
260
+ /** A marker the walk writes in place of a value, charged like any string. */
261
+ function marker(text, walk) {
262
+ return write(text, text.length + 2, walk.repeating, walk);
263
+ }
264
+ /** Charges `cost` characters of repeated content: false, and nothing charged, when fewer are left. */
265
+ function charge(cost, walk) {
266
+ if (cost > walk.chars)
267
+ return false;
268
+ walk.chars -= cost;
269
+ return true;
270
+ }
271
+ /** Whether the walk wrote this long string or field name before; remembers it when not. */
272
+ function seenLong(text, walk) {
273
+ walk.long ??= new Map();
274
+ return holdsLong(walk.long, text, true);
275
+ }
276
+ /** Remembers a long string or field name the walk writes. */
277
+ function rememberLong(text, walk) {
278
+ seenLong(text, walk);
279
+ }
280
+ /**
281
+ * Whether `long` holds `text`, adding it when it does not and `add` is set.
282
+ * Every match is confirmed by `===`, so distinct text is never taken for text
283
+ * written before.
284
+ */
285
+ function holdsLong(long, text, add) {
286
+ const key = longKey(text);
287
+ const bucket = long.get(key);
288
+ if (bucket === undefined) {
289
+ if (add)
290
+ long.set(key, [text]);
291
+ return false;
292
+ }
293
+ if (Array.isArray(bucket)) {
294
+ if (bucket.includes(text))
295
+ return true;
296
+ if (add && bucket.push(text) > SAMPLE_BUCKET) {
297
+ const byHash = new Map();
298
+ for (const held of bucket)
299
+ pushByHash(byHash, contentHash(held), held);
300
+ long.set(key, byHash);
301
+ }
302
+ return false;
303
+ }
304
+ const hash = contentHash(text);
305
+ if (bucket.get(hash)?.includes(text))
306
+ return true;
307
+ if (add)
308
+ pushByHash(bucket, hash, text);
309
+ return false;
310
+ }
311
+ /**
312
+ * The key a long text is remembered under: the text itself up to
313
+ * {@link HASHED_TEXT} characters, else its length and its first, middle, and
314
+ * last 128 characters — shorter than {@link LONG_TEXT}, so never another text.
315
+ */
316
+ function longKey(text) {
317
+ if (text.length <= HASHED_TEXT)
318
+ return text;
319
+ const middle = text.length >> 1;
320
+ return `${text.length}:${text.slice(0, 128)}${text.slice(middle - 64, middle + 64)}${text.slice(-128)}`;
321
+ }
322
+ /** A 32-bit FNV-1a hash of every character of `text`. */
323
+ function contentHash(text) {
324
+ let hash = 0x811c9dc5;
325
+ for (let i = 0; i < text.length; i++)
326
+ hash = Math.imul(hash ^ text.charCodeAt(i), 0x01000193);
327
+ return hash;
328
+ }
329
+ /** Adds `text` to the texts `byHash` keeps under `hash`. */
330
+ function pushByHash(byHash, hash, text) {
331
+ const texts = byHash.get(hash);
332
+ if (texts)
333
+ texts.push(text);
334
+ else
335
+ byHash.set(hash, [text]);
336
+ }
337
+ /** The characters a repeated object's field names write, each with its quotes, colon, and comma. */
338
+ function nameChars(keys) {
339
+ let chars = 0;
340
+ for (let i = 0; i < keys.length; i++)
341
+ chars += keys[i].length + 4;
342
+ return chars;
343
+ }
344
+ /**
345
+ * Charges an object reached for the first time for each of its long field names
346
+ * the walk wrote before; {@link walkRecord} remembers them as it writes them. False
347
+ * when they do not fit: the object is then written as `'[Truncated]'`.
348
+ */
349
+ function chargeLongNames(keys, long, walk) {
350
+ let cost = 0;
351
+ for (let i = 0; i < keys.length; i++) {
352
+ const key = keys[i];
353
+ if (key.length >= LONG_TEXT && holdsLong(long, key, false))
354
+ cost += key.length + 4;
355
+ }
356
+ return cost === 0 || charge(cost, walk);
357
+ }
358
+ /** Which kind of `Error` `err` is, for {@link walkError}. */
359
+ function errorShape(err) {
360
+ if (err instanceof McpError)
361
+ return 'mcpError';
362
+ return err instanceof AggregateError ? 'aggregateError' : 'error';
363
+ }
364
+ /**
365
+ * Copies `length` elements of an array, each through {@link walkField}. Ends
366
+ * where the walk stops, and a repeated array after the value that did not fit.
367
+ */
368
+ function walkArray(array, length, depth, walk) {
369
+ const out = [];
370
+ for (let i = 0; i < length; i++) {
371
+ const value = walkField(read(array, i), depth + 1, walk);
372
+ out.push(value === CUT ? '[Truncated]' : value);
373
+ if (walk.stopped || (value === CUT && walk.repeating))
374
+ break;
375
+ }
376
+ return out;
377
+ }
378
+ /**
379
+ * Copies the fields named by `keys`, each through {@link walkField}, redacting
380
+ * each sensitive one — except, on the root object, a key the walk exempts —
381
+ * for a read, though its value is never read, and dropping each that walks to
382
+ * `undefined`. Each name is charged against {@link MAX_WRITTEN_CHARS} before its
383
+ * value is read, a dropped field's included; a name that does not fit is written
384
+ * as `'[Truncated]'`, and so is its value. Ends where the walk stops, and a
385
+ * repeated object after the field that did not fit.
386
+ */
387
+ function walkRecord(object, keys, depth, walk) {
388
+ const out = {};
389
+ for (let i = 0; i < keys.length; i++) {
390
+ const key = keys[i];
391
+ walk.room -= key.length + 4;
392
+ if (walk.room < 0) {
393
+ stop(walk);
394
+ out['[Truncated]'] = '[Truncated]';
395
+ break;
396
+ }
397
+ if (key.length >= LONG_TEXT)
398
+ rememberLong(key, walk);
399
+ const field = isSensitiveKey(key) && !(depth === 0 && walk.exemptRootKey?.(key))
400
+ ? --walk.reads < 0
401
+ ? stop(walk)
402
+ : marker('[REDACTED]', walk)
403
+ : walkField(read(object, key), depth + 1, walk);
404
+ if (field === undefined)
405
+ continue;
406
+ const value = field === CUT ? '[Truncated]' : field;
407
+ // An own `__proto__` key (from `JSON.parse`) would hit the prototype setter.
408
+ if (key === '__proto__') {
409
+ Object.defineProperty(out, key, {
410
+ configurable: true,
411
+ enumerable: true,
412
+ value,
413
+ writable: true,
414
+ });
415
+ }
416
+ else {
417
+ out[key] = value;
418
+ }
419
+ if (walk.stopped || (field === CUT && walk.repeating))
420
+ break;
421
+ }
422
+ return out;
423
+ }
424
+ /**
425
+ * Sets one field of a written `Error` unless it walked to `undefined`. False
426
+ * once the error must end there: the walk stopped, or a repeated error's field
427
+ * did not fit.
428
+ */
429
+ function put(out, key, field, walk) {
430
+ if (field !== undefined)
431
+ out[key] = field === CUT ? '[Truncated]' : field;
432
+ return !(walk.stopped || (field === CUT && walk.repeating));
433
+ }
434
+ /**
435
+ * Writes one `Error`. Mirror mode: `{ type, message }`. Log mode: `type` (its
436
+ * `name`), `message`, `stack` unless the walk is stack-free, a string `code` —
437
+ * or an `McpError`'s numeric `code` and its `data` — and `cause` and an
438
+ * `AggregateError`'s `errors`, each walked like any other value, so a nested
439
+ * `Error` takes this same shape. No other own property is copied: runtimes put
440
+ * request URLs (`path`, `input`) and server file paths (`sourceURL`) on them.
441
+ * A stack equal to the parent error's — the error whose `cause` or `errors`
442
+ * this one is — is left out, so a chain sharing one stack writes it once. An
443
+ * unreadable `code` is left out; any other unreadable field is `'[Unreadable]'`.
444
+ */
445
+ function walkError(err, shape, depth, walk) {
446
+ const { parentStack } = walk;
447
+ walk.parentStack = undefined;
448
+ const out = {};
449
+ if (put(out, 'type', walkValue(read(err, 'name'), depth + 1, walk), walk) &&
450
+ put(out, 'message', walkValue(read(err, 'message'), depth + 1, walk), walk) &&
451
+ walk.mode === 'log') {
452
+ const stack = walk.includeStack ? read(err, 'stack') : undefined;
453
+ let more = stack === undefined ||
454
+ stack === parentStack ||
455
+ put(out, 'stack', walkValue(stack, depth + 1, walk), walk);
456
+ if (more) {
457
+ const code = read(err, 'code');
458
+ if (shape === 'mcpError') {
459
+ if (code !== UNREADABLE)
460
+ out.code = code;
461
+ more = put(out, 'data', walkValue(read(err, 'data'), depth + 1, walk), walk);
462
+ }
463
+ else if (typeof code === 'string') {
464
+ out.code = code;
465
+ }
466
+ }
467
+ if (more) {
468
+ walk.parentStack = stack === UNREADABLE ? undefined : stack;
469
+ more = put(out, 'cause', walkValue(read(err, 'cause'), depth + 1, walk), walk);
470
+ if (more && shape === 'aggregateError') {
471
+ put(out, 'errors', walkValue(read(err, 'errors'), depth + 1, walk), walk);
472
+ }
473
+ }
474
+ }
475
+ walk.parentStack = parentStack;
476
+ return out;
477
+ }
478
+ /** A fresh walk: nothing entered yet, every read left, and the full bound on repeated content. */
479
+ function newWalk(mode, includeStack, exemptRootKey) {
480
+ return {
481
+ ancestors: [],
482
+ chars: MAX_REPEATED_CHARS,
483
+ exemptRootKey,
484
+ includeStack,
485
+ long: undefined,
486
+ mode,
487
+ parentStack: undefined,
488
+ reads: MAX_READS,
489
+ repeating: false,
490
+ room: MAX_WRITTEN_CHARS,
491
+ seen: new Set(),
492
+ stopped: false,
493
+ };
494
+ }
495
+ /**
496
+ * The JSON-safe form a log record writes for `value`, as the walk pino runs on
497
+ * every record produces it. With `includeStack: false`, every `Error` in it is
498
+ * written without its `stack`: a stack-free record passes its fields through
499
+ * this first, since the walk pino runs keeps stacks. A key of `value` itself
500
+ * for which `exemptRootKey` returns true is never redacted; the same key deeper
501
+ * down is.
502
+ *
503
+ * @internal Exported for the logger, stack-free log records, `ctx.log` data a spread cannot
504
+ * read, and unit testing. Not part of the public API.
505
+ */
506
+ export function toLogValue(value, options = {}) {
507
+ const out = walkValue(value, 0, newWalk('log', options.includeStack ?? true, options.exemptRootKey));
508
+ return out === CUT ? '[Truncated]' : out;
509
+ }
510
+ /**
511
+ * The copy of a `ctx.log` call's data the client mirror sends: what
512
+ * `JSON.stringify` reads from it (an object's `toJSON()` result, else its own
513
+ * enumerable fields), with every sensitive field masked as `'[REDACTED]'` and
514
+ * every `Error` written as `{ type, message }` — no stack, cause, or own
515
+ * property such as a request URL. The process log's bounds and markers apply:
516
+ * `'[Circular]'`, `'[MaxDepth]'` (the data's own fields sit at depth 1, as they
517
+ * do in the log record), `'[Truncated]'` where the ceiling on reads, the ceiling
518
+ * on characters written, or the bound on repeated content stops it — a `toJSON()`
519
+ * result reached again from another object included — and `'[Unreadable]'`,
520
+ * with data that has no readable keys at all as `{ data: '[Unreadable]' }`, as
521
+ * the process log writes it. Nothing passes through `structuredClone`, which
522
+ * rejects a `URL` or a function, and the input is never modified.
523
+ *
524
+ * @internal Masks the `ctx.log` mirror to the client. Not part of the public API.
525
+ */
526
+ export function toMirrorValue(fields) {
527
+ const walk = newWalk('mirror', false);
528
+ let keys;
529
+ try {
530
+ keys = Object.keys(fields);
531
+ }
532
+ catch {
533
+ return { data: '[Unreadable]' };
534
+ }
535
+ // On the ancestor stack for the whole walk, so a reference back to it is `'[Circular]'`.
536
+ walk.ancestors.push(fields);
537
+ return walkRecord(fields, keys, 0, walk);
538
+ }
539
+ //# sourceMappingURL=logValue.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"logValue.js","sourceRoot":"","sources":["../../../src/utils/internal/logValue.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AACH,OAAO,EAAE,QAAQ,EAAE,MAAM,0BAA0B,CAAC;AACpD,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AAErE;;;;;;;GAOG;AACH,MAAM,SAAS,GAAG,EAAE,CAAC;AAErB;;;;;;;;;;;;;GAaG;AACH,MAAM,SAAS,GAAG,OAAO,CAAC;AAE1B;;;;GAIG;AACH,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAE7B;;;;;;;;;;GAUG;AACH,MAAM,kBAAkB,GAAG,SAAS,CAAC;AAErC;;;;;;;;;GASG;AACH,MAAM,iBAAiB,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAE3C;;;;GAIG;AACH,MAAM,SAAS,GAAG,KAAK,CAAC;AAExB;;;;;;GAMG;AACH,MAAM,WAAW,GAAG,MAAM,CAAC;AAE3B;;;;;;GAMG;AACH,MAAM,aAAa,GAAG,CAAC,CAAC;AAQxB,8FAA8F;AAC9F,MAAM,UAAU,GAAG,MAAM,CAAC,YAAY,CAAC,CAAC;AAExC,8FAA8F;AAC9F,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;AA0C1B,0GAA0G;AAC1G,SAAS,IAAI,CAAC,MAAc,EAAE,GAAgB;IAC5C,IAAI,CAAC;QACH,OAAQ,MAAuC,CAAC,GAAG,CAAC,CAAC;IACvD,CAAC;IAAC,M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