diff --git a/.changeset/twelve-dodos-taste.md b/.changeset/twelve-dodos-taste.md new file mode 100644 index 000000000..1b0fdc19d --- /dev/null +++ b/.changeset/twelve-dodos-taste.md @@ -0,0 +1,5 @@ +--- +"@modelcontextprotocol/express": patch +--- + +Add jsonLimit option to createMcpExpressApp diff --git a/packages/middleware/express/src/express.ts b/packages/middleware/express/src/express.ts index af156a229..252502952 100644 --- a/packages/middleware/express/src/express.ts +++ b/packages/middleware/express/src/express.ts @@ -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) { diff --git a/packages/middleware/express/test/express.test.ts b/packages/middleware/express/test/express.test.ts index 64cf533bc..f4be9f998 100644 --- a/packages/middleware/express/test/express.test.ts +++ b/packages/middleware/express/test/express.test.ts @@ -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(); + }); }); });