Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 | 23x 23x 122x 122x 27x 27x 6x 6x 21x | import express, { type RequestHandler } from 'express';
/** Parse admitted MCP messages once and report size errors in the JSON-RPC envelope. */
export function mcpJsonBodyParser(limit: number): RequestHandler {
const parse = express.json({ limit });
return (req, res, next) => {
parse(req, res, (error: unknown) => {
if (
error &&
typeof error === 'object' &&
'type' in error &&
error.type === 'entity.too.large'
) {
res.status(413).json({
jsonrpc: '2.0',
id: null,
error: {
code: -32600,
message: `JSON request exceeds ${limit} bytes; configure MCP_REQUEST_BODY_LIMIT to raise the limit.`,
},
});
return;
}
next(error);
});
};
}
|