MCPcopy Index your code
hub / github.com/simstudioai/sim / validateRequestBodySize

Function validateRequestBodySize

apps/sim/tools/index.ts:698–717  ·  view source on GitHub ↗

* Validates request body size and throws a user-friendly error if exceeded * @param body - The request body string to check * @param requestId - Request ID for logging * @param context - Context string for logging (e.g., toolId) * @throws Error if body size exceeds the limit

(
  body: string | undefined,
  requestId: string,
  context: string
)

Source from the content-addressed store, hash-verified

696 * @throws Error if body size exceeds the limit
697 */
698function validateRequestBodySize(
699 body: string | undefined,
700 requestId: string,
701 context: string
702): void {
703 if (!body) return
704
705 const bodySize = Buffer.byteLength(body, 'utf8')
706 if (bodySize > MAX_REQUEST_BODY_SIZE_BYTES) {
707 const bodySizeMB = (bodySize / (1024 * 1024)).toFixed(2)
708 const maxSizeMB = (MAX_REQUEST_BODY_SIZE_BYTES / (1024 * 1024)).toFixed(0)
709 logger.error(`[${requestId}] Request body size exceeds limit for ${context}:`, {
710 bodySize,
711 bodySizeMB: `${bodySizeMB}MB`,
712 maxSize: MAX_REQUEST_BODY_SIZE_BYTES,
713 maxSizeMB: `${maxSizeMB}MB`,
714 })
715 throw new Error(BODY_SIZE_LIMIT_ERROR_MESSAGE)
716 }
717}
718
719/**
720 * Checks if an error message indicates a body size limit issue

Callers 2

executeToolRequestFunction · 0.85
executeMcpToolFunction · 0.85

Calls 1

errorMethod · 0.80

Tested by

no test coverage detected