@cyanheads/mcp-ts-core 0.11.2 → 0.11.3

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 (117) hide show
  1. package/AGENTS.md +14 -10
  2. package/CLAUDE.md +14 -10
  3. package/README.md +3 -3
  4. package/changelog/0.11.x/0.11.3.md +49 -0
  5. package/dist/config/index.d.ts +0 -10
  6. package/dist/config/index.d.ts.map +1 -1
  7. package/dist/config/index.js +1 -25
  8. package/dist/config/index.js.map +1 -1
  9. package/dist/config/logLevelAlias.d.ts +15 -0
  10. package/dist/config/logLevelAlias.d.ts.map +1 -0
  11. package/dist/config/logLevelAlias.js +30 -0
  12. package/dist/config/logLevelAlias.js.map +1 -0
  13. package/dist/core/context.d.ts +10 -0
  14. package/dist/core/context.d.ts.map +1 -1
  15. package/dist/core/context.js +10 -1
  16. package/dist/core/context.js.map +1 -1
  17. package/dist/core/worker.js +1 -1
  18. package/dist/core/worker.js.map +1 -1
  19. package/dist/logs/combined.log +16 -0
  20. package/dist/logs/error.log +12 -0
  21. package/dist/logs/interactions.log +0 -0
  22. package/dist/services/mirror/sqlite/sqliteMirrorStore.d.ts +10 -10
  23. package/dist/services/mirror/sqlite/sqliteMirrorStore.d.ts.map +1 -1
  24. package/dist/services/mirror/sqlite/sqliteMirrorStore.js +29 -24
  25. package/dist/services/mirror/sqlite/sqliteMirrorStore.js.map +1 -1
  26. package/dist/storage/core/storageValidation.d.ts +4 -4
  27. package/dist/storage/core/storageValidation.d.ts.map +1 -1
  28. package/dist/storage/core/storageValidation.js +4 -20
  29. package/dist/storage/core/storageValidation.js.map +1 -1
  30. package/dist/testing/index.d.ts +45 -13
  31. package/dist/testing/index.d.ts.map +1 -1
  32. package/dist/testing/index.js +29 -76
  33. package/dist/testing/index.js.map +1 -1
  34. package/dist/testing/vitest.d.ts +1 -1
  35. package/dist/utils/formatting/diffFormatter.d.ts +5 -5
  36. package/dist/utils/formatting/diffFormatter.d.ts.map +1 -1
  37. package/dist/utils/formatting/diffFormatter.js +1 -1
  38. package/dist/utils/formatting/diffFormatter.js.map +1 -1
  39. package/dist/utils/formatting/tableFormatter.d.ts +3 -3
  40. package/dist/utils/formatting/tableFormatter.d.ts.map +1 -1
  41. package/dist/utils/formatting/tableFormatter.js +1 -1
  42. package/dist/utils/formatting/tableFormatter.js.map +1 -1
  43. package/dist/utils/formatting/treeFormatter.d.ts +3 -3
  44. package/dist/utils/formatting/treeFormatter.d.ts.map +1 -1
  45. package/dist/utils/formatting/treeFormatter.js +1 -1
  46. package/dist/utils/formatting/treeFormatter.js.map +1 -1
  47. package/dist/utils/metrics/tokenCounter.d.ts +3 -3
  48. package/dist/utils/metrics/tokenCounter.d.ts.map +1 -1
  49. package/dist/utils/metrics/tokenCounter.js.map +1 -1
  50. package/dist/utils/network/fetchWithTimeout.d.ts +43 -15
  51. package/dist/utils/network/fetchWithTimeout.d.ts.map +1 -1
  52. package/dist/utils/network/fetchWithTimeout.js +163 -44
  53. package/dist/utils/network/fetchWithTimeout.js.map +1 -1
  54. package/dist/utils/network/httpError.d.ts.map +1 -1
  55. package/dist/utils/network/httpError.js +1 -2
  56. package/dist/utils/network/httpError.js.map +1 -1
  57. package/dist/utils/network/responseBody.d.ts +27 -7
  58. package/dist/utils/network/responseBody.d.ts.map +1 -1
  59. package/dist/utils/network/responseBody.js +54 -13
  60. package/dist/utils/network/responseBody.js.map +1 -1
  61. package/dist/utils/network/retry.d.ts +2 -2
  62. package/dist/utils/network/retry.d.ts.map +1 -1
  63. package/dist/utils/pagination/pagination.d.ts +3 -3
  64. package/dist/utils/pagination/pagination.d.ts.map +1 -1
  65. package/dist/utils/pagination/pagination.js.map +1 -1
  66. package/dist/utils/parsing/csvParser.d.ts +2 -2
  67. package/dist/utils/parsing/csvParser.d.ts.map +1 -1
  68. package/dist/utils/parsing/csvParser.js +1 -1
  69. package/dist/utils/parsing/csvParser.js.map +1 -1
  70. package/dist/utils/parsing/dateParser.d.ts +11 -7
  71. package/dist/utils/parsing/dateParser.d.ts.map +1 -1
  72. package/dist/utils/parsing/dateParser.js +8 -4
  73. package/dist/utils/parsing/dateParser.js.map +1 -1
  74. package/dist/utils/parsing/frontmatterParser.d.ts +5 -4
  75. package/dist/utils/parsing/frontmatterParser.d.ts.map +1 -1
  76. package/dist/utils/parsing/frontmatterParser.js +5 -4
  77. package/dist/utils/parsing/frontmatterParser.js.map +1 -1
  78. package/dist/utils/parsing/htmlExtractor.d.ts +5 -4
  79. package/dist/utils/parsing/htmlExtractor.d.ts.map +1 -1
  80. package/dist/utils/parsing/htmlExtractor.js +4 -3
  81. package/dist/utils/parsing/htmlExtractor.js.map +1 -1
  82. package/dist/utils/parsing/inputBudget.d.ts +18 -11
  83. package/dist/utils/parsing/inputBudget.d.ts.map +1 -1
  84. package/dist/utils/parsing/inputBudget.js +20 -17
  85. package/dist/utils/parsing/inputBudget.js.map +1 -1
  86. package/dist/utils/parsing/jsonParser.d.ts +5 -4
  87. package/dist/utils/parsing/jsonParser.d.ts.map +1 -1
  88. package/dist/utils/parsing/jsonParser.js +5 -4
  89. package/dist/utils/parsing/jsonParser.js.map +1 -1
  90. package/dist/utils/parsing/pdfParser.d.ts +38 -24
  91. package/dist/utils/parsing/pdfParser.d.ts.map +1 -1
  92. package/dist/utils/parsing/pdfParser.js +42 -31
  93. package/dist/utils/parsing/pdfParser.js.map +1 -1
  94. package/dist/utils/parsing/xmlParser.d.ts +3 -3
  95. package/dist/utils/parsing/xmlParser.d.ts.map +1 -1
  96. package/dist/utils/parsing/xmlParser.js +3 -6
  97. package/dist/utils/parsing/xmlParser.js.map +1 -1
  98. package/dist/utils/parsing/yamlParser.d.ts +3 -3
  99. package/dist/utils/parsing/yamlParser.d.ts.map +1 -1
  100. package/dist/utils/parsing/yamlParser.js +3 -3
  101. package/dist/utils/parsing/yamlParser.js.map +1 -1
  102. package/dist/utils/security/rateLimiter.d.ts +2 -2
  103. package/dist/utils/security/rateLimiter.d.ts.map +1 -1
  104. package/dist/utils/security/rateLimiter.js +1 -1
  105. package/dist/utils/security/rateLimiter.js.map +1 -1
  106. package/dist/utils/telemetry/trace.d.ts +3 -3
  107. package/dist/utils/telemetry/trace.d.ts.map +1 -1
  108. package/dist/utils/telemetry/trace.js.map +1 -1
  109. package/package.json +1 -1
  110. package/skills/add-test/SKILL.md +2 -2
  111. package/skills/api-auth/SKILL.md +5 -5
  112. package/skills/api-context/SKILL.md +13 -12
  113. package/skills/api-testing/SKILL.md +29 -10
  114. package/skills/api-utils/SKILL.md +4 -2
  115. package/skills/api-utils/references/parsing.md +3 -2
  116. package/templates/AGENTS.md +1 -1
  117. package/templates/CLAUDE.md +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"inputBudget.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/inputBudget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,2DAA2D;AAC3D,eAAO,MAAM,6BAA6B,QAAc,CAAC;AAEzD,wDAAwD;AACxD,eAAO,MAAM,+BAA+B,QAAmB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAgBD,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAyBpD;AAcD,kFAAkF;AAClF,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,MAAM,CAG/F;AAED,8EAA8E;AAC9E,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,UAAU,GAAG,WAAW,EAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAGR;AAED,gGAAgG;AAChG,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,CAAC,UAAU,GAAG,WAAW,CAAC,EAAE,EAC7C,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAIR"}
1
+ {"version":3,"file":"inputBudget.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/inputBudget.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAIH;;;GAGG;AACH,eAAO,MAAM,6BAA6B,QAAc,CAAC;AAEzD;;;GAGG;AACH,eAAO,MAAM,+BAA+B,QAAmB,CAAC;AAEhE;;;;;GAKG;AACH,MAAM,WAAW,wBAAwB;IACvC,QAAQ,CAAC,EAAE,MAAM,CAAC;CACnB;AAeD,kFAAkF;AAClF,wBAAgB,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAyBpD;AAcD,8FAA8F;AAC9F,wBAAgB,qBAAqB,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,wBAAwB,GAAG,MAAM,CAE/F;AAED,0FAA0F;AAC1F,wBAAgB,uBAAuB,CACrC,KAAK,EAAE,UAAU,GAAG,WAAW,EAC/B,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAER;AAED,gGAAgG;AAChG,wBAAgB,wBAAwB,CACtC,MAAM,EAAE,SAAS,CAAC,UAAU,GAAG,WAAW,CAAC,EAAE,EAC7C,OAAO,CAAC,EAAE,wBAAwB,GACjC,MAAM,CAGR"}
@@ -1,22 +1,28 @@
1
1
  /**
2
- * @fileoverview Input byte budgets shared by the parsing utilities. Bounds the
3
- * work a single parse can schedule, so a hostile document cannot amplify a
4
- * modest request into unbounded CPU or memory in the parser dependency.
2
+ * @fileoverview Opt-in input byte budgets shared by the parsing utilities. A
3
+ * parser is unbounded unless its caller supplies `maxBytes`: the input is
4
+ * already resident in memory by the time a parser sees it, so a budget is a
5
+ * caller's work-shaping knob rather than a trust boundary.
5
6
  * @module src/utils/parsing/inputBudget
6
7
  */
7
8
  import { validationError } from '../../types-global/errors.js';
8
- /** Default UTF-8 input budget for text parsers (1 MiB). */
9
+ /**
10
+ * Suggested UTF-8 input budget for text parsers (1 MiB). Not applied unless a
11
+ * caller passes it as `maxBytes`.
12
+ */
9
13
  export const DEFAULT_TEXT_PARSER_MAX_BYTES = 1024 * 1024;
10
- /** Default input budget for binary parsers (25 MiB). */
14
+ /**
15
+ * Suggested input budget for binary parsers (25 MiB). Not applied unless a
16
+ * caller passes it as `maxBytes`.
17
+ */
11
18
  export const DEFAULT_BINARY_PARSER_MAX_BYTES = 25 * 1024 * 1024;
12
- function resolveLimit(options, defaultLimit) {
19
+ function resolveLimit(options) {
13
20
  const requested = options?.maxBytes;
14
21
  if (requested === undefined)
15
- return defaultLimit;
22
+ return;
16
23
  if (!Number.isSafeInteger(requested) || requested < 1) {
17
24
  throw validationError('Parser input byte limit must be a positive safe integer.', {
18
25
  reason: 'parser_input_limit_invalid',
19
- limitBytes: defaultLimit,
20
26
  });
21
27
  }
22
28
  return requested;
@@ -48,7 +54,7 @@ export function utf8ByteLength(input) {
48
54
  return bytes;
49
55
  }
50
56
  function assertWithinLimit(sizeBytes, limitBytes) {
51
- if (sizeBytes > limitBytes) {
57
+ if (limitBytes !== undefined && sizeBytes > limitBytes) {
52
58
  throw validationError('Parser input exceeds the maximum allowed byte size.', {
53
59
  reason: 'parser_input_too_large',
54
60
  sizeBytes,
@@ -57,20 +63,17 @@ function assertWithinLimit(sizeBytes, limitBytes) {
57
63
  }
58
64
  return sizeBytes;
59
65
  }
60
- /** Assert a text input fits its budget. Returns the input's UTF-8 byte length. */
66
+ /** Assert a text input fits any budget the caller declared. Returns its UTF-8 byte length. */
61
67
  export function assertTextInputBudget(input, options) {
62
- const limitBytes = resolveLimit(options, DEFAULT_TEXT_PARSER_MAX_BYTES);
63
- return assertWithinLimit(utf8ByteLength(input), limitBytes);
68
+ return assertWithinLimit(utf8ByteLength(input), resolveLimit(options));
64
69
  }
65
- /** Assert a binary input fits its budget. Returns the input's byte length. */
70
+ /** Assert a binary input fits any budget the caller declared. Returns its byte length. */
66
71
  export function assertBinaryInputBudget(input, options) {
67
- const limitBytes = resolveLimit(options, DEFAULT_BINARY_PARSER_MAX_BYTES);
68
- return assertWithinLimit(input.byteLength, limitBytes);
72
+ return assertWithinLimit(input.byteLength, resolveLimit(options));
69
73
  }
70
74
  /** Assert a set of binary inputs fits one shared budget. Returns their combined byte length. */
71
75
  export function assertBinaryInputsBudget(inputs, options) {
72
- const limitBytes = resolveLimit(options, DEFAULT_BINARY_PARSER_MAX_BYTES);
73
76
  const sizeBytes = inputs.reduce((total, input) => total + input.byteLength, 0);
74
- return assertWithinLimit(sizeBytes, limitBytes);
77
+ return assertWithinLimit(sizeBytes, resolveLimit(options));
75
78
  }
76
79
  //# sourceMappingURL=inputBudget.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"inputBudget.js","sourceRoot":"","sources":["../../../src/utils/parsing/inputBudget.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,2DAA2D;AAC3D,MAAM,CAAC,MAAM,6BAA6B,GAAG,IAAI,GAAG,IAAI,CAAC;AAEzD,wDAAwD;AACxD,MAAM,CAAC,MAAM,+BAA+B,GAAG,EAAE,GAAG,IAAI,GAAG,IAAI,CAAC;AAYhE,SAAS,YAAY,CAAC,OAA6C,EAAE,YAAoB;IACvF,MAAM,SAAS,GAAG,OAAO,EAAE,QAAQ,CAAC;IACpC,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,YAAY,CAAC;IAEjD,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,SAAS,CAAC,IAAI,SAAS,GAAG,CAAC,EAAE,CAAC;QACtD,MAAM,eAAe,CAAC,0DAA0D,EAAE;YAChF,MAAM,EAAE,4BAA4B;YACpC,UAAU,EAAE,YAAY;SACzB,CAAC,CAAC;IACL,CAAC;IAED,OAAO,SAAS,CAAC;AACnB,CAAC;AAED,kFAAkF;AAClF,MAAM,UAAU,cAAc,CAAC,KAAa;IAC1C,IAAI,KAAK,GAAG,CAAC,CAAC;IAEd,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,KAAK,CAAC,MAAM,EAAE,KAAK,IAAI,CAAC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AAU,uBAAuB,CACrC,KAA+B,EAC/B,OAAkC;IAElC,OAAO,iBAAiB,CAAC,KAAK,CAAC,UAAU,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AACpE,CAAC;AAED,gGAAgG;AAChG,MAAM,UAAU,wBAAwB,CACtC,MAA6C,EAC7C,OAAkC;IAElC,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,KAAK,GAAG,KAAK,CAAC,UAAU,EAAE,CAAC,CAAC,CAAC;IAC/E,OAAO,iBAAiB,CAAC,SAAS,EAAE,YAAY,CAAC,OAAO,CAAC,CAAC,CAAC;AAC7D,CAAC"}
@@ -1,4 +1,4 @@
1
- import { type RequestContext } from '../../utils/internal/requestContext.js';
1
+ import { type RequestContext, type RequestContextLike } from '../../utils/internal/requestContext.js';
2
2
  import { type ParserInputBudgetOptions } from './inputBudget.js';
3
3
  /**
4
4
  * Bit flags specifying which partial JSON types are permissible during parsing.
@@ -68,8 +68,9 @@ export declare class JsonParser {
68
68
  * and/or be a partial (incomplete) JSON value.
69
69
  * @param allowPartial - Bitwise OR combination of `Allow` flags controlling which
70
70
  * partial JSON types are accepted. Defaults to `Allow.ALL`.
71
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
72
- * @param budget - Optional UTF-8 byte budget for the input. Defaults to 1 MiB.
71
+ * @param context - Optional context for correlated logging and error metadata. The
72
+ * handler `Context` is accepted directly.
73
+ * @param budget - Optional UTF-8 byte budget for the input. Unbounded when omitted.
73
74
  * @returns The parsed JavaScript value cast to `T`.
74
75
  * @throws {McpError} With `ValidationError` if the string is empty after stripping the
75
76
  * `<think>` block and trimming, or if `partial-json` fails to parse the content.
@@ -88,7 +89,7 @@ export declare class JsonParser {
88
89
  * console.log(result); // { items: [1, 2] }
89
90
  * ```
90
91
  */
91
- parse<T = unknown>(jsonString: string, allowPartial?: number, context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<T>;
92
+ parse<T = unknown>(jsonString: string, allowPartial?: number, context?: RequestContextLike | RequestContext, budget?: ParserInputBudgetOptions): Promise<T>;
92
93
  }
93
94
  /**
94
95
  * Singleton instance of `JsonParser`.
@@ -1 +1 @@
1
- {"version":3,"file":"jsonParser.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/jsonParser.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAAyB,KAAK,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAQxF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK;IAChB,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,4BAA4B;aAC5B,GAAG,EAAE,CAAG;IACR,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,iCAAiC;aACjC,IAAI,EAAE,EAAI;IACV,8BAA8B;aAC9B,IAAI,EAAE,EAAI;IACV,wBAAwB;aACxB,GAAG,EAAE,EAAI;IACT,+BAA+B;aAC/B,QAAQ,EAAE,GAAI;IACd,+BAA+B;aAC/B,SAAS,EAAE,GAAK;IAChB,0EAA0E;aAC1E,GAAG;IACH,sEAAsE;aACtE,OAAO;IACP,8EAA8E;aAC9E,IAAI;IACJ,8CAA8C;aAC9C,UAAU;IACV,+BAA+B;aAC/B,GAAG;CACK,CAAC;AAEX;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EACrB,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,MAAkB,EAChC,OAAO,CAAC,EAAE,cAAc,EACxB,MAAM,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,CAAC,CAAC,CAyDZ;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,UAAU,YAAmB,CAAC"}
1
+ {"version":3,"file":"jsonParser.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/jsonParser.ts"],"names":[],"mappings":"AASA,OAAO,EACL,KAAK,cAAc,EACnB,KAAK,kBAAkB,EAExB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,EAAyB,KAAK,wBAAwB,EAAE,MAAM,kBAAkB,CAAC;AAQxF;;;;;;;;;;;;;GAaG;AACH,eAAO,MAAM,KAAK;IAChB,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,4BAA4B;aAC5B,GAAG,EAAE,CAAG;IACR,6BAA6B;aAC7B,GAAG,EAAE,CAAG;IACR,iCAAiC;aACjC,IAAI,EAAE,EAAI;IACV,8BAA8B;aAC9B,IAAI,EAAE,EAAI;IACV,wBAAwB;aACxB,GAAG,EAAE,EAAI;IACT,+BAA+B;aAC/B,QAAQ,EAAE,GAAI;IACd,+BAA+B;aAC/B,SAAS,EAAE,GAAK;IAChB,0EAA0E;aAC1E,GAAG;IACH,sEAAsE;aACtE,OAAO;IACP,8EAA8E;aAC9E,IAAI;IACJ,8CAA8C;aAC9C,UAAU;IACV,+BAA+B;aAC/B,GAAG;CACK,CAAC;AAEX;;;;;;;GAOG;AACH,qBAAa,UAAU;IACrB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACG,KAAK,CAAC,CAAC,GAAG,OAAO,EACrB,UAAU,EAAE,MAAM,EAClB,YAAY,GAAE,MAAkB,EAChC,OAAO,CAAC,EAAE,kBAAkB,GAAG,cAAc,EAC7C,MAAM,CAAC,EAAE,wBAAwB,GAChC,OAAO,CAAC,CAAC,CAAC,CAyDZ;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,eAAO,MAAM,UAAU,YAAmB,CAAC"}
@@ -7,7 +7,7 @@
7
7
  import { validationError } from '../../types-global/errors.js';
8
8
  import { lazyImport } from '../../utils/internal/lazyImport.js';
9
9
  import { logger } from '../../utils/internal/logger.js';
10
- import { requestContextService } from '../../utils/internal/requestContext.js';
10
+ import { requestContextService, } from '../../utils/internal/requestContext.js';
11
11
  import { assertTextInputBudget } from './inputBudget.js';
12
12
  import { thinkBlockRegex } from './thinkBlock.js';
13
13
  const getPartialJson = lazyImport(() => import('partial-json'), 'Install "partial-json" to use partial JSON parsing: bun add partial-json');
@@ -79,8 +79,9 @@ export class JsonParser {
79
79
  * and/or be a partial (incomplete) JSON value.
80
80
  * @param allowPartial - Bitwise OR combination of `Allow` flags controlling which
81
81
  * partial JSON types are accepted. Defaults to `Allow.ALL`.
82
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
83
- * @param budget - Optional UTF-8 byte budget for the input. Defaults to 1 MiB.
82
+ * @param context - Optional context for correlated logging and error metadata. The
83
+ * handler `Context` is accepted directly.
84
+ * @param budget - Optional UTF-8 byte budget for the input. Unbounded when omitted.
84
85
  * @returns The parsed JavaScript value cast to `T`.
85
86
  * @throws {McpError} With `ValidationError` if the string is empty after stripping the
86
87
  * `<think>` block and trimming, or if `partial-json` fails to parse the content.
@@ -140,7 +141,7 @@ export class JsonParser {
140
141
  errorDetails: error.message,
141
142
  contentAttempted: stringToParse.substring(0, 200),
142
143
  });
143
- throw validationError('Failed to parse JSON content.', { reason: 'json_parse_failed' }, { cause: error });
144
+ throw validationError(`Failed to parse JSON content: ${error.message}`, { reason: 'json_parse_failed' }, { cause: error });
144
145
  }
145
146
  }
146
147
  }
@@ -1 +1 @@
1
- {"version":3,"file":"jsonParser.js","sourceRoot":"","sources":["../../../src/utils/parsing/jsonParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAC3D,OAAO,EAAE,UAAU,EAAE,MAAM,gCAAgC,CAAC;AAC5D,OAAO,EAAE,MAAM,EAAE,MAAM,4BAA4B,CAAC;AACpD,OAAO,EAAuB,qBAAqB,EAAE,MAAM,oCAA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AAM,EAAE,mBAAmB,EAAE,EAC/B,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG,IAAI,UAAU,EAAE,CAAC"}
@@ -5,7 +5,7 @@
5
5
  * @module src/utils/parsing/pdfParser
6
6
  */
7
7
  import type { PDFDocument, PDFFont, PDFImage, PDFPage, RGB } from 'pdf-lib';
8
- import { type RequestContext } from '../../utils/internal/requestContext.js';
8
+ import { type RequestContext, type RequestContextLike } from '../../utils/internal/requestContext.js';
9
9
  import { type ParserInputBudgetOptions } from './inputBudget.js';
10
10
  /**
11
11
  * Options for adding a new page to a PDF document.
@@ -74,7 +74,7 @@ export interface EmbedImageOptions {
74
74
  * Image data as Uint8Array or ArrayBuffer.
75
75
  */
76
76
  imageBytes: Uint8Array | ArrayBuffer;
77
- /** Input budget in bytes. Defaults to 25 MiB; raise it for known-large images. */
77
+ /** Input budget in bytes. Unbounded when omitted. */
78
78
  maxBytes?: number;
79
79
  }
80
80
  /**
@@ -211,8 +211,13 @@ export interface FillFormOptions {
211
211
  * Options for extracting text from a PDF document.
212
212
  */
213
213
  export interface ExtractTextOptions {
214
- /** Input budget in bytes. Defaults to 25 MiB; raise it for known-large documents. */
214
+ /** Input budget in bytes. Unbounded when omitted. */
215
215
  maxBytes?: number;
216
+ /**
217
+ * Ceiling in pixels on a single decoded image, forwarded to pdf.js as
218
+ * `maxImageSize`. Unbounded when omitted, matching pdf.js's own default.
219
+ */
220
+ maxImageSize?: number;
216
221
  /**
217
222
  * Whether to merge all pages into a single string.
218
223
  * If true, returns text as a single string.
@@ -250,7 +255,8 @@ export declare class PdfParser {
250
255
  *
251
256
  * Async due to lazy loading of the `pdf-lib` peer dependency (`bun add pdf-lib`).
252
257
  *
253
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
258
+ * @param context - Optional context for correlated logging and error metadata. The
259
+ * handler `Context` is accepted directly.
254
260
  * @returns A new empty `PDFDocument` instance.
255
261
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
256
262
  * @throws {McpError} With `InternalError` if document creation fails.
@@ -260,15 +266,16 @@ export declare class PdfParser {
260
266
  * const page = pdfParser.addPage(doc);
261
267
  * ```
262
268
  */
263
- createDocument(context?: RequestContext): Promise<PDFDocument>;
269
+ createDocument(context?: RequestContextLike | RequestContext): Promise<PDFDocument>;
264
270
  /**
265
271
  * Loads an existing PDF document from raw bytes.
266
272
  *
267
273
  * Async due to lazy loading of the `pdf-lib` peer dependency (`bun add pdf-lib`).
268
274
  *
269
275
  * @param pdfBytes - The PDF file contents as `Uint8Array` or `ArrayBuffer`.
270
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
271
- * @param budget - Optional byte budget for the input. Defaults to 25 MiB.
276
+ * @param context - Optional context for correlated logging and error metadata. The
277
+ * handler `Context` is accepted directly.
278
+ * @param budget - Optional byte budget for the input. Unbounded when omitted.
272
279
  * @returns The loaded `PDFDocument` instance.
273
280
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
274
281
  * @throws {McpError} With `ValidationError` if the bytes are not a valid PDF.
@@ -279,7 +286,7 @@ export declare class PdfParser {
279
286
  * const doc = await pdfParser.loadDocument(pdfBytes);
280
287
  * ```
281
288
  */
282
- loadDocument(pdfBytes: Uint8Array | ArrayBuffer, context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument>;
289
+ loadDocument(pdfBytes: Uint8Array | ArrayBuffer, context?: RequestContextLike | RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument>;
283
290
  /**
284
291
  * Adds a new blank page to a PDF document.
285
292
  *
@@ -303,7 +310,8 @@ export declare class PdfParser {
303
310
  *
304
311
  * @param doc - The `PDFDocument` to embed the font into.
305
312
  * @param fontName - A `StandardFonts` key. Defaults to `'Helvetica'`.
306
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
313
+ * @param context - Optional context for correlated logging and error metadata. The
314
+ * handler `Context` is accepted directly.
307
315
  * @returns The embedded `PDFFont` ready to pass to `drawText`.
308
316
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
309
317
  * @throws {McpError} With `InternalError` if the font name is invalid or embedding fails.
@@ -312,7 +320,7 @@ export declare class PdfParser {
312
320
  * const font = await pdfParser.embedFont(doc, 'TimesRoman');
313
321
  * ```
314
322
  */
315
- embedFont(doc: PDFDocument, fontName?: string, context?: RequestContext): Promise<PDFFont>;
323
+ embedFont(doc: PDFDocument, fontName?: string, context?: RequestContextLike | RequestContext): Promise<PDFFont>;
316
324
  /**
317
325
  * Embeds a PNG or JPEG image into a PDF document for later rendering.
318
326
  *
@@ -321,7 +329,8 @@ export declare class PdfParser {
321
329
  *
322
330
  * @param doc - The `PDFDocument` to embed the image into.
323
331
  * @param options - Image bytes and format (`'png'` or `'jpg'`).
324
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
332
+ * @param context - Optional context for correlated logging and error metadata. The
333
+ * handler `Context` is accepted directly.
325
334
  * @returns The embedded `PDFImage`, usable as the `image` option in `drawImage`.
326
335
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
327
336
  * @throws {McpError} With `InternalError` if the image data is invalid or embedding fails.
@@ -333,7 +342,7 @@ export declare class PdfParser {
333
342
  * pdfParser.drawImage(page, { image, x: 50, y: 700, width: 100, height: 50 });
334
343
  * ```
335
344
  */
336
- embedImage(doc: PDFDocument, options: EmbedImageOptions, context?: RequestContext): Promise<PDFImage>;
345
+ embedImage(doc: PDFDocument, options: EmbedImageOptions, context?: RequestContextLike | RequestContext): Promise<PDFImage>;
337
346
  /**
338
347
  * Draws text on a PDF page with optional font, size, color, rotation, and word-wrap.
339
348
  *
@@ -391,8 +400,9 @@ export declare class PdfParser {
391
400
  * `pdf-lib` (`bun add pdf-lib`).
392
401
  *
393
402
  * @param pdfBytesArray - Source PDF files as `Uint8Array` or `ArrayBuffer` elements.
394
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
395
- * @param budget - Optional aggregate byte budget across all inputs. Defaults to 25 MiB.
403
+ * @param context - Optional context for correlated logging and error metadata. The
404
+ * handler `Context` is accepted directly.
405
+ * @param budget - Optional aggregate byte budget across all inputs. Unbounded when omitted.
396
406
  * @returns A new `PDFDocument` containing all pages from the input documents.
397
407
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
398
408
  * @throws {McpError} With `InternalError` if any source PDF is invalid or merging fails.
@@ -405,7 +415,7 @@ export declare class PdfParser {
405
415
  * const bytes = await pdfParser.saveDocument(merged);
406
416
  * ```
407
417
  */
408
- mergePdfs(pdfBytesArray: (Uint8Array | ArrayBuffer)[], context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument>;
418
+ mergePdfs(pdfBytesArray: (Uint8Array | ArrayBuffer)[], context?: RequestContextLike | RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument>;
409
419
  /**
410
420
  * Splits a PDF document into multiple new documents based on page ranges.
411
421
  *
@@ -415,8 +425,9 @@ export declare class PdfParser {
415
425
  *
416
426
  * @param pdfBytes - The source PDF as `Uint8Array` or `ArrayBuffer`.
417
427
  * @param ranges - Page ranges to extract; each produces one output document.
418
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
419
- * @param budget - Optional byte budget for the input. Defaults to 25 MiB.
428
+ * @param context - Optional context for correlated logging and error metadata. The
429
+ * handler `Context` is accepted directly.
430
+ * @param budget - Optional byte budget for the input. Unbounded when omitted.
420
431
  * @returns An array of new `PDFDocument` instances, one per range, in order.
421
432
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
422
433
  * @throws {McpError} With `InternalError` if the source PDF is invalid or a page index is out of bounds.
@@ -430,7 +441,7 @@ export declare class PdfParser {
430
441
  * ]);
431
442
  * ```
432
443
  */
433
- splitPdf(pdfBytes: Uint8Array | ArrayBuffer, ranges: PageRange[], context?: RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument[]>;
444
+ splitPdf(pdfBytes: Uint8Array | ArrayBuffer, ranges: PageRange[], context?: RequestContextLike | RequestContext, budget?: ParserInputBudgetOptions): Promise<PDFDocument[]>;
434
445
  /**
435
446
  * Fills form fields in a PDF document.
436
447
  *
@@ -441,7 +452,8 @@ export declare class PdfParser {
441
452
  *
442
453
  * @param doc - The `PDFDocument` containing the AcroForm.
443
454
  * @param options - Map of field names to values, plus optional `flatten` flag.
444
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
455
+ * @param context - Optional context for correlated logging and error metadata. The
456
+ * handler `Context` is accepted directly.
445
457
  * @throws {McpError} With `InternalError` if the overall form operation fails.
446
458
  * @example
447
459
  * ```typescript
@@ -455,7 +467,7 @@ export declare class PdfParser {
455
467
  * });
456
468
  * ```
457
469
  */
458
- fillForm(doc: PDFDocument, options: FillFormOptions, context?: RequestContext): void;
470
+ fillForm(doc: PDFDocument, options: FillFormOptions, context?: RequestContextLike | RequestContext): void;
459
471
  /**
460
472
  * Extracts metadata from a PDF document.
461
473
  *
@@ -504,7 +516,8 @@ export declare class PdfParser {
504
516
  * @param input - Raw PDF bytes (`Uint8Array` | `ArrayBuffer`) or a loaded `PDFDocument`.
505
517
  * @param options - Optional extraction options. Set `mergePages: true` to get a
506
518
  * single concatenated string instead of one string per page.
507
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
519
+ * @param context - Optional context for correlated logging and error metadata. The
520
+ * handler `Context` is accepted directly.
508
521
  * @returns An `ExtractTextResult` with `totalPages` and `text` — a `string[]` (one
509
522
  * per page) by default, or a single `string` when `mergePages` is `true`.
510
523
  * @throws {McpError} With `ConfigurationError` if `unpdf` is not installed (or
@@ -521,7 +534,7 @@ export declare class PdfParser {
521
534
  * const perPage = await pdfParser.extractText(doc);
522
535
  * ```
523
536
  */
524
- extractText(input: PDFDocument | Uint8Array | ArrayBuffer, options?: ExtractTextOptions, context?: RequestContext): Promise<ExtractTextResult>;
537
+ extractText(input: PDFDocument | Uint8Array | ArrayBuffer, options?: ExtractTextOptions, context?: RequestContextLike | RequestContext): Promise<ExtractTextResult>;
525
538
  /**
526
539
  * Serializes a PDF document to a `Uint8Array` for writing to disk or transmission.
527
540
  *
@@ -529,7 +542,8 @@ export declare class PdfParser {
529
542
  * compatible). Does not reload peer dependencies if already cached.
530
543
  *
531
544
  * @param doc - The `PDFDocument` to serialize.
532
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
545
+ * @param context - Optional context for correlated logging and error metadata. The
546
+ * handler `Context` is accepted directly.
533
547
  * @returns The complete PDF file as a `Uint8Array`.
534
548
  * @throws {McpError} With `InternalError` if serialization fails.
535
549
  * @example
@@ -539,7 +553,7 @@ export declare class PdfParser {
539
553
  * await writeFile('output.pdf', pdfBytes);
540
554
  * ```
541
555
  */
542
- saveDocument(doc: PDFDocument, context?: RequestContext): Promise<Uint8Array>;
556
+ saveDocument(doc: PDFDocument, context?: RequestContextLike | RequestContext): Promise<Uint8Array>;
543
557
  }
544
558
  /**
545
559
  * Singleton instance of `PdfParser`.
@@ -1 +1 @@
1
- {"version":3,"file":"pdfParser.d.ts","sourceRoot":"","sources":["../../../src/utils/parsing/pdfParser.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC;AAK5E,OAAO,EAAE,KAAK,cAAc,EAAyB,MAAM,oCAAoC,CAAC;AAChG,OAAO,EAGL,KAAK,wBAAwB,EAC9B,MAAM,kBAAkB,CAAC;AAgC1B;;GAEG;AACH,MAAM,WAAW,cAAc;IAC7B;;OAEG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,KAAK,CAAC,EAAE,GAAG,CAAC;IAEZ;;;OAGG;IACH,IAAI,CAAC,E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E,WAAW,EAChB,OAAO,CAAC,EAAE,kBAAkB,GAAG,cAAc,GAC5C,OAAO,CAAC,UAAU,CAAC,CA6BrB;CACF;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;GA2BG;AACH,eAAO,MAAM,SAAS,WAAkB,CAAC;AAEzC,YAAY,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,SAAS,CAAC"}
@@ -1,24 +1,26 @@
1
1
  import { JsonRpcErrorCode, McpError } from '../../types-global/errors.js';
2
2
  import { lazyImport } from '../../utils/internal/lazyImport.js';
3
3
  import { logger } from '../../utils/internal/logger.js';
4
- import { requestContextService } from '../../utils/internal/requestContext.js';
4
+ import { requestContextService, } from '../../utils/internal/requestContext.js';
5
5
  import { assertBinaryInputBudget, assertBinaryInputsBudget, } from './inputBudget.js';
6
6
  const getPdfLib = lazyImport(() => import('pdf-lib'), 'Install "pdf-lib" to use PDF operations: bun add pdf-lib');
7
7
  const getUnpdf = lazyImport(() => import('unpdf'), 'Install "unpdf" to use PDF text extraction: bun add unpdf');
8
8
  /**
9
- * Build the client-facing PDF failure envelope without copying parser/library
10
- * diagnostics into `McpError.data` or `message`. The original failure remains
11
- * available to the internal error pipeline through `cause`.
9
+ * Build the client-facing PDF failure envelope: a fixed summary plus the
10
+ * library's own diagnostic, which is what tells a caller how to repair the
11
+ * input. `data` carries only the stable `reason` discriminator — never a
12
+ * content sample or a stack, both of which stay on `cause` for the internal
13
+ * error pipeline.
12
14
  *
13
15
  * An `McpError` thrown from inside the operation is already classified and
14
16
  * client-safe — most often the `ConfigurationError` a lazy import raises for a
15
17
  * missing peer dependency — so it passes through with its code and remediation
16
18
  * intact rather than being relabelled as a PDF failure.
17
19
  */
18
- function pdfFailure(code, message, reason, cause) {
20
+ function pdfFailure(code, summary, reason, cause) {
19
21
  if (cause instanceof McpError)
20
22
  return cause;
21
- return new McpError(code, message, { reason }, { cause });
23
+ return new McpError(code, `${summary}: ${cause.message}`, { reason }, { cause });
22
24
  }
23
25
  /**
24
26
  * Utility class for creating, modifying, and parsing PDF documents.
@@ -34,7 +36,8 @@ export class PdfParser {
34
36
  *
35
37
  * Async due to lazy loading of the `pdf-lib` peer dependency (`bun add pdf-lib`).
36
38
  *
37
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
39
+ * @param context - Optional context for correlated logging and error metadata. The
40
+ * handler `Context` is accepted directly.
38
41
  * @returns A new empty `PDFDocument` instance.
39
42
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
40
43
  * @throws {McpError} With `InternalError` if document creation fails.
@@ -61,7 +64,7 @@ export class PdfParser {
61
64
  ...logContext,
62
65
  errorDetails: error.message,
63
66
  });
64
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to create PDF document.', 'pdf_create_failed', error);
67
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to create PDF document', 'pdf_create_failed', error);
65
68
  }
66
69
  }
67
70
  /**
@@ -70,8 +73,9 @@ export class PdfParser {
70
73
  * Async due to lazy loading of the `pdf-lib` peer dependency (`bun add pdf-lib`).
71
74
  *
72
75
  * @param pdfBytes - The PDF file contents as `Uint8Array` or `ArrayBuffer`.
73
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
74
- * @param budget - Optional byte budget for the input. Defaults to 25 MiB.
76
+ * @param context - Optional context for correlated logging and error metadata. The
77
+ * handler `Context` is accepted directly.
78
+ * @param budget - Optional byte budget for the input. Unbounded when omitted.
75
79
  * @returns The loaded `PDFDocument` instance.
76
80
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
77
81
  * @throws {McpError} With `ValidationError` if the bytes are not a valid PDF.
@@ -103,7 +107,7 @@ export class PdfParser {
103
107
  ...logContext,
104
108
  errorDetails: error.message,
105
109
  });
106
- throw pdfFailure(JsonRpcErrorCode.ValidationError, 'Failed to load PDF document.', 'pdf_load_failed', error);
110
+ throw pdfFailure(JsonRpcErrorCode.ValidationError, 'Failed to load PDF document', 'pdf_load_failed', error);
107
111
  }
108
112
  }
109
113
  /**
@@ -133,7 +137,8 @@ export class PdfParser {
133
137
  *
134
138
  * @param doc - The `PDFDocument` to embed the font into.
135
139
  * @param fontName - A `StandardFonts` key. Defaults to `'Helvetica'`.
136
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
140
+ * @param context - Optional context for correlated logging and error metadata. The
141
+ * handler `Context` is accepted directly.
137
142
  * @returns The embedded `PDFFont` ready to pass to `drawText`.
138
143
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
139
144
  * @throws {McpError} With `InternalError` if the font name is invalid or embedding fails.
@@ -163,7 +168,7 @@ export class PdfParser {
163
168
  fontName,
164
169
  errorDetails: error.message,
165
170
  });
166
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to embed PDF font.', 'pdf_font_embed_failed', error);
171
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to embed PDF font', 'pdf_font_embed_failed', error);
167
172
  }
168
173
  }
169
174
  /**
@@ -174,7 +179,8 @@ export class PdfParser {
174
179
  *
175
180
  * @param doc - The `PDFDocument` to embed the image into.
176
181
  * @param options - Image bytes and format (`'png'` or `'jpg'`).
177
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
182
+ * @param context - Optional context for correlated logging and error metadata. The
183
+ * handler `Context` is accepted directly.
178
184
  * @returns The embedded `PDFImage`, usable as the `image` option in `drawImage`.
179
185
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
180
186
  * @throws {McpError} With `InternalError` if the image data is invalid or embedding fails.
@@ -209,7 +215,7 @@ export class PdfParser {
209
215
  format: options.format,
210
216
  errorDetails: error.message,
211
217
  });
212
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to embed PDF image.', 'pdf_image_embed_failed', error);
218
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to embed PDF image', 'pdf_image_embed_failed', error);
213
219
  }
214
220
  }
215
221
  /**
@@ -331,8 +337,9 @@ export class PdfParser {
331
337
  * `pdf-lib` (`bun add pdf-lib`).
332
338
  *
333
339
  * @param pdfBytesArray - Source PDF files as `Uint8Array` or `ArrayBuffer` elements.
334
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
335
- * @param budget - Optional aggregate byte budget across all inputs. Defaults to 25 MiB.
340
+ * @param context - Optional context for correlated logging and error metadata. The
341
+ * handler `Context` is accepted directly.
342
+ * @param budget - Optional aggregate byte budget across all inputs. Unbounded when omitted.
336
343
  * @returns A new `PDFDocument` containing all pages from the input documents.
337
344
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
338
345
  * @throws {McpError} With `InternalError` if any source PDF is invalid or merging fails.
@@ -377,7 +384,7 @@ export class PdfParser {
377
384
  ...logContext,
378
385
  errorDetails: error.message,
379
386
  });
380
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to merge PDF documents.', 'pdf_merge_failed', error);
387
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to merge PDF documents', 'pdf_merge_failed', error);
381
388
  }
382
389
  }
383
390
  /**
@@ -389,8 +396,9 @@ export class PdfParser {
389
396
  *
390
397
  * @param pdfBytes - The source PDF as `Uint8Array` or `ArrayBuffer`.
391
398
  * @param ranges - Page ranges to extract; each produces one output document.
392
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
393
- * @param budget - Optional byte budget for the input. Defaults to 25 MiB.
399
+ * @param context - Optional context for correlated logging and error metadata. The
400
+ * handler `Context` is accepted directly.
401
+ * @param budget - Optional byte budget for the input. Unbounded when omitted.
394
402
  * @returns An array of new `PDFDocument` instances, one per range, in order.
395
403
  * @throws {McpError} With `ConfigurationError` if `pdf-lib` is not installed.
396
404
  * @throws {McpError} With `InternalError` if the source PDF is invalid or a page index is out of bounds.
@@ -441,7 +449,7 @@ export class PdfParser {
441
449
  ...logContext,
442
450
  errorDetails: error.message,
443
451
  });
444
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to split PDF document.', 'pdf_split_failed', error);
452
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to split PDF document', 'pdf_split_failed', error);
445
453
  }
446
454
  }
447
455
  /**
@@ -454,7 +462,8 @@ export class PdfParser {
454
462
  *
455
463
  * @param doc - The `PDFDocument` containing the AcroForm.
456
464
  * @param options - Map of field names to values, plus optional `flatten` flag.
457
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
465
+ * @param context - Optional context for correlated logging and error metadata. The
466
+ * handler `Context` is accepted directly.
458
467
  * @throws {McpError} With `InternalError` if the overall form operation fails.
459
468
  * @example
460
469
  * ```typescript
@@ -524,7 +533,7 @@ export class PdfParser {
524
533
  ...logContext,
525
534
  errorDetails: error.message,
526
535
  });
527
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to fill PDF form.', 'pdf_form_fill_failed', error);
536
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to fill PDF form', 'pdf_form_fill_failed', error);
528
537
  }
529
538
  }
530
539
  /**
@@ -617,7 +626,8 @@ export class PdfParser {
617
626
  * @param input - Raw PDF bytes (`Uint8Array` | `ArrayBuffer`) or a loaded `PDFDocument`.
618
627
  * @param options - Optional extraction options. Set `mergePages: true` to get a
619
628
  * single concatenated string instead of one string per page.
620
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
629
+ * @param context - Optional context for correlated logging and error metadata. The
630
+ * handler `Context` is accepted directly.
621
631
  * @returns An `ExtractTextResult` with `totalPages` and `text` — a `string[]` (one
622
632
  * per page) by default, or a single `string` when `mergePages` is `true`.
623
633
  * @throws {McpError} With `ConfigurationError` if `unpdf` is not installed (or
@@ -657,7 +667,7 @@ export class PdfParser {
657
667
  ...logContext,
658
668
  errorDetails: error.message,
659
669
  });
660
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to extract text from PDF.', 'pdf_text_extract_failed', error);
670
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to extract text from PDF', 'pdf_text_extract_failed', error);
661
671
  }
662
672
  assertBinaryInputBudget(rawBytes, options);
663
673
  pdfBytes = rawBytes;
@@ -669,9 +679,9 @@ export class PdfParser {
669
679
  inputKind: isBytes ? 'bytes' : 'document',
670
680
  });
671
681
  const { getDocumentProxy, extractText: unpdfExtractText } = await getUnpdf();
672
- // Cap decoded images at 4096×4096 pixels (pdf.js defaults to unbounded), so a
673
- // crafted page cannot force a huge raster allocation during extraction.
674
- const pdfProxy = await getDocumentProxy(pdfBytes, { maxImageSize: 4096 * 4096 });
682
+ const pdfProxy = options?.maxImageSize === undefined
683
+ ? await getDocumentProxy(pdfBytes)
684
+ : await getDocumentProxy(pdfBytes, { maxImageSize: options.maxImageSize });
675
685
  const result = mergePages
676
686
  ? await unpdfExtractText(pdfProxy, { mergePages: true })
677
687
  : await unpdfExtractText(pdfProxy, { mergePages: false });
@@ -693,7 +703,7 @@ export class PdfParser {
693
703
  ...logContext,
694
704
  errorDetails: error.message,
695
705
  });
696
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to extract text from PDF.', 'pdf_text_extract_failed', error);
706
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to extract text from PDF', 'pdf_text_extract_failed', error);
697
707
  }
698
708
  }
699
709
  /**
@@ -703,7 +713,8 @@ export class PdfParser {
703
713
  * compatible). Does not reload peer dependencies if already cached.
704
714
  *
705
715
  * @param doc - The `PDFDocument` to serialize.
706
- * @param context - Optional `RequestContext` for correlated logging and error metadata.
716
+ * @param context - Optional context for correlated logging and error metadata. The
717
+ * handler `Context` is accepted directly.
707
718
  * @returns The complete PDF file as a `Uint8Array`.
708
719
  * @throws {McpError} With `InternalError` if serialization fails.
709
720
  * @example
@@ -733,7 +744,7 @@ export class PdfParser {
733
744
  ...logContext,
734
745
  errorDetails: error.message,
735
746
  });
736
- throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to save PDF document.', 'pdf_save_failed', error);
747
+ throw pdfFailure(JsonRpcErrorCode.InternalError, 'Failed to save PDF document', 'pdf_save_failed', error);
737
748
  }
738
749
  }
739
750
  }