Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/mcp-limit-fix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@modelcontextprotocol/server": patch
---

fix(server): add limit option for express json body parser
8 changes: 4 additions & 4 deletions docs/server-quickstart.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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';
Expand Down Expand Up @@ -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
Expand Down
8 changes: 6 additions & 2 deletions packages/middleware/express/src/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ export interface CreateMcpExpressAppOptions {
* to restrict which hostnames are allowed.
*/
allowedHosts?: string[];
/**
* Controls the maximum request body size.
*/
limit?: string;
}

/**
Expand Down Expand Up @@ -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) {
Expand Down