Support remote/HTTP MCP servers in the integrations gateway (#229)#230
Merged
Conversation
Extend the MCP client to speak the Streamable HTTP transport in addition to stdio. A connection with a `url` in its transport config now POSTs JSON-RPC to that URL, accepting both `application/json` and `text/event-stream` (SSE) responses and running the same initialize -> notifications/initialized -> tools/list / tools/call flow. Auth is injected at the HTTP boundary via resolveConnectionAuth (the same resolveAuth + getConnectionSecrets path the REST/OpenAPI executor uses), so a static Bearer token attaches exactly as it does for those transports. The optional Mcp-Session-Id handed back on initialize is carried on subsequent requests. The stdio path is unchanged (split into its own helper). No gateway plumbing changes were needed. Adds unit tests for the HTTP transport: JSON and SSE framing, auth header injection, 401/non-2xx handling, missing-credential short-circuit, and the no-command/no-url rejection. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
3 tasks
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
Extends
server/lib/mcp-client.tsto support remote MCP servers over the Streamable HTTP transport, in addition to the existing stdio transport. A connection with aurlin its transport config now POSTs JSON-RPC to that URL, accepting bothapplication/jsonandtext/event-stream(SSE) responses, and runs the sameinitialize→notifications/initialized→tools/list/tools/callflow as stdio.Closes #229 (platform work). Registering Cloudflare (Code Mode) as the first consumer is a follow-up user action — see below.
Changes
withSessionbranches on config —url→withHttpSession,command→withStdioSession(existing logic, unchanged, just extracted), neither → a clear error.Accept: application/json, text/event-stream; parses both a single JSON body and SSEdata:frames. Carries the optionalMcp-Session-Idhanded back oninitializeonto subsequent requests.resolveConnectionAuth— the sameresolveAuth+getConnectionSecretspath the REST/OpenAPI executor uses — so a staticAuthorization: Bearer <token>attaches identically. A 401/403 surfaces a credentials error; other non-2xx surfaces status + body; a missing credential short-circuits before any network call.integration-gateway.tsalready routesmcpmode throughmcpListTools/mcpCallTool/mcpStatus, and the connection form already exposes theurlfield + Bearer preset.Validation
mcp-client.test.ts: 9 tests — JSON + SSE framing, auth header injection, status/tool-count,tools/call, 401, non-2xx, missing-credential short-circuit, no-command/no-url rejection.tsc -p server/tsconfig.json --noEmit: clean.Follow-up: Cloudflare (Code Mode)
The platform now supports it, but registration is a user action (the UI writes the Bearer API token to the encrypted secret store — not a repo artifact). After merge: add an MCP connection in Controller → Integrations with URL
https://mcp.cloudflare.com/mcp+ Bearer token, then verify withintegrations tools / call / status.🤖 Generated with Claude Code