File tree Expand file tree Collapse file tree 2 files changed +21
-2
lines changed
packages/middleware/express Expand file tree Collapse file tree 2 files changed +21
-2
lines changed Original file line number Diff line number Diff 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.json({ limit })`.
29+ * Defaults to Express's built-in default of '100kb' when not specified.
30+ *
31+ * @example '10mb'
32+ */
33+ limit ?: string | number ;
2534}
2635
2736/**
@@ -48,10 +57,10 @@ export interface CreateMcpExpressAppOptions {
4857 * ```
4958 */
5059export function createMcpExpressApp ( options : CreateMcpExpressAppOptions = { } ) : Express {
51- const { host = '127.0.0.1' , allowedHosts } = options ;
60+ const { host = '127.0.0.1' , allowedHosts, limit } = options ;
5261
5362 const app = express ( ) ;
54- app . use ( express . json ( ) ) ;
63+ app . use ( express . json ( limit !== undefined ? { limit } : undefined ) ) ;
5564
5665 // If allowedHosts is explicitly provided, use that for validation
5766 if ( allowedHosts ) {
Original file line number Diff line number Diff line change @@ -167,6 +167,16 @@ describe('@modelcontextprotocol/express', () => {
167167 warn . mockRestore ( ) ;
168168 } ) ;
169169
170+ test ( 'should accept limit option for JSON body parser' , ( ) => {
171+ const app = createMcpExpressApp ( { limit : '10mb' } ) ;
172+ expect ( app ) . toBeDefined ( ) ;
173+ } ) ;
174+
175+ test ( 'should accept numeric limit option for JSON body parser' , ( ) => {
176+ const app = createMcpExpressApp ( { limit : 1048576 } ) ;
177+ expect ( app ) . toBeDefined ( ) ;
178+ } ) ;
179+
170180 test ( 'should not apply host validation for non-localhost hosts without allowedHosts' , ( ) => {
171181 const warn = vi . spyOn ( console , 'warn' ) . mockImplementation ( ( ) => { } ) ;
172182
You can’t perform that action at this time.
0 commit comments