Add streamable HTTP server mode#14
Closed
Conversation
There was a problem hiding this comment.
Pull Request Overview
This PR adds the ability to run the Lightdash MCP Server in streamable HTTP mode using Server-Sent Events (SSE) and provides a CLI flag to enable it, while still supporting the existing stdio mode.
- Upgraded the MCP SDK to ^1.1.0
- Added HTTP mode with SSE endpoint support and corresponding error handling
- Updated README to document the usage of the --port flag
Reviewed Changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| src/index.ts | Introduces separate functions for stdio and HTTP modes including SSE transport handling |
| README.md | Documents the new --port flag for activating the HTTP server mode |
Files not reviewed (1)
- package.json: Language not supported
Comment on lines
+454
to
+464
| 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) => { |
There was a problem hiding this comment.
Using a single 'transport' variable to manage the SSE connection might lead to issues when handling multiple concurrent connections; consider implementing a mechanism (e.g., mapping session IDs to transports) to support multiple clients.
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) => { | |
| const transports = new Map<string, SSEServerTransport>(); | |
| 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}` | |
| ); | |
| // Clean up when the connection is closed | |
| res.on('close', () => { | |
| transports.delete(transport.sessionId); | |
| console.error(`SSE connection closed: ${transport.sessionId}`); | |
| }); | |
| }); | |
| app.post('/message', async (req, res) => { | |
| const sessionId = req.body.sessionId; | |
| const transport = transports.get(sessionId); |
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