Skip to content

refactor(mcp-clients): dedupe HTTP/Websocket and SSE transport setup - #6136

Open
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/outbound-http-transport-dedupe-w4
Open

refactor(mcp-clients): dedupe HTTP/Websocket and SSE transport setup#6136
pedrofrxncx wants to merge 1 commit into
mainfrom
refactor/outbound-http-transport-dedupe-w4

Conversation

@pedrofrxncx

@pedrofrxncx pedrofrxncx commented Aug 15, 2026

Copy link
Copy Markdown
Collaborator

Follows issue #4468 (simplify the MCP-mesh machinery).

createOutboundClient in apps/api/src/mcp-clients/outbound/index.ts had three near-identical blocks for the HTTP, Websocket, and SSE connection types: validate connection_url, build request headers, merge any custom headers, construct the transport, then compose it with AuthTransport + MonitoringTransport. Only the transport constructor (StreamableHTTPClientTransport vs SSEClientTransport) differed. Extracted the shared steps into one buildHttpLikeTransport(connection, ctx, superUser, virtualMcpId, TransportCtor) helper, parameterized only by the constructor.

A maintainer gets a smaller, single home for this logic instead of three call sites that must all be kept in sync by hand whenever header-building or transport composition changes.

Behavior-preserving: the error message stays ${connection.connection_type} connection missing URL — for the SSE branch this was already the literal string "SSE connection missing URL" before this change, since connection.connection_type is "SSE" in that branch, so the template produces the identical text. Header building, transport composition order (AuthTransport then MonitoringTransport), and the final ctx.getOrCreateClient call are all unchanged — this is a pure code-motion, no new branches or altered control flow.

Net diff: -54/+51 lines in one file.

Reviewer check: cd apps/api && bunx tsc --noEmit (clean) — there's no existing unit test isolating createOutboundClient (it needs a live/mocked MCP transport, which is e2e territory per this repo's testing tiers), so this is verified by typecheck + a line-by-line diff of the extracted logic against the original three blocks.

Locally ran: bun run fmt, cd apps/api && bunx tsc --noEmit, bunx oxlint apps/api/src/mcp-clients/outbound/index.ts (0 errors/warnings). Full CI validates the rest.


Summary by cubic

Dedupes outbound HTTP/Websocket and SSE transport setup in createOutboundClient by extracting a shared helper, buildHttpLikeTransport. This reduces duplication and centralizes header and composition logic without changing behavior.

  • The helper validates the URL, builds request headers, merges connection_headers.headers, constructs the transport, and composes with AuthTransport then MonitoringTransport.
  • It is parameterized only by the transport constructor: StreamableHTTPClientTransport for HTTP/Websocket and SSEClientTransport for SSE.
  • Preserves error text ("${connection.connection_type} connection missing URL"), header-building semantics, composition order, and ctx.getOrCreateClient usage.
  • Review focus: confirm the helper mirrors the removed blocks, especially header merge order, SSE error string, and passing connectionId and virtualMcpId to MonitoringTransport.

Written for commit 05d8c2d. Summary will update on new commits.

Review in cubic

The HTTP/Websocket and SSE cases in createOutboundClient built headers,
validated the connection URL, constructed the transport, and composed
auth+monitoring transports in three near-identical blocks. Extract the
shared logic into buildHttpLikeTransport, parameterized only by the
transport constructor.

Behavior-preserving: same error message (`${connection.connection_type} connection missing URL`, which was already the literal text for SSE), same header building, same transport composition order, same getOrCreateClient call.

Net: -54/+51 lines, collapsing the duplication down to one shared helper.
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.

1 participant