Skip to content

Commit 04ff8a5

Browse files
committed
feat: Add HTTP Stream transport with improved session handling and CORS support
1 parent d29fb5f commit 04ff8a5

File tree

8 files changed

+1069
-148
lines changed

8 files changed

+1069
-148
lines changed

README.md

+51-5
Original file line numberDiff line numberDiff line change
@@ -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
@@ -278,7 +299,7 @@ const server = new MCPServer({
278299
options: {
279300
port: 8080, // Optional (default: 8080)
280301
endpoint: "/mcp", // Optional (default: "/mcp")
281-
responseMode: "stream", // Optional (default: "stream"), can be "batch" or "stream"
302+
responseMode: "batch", // Optional (default: "batch"), can be "batch" or "stream"
282303
batchTimeout: 30000, // Optional (default: 30000ms) - timeout for batch responses
283304
maxMessageSize: "4mb", // Optional (default: "4mb") - maximum message size
284305
@@ -299,8 +320,8 @@ const server = new MCPServer({
299320
cors: {
300321
allowOrigin: "*",
301322
allowMethods: "GET, POST, DELETE, OPTIONS",
302-
allowHeaders: "Content-Type, Accept, Mcp-Session-Id, Last-Event-ID",
303-
exposeHeaders: "Content-Type, Mcp-Session-Id",
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",
304325
maxAge: "86400"
305326
}
306327
}
@@ -312,8 +333,33 @@ const server = new MCPServer({
312333
313334
The HTTP Stream transport supports two response modes:
314335
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.
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+
```
317363
318364
#### HTTP Stream Transport Features
319365

0 commit comments

Comments
 (0)