This is the documentation for v2 — looking for the v1 documentation?
Skip to content

MCP TypeScript SDK (V2) / @modelcontextprotocol/server / server/requestBody

server/requestBody

Variables

DEFAULT_MAX_REQUEST_BODY_SIZE

const DEFAULT_MAX_REQUEST_BODY_SIZE: number

Defined in: packages/server/src/server/requestBody.ts:2

Default upper bound, in bytes, on a request body read by the HTTP entry points (4 MiB).


MAX_BATCH_SIZE

const MAX_BATCH_SIZE: 100 = 100

Defined in: packages/server/src/server/requestBody.ts:5

Upper bound on the number of messages accepted in one JSON-RPC batch array.

Functions

readRequestBody()

readRequestBody(request, maxBytes?): Promise<{ tooLarge: true; } | { text: string; tooLarge: false; }>

Defined in: packages/server/src/server/requestBody.ts:33

Reads a request body as text, up to maxBytes (default DEFAULT_MAX_REQUEST_BODY_SIZE). A declared Content-Length over the limit is refused without reading anything; otherwise the read stops as soon as more than the limit has arrived. Stream failures propagate.

Parameters

request

Request

maxBytes?

number = DEFAULT_MAX_REQUEST_BODY_SIZE

Returns

Promise<{ tooLarge: true; } | { text: string; tooLarge: false; }>


requestBodyTooLargeMessage()

requestBodyTooLargeMessage(maxBytes): string

Defined in: packages/server/src/server/requestBody.ts:8

The message answered with 413 for a request body over maxBytes.

Parameters

maxBytes

number

Returns

string


resolveMaxRequestBodySize()

resolveMaxRequestBodySize(value): number

Defined in: packages/server/src/server/requestBody.ts:17

Resolves a maxRequestBodySize option to the bound to apply: the default when omitted, otherwise the value itself, which must be a positive finite number of bytes (a RangeError is thrown at configuration time for anything else).

Parameters

value

number | undefined

Returns

number