Skip to content

Commit d29fb5f

Browse files
committed
feat: HTTP stream transport implementation (v0.2.0-beta.16)
1 parent 27c255b commit d29fb5f

File tree

7 files changed

+1090
-148
lines changed

7 files changed

+1090
-148
lines changed

README.md

+56-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ MCP-Framework gives you architecture out of the box, with automatic directory-ba
77
## Features
88

99
- 🛠️ Automatic discovery and loading of tools, resources, and prompts
10-
- Multiple transport support (stdio, SSE)
10+
- Multiple transport support (stdio, SSE, HTTP Stream)
1111
- TypeScript-first development with full type safety
1212
- Built on the official MCP SDK
1313
- Easy-to-use base classes for tools, prompts, and resources
@@ -267,6 +267,61 @@ const server = new MCPServer({
267267
});
268268
```
269269

270+
### HTTP Stream Transport (New!)
271+
272+
The HTTP Stream transport provides a streamable JSON-RPC interface over HTTP with support for batch and streaming response modes:
273+
274+
```typescript
275+
const server = new MCPServer({
276+
transport: {
277+
type: "http-stream",
278+
options: {
279+
port: 8080, // Optional (default: 8080)
280+
endpoint: "/mcp", // Optional (default: "/mcp")
281+
responseMode: "stream", // Optional (default: "stream"), can be "batch" or "stream"
282+
batchTimeout: 30000, // Optional (default: 30000ms) - timeout for batch responses
283+
maxMessageSize: "4mb", // Optional (default: "4mb") - maximum message size
284+
285+
// Session configuration
286+
session: {
287+
enabled: true, // Optional (default: true)
288+
headerName: "Mcp-Session-Id", // Optional (default: "Mcp-Session-Id")
289+
allowClientTermination: true, // Optional (default: true)
290+
},
291+
292+
// Stream resumability (for missed messages)
293+
resumability: {
294+
enabled: false, // Optional (default: false)
295+
historyDuration: 300000, // Optional (default: 300000ms = 5min) - how long to keep message history
296+
},
297+
298+
// CORS configuration (same as SSE transport)
299+
cors: {
300+
allowOrigin: "*",
301+
allowMethods: "GET, POST, DELETE, OPTIONS",
302+
allowHeaders: "Content-Type, Accept, Mcp-Session-Id, Last-Event-ID",
303+
exposeHeaders: "Content-Type, Mcp-Session-Id",
304+
maxAge: "86400"
305+
}
306+
}
307+
}
308+
});
309+
```
310+
311+
#### Response Modes
312+
313+
The HTTP Stream transport supports two response modes:
314+
315+
1. **Stream Mode** (Default): All responses are sent over a persistent SSE connection. This is ideal for real-time applications.
316+
2. **Batch Mode**: Responses are collected and sent as a single JSON-RPC response. This is suitable for traditional REST-like integrations.
317+
318+
#### HTTP Stream Transport Features
319+
320+
- **Session Management**: Automatic session tracking and management
321+
- **Stream Resumability**: Optional support for resuming streams after connection loss
322+
- **Batch Processing**: Support for JSON-RPC batch requests/responses
323+
- **Comprehensive Error Handling**: Detailed error responses with JSON-RPC error codes
324+
270325
## Authentication
271326

272327
MCP Framework provides optional authentication for SSE endpoints. You can choose between JWT and API Key authentication, or implement your own custom authentication provider.

package-lock.json

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mcp-framework",
3-
"version": "0.1.29",
3+
"version": "0.2.0-beta.16",
44
"description": "Framework for building Model Context Protocol (MCP) servers in Typescript",
55
"type": "module",
66
"author": "Alex Andru <[email protected]>",
@@ -45,10 +45,12 @@
4545
"dependencies": {
4646
"@types/prompts": "^2.4.9",
4747
"commander": "^12.1.0",
48+
"content-type": "^1.0.5",
4849
"execa": "^9.5.2",
4950
"find-up": "^7.0.0",
5051
"jsonwebtoken": "^9.0.2",
5152
"prompts": "^2.4.2",
53+
"raw-body": "^2.5.2",
5254
"typescript": "^5.3.3",
5355
"zod": "^3.23.8"
5456
},

0 commit comments

Comments
 (0)