diff --git a/.changeset/mcp-limit-fix.md b/.changeset/mcp-limit-fix.md new file mode 100644 index 000000000..aa2d4ac4d --- /dev/null +++ b/.changeset/mcp-limit-fix.md @@ -0,0 +1,5 @@ +--- +"@modelcontextprotocol/server": patch +--- + +fix(server): add limit option for express json body parser diff --git a/docs/server-quickstart.md b/docs/server-quickstart.md index ffa49cec5..17ebdd380 100644 --- a/docs/server-quickstart.md +++ b/docs/server-quickstart.md @@ -53,7 +53,7 @@ cd weather npm init -y # Install dependencies -npm install @modelcontextprotocol/server zod +npm install @modelcontextprotocol/sdk zod npm install -D @types/node typescript # Create our files @@ -72,7 +72,7 @@ cd weather npm init -y # Install dependencies -npm install @modelcontextprotocol/server zod +npm install @modelcontextprotocol/sdk zod npm install -D @types/node typescript # Create our files @@ -124,7 +124,7 @@ Now let's dive into building your server. Add these to the top of your `src/index.ts`: ```ts source="../examples/server-quickstart/src/index.ts#prelude" -import { McpServer, StdioServerTransport } from '@modelcontextprotocol/server'; +import { McpServer, StdioServerTransport } from '@modelcontextprotocol/sdk'; import * as z from 'zod/v4'; const NWS_API_BASE = 'https://api.weather.gov'; @@ -212,7 +212,7 @@ interface ForecastResponse { ### Registering tools -Each tool is registered with {@linkcode @modelcontextprotocol/server!server/mcp.McpServer#registerTool | server.registerTool()}, which takes the tool name, a configuration object (with description and input schema), and a callback that implements the tool logic. Let's register our two weather tools: +Each tool is registered with {@linkcode @modelcontextprotocol/sdk!server/mcp.McpServer#registerTool | server.registerTool()}, which takes the tool name, a configuration object (with description and input schema), and a callback that implements the tool logic. Let's register our two weather tools: ```ts source="../examples/server-quickstart/src/index.ts#registerTools" // Register weather tools diff --git a/packages/middleware/express/src/express.ts b/packages/middleware/express/src/express.ts index af156a229..2e9404a0a 100644 --- a/packages/middleware/express/src/express.ts +++ b/packages/middleware/express/src/express.ts @@ -22,6 +22,10 @@ export interface CreateMcpExpressAppOptions { * to restrict which hostnames are allowed. */ allowedHosts?: string[]; + /** + * Controls the maximum request body size. + */ + limit?: string; } /** @@ -51,10 +55,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, limit } = options; const app = express(); - app.use(express.json()); + app.use(limit ? express.json({ limit }) : express.json()); // If allowedHosts is explicitly provided, use that for validation if (allowedHosts) {