Skip to content

Commit 1fe9eda

Browse files
rameshreddy-adutlaCopilotKKonstantinov
authored
Add jsonLimit option to createMcpExpressApp (#1625)
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Co-authored-by: Konstantin Konstantinov <KKonstantinov@users.noreply.github.com>
1 parent 5a2c8a6 commit 1fe9eda

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

.changeset/twelve-dodos-taste.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@modelcontextprotocol/express": patch
3+
---
4+
5+
Add jsonLimit option to createMcpExpressApp

packages/middleware/express/src/express.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,15 @@ 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+
* Passed directly to Express's `express.json({ limit })` option.
29+
* Defaults to Express's built-in default of `'100kb'`.
30+
*
31+
* @example '1mb', '500kb', '10mb'
32+
*/
33+
jsonLimit?: string;
2534
}
2635

2736
/**
@@ -51,10 +60,10 @@ export interface CreateMcpExpressAppOptions {
5160
* ```
5261
*/
5362
export function createMcpExpressApp(options: CreateMcpExpressAppOptions = {}): Express {
54-
const { host = '127.0.0.1', allowedHosts } = options;
63+
const { host = '127.0.0.1', allowedHosts, jsonLimit } = options;
5564

5665
const app = express();
57-
app.use(express.json());
66+
app.use(express.json(jsonLimit ? { limit: jsonLimit } : undefined));
5867

5968
// If allowedHosts is explicitly provided, use that for validation
6069
if (allowedHosts) {

packages/middleware/express/test/express.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,15 @@ describe('@modelcontextprotocol/express', () => {
178178

179179
warn.mockRestore();
180180
});
181+
182+
test('should accept jsonLimit option', () => {
183+
const app = createMcpExpressApp({ jsonLimit: '10mb' });
184+
expect(app).toBeDefined();
185+
});
186+
187+
test('should work without jsonLimit option', () => {
188+
const app = createMcpExpressApp();
189+
expect(app).toBeDefined();
190+
});
181191
});
182192
});

0 commit comments

Comments
 (0)