XHS MCP Server now supports both SSE (Server-Sent Events) and Streamable HTTP transports, in addition to the traditional stdio transport.
/mcp
/sse
(GET) - Establish SSE stream/messages
(POST) - Send messages# Start HTTP server on default port 3000
npm run start:http
# Start HTTP server on custom port
npm run start:http -- --port 8080
# Development mode with HTTP server
npm run dev:http
# Development mode with custom port
npm run dev:http -- --port 8080
# Show help
node dist/index.js --help
# Start in stdio mode (default)
node dist/index.js --mode stdio
# Start in HTTP mode
node dist/index.js --mode http --port 3000
GET /health
Returns server status and supported transports.
Response:
{
"status": "healthy",
"server": "xhs-mcp",
"version": "0.2.10",
"transports": ["streamable-http", "sse"]
}
POST /mcp
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2025-03-26",
"capabilities": {},
"clientInfo": {
"name": "client-name",
"version": "1.0.0"
}
}
}
Response Headers:
Mcp-Session-Id: <session-id>
POST /mcp
Content-Type: application/json
Mcp-Session-Id: <session-id>
{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/list"
}
GET /mcp
Mcp-Session-Id: <session-id>
DELETE /mcp
Mcp-Session-Id: <session-id>
GET /sse
POST /messages?sessionId=<session-id>
Content-Type: application/json
{
"jsonrpc": "2.0",
"id": 1,
"method": "initialize",
"params": {
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "client-name",
"version": "1.0.0"
}
}
}
A test script is provided to verify the HTTP server functionality:
# Start the HTTP server in one terminal
npm run dev:http
# Run tests in another terminal
node test-http-server.js
XHS_ENABLE_LOGGING=true
- Enable detailed loggingPORT
- HTTP server port (default: 3000)The HTTP server is configured with permissive CORS settings for development:
app.use(cors({
origin: '*', // Allow all origins
exposedHeaders: ['Mcp-Session-Id']
}));
For production, you should restrict the origin
to specific domains.
Both SSE and Streamable HTTP transports support DNS rebinding protection:
const transport = new SSEServerTransport('/messages', res, {
allowedHosts: ['localhost', '127.0.0.1'],
allowedOrigins: ['http://localhost:3000'],
enableDnsRebindingProtection: true
});
2024-11-05
to 2025-03-26
/mcp
endpoint instead of separate /sse
and /messages
--port
optionEnable detailed logging:
XHS_ENABLE_LOGGING=true npm run dev:http
Always verify server status:
curl http://localhost:3000/health