Skip to content

Commit 43bef9a

Browse files
corvid-agentclaude
andcommitted
feat(express): add jsonBodyLimit option to createMcpExpressApp
Allow configuring the maximum request body size for the JSON body parser via a new `jsonBodyLimit` option. This is needed when MCP payloads exceed Express's default 100kb limit. Closes modelcontextprotocol#1354 Co-Authored-By: Claude Opus 4.6 <[email protected]>
1 parent 65bbcea commit 43bef9a

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

‎packages/middleware/express/src/express.ts‎

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ export interface CreateMcpExpressAppOptions {
2222
* to restrict which hostnames are allowed.
2323
*/
2424
allowedHosts?: string[];
25+
26+
/**
27+
* Controls the maximum request body size for the JSON body parser.
28+
* Accepts a number (bytes) or a string (e.g., '1mb', '500kb').
29+
* Defaults to Express's built-in default of '100kb' if not specified.
30+
*/
31+
jsonBodyLimit?: string | number;
2532
}
2633

2734
/**
@@ -48,10 +55,10 @@ export interface CreateMcpExpressAppOptions {
4855
* ```
4956
*/
5057
export function createMcpExpressApp(options: CreateMcpExpressAppOptions = {}): Express {
51-
const { host = '127.0.0.1', allowedHosts } = options;
58+
const { host = '127.0.0.1', allowedHosts, jsonBodyLimit } = options;
5259

5360
const app = express();
54-
app.use(express.json());
61+
app.use(express.json(jsonBodyLimit !== undefined ? { limit: jsonBodyLimit } : {}));
5562

5663
// If allowedHosts is explicitly provided, use that for validation
5764
if (allowedHosts) {

0 commit comments

Comments
 (0)