Add streamable HTTP server mode#13
Closed
Conversation
There was a problem hiding this comment.
Pull Request Overview
Adds an HTTP-based SSE server alongside the existing stdio transport, upgrades the MCP SDK, and updates docs.
- Upgrades
@modelcontextprotocol/sdkto^1.1.0 - Introduces
--portflag to switch between stdio and HTTP/SSE modes with port validation - Updates README to document the new
--portusage
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/index.ts | Added startHttpServer, updated main to parse --port, and renamed runServer to startStdioServer |
| README.md | Documented --port flag usage and example for HTTP/SSE server mode |
Files not reviewed (1)
- package.json: Language not supported
Comments suppressed due to low confidence (1)
src/index.ts:479
- The new HTTP and stdio server flows lack dedicated tests. Add unit or integration tests to cover both code paths and verify SSE handshake and message handling.
async function main() {
Comment on lines
+454
to
+469
| let transport: SSEServerTransport | undefined; | ||
|
|
||
| app.get('/sse', async (_req, res) => { | ||
| transport = new SSEServerTransport('/message', res); | ||
| await server.connect(transport); | ||
| console.error( | ||
| `Lightdash MCP Server new SSE connection ${transport.sessionId}` | ||
| ); | ||
| }); | ||
|
|
||
| app.post('/message', async (req, res) => { | ||
| if (!transport) { | ||
| res.status(404).send('Session not initialized'); | ||
| return; | ||
| } | ||
| await transport.handlePostMessage(req, res, req.body); |
There was a problem hiding this comment.
This only tracks a single SSE transport instance, so concurrent clients will overwrite each other. Consider mapping transports by sessionId and parameterizing the POST endpoint to support multiple simultaneous connections.
Suggested change
| let transport: SSEServerTransport | undefined; | |
| app.get('/sse', async (_req, res) => { | |
| transport = new SSEServerTransport('/message', res); | |
| await server.connect(transport); | |
| console.error( | |
| `Lightdash MCP Server new SSE connection ${transport.sessionId}` | |
| ); | |
| }); | |
| app.post('/message', async (req, res) => { | |
| if (!transport) { | |
| res.status(404).send('Session not initialized'); | |
| return; | |
| } | |
| await transport.handlePostMessage(req, res, req.body); | |
| const transports: Map<string, SSEServerTransport> = new Map(); | |
| app.get('/sse', async (_req, res) => { | |
| const transport = new SSEServerTransport('/message', res); | |
| transports.set(transport.sessionId, transport); | |
| await server.connect(transport); | |
| console.error( | |
| `Lightdash MCP Server new SSE connection ${transport.sessionId}` | |
| ); | |
| res.on('close', () => { | |
| transports.delete(transport.sessionId); | |
| console.error(`SSE connection closed: ${transport.sessionId}`); | |
| }); | |
| }); | |
| app.post('/message', async (req, res) => { | |
| const { sessionId, message } = req.body; | |
| const transport = transports.get(sessionId); | |
| if (!transport) { | |
| res.status(404).send('Session not found'); | |
| return; | |
| } | |
| await transport.handlePostMessage(req, res, message); |
| Specify a port with `--port` to expose a streamable HTTP endpoint instead of | ||
| stdio. The port must be between `1024` and `65535`: | ||
|
|
||
| ```bash |
There was a problem hiding this comment.
[nitpick] It may help to document the POST /message endpoint usage after the SSE connection, so consumers know how to send messages back to the server.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
--portcommand line flag to enable HTTP mode--portflag in READMETesting
npm run lintnpm test