feat: add HTTP/SSE transport support for MCP server#105
Open
Conversation
Add StreamableHTTPServerTransport as an alternative to the default stdio transport, enabling remote MCP client connections over HTTP. Transport is selectable via TRANSPORT env var (stdio|http) or --transport CLI flag.
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
Switch the MCP server to HTTP/SSE transport and remove the signed session token (~500+ chars) from all tool response content, eliminating persistent JWT bloat from the LLM context window. The token remains accessible via
_meta.session_tokenfor SDK-level auto-threading and as a required tool parameter.🎫 Ticket 📐 Engineering 🧪 Test Plan
Motivation
The server currently uses stdio transport. Workflow state is encoded as a signed JWT session token (~500+ chars) and returned in tool call result content on every tool call. This token is visible to the LLM and persists in the context window for the entire workflow session, consuming tokens on every turn. For workflows with 10-30+ tool calls, this results in kilobytes of repeated token content.
Switching to HTTP/SSE transport with
StreamableHTTPServerTransport(already present in the MCP TypeScript SDK v1.25.2) provides a separate metadata channel. The session token is removed entirely from response content and carried only in_meta.session_token, which is accessible to SDK-level client tooling but not shown to the LLM. The server remains fully stateless — no session store is added.Key design decision: The
Mcp-Session-Idheader is not used because its strict validation rejects mutating tokens (confirmed in SDK source analysis DD-1). Instead,sessionIdGenerator: undefineddisables the header entirely (stateless mode), and_meta.session_tokenserves as the authoritative token source.Changes
Implementation (coming next):
transport,httpPort,httpHostfields already added toServerConfigwithTRANSPORT,HTTP_PORT,HTTP_HOSTenv vars insrc/config.ts:14-18,34-44(T1 complete, uncommitted)src/index.tsto conditionally createStdioServerTransport(default) orStreamableHTTPServerTransportbased onconfig.transport(T2)session_tokenfrom 6 JSON response objects, 3 TOON header prefixes; removecheckpoint_handlefrom 3 JSON objects and 1 TOON object (13 sites total). Keepclient_session_tokenindispatch_workflow. (T3)session_tokenfrom 1 JSON response object, 3 TOON header prefixes (4 sites total) (T4)tests/mcp-server.test.tsto read from_metainstead of parsed content (required — A-12/A-17 invalidated: 8 assertions + 11 token reads currently parse content text) (T5)npm testandnpm run typecheck; all must pass (T6)Retained (not removed):
_meta.session_token— remains in all 16 relevant tool responses as the authoritative token sourcesession_id(UUID, 36 chars) — remains instart_sessionresponse for stale-session detectionclient_session_token— remains indispatch_workflowresponse (one-time dispatch, not per-call bloat)session_tokenas a tool input parameter — remains required on all tools that need itAssumptions reconciliation (plan-prepare):
_meta(A-09, same as A-06) — medium risk, mitigated by_metamechanism working at SDK level (confirmed by test helpers)📌 Submission Checklist
🔱 Fork Strategy
🗹 TODO before merging