Skip to content

Commit a40b353

Browse files
authored
Merge branch 'main' into feat/structured-content-with-type-safety
2 parents fb303d7 + a1a486d commit a40b353

33 files changed

+2054
-136
lines changed

README.md

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -444,7 +444,11 @@ app.post('/mcp', async (req, res) => {
444444
onsessioninitialized: (sessionId) => {
445445
// Store the transport by session ID
446446
transports[sessionId] = transport;
447-
}
447+
},
448+
// DNS rebinding protection is disabled by default for backwards compatibility. If you are running this server
449+
// locally, make sure to set:
450+
// enableDnsRebindingProtection: true,
451+
// allowedHosts: ['127.0.0.1'],
448452
});
449453

450454
// Clean up transport when closed
@@ -500,6 +504,21 @@ app.delete('/mcp', handleSessionRequest);
500504
app.listen(3000);
501505
```
502506

507+
> [!TIP]
508+
> When using this in a remote environment, make sure to allow the header parameter `mcp-session-id` in CORS. Otherwise, it may result in a `Bad Request: No valid session ID provided` error.
509+
>
510+
> For example, in Node.js you can configure it like this:
511+
>
512+
> ```ts
513+
> app.use(
514+
> cors({
515+
> origin: ['https://your-remote-domain.com, https://your-other-remote-domain.com'],
516+
> exposedHeaders: ['mcp-session-id'],
517+
> allowedHeaders: ['Content-Type', 'mcp-session-id'],
518+
> })
519+
> );
520+
> ```
521+
503522
#### Without Session Management (Stateless)
504523
505524
For simpler use cases where session management isn't needed:
@@ -540,6 +559,7 @@ app.post('/mcp', async (req: Request, res: Response) => {
540559
}
541560
});
542561
562+
// SSE notifications not supported in stateless mode
543563
app.get('/mcp', async (req: Request, res: Response) => {
544564
console.log('Received GET MCP request');
545565
res.writeHead(405).end(JSON.stringify({
@@ -552,6 +572,7 @@ app.get('/mcp', async (req: Request, res: Response) => {
552572
}));
553573
});
554574
575+
// Session termination not needed in stateless mode
555576
app.delete('/mcp', async (req: Request, res: Response) => {
556577
console.log('Received DELETE MCP request');
557578
res.writeHead(405).end(JSON.stringify({
@@ -579,6 +600,22 @@ This stateless approach is useful for:
579600
- RESTful scenarios where each request is independent
580601
- Horizontally scaled deployments without shared session state
581602

603+
#### DNS Rebinding Protection
604+
605+
The Streamable HTTP transport includes DNS rebinding protection to prevent security vulnerabilities. By default, this protection is **disabled** for backwards compatibility.
606+
607+
**Important**: If you are running this server locally, enable DNS rebinding protection:
608+
609+
```typescript
610+
const transport = new StreamableHTTPServerTransport({
611+
sessionIdGenerator: () => randomUUID(),
612+
enableDnsRebindingProtection: true,
613+
614+
allowedHosts: ['127.0.0.1', ...],
615+
allowedOrigins: ['https://yourdomain.com', 'https://www.yourdomain.com']
616+
});
617+
```
618+
582619
### Testing and Debugging
583620

584621
To test your server, you can use the [MCP Inspector](https://github.com/modelcontextprotocol/inspector). See its README for more information.

eslint.config.mjs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,12 @@ export default tseslint.config(
1515
{ "argsIgnorePattern": "^_" }
1616
]
1717
}
18+
},
19+
{
20+
files: ["src/client/**/*.ts", "src/server/**/*.ts"],
21+
ignores: ["**/*.test.ts"],
22+
rules: {
23+
"no-console": "error"
24+
}
1825
}
1926
);

package-lock.json

Lines changed: 33 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@modelcontextprotocol/sdk",
3-
"version": "1.13.0",
3+
"version": "1.13.2",
44
"description": "Model Context Protocol implementation for TypeScript",
55
"license": "MIT",
66
"author": "Anthropic, PBC (https://anthropic.com)",
@@ -54,6 +54,7 @@
5454
"cors": "^2.8.5",
5555
"cross-spawn": "^7.0.5",
5656
"eventsource": "^3.0.2",
57+
"eventsource-parser": "^3.0.0",
5758
"express": "^5.0.1",
5859
"express-rate-limit": "^7.5.0",
5960
"pkce-challenge": "^5.0.0",

0 commit comments

Comments
 (0)