refactor(mcp-clients): dedupe HTTP/Websocket and SSE transport setup - #6136
Open
pedrofrxncx wants to merge 1 commit into
Open
refactor(mcp-clients): dedupe HTTP/Websocket and SSE transport setup#6136pedrofrxncx wants to merge 1 commit into
pedrofrxncx wants to merge 1 commit into
Conversation
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.
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.
Follows issue #4468 (simplify the MCP-mesh machinery).
createOutboundClientinapps/api/src/mcp-clients/outbound/index.tshad three near-identical blocks for the HTTP, Websocket, and SSE connection types: validateconnection_url, build request headers, merge any custom headers, construct the transport, then compose it withAuthTransport+MonitoringTransport. Only the transport constructor (StreamableHTTPClientTransportvsSSEClientTransport) differed. Extracted the shared steps into onebuildHttpLikeTransport(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, sinceconnection.connection_typeis"SSE"in that branch, so the template produces the identical text. Header building, transport composition order (AuthTransportthenMonitoringTransport), and the finalctx.getOrCreateClientcall 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 isolatingcreateOutboundClient(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.
Written for commit 05d8c2d. Summary will update on new commits.