Skip to content

Commit 0e2693c

Browse files
committed
fix: patch json body parser limit
* opened issue modelcontextprotocol/typescript-sdk#1354
1 parent 25b5c18 commit 0e2693c

3 files changed

Lines changed: 38 additions & 3 deletions

File tree

‎package.json‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
"type": "module",
77
"scripts": {
88
"build": "tsc",
9+
"postinstall": "patch-package",
910
"watch": "tsc -w",
1011
"start": "node dist/index.js",
1112
"inspector": "npx @modelcontextprotocol/inspector"
@@ -20,6 +21,7 @@
2021
"@modelcontextprotocol/sdk": "^1.25.1",
2122
"@toon-format/toon": "^2.1.0",
2223
"express": "^5.2.1",
24+
"patch-package": "^8.0.1",
2325
"zod": "^4.2.1"
2426
},
2527
"devDependencies": {
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
diff --git a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts b/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts
2+
index 7746e82..824b80f 100644
3+
--- a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts
4+
+++ b/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.d.ts
5+
@@ -17,6 +17,8 @@ export interface CreateMcpExpressAppOptions {
6+
* to restrict which hostnames are allowed.
7+
*/
8+
allowedHosts?: string[];
9+
+ /** Controls the maximum request body size. */
10+
+ limit?: string;
11+
}
12+
/**
13+
* Creates an Express application pre-configured for MCP servers.
14+
diff --git a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js b/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js
15+
index a23a57b..0ad4703 100644
16+
--- a/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js
17+
+++ b/node_modules/@modelcontextprotocol/sdk/dist/esm/server/express.js
18+
@@ -24,9 +24,9 @@ import { hostHeaderValidation, localhostHostValidation } from './middleware/host
19+
* ```
20+
*/
21+
export function createMcpExpressApp(options = {}) {
22+
- const { host = '127.0.0.1', allowedHosts } = options;
23+
+ const { host = '127.0.0.1', allowedHosts, limit } = options;
24+
const app = express();
25+
- app.use(express.json());
26+
+ limit ? app.use(express.json({ limit })) : app.use(express.json());
27+
// If allowedHosts is explicitly provided, use that for validation
28+
if (allowedHosts) {
29+
app.use(hostHeaderValidation(allowedHosts));

‎src/streamableHttp/server.ts‎

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,13 @@ import { createMcpExpressApp } from '@modelcontextprotocol/sdk/server/express.js
88
const __dirname = dirname(fileURLToPath(import.meta.url));
99
const port = env.PORT || 3000;
1010

11-
/* Express app with DNS rebinding protection */
12-
const app = createMcpExpressApp();
13-
app.use(express.json({ limit: '10mb' }));
11+
/**
12+
* Express app with DNS rebinding protection
13+
* [TODO] monitor the issue I opened
14+
* https://github.com/modelcontextprotocol/typescript-sdk/issues/1354
15+
* to patch the json bodyparser limit
16+
*/
17+
const app = createMcpExpressApp({ limit: '10mb' });
1418
app.use(express.static('public'));
1519

1620
app.get('/health', (_req, res) =>

0 commit comments

Comments
 (0)