Skip to content

Commit 970682b

Browse files
committed
Added option for json payload size
1 parent b6f900d commit 970682b

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

mcp-openapi/README.md

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -510,11 +510,33 @@ The MCP server provides authentication-aware error handling with structured resp
510510

511511
### Security Features
512512

513+
- **Request Size Limiting**: Configurable JSON payload size limits prevent DoS attacks (default: 2MB)
513514
- **Security Event Logging**: 401/403 errors are logged with `[SECURITY]` prefix for monitoring
514515
- **Error Context Preservation**: Backend API error responses are included in `details`
515516
- **Privacy Protection**: Query parameters are stripped from URLs in error messages
516517
- **Structured Responses**: All errors return JSON with consistent format instead of throwing exceptions
517518

519+
#### Request Size Configuration
520+
521+
The server automatically limits JSON request body sizes to prevent denial-of-service attacks and memory exhaustion:
522+
523+
```bash
524+
# Use default 2MB limit
525+
mcp-openapi-server --http
526+
527+
# Set custom limit
528+
mcp-openapi-server --http --max-request-size 5mb
529+
530+
# Other valid formats
531+
mcp-openapi-server --max-request-size 1024kb
532+
mcp-openapi-server --max-request-size 512kb
533+
```
534+
535+
**Recommended limits for banking APIs:**
536+
- **Conservative**: `1mb` - Handles most banking operations with safety margin
537+
- **Standard**: `2mb` (default) - Balances security and functionality
538+
- **Liberal**: `5mb` - For batch operations or document attachments
539+
518540
## OpenAPI Specification Setup
519541

520542
### Custom Spec IDs
@@ -643,6 +665,7 @@ interface ServerOptions {
643665
verbose?: boolean; // Enable verbose logging
644666
baseUrl?: string; // Base URL for backend APIs (overrides config file)
645667
maxToolNameLength?: number; // Maximum length for generated tool names (default: 48)
668+
maxRequestSize?: string; // Maximum size for JSON request bodies (default: "2mb")
646669
}
647670
```
648671

@@ -656,6 +679,7 @@ Options:
656679
--port <number> Port for HTTP server mode (default: "4000")
657680
--base-url <url> Base URL for backend APIs (overrides config file)
658681
--max-tool-name-length <number> Maximum length for generated tool names (default: "48")
682+
--max-request-size <size> Maximum size for JSON request bodies (default: "2mb")
659683
--http Run in HTTP server mode instead of stdio (default: false)
660684
-v, --verbose Enable verbose logging (default: true)
661685
-h, --help Display help for command

mcp-openapi/src/cli.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ program
1919
.option('--port <number>', 'Port for HTTP server mode', '4000')
2020
.option('--base-url <url>', 'Base URL for backend APIs (overrides config file)')
2121
.option('--max-tool-name-length <number>', 'Maximum length for generated tool names', '48')
22+
.option('--max-request-size <size>', 'Maximum size for JSON request bodies', '2mb')
2223
.option('--http', 'Run in HTTP server mode instead of stdio', false)
2324
.option('-v, --verbose', 'Enable verbose logging', true)
2425
.action(async (options) => {
@@ -29,7 +30,8 @@ program
2930
port: parseInt(options.port),
3031
verbose: options.verbose,
3132
...(options.baseUrl && { baseUrl: options.baseUrl }),
32-
...(options.maxToolNameLength && { maxToolNameLength: parseInt(options.maxToolNameLength) })
33+
...(options.maxToolNameLength && { maxToolNameLength: parseInt(options.maxToolNameLength) }),
34+
...(options.maxRequestSize && { maxRequestSize: options.maxRequestSize })
3335
};
3436

3537
const server = new MCPOpenAPIServer(serverOptions);

mcp-openapi/src/server.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ export class MCPOpenAPIServer {
6363
port: 4000,
6464
verbose: true,
6565
maxToolNameLength: 48,
66+
maxRequestSize: '2mb',
6667
...options
6768
};
6869

@@ -102,7 +103,7 @@ export class MCPOpenAPIServer {
102103
private setupExpress() {
103104
const corsOptions = this.config.cors || {};
104105
this.app.use(cors(corsOptions));
105-
this.app.use(express.json());
106+
this.app.use(express.json({ limit: this.options.maxRequestSize }));
106107
}
107108

108109
async initialize(): Promise<void> {

mcp-openapi/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,4 +86,5 @@ export interface ServerOptions {
8686
verbose?: boolean;
8787
baseUrl?: string;
8888
maxToolNameLength?: number;
89+
maxRequestSize?: string;
8990
}

0 commit comments

Comments
 (0)