velocious 1.0.700 → 1.0.701

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.
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "velocious": "build/bin/velocious.js"
4
4
  },
5
5
  "name": "velocious",
6
- "version": "1.0.700",
6
+ "version": "1.0.701",
7
7
  "main": "build/index.js",
8
8
  "types": "build/index.d.ts",
9
9
  "files": [
@@ -329,7 +329,7 @@
329
329
  * @property {string} [host] - Hostname to bind the HTTP server to.
330
330
  * @property {boolean} [inProcess] - Run HTTP handlers in the main thread instead of worker threads.
331
331
  * @property {number} [maxBufferedResponseBodyBytes] - Maximum UTF-8/binary byte length accepted by buffered response bodies. Unbounded when absent; streamed file responses are unaffected.
332
- * @property {number} [maxRequestBodyBytes] - Maximum decoded request-body bytes accepted before routing. Unbounded when absent.
332
+ * @property {number} [maxRequestBodyBytes] - Maximum decoded request-body bytes accepted before routing. Unbounded when absent, except the built-in MCP endpoint, which defaults to a 1 MiB cap that this option overrides.
333
333
  * @property {HttpRequestBodyPolicyResolver} [requestBodyPolicyResolver] - Optional synchronous header-stage resolver for per-request limits and raw-body handling.
334
334
  * @property {number} [maxWorkers] - Backward-compatible alias for workers.
335
335
  * @property {number} [port] - Port to bind the HTTP server to.
@@ -229,6 +229,14 @@ function normalizeHttpCompression(value) {
229
229
  }
230
230
  }
231
231
 
232
+ /**
233
+ * Default request-body limit for the built-in MCP endpoint. JSON-RPC messages are small,
234
+ * so the framework caps them instead of making every app that enables `mcp: true` restate
235
+ * a request-body policy. Explicit `httpServer.maxRequestBodyBytes` or a resolver limit wins.
236
+ * @type {number}
237
+ */
238
+ const DEFAULT_MCP_MAX_REQUEST_BODY_BYTES = 1024 * 1024
239
+
232
240
  export default class VelociousConfiguration {
233
241
  /**
234
242
  * Close database connections promise.
@@ -776,31 +784,58 @@ export default class VelociousConfiguration {
776
784
  resolveHttpRequestBodyPolicy(args) {
777
785
  const resolver = this.httpServer.requestBodyPolicyResolver
778
786
  const configuredPolicy = resolver ? resolver(args) : undefined
787
+ /** @type {import("./configuration-types.js").ResolvedHttpRequestBodyPolicy} */
788
+ let resolvedPolicy
779
789
 
780
790
  if (configuredPolicy === undefined) {
781
- return {maxRequestBodyBytes: this.httpServer.maxRequestBodyBytes, mode: "parsed"}
782
- }
791
+ resolvedPolicy = {maxRequestBodyBytes: this.httpServer.maxRequestBodyBytes, mode: "parsed"}
792
+ } else {
793
+ if (!configuredPolicy || typeof configuredPolicy !== "object" || Array.isArray(configuredPolicy)) {
794
+ throw new TypeError("httpServer.requestBodyPolicyResolver must return an object or undefined")
795
+ }
783
796
 
784
- if (!configuredPolicy || typeof configuredPolicy !== "object" || Array.isArray(configuredPolicy)) {
785
- throw new TypeError("httpServer.requestBodyPolicyResolver must return an object or undefined")
786
- }
797
+ const {maxRequestBodyBytes, mode = "parsed", ...restPolicy} = configuredPolicy
798
+ const unknownKeys = Object.keys(restPolicy)
787
799
 
788
- const {maxRequestBodyBytes, mode = "parsed", ...restPolicy} = configuredPolicy
789
- const unknownKeys = Object.keys(restPolicy)
800
+ if (unknownKeys.length > 0) {
801
+ throw new TypeError(`httpServer.requestBodyPolicyResolver returned unknown keys: ${unknownKeys.join(", ")} (supported: maxRequestBodyBytes, mode)`)
802
+ }
803
+ if (mode !== "parsed" && mode !== "raw") {
804
+ throw new TypeError(`httpServer.requestBodyPolicyResolver mode must be "parsed" or "raw", got: ${String(mode)}`)
805
+ }
790
806
 
791
- if (unknownKeys.length > 0) {
792
- throw new TypeError(`httpServer.requestBodyPolicyResolver returned unknown keys: ${unknownKeys.join(", ")} (supported: maxRequestBodyBytes, mode)`)
793
- }
794
- if (mode !== "parsed" && mode !== "raw") {
795
- throw new TypeError(`httpServer.requestBodyPolicyResolver mode must be "parsed" or "raw", got: ${String(mode)}`)
807
+ resolvedPolicy = {
808
+ maxRequestBodyBytes: maxRequestBodyBytes === undefined
809
+ ? this.httpServer.maxRequestBodyBytes
810
+ : optionalPositiveSafeInteger(maxRequestBodyBytes, "httpServer.requestBodyPolicyResolver maxRequestBodyBytes"),
811
+ mode
812
+ }
796
813
  }
797
814
 
798
- return {
799
- maxRequestBodyBytes: maxRequestBodyBytes === undefined
800
- ? this.httpServer.maxRequestBodyBytes
801
- : optionalPositiveSafeInteger(maxRequestBodyBytes, "httpServer.requestBodyPolicyResolver maxRequestBodyBytes"),
802
- mode
815
+ return this._applyMcpRequestBodyPolicyDefaults({args, policy: resolvedPolicy})
816
+ }
817
+
818
+ /**
819
+ * Enforces the built-in MCP endpoint's body contract without per-app plumbing: the
820
+ * JSON-RPC envelope is read from parsed params, so raw mode is rejected with an
821
+ * actionable error, and a framework default byte cap applies when the app configured none.
822
+ * @param {{args: import("./configuration-types.js").HttpRequestBodyPolicyResolverArgs, policy: import("./configuration-types.js").ResolvedHttpRequestBodyPolicy}} options - Resolution inputs.
823
+ * @returns {import("./configuration-types.js").ResolvedHttpRequestBodyPolicy} - Effective request policy.
824
+ */
825
+ _applyMcpRequestBodyPolicyDefaults({args, policy}) {
826
+ if (!this._mcp.enabled) return policy
827
+ if (args.httpMethod !== "POST") return policy
828
+ if (args.path.split("?")[0] !== this._mcp.path) return policy
829
+
830
+ if (policy.mode === "raw") {
831
+ throw new TypeError(
832
+ `The built-in MCP endpoint at ${this._mcp.path} requires parsed request bodies because its JSON-RPC envelope is read from params. Remove the raw-mode httpServer.requestBodyPolicyResolver entry for this path.`
833
+ )
803
834
  }
835
+
836
+ if (policy.maxRequestBodyBytes !== undefined) return policy
837
+
838
+ return {maxRequestBodyBytes: DEFAULT_MCP_MAX_REQUEST_BODY_BYTES, mode: policy.mode}
804
839
  }
805
840
 
806
841
  /**