paperclipai/paperclip · warning · Error
Request body too large.
Error message
Request body too large.
What it means
Identical guard to the google-sheets server: readJsonBody in the kv-demo MCP HTTP layer caps total streamed body at 1,000,000 bytes and throws mid-stream. The kv-demo store API is small but the same cap applies to MCP requests and to bulk set operations.
Source
Thrown at packages/kv-demo-mcp-server/src/http.ts:52
"content-type": "text/html; charset=utf-8",
"content-length": Buffer.byteLength(html),
});
res.end(html);
}
function presentedToken(req: IncomingMessage): string | null {
const header = req.headers.authorization;
if (header && header.startsWith("Bearer ")) return header.slice("Bearer ".length).trim();
return null;
}
async function readJsonBody(req: IncomingMessage): Promise<unknown> {
const chunks: Buffer[] = [];
let size = 0;
for await (const chunk of req) {
const buffer = chunk as Buffer;
size += buffer.length;
if (size > 1_000_000) throw new Error("Request body too large.");
chunks.push(buffer);
}
if (chunks.length === 0) return undefined;
const raw = Buffer.concat(chunks).toString("utf8").trim();
if (!raw) return undefined;
return JSON.parse(raw);
}
async function handleMcp(
req: IncomingMessage,
res: ServerResponse,
store: KvStore,
): Promise<void> {
// Stateless: a fresh MCP server + transport per request. The shared store is
// what carries state between calls, so no session bookkeeping is needed.
let parsedBody: unknown;
try {
parsedBody = req.method === "POST" ? await readJsonBody(req) : undefined;View on GitHub (pinned to 67001ec6eb)
Solutions
- Store the large value out-of-band and keep only a reference in the KV store.
- Chunk the value across multiple keys.
- If genuinely needed, fork and raise the 1_000_000 literal.
Example fix
// before
await set('big', hugeJsonString) // > 1MiB -> error
// after
await set('big.ref', uploadLargeBlobElsewhere(hugeJsonString)) Defensive patterns
Strategy: validation
Validate before calling
function under1MiB(payload: unknown): boolean {
return Buffer.byteLength(JSON.stringify(payload), 'utf8') <= 1_000_000;
} Prevention
- Keep KV values small — store large blobs externally and keep references.
- Estimate body size client-side before POSTing to /api/state.
- Treat the 1 MiB cap as a fixed contract.
When it happens
Trigger: Any request to the kv-demo HTTP endpoint whose body exceeds 1 MiB — typically a POST /api/state with a very large value, a bulk set, or an MCP tools/call with oversized arguments.
Common situations: Storing a large blob (image base64, big JSON document) as a single KV value; a client retrying with an ever-growing payload.
Related errors
- Request body too large.
- HTTP ${status}
- API error ${response.status}: ${message}
- Request failed with status ${response.status}
- API error ${response.status}: ${bytes.toString("utf8")}
AI-assisted analysis of paperclipai/paperclip@67001ec6eb (2026-08-12).
Data as JSON: /api/errors/1822c458e32f843c.
Report an issue: GitHub.