Skip to content

refactor: split oversized files by responsibility (mcp/connection, proxy/handler, httputil) - #4701

Merged
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering
Apr 28, 2026
Merged

refactor: split oversized files by responsibility (mcp/connection, proxy/handler, httputil)#4701
lpcox merged 3 commits into
mainfrom
copilot/refactor-semantic-function-clustering

Conversation

Copilot AI commented Apr 28, 2026

Copy link
Copy Markdown
Contributor

Three files had grown beyond single-responsibility: mcp/connection.go (749 lines, 4 distinct concerns), proxy/handler.go (618 lines, HTTP dispatch mixed with JSON transforms), and httputil/httputil.go (generic utilities mixed with GitHub-specific helpers). Pure mechanical splits — zero logic changes.

internal/mcp/connection.go → 4 files

File Responsibility
connection.go Lifecycle: NewConnection, NewHTTPConnection, Close, reconnect*, SendRequest*
connection_methods.go RPC dispatch: callSDKMethod, listTools, callTool, listResources, readResource, listPrompts, getPrompt
connection_logging.go RPC logging: logOutboundRPCRequest, logInboundRPC*, logReconnect*
pagination.go Generic helpers: paginateAll, listMCPItems, marshalToResponse, unmarshalParams, callParamMethod

internal/proxy/handler.go → new response_transform.go

Extracted 5 pure data-manipulation utilities that had no business sitting in the HTTP handler layer:

// response_transform.go
func deepCloneJSON(v interface{}) interface{}
func rewrapSearchResponse(originalData, filteredItems interface{}) interface{}
func unwrapSingleObject(originalData, filteredData interface{}) interface{}
func replaceNodesArray(v interface{}, items []interface{}) bool
func rebuildGraphQLResponse(originalData interface{}, filtered *difc.FilteredCollectionLabeledData) interface{}

internal/httputil/httputil.go → new github_http.go

Follows the existing envutil/github.go pattern — GitHub-specific helpers extracted to a dedicated file:

httputil.go       ← WriteJSONResponse, IsTransientHTTPError
github_http.go    ← GitHubUserAgent, ApplyGitHubAPIHeaders, ParseRateLimitResetHeader

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
    • Triggering command: /tmp/go-build864305169/b509/launcher.test /tmp/go-build864305169/b509/launcher.test -test.testlogfile=/tmp/go-build864305169/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.9/x64/src/runtime/c--gdwarf-5 8J3C/BnJLWL_dWV6lGp5L8J3C x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build1786442162/b513/launcher.test /tmp/go-build1786442162/b513/launcher.test -test.testlogfile=/tmp/go-build1786442162/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s (dns block)
  • invalid-host-that-does-not-exist-12345.com
    • Triggering command: /tmp/go-build864305169/b491/config.test /tmp/go-build864305169/b491/config.test -test.testlogfile=/tmp/go-build864305169/b491/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true rnal/descopts/op-errorsas ache/go/1.25.9/x-ifaceassert x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build1786442162/b495/config.test /tmp/go-build1786442162/b495/config.test -test.testlogfile=/tmp/go-build1786442162/b495/testlog.txt -test.paniconexit0 -test.timeout=10m0s (dns block)
  • nonexistent.local
    • Triggering command: /tmp/go-build864305169/b509/launcher.test /tmp/go-build864305169/b509/launcher.test -test.testlogfile=/tmp/go-build864305169/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.9/x64/src/runtime/c--gdwarf-5 8J3C/BnJLWL_dWV6lGp5L8J3C x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build1786442162/b513/launcher.test /tmp/go-build1786442162/b513/launcher.test -test.testlogfile=/tmp/go-build1786442162/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s (dns block)
  • slow.example.com
    • Triggering command: /tmp/go-build864305169/b509/launcher.test /tmp/go-build864305169/b509/launcher.test -test.testlogfile=/tmp/go-build864305169/b509/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true ache/go/1.25.9/x64/src/runtime/c--gdwarf-5 8J3C/BnJLWL_dWV6lGp5L8J3C x_amd64/compile (dns block)
    • Triggering command: /tmp/go-build1786442162/b513/launcher.test /tmp/go-build1786442162/b513/launcher.test -test.testlogfile=/tmp/go-build1786442162/b513/testlog.txt -test.paniconexit0 -test.timeout=10m0s (dns block)
  • this-host-does-not-exist-12345.com
    • Triggering command: /tmp/go-build864305169/b518/mcp.test /tmp/go-build864305169/b518/mcp.test -test.testlogfile=/tmp/go-build864305169/b518/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -quiet 649241/b151/ x_amd64/vet -I . -imultiarch x_amd64/vet 6492�� 1.80.0/balancer/balancer.go 1.80.0/balancer/conn_state_evalu-nolocalimports x_amd64/vet --gdwarf-5 --64 -o jk0CHzx/dUnZUsTpJceORqTvO77n (dns block)
    • Triggering command: /tmp/go-build1786442162/b522/mcp.test /tmp/go-build1786442162/b522/mcp.test -test.testlogfile=/tmp/go-build1786442162/b522/testlog.txt -test.paniconexit0 -test.timeout=10m0s -o /tmp/go-build175649241/b461/_pkg-p -trimpath x_amd64/vet -p github.com/githu/usr/bin/runc -lang=go1.25 x_amd64/vet -uns�� -unreachable=false /tmp/go-build864305169/b035/vet.-nolocalimports x_amd64/vet -c=4 -nolocalimports -importcfg x_amd64/vet (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot AI changed the title [WIP] Refactor semantic function clustering analysis based on identified opportunities refactor: split oversized files by responsibility (mcp/connection, proxy/handler, httputil) Apr 28, 2026
Copilot AI requested a review from lpcox April 28, 2026 02:03
@lpcox
lpcox marked this pull request as ready for review April 28, 2026 02:54
Copilot AI review requested due to automatic review settings April 28, 2026 02:54

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Refactors oversized internal packages by splitting mixed-responsibility Go files into smaller units (MCP connection/pagination/logging, proxy response transforms, and GitHub-specific HTTP utilities) while keeping behavior the same.

Changes:

  • Split internal/mcp/connection.go into dedicated files for SDK method dispatch, RPC logging, and pagination/helpers.
  • Extract proxy JSON response transformation helpers from handler.go into response_transform.go.
  • Extract GitHub-specific HTTP helpers from httputil.go into github_http.go.
Show a summary per file
File Description
internal/mcp/connection.go Removes logging/SDK dispatch/pagination helpers that were moved into dedicated files.
internal/mcp/connection_methods.go New file containing SDK RPC method dispatch and list/call/read wrappers.
internal/mcp/connection_logging.go New file containing reconnect + RPC request/response logging helpers.
internal/mcp/pagination.go New file containing shared marshal/unmarshal helpers and pagination utilities.
internal/proxy/handler.go Removes response-shape transformation helpers now living outside the HTTP handler.
internal/proxy/response_transform.go New file containing JSON response transformation + deep-clone helpers.
internal/httputil/httputil.go Keeps generic HTTP helpers; removes GitHub-specific helpers.
internal/httputil/github_http.go New file containing GitHub-specific headers + rate limit reset parsing.

Copilot's findings

Tip

Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

  • Files reviewed: 8/8 changed files
  • Comments generated: 1

Comment thread internal/mcp/connection_methods.go Outdated
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@lpcox
lpcox merged commit daf15b6 into main Apr 28, 2026
16 checks passed
@lpcox
lpcox deleted the copilot/refactor-semantic-function-clustering branch April 28, 2026 03:40
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.

[refactor] Semantic Function Clustering Analysis — Refactoring Opportunities

3 participants