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>
This commit is contained in:
Ramesh Reddy Adutla 2026-03-05 06:57:40 +00:00 • committed by GitHub
commit 1fe9eda4a7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 26 additions and 2 deletions

View file

@ -0,0 +1,5 @@
---
"@modelcontextprotocol/express": patch
---
Add jsonLimit option to createMcpExpressApp

View file

@ -22,6 +22,15 @@ export interface CreateMcpExpressAppOptions {
* to restrict which hostnames are allowed.
*/
allowedHosts?: string[];
/**
* Controls the maximum request body size for the JSON body parser.
* Passed directly to Express's `express.json({ limit })` option.
* Defaults to Express's built-in default of `'100kb'`.
*
* @example '1mb', '500kb', '10mb'
*/
jsonLimit?: string;
}
/**
@ -51,10 +60,10 @@ export interface CreateMcpExpressAppOptions {
* ```
*/
export function createMcpExpressApp(options: CreateMcpExpressAppOptions = {}): Express {
const { host = '127.0.0.1', allowedHosts } = options;
const { host = '127.0.0.1', allowedHosts, jsonLimit } = options;
const app = express();
app.use(express.json());
app.use(express.json(jsonLimit ? { limit: jsonLimit } : undefined));
// If allowedHosts is explicitly provided, use that for validation
if (allowedHosts) {

View file

@ -178,5 +178,15 @@ describe('@modelcontextprotocol/express', () => {
warn.mockRestore();
});
test('should accept jsonLimit option', () => {
const app = createMcpExpressApp({ jsonLimit: '10mb' });
expect(app).toBeDefined();
});
test('should work without jsonLimit option', () => {
const app = createMcpExpressApp();
expect(app).toBeDefined();
});
});
});