Fix 'stream is not readable' error in SSE message handler

- Replace getRawBody with direct req.body usage since express.json() middleware already parses it
- Add debugging support with --inspect flag for dev scripts
- Add VS Code launch configurations for debugging

The issue was that getRawBody tried to read an already-consumed stream. Since express.json()
middleware is applied globally, we can directly use req.body instead.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
Jerome 2025-07-15 13:41:34 +01:00
commit 927d34c0d1
No known key found for this signature in database

View file

@ -2,14 +2,11 @@ import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
import contentType from "content-type";
import { Request, Response } from "express";
import getRawBody from "raw-body";
import { redisClient } from "../redis.js";
import { createMcpServer } from "../services/mcp.js";
import { logMcpMessage } from "./common.js";
import { logger } from "../utils/logger.js";
const MAXIMUM_MESSAGE_SIZE = "4mb";
declare module "express-serve-static-core" {
interface Request {
/**
@ -90,10 +87,7 @@ export async function handleMessage(req: Request, res: Response) {
throw new Error(`Unsupported content-type: ${ct}`);
}
body = await getRawBody(req, {
limit: MAXIMUM_MESSAGE_SIZE,
encoding: ct.parameters.charset ?? "utf-8",
});
body = JSON.stringify(req.body);
} catch (error) {
res.status(400).json(error);
logger.error('Bad POST request', error as Error, {