Skip to content

feat(mcp-server): add Streamable HTTP transport support - #230

Open
Marlin-Phone wants to merge 1 commit into
wechatsync:v2from
Marlin-Phone:feat/mcp-streamable-http
Open

feat(mcp-server): add Streamable HTTP transport support#230
Marlin-Phone wants to merge 1 commit into
wechatsync:v2from
Marlin-Phone:feat/mcp-streamable-http

Conversation

@Marlin-Phone

Copy link
Copy Markdown

Summary

Add Streamable HTTP transport support to the MCP server via a new --http mode.
Standard MCP clients (official SDK) could not complete the SSE handshake
(POST /message returned 400) because the existing SSE implementation uses a
single global transport and calls server.connect() repeatedly.

Closes #229

Changes

  • packages/mcp-server/src/index.ts:
    • Import StreamableHTTPServerTransport, add --http mode detection
    • Add express.json() middleware
    • Pass pre-parsed body to handleRequest(req, res, req.body) (SDK convention)
    • Multi-session support: per-session Server + Transport in a Map keyed by
      mcp-session-id, handled in POST/GET/DELETE /mcp
    • transport.onclose cleans up the session

Testing

  • pnpm --filter mcp-server build passes (ESM + DTS clean)
  • initialize handshake verified with curl: returns protocolVersion + serverInfo + capabilities
  • Tool listing verified with official Python MCP SDK client: 5 tools
    (list_platforms / check_auth / sync_article / extract_article / upload_image_file)
  • Existing stdio/SSE modes unchanged

Add a new --http mode using StreamableHTTPServerTransport so standard MCP
clients (official SDK) can connect. The existing SSE mode fails the
initialize handshake with 400 on POST /message because it uses a single
global transport and calls server.connect() repeatedly.

Multi-session support: each sessionId gets its own Server(Protocol) +
Transport stored in a Map, dispatched by the mcp-session-id header on
POST/GET/DELETE /mcp. transport.onclose cleans up the session.

stdlib/SSE modes are unchanged.

Closes wechatsync#229
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: MCP Server SSE 模式无法与标准 MCP 客户端完成握手(POST /message 返回 400)

1 participant