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:
parent
5a2c8a69c9
commit
1fe9eda4a7
3 changed files with 26 additions and 2 deletions
5
.changeset/twelve-dodos-taste.md
Normal file
5
.changeset/twelve-dodos-taste.md
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"@modelcontextprotocol/express": patch
|
||||
---
|
||||
|
||||
Add jsonLimit option to createMcpExpressApp
|
||||
|
|
@ -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) {
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in a new issue