Skip to content

Add streamable HTTP server mode#13

Closed
syucream wants to merge 1 commit intomainfrom
codex/mcp-sdkの最新化とtransport設定の変更

Hidden character warning

The head ref may contain hidden characters: "codex/mcp-sdk\u306e\u6700\u65b0\u5316\u3068transport\u8a2d\u5b9a\u306e\u5909\u66f4"
Closed

Add streamable HTTP server mode#13
syucream wants to merge 1 commit intomainfrom
codex/mcp-sdkの最新化とtransport設定の変更

Conversation

@syucream
Copy link
Copy Markdown
Owner

Summary

  • update MCP SDK to ^1.1.0
  • add ability to run server either on stdio or streamable HTTP
  • support --port command line flag to enable HTTP mode
  • document --port flag in README
  • validate port is not within well-known port range (1024-65535)

Testing

  • npm run lint
  • npm test

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds an HTTP-based SSE server alongside the existing stdio transport, upgrades the MCP SDK, and updates docs.

  • Upgrades @modelcontextprotocol/sdk to ^1.1.0
  • Introduces --port flag to switch between stdio and HTTP/SSE modes with port validation
  • Updates README to document the new --port usage

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 thread src/index.ts
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);
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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);

Copilot uses AI. Check for mistakes.
Comment thread README.md
Specify a port with `--port` to expose a streamable HTTP endpoint instead of
stdio. The port must be between `1024` and `65535`:

```bash
Copy link

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Copilot uses AI. Check for mistakes.
@syucream syucream closed this May 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants