Conversation
… misplaced server helpers Co-authored-by: lpcox <15877973+lpcox@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR performs a clean refactoring to improve code organization by splitting files based on functional concerns and relocating misplaced helper functions. The refactoring reduces internal/mcp/connection.go from 973 to 492 lines by extracting HTTP transport logic into a new dedicated file, and consolidates authentication and logging helpers in internal/server/ into their semantically appropriate locations.
Changes:
- Split
internal/mcp/connection.goby extracting HTTP transport negotiation (~496 lines) into newinternal/mcp/http_transport.go - Moved
applyAuthIfConfiguredfromserver/transport.gotoserver/auth.go(alongsideauthMiddleware) - Moved
withResponseLoggingfromserver/transport.gotoserver/http_helpers.go(alongside other HTTP helpers)
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| internal/mcp/http_transport.go | New file containing HTTP transport layer: transport type negotiation, request lifecycle helpers, SSE parsing, and supporting types (HTTPTransportType, httpRequestResult, etc.) |
| internal/mcp/connection.go | Reduced from 973→492 lines; now focused on core MCP session management (Connection struct, NewConnection, SendRequest methods, SDK dispatch) |
| internal/server/transport.go | Removed misplaced helpers; now contains only HTTPTransport SDK adapter and CreateHTTPServerForMCP |
| internal/server/http_helpers.go | Added withResponseLogging function (moved from transport.go) alongside other HTTP helper functions |
| internal/server/auth.go | Added applyAuthIfConfigured function (moved from transport.go) alongside authMiddleware |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
GitHub MCP: ✅
|
connection.go(973 lines) mixed core MCP session management with HTTP transport negotiation. Two helpers inserver/transport.gobelonged in other files.Changes
internal/mcp/— split by concernhttp_transport.go(~496 lines): transport type negotiation (tryStreamableHTTPTransport,trySSETransport,tryPlainJSONTransport,trySDKTransport), request lifecycle helpers (setupHTTPRequest,executeHTTPRequest,initializeHTTPSession,sendHTTPRequest), parsing utilities (parseSSEResponse,parseJSONRPCResponseWithSSE), and supporting types/vars (HTTPTransportType,httpRequestResult,transportConnector,requestIDCounter)connection.goreduced from 973 → 492 lines; now contains onlyConnectionstruct,NewConnection/NewHTTPConnection,SendRequest*, SDK method dispatch, andCloseinternal/server/— relocate misplaced helpersapplyAuthIfConfiguredfromtransport.go→auth.go(alongsideauthMiddleware)withResponseLoggingfromtransport.go→http_helpers.go(alongsidewrapWithMiddleware,logHTTPRequestBody)transport.gonow contains onlyHTTPTransportSDK adapter andCreateHTTPServerForMCPAll moves are within-package reorganizations; no logic changes.
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
example.com/tmp/go-build80772430/b284/launcher.test /tmp/go-build80772430/b284/launcher.test -test.testlogfile=/tmp/go-build80772430/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a MQ_U/XgBWM_timxeqS5QdMQ_U x_amd64/vet OUTPUT -d 168.63.129.16 x_amd64/vet 6728�� lang.org/x/sys/cpu/cpu_gc_x86.s ache/go/1.25.6/x64/src/internal/testlog/exit.go x_amd64/vet INVALID,NEW -j DROP x_amd64/vet(dns block)invalid-host-that-does-not-exist-12345.com/tmp/go-build80772430/b266/config.test /tmp/go-build80772430/b266/config.test -test.testlogfile=/tmp/go-build80772430/b266/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true aCJj/o1rujB_p3NGFKnssaCJj 83FPnLSVe x_amd64/vet(dns block)nonexistent.local/tmp/go-build80772430/b284/launcher.test /tmp/go-build80772430/b284/launcher.test -test.testlogfile=/tmp/go-build80772430/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a MQ_U/XgBWM_timxeqS5QdMQ_U x_amd64/vet OUTPUT -d 168.63.129.16 x_amd64/vet 6728�� lang.org/x/sys/cpu/cpu_gc_x86.s ache/go/1.25.6/x64/src/internal/testlog/exit.go x_amd64/vet INVALID,NEW -j DROP x_amd64/vet(dns block)slow.example.com/tmp/go-build80772430/b284/launcher.test /tmp/go-build80772430/b284/launcher.test -test.testlogfile=/tmp/go-build80772430/b284/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true g_.a MQ_U/XgBWM_timxeqS5QdMQ_U x_amd64/vet OUTPUT -d 168.63.129.16 x_amd64/vet 6728�� lang.org/x/sys/cpu/cpu_gc_x86.s ache/go/1.25.6/x64/src/internal/testlog/exit.go x_amd64/vet INVALID,NEW -j DROP x_amd64/vet(dns block)this-host-does-not-exist-12345.com/tmp/go-build2273372946/b225/mcp.test /tmp/go-build2273372946/b225/mcp.test -test.testlogfile=/tmp/go-build2273372946/b225/testlog.txt -test.paniconexit0 -test.timeout=10m0s conf�� go user.name bin/git(dns block)/tmp/go-build80772430/b293/mcp.test /tmp/go-build80772430/b293/mcp.test -test.testlogfile=/tmp/go-build80772430/b293/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true 64/src/net ternal/fips140/hkdf/cast.go x_amd64/vet(dns block)If you need me to access, download, or install something from one of these locations, you can either:
Original prompt
This section details on the original issue you should resolve
<issue_title>[refactor] Semantic Function Clustering Analysis: Refactoring Opportunities</issue_title>
<issue_description>## Overview
Automated semantic function clustering analysis of 67 non-test Go source files (428 functions) across 16 packages in
internal/. The analysis identified two primary refactoring opportunities with medium-to-high impact: functions placed in files where they don't logically belong, and a large file with mixed concerns that warrants a split. Additionally, two cases of semantically similar (near-duplicate) functions were found.Overall code organization is healthy — packages are well-structured, naming is consistent, and the logger package's documented intentional patterns are recognized as such.
Full Report
Function Inventory
authcmdconfigdifcdockerutilenvutilguardlauncherloggermcpconnection.gois oversized — see belowmiddlewareserverstrutilsysttyversionIdentified Issues
1. 🔴
internal/mcp/connection.goHas Two Distinct Concerns (973 lines, 33 functions)Issue:
connection.goconflates MCP session/operation management with HTTP transport negotiation. The file has grown to 973 lines because it handles two separate responsibilities:Concern A — MCP session operations (correct location):
NewConnection,NewHTTPConnectionSendRequest,SendRequestWithServerIDlistTools,callTool,listResources,readResource,listPrompts,getPromptrequireSession,Close,IsHTTP,GetHTTPURL,GetHTTPHeadersConcern B — HTTP transport negotiation (candidates for extraction):
trySDKTransport,tryStreamableHTTPTransport,trySSETransport,tryPlainJSONTransportsetupHTTPRequest,executeHTTPRequest,initializeHTTPSession,sendHTTPRequestparseSSEResponse,parseJSONRPCResponseWithSSEnewMCPClient,newHTTPConnection,isHTTPConnectionErrorRecommendation: Extract the HTTP transport negotiation functions into
internal/mcp/http_transport.go. This follows the same pattern already established ininternal/server/where transport concerns live intransport.go.Estimated effort: 1–2 hours (pure file split, no logic changes)
Estimated impact: Significantly improved navigability;
connection.gobecomes focused on what developers expect to find there2. 🟡
internal/server/transport.goContains Auth and Logging Helpers That Belong ElsewhereIssue:
transport.gois primarily responsible for theHTTPTransportSDK adapter struct andCreateHTTPServerForMCP. However, it also defines two middleware helpers that are out of place:applyAuthIfConfigured(line 61 intransport.go)This is an auth helper that wraps
authMiddlewarefromauth.go. It is called fromhandlers.goandhttp_helpers.go— not from anything transport-specific. It belongs inauth.gonext toauthMiddleware.withResponseLogging(line 48 intransport.go)This is an HTTP response logging middleware used in
handlers.go(for/health,/close, OAuth discovery endpoints). It belongs inhttp_helpers.goalongsidewrapWithMiddlewareandlogHTTPRequestBody, or inhandlers.gosince it's only used there.Recommendation:
applyAuthIfConfigured→internal/server/auth.gowithResponseLogging→internal/server/http_helpers.goEstimated effort: 30 minutes (two function moves, same package — no import changes needed)
Estimated impact:
transport.gobecomes purely about theHTTPTransportSDK adapter; auth functions are consolidated inauth.go3. 🟢 Near-Duplicate:
auth.TruncateSessionIDvssanitize.TruncateSecretIssue: Two similar truncation functions exist for se...
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.