Skip to content

Commit 927d34c

Browse files
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 <[email protected]>
1 parent 2f1aa9c commit 927d34c

File tree

3 files changed

+19
-71
lines changed

3 files changed

+19
-71
lines changed

.vscode/launch.json

Lines changed: 16 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -2,78 +2,31 @@
22
"version": "0.2.0",
33
"configurations": [
44
{
5-
"name": "Debug MCP Server (tsx watch)",
65
"type": "node",
7-
"request": "launch",
8-
"program": "${workspaceFolder}/node_modules/.bin/tsx",
9-
"args": ["watch", "src/index.ts"],
10-
"console": "integratedTerminal",
6+
"request": "attach",
7+
"name": "Attach to Dev Server",
8+
"port": 9229,
119
"restart": true,
1210
"skipFiles": ["<node_internals>/**"],
13-
"env": {
14-
"NODE_ENV": "development"
15-
}
11+
"sourceMaps": true,
12+
"resolveSourceMapLocations": [
13+
"${workspaceFolder}/**",
14+
"!**/node_modules/**"
15+
]
1616
},
1717
{
18-
"name": "Debug Jest Tests",
1918
"type": "node",
2019
"request": "launch",
21-
"runtimeArgs": [
22-
"--experimental-vm-modules",
23-
"--inspect-brk",
24-
"${workspaceFolder}/node_modules/.bin/jest",
25-
"--runInBand"
26-
],
27-
"console": "integratedTerminal",
28-
"internalConsoleOptions": "neverOpen",
20+
"name": "Debug Dev Server",
21+
"runtimeExecutable": "npm",
22+
"runtimeArgs": ["run", "dev"],
2923
"skipFiles": ["<node_internals>/**"],
30-
"env": {
31-
"NODE_OPTIONS": "--experimental-vm-modules"
32-
}
33-
},
34-
{
35-
"name": "Debug Current Jest Test File",
36-
"type": "node",
37-
"request": "launch",
38-
"runtimeArgs": [
39-
"--experimental-vm-modules",
40-
"--inspect-brk",
41-
"${workspaceFolder}/node_modules/.bin/jest",
42-
"--runInBand",
43-
"${relativeFile}"
24+
"sourceMaps": true,
25+
"resolveSourceMapLocations": [
26+
"${workspaceFolder}/**",
27+
"!**/node_modules/**"
4428
],
45-
"console": "integratedTerminal",
46-
"internalConsoleOptions": "neverOpen",
47-
"skipFiles": ["<node_internals>/**"],
48-
"env": {
49-
"NODE_OPTIONS": "--experimental-vm-modules"
50-
}
51-
},
52-
{
53-
"name": "Debug Jest Test by Pattern",
54-
"type": "node",
55-
"request": "launch",
56-
"runtimeArgs": [
57-
"--experimental-vm-modules",
58-
"--inspect-brk",
59-
"${workspaceFolder}/node_modules/.bin/jest",
60-
"--runInBand",
61-
"--testNamePattern",
62-
"${input:testNamePattern}"
63-
],
64-
"console": "integratedTerminal",
65-
"internalConsoleOptions": "neverOpen",
66-
"skipFiles": ["<node_internals>/**"],
67-
"env": {
68-
"NODE_OPTIONS": "--experimental-vm-modules"
69-
}
70-
}
71-
],
72-
"inputs": [
73-
{
74-
"id": "testNamePattern",
75-
"type": "promptString",
76-
"description": "Test name pattern to match (e.g., 'should trigger onsessionclosed')"
29+
"console": "integratedTerminal"
7730
}
7831
]
7932
}

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66
"main": "dist/index.js",
77
"scripts": {
88
"start": "node dist/index.js",
9-
"dev": "tsx watch src/index.ts",
9+
"dev": "tsx watch --inspect src/index.ts",
10+
"dev:break": "tsx --inspect-brk watch src/index.ts",
1011
"build": "tsc && npm run copy-static",
1112
"copy-static": "mkdir -p dist/static && cp -r src/static/* dist/static/",
1213
"lint": "eslint src/",

src/handlers/sse.ts

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,11 @@ import { AuthInfo } from "@modelcontextprotocol/sdk/server/auth/types.js";
22
import { SSEServerTransport } from "@modelcontextprotocol/sdk/server/sse.js";
33
import contentType from "content-type";
44
import { Request, Response } from "express";
5-
import getRawBody from "raw-body";
65
import { redisClient } from "../redis.js";
76
import { createMcpServer } from "../services/mcp.js";
87
import { logMcpMessage } from "./common.js";
98
import { logger } from "../utils/logger.js";
109

11-
const MAXIMUM_MESSAGE_SIZE = "4mb";
12-
1310
declare module "express-serve-static-core" {
1411
interface Request {
1512
/**
@@ -90,10 +87,7 @@ export async function handleMessage(req: Request, res: Response) {
9087
throw new Error(`Unsupported content-type: ${ct}`);
9188
}
9289

93-
body = await getRawBody(req, {
94-
limit: MAXIMUM_MESSAGE_SIZE,
95-
encoding: ct.parameters.charset ?? "utf-8",
96-
});
90+
body = JSON.stringify(req.body);
9791
} catch (error) {
9892
res.status(400).json(error);
9993
logger.error('Bad POST request', error as Error, {

0 commit comments

Comments
 (0)