Skip to content

Commit 1686e74

Browse files
authored
Merge pull request #35 from QuantGeekDev/feat/http-stream-organized
Feat/http stream
2 parents 27c255b + 04ff8a5 commit 1686e74

File tree

9 files changed

+2086
-223
lines changed

9 files changed

+2086
-223
lines changed

README.md

+102-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
@@ -139,6 +139,27 @@ Add this configuration to your Claude Desktop config file:
139139
2. Run \`npm run build\` to compile
140140
3. The server will automatically load your tools on startup
141141

142+
## Environment Variables
143+
144+
The framework supports the following environment variables for configuration:
145+
146+
| Variable | Description | Default |
147+
|-----------------------|-------------------------------------------------------|-------------|
148+
| MCP_ENABLE_FILE_LOGGING | Enable logging to files (true/false) | false |
149+
| MCP_LOG_DIRECTORY | Directory where log files will be stored | logs |
150+
| MCP_DEBUG_CONSOLE | Display debug level messages in console (true/false) | false |
151+
152+
Example usage:
153+
154+
```bash
155+
# Enable file logging
156+
MCP_ENABLE_FILE_LOGGING=true node dist/index.js
157+
158+
# Specify a custom log directory
159+
MCP_ENABLE_FILE_LOGGING=true MCP_LOG_DIRECTORY=my-logs
160+
# Enable debug messages in console
161+
MCP_DEBUG_CONSOLE=true```
162+
142163
## Quick Start
143164
144165
### Creating a Tool
@@ -267,6 +288,86 @@ const server = new MCPServer({
267288
});
268289
```
269290
291+
### HTTP Stream Transport (New!)
292+
293+
The HTTP Stream transport provides a streamable JSON-RPC interface over HTTP with support for batch and streaming response modes:
294+
295+
```typescript
296+
const server = new MCPServer({
297+
transport: {
298+
type: "http-stream",
299+
options: {
300+
port: 8080, // Optional (default: 8080)
301+
endpoint: "/mcp", // Optional (default: "/mcp")
302+
responseMode: "batch", // Optional (default: "batch"), can be "batch" or "stream"
303+
batchTimeout: 30000, // Optional (default: 30000ms) - timeout for batch responses
304+
maxMessageSize: "4mb", // Optional (default: "4mb") - maximum message size
305+
306+
// Session configuration
307+
session: {
308+
enabled: true, // Optional (default: true)
309+
headerName: "Mcp-Session-Id", // Optional (default: "Mcp-Session-Id")
310+
allowClientTermination: true, // Optional (default: true)
311+
},
312+
313+
// Stream resumability (for missed messages)
314+
resumability: {
315+
enabled: false, // Optional (default: false)
316+
historyDuration: 300000, // Optional (default: 300000ms = 5min) - how long to keep message history
317+
},
318+
319+
// CORS configuration (same as SSE transport)
320+
cors: {
321+
allowOrigin: "*",
322+
allowMethods: "GET, POST, DELETE, OPTIONS",
323+
allowHeaders: "Content-Type, Accept, Authorization, x-api-key, Mcp-Session-Id, Last-Event-ID",
324+
exposeHeaders: "Content-Type, Authorization, x-api-key, Mcp-Session-Id",
325+
maxAge: "86400"
326+
}
327+
}
328+
}
329+
});
330+
```
331+
332+
#### Response Modes
333+
334+
The HTTP Stream transport supports two response modes:
335+
336+
1. **Batch Mode** (Default): Responses are collected and sent as a single JSON-RPC response. This is suitable for typical request-response patterns and is more efficient for most use cases.
337+
338+
2. **Stream Mode**: All responses are sent over a persistent SSE connection opened for each request. This is ideal for long-running operations or when the server needs to send multiple messages in response to a single request.
339+
340+
You can configure the response mode based on your specific needs:
341+
342+
```typescript
343+
// For batch mode (default):
344+
const server = new MCPServer({
345+
transport: {
346+
type: "http-stream",
347+
options: {
348+
responseMode: "batch"
349+
}
350+
}
351+
});
352+
353+
// For stream mode:
354+
const server = new MCPServer({
355+
transport: {
356+
type: "http-stream",
357+
options: {
358+
responseMode: "stream"
359+
}
360+
}
361+
});
362+
```
363+
364+
#### HTTP Stream Transport Features
365+
366+
- **Session Management**: Automatic session tracking and management
367+
- **Stream Resumability**: Optional support for resuming streams after connection loss
368+
- **Batch Processing**: Support for JSON-RPC batch requests/responses
369+
- **Comprehensive Error Handling**: Detailed error responses with JSON-RPC error codes
370+
270371
## Authentication
271372
272373
MCP Framework provides optional authentication for SSE endpoints. You can choose between JWT and API Key authentication, or implement your own custom authentication provider.

0 commit comments

Comments
 (0)