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

Function readMcpJsonBodyWithLimit

apps/sim/lib/mcp/middleware.ts:57–87  ·  view source on GitHub ↗
(request: NextRequest)

Source from the content-addressed store, hash-verified

55}
56
57export async function readMcpJsonBodyWithLimit(request: NextRequest): Promise<unknown> {
58 const cached = parsedBodies.get(request)
59 if (cached !== undefined) return cached
60
61 try {
62 assertContentLengthWithinLimit(
63 request.headers,
64 MAX_MCP_MANAGEMENT_BODY_BYTES,
65 'MCP management request body'
66 )
67 const buffer = await readStreamToBufferWithLimit(request.body, {
68 maxBytes: MAX_MCP_MANAGEMENT_BODY_BYTES,
69 label: 'MCP management request body',
70 signal: request.signal,
71 })
72 const body = buffer.byteLength > 0 ? JSON.parse(buffer.toString('utf-8')) : {}
73 parsedBodies.set(request, body)
74 return body
75 } catch (error) {
76 if (request.signal.aborted) {
77 throw new McpBodyReadError('aborted', error)
78 }
79 if (isPayloadSizeLimitError(error)) {
80 throw new McpBodyReadError('payload_too_large', error)
81 }
82 if (error instanceof SyntaxError) {
83 throw new McpBodyReadError('invalid_json', error)
84 }
85 throw error
86 }
87}
88
89export function mcpBodyReadErrorResponse(
90 error: unknown,

Callers 10

route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
route.tsFile · 0.90
validateMcpAuthFunction · 0.85

Calls 7

isPayloadSizeLimitErrorFunction · 0.90
parseMethod · 0.80
getMethod · 0.65
setMethod · 0.65
toStringMethod · 0.45

Tested by

no test coverage detected