RocketChat/Rocket.Chat · error · Error
MCP tool response exceeds the 5 MiB limit
Error message
MCP tool response exceeds the 5 MiB limit
What it means
Fast-fail guard in readResponseText: before reading the body of the loopback REST response for an MCP tool call, it parses the content-length header and throws when the declared size already exceeds MAX_TOOL_RESPONSE_BYTES (5 MiB). The oversized single-tool response is rejected without transferring its body.
Source
Thrown at apps/meteor/ee/server/api/mcp/dispatch.ts:39
export const createMcpResponseBudget = (maxBytes = MAX_TOOL_RESPONSE_BYTES): McpResponseBudget => {
let remainingBytes = maxBytes;
const formattedLimit = formatByteLimit(maxBytes);
return {
consume(bytes) {
if (bytes > remainingBytes) {
throw new Error(`MCP batch response exceeds the ${formattedLimit} limit`);
}
remainingBytes -= bytes;
},
};
};
const readResponseText = async (response: Response, responseBudget?: McpResponseBudget): Promise<string> => {
const contentLength = Number(response.headers.get('content-length'));
if (Number.isFinite(contentLength) && contentLength > MAX_TOOL_RESPONSE_BYTES) {
throw new Error('MCP tool response exceeds the 5 MiB limit');
}
if (!response.body) {
return '';
}
const reader = response.body.getReader();
const decoder = new TextDecoder();
const chunks: string[] = [];
let receivedBytes = 0;
while (true) {
const { done, value } = await reader.read();
if (done) {
break;
}
receivedBytes += value.byteLength;View on GitHub (pinned to b2c16d5842)
Solutions
- Call the tool with stricter pagination args (count/offset) so the response stays under 5 MiB
- Use a narrower filter or a tool that returns summaries instead of full objects
- Return a reference (file URL, export job id) instead of inline bulk data
Example fix
// before
const result = await callTool('channels_list', {}); // full dataset, content-length > 5 MiB
// after
const result = await callTool('channels_list', { count: 100, offset: 0 }); Defensive patterns
Strategy: validation
Validate before calling
const response = await fetch(url);
const contentLength = Number(response.headers.get('content-length'));
if (Number.isFinite(contentLength) && contentLength > 5 * 1024 * 1024) {
throw new Error('tool response would exceed 5 MiB - narrow the query (count/offset)');
}
const text = await response.text(); Try / catch
try {
return await callTool(name, args);
} catch (error) {
if (error instanceof Error && error.message.includes('MCP tool response exceeds the 5 MiB limit')) {
return callTool(name, { ...args, count: Math.min(args.count ?? 100, 100) });
}
throw error;
} Prevention
- Always send pagination params when calling list-type tools
- Test MCP tools against a heavily populated workspace before shipping
- Map only paginated REST endpoints to MCP tools
When it happens
Trigger: dispatchTool fetches the REST endpoint behind an MCP tool and that endpoint declares content-length greater than 5,242,880 bytes (e.g. a list endpoint returning thousands of records because no count was passed).
Common situations: Tools mapped to export/list endpoints that ignore pagination params; test workspaces seeded with large datasets queried without a count; tool args not forwarded to the REST query.
Understand the failure class
Background: payload too large / request exceeds maximum size: why libraries cap bytes and how to fix oversize payloads — this error's family across 50 libraries.
Related errors
- MCP batch response exceeds the ${formattedLimit} limit
- FileUpload_Error
- Integration payload must be a JSON object, not an array or p
- could-not-access-webdav
- Failed to complete OAuth handshake with ${this.name} at ${th
AI-assisted analysis of RocketChat/Rocket.Chat@b2c16d5842 (2026-08-18).
Data as JSON: /api/errors/448ced457321469c.
Report an issue: GitHub.