Skip to content

Refactor: Split connection.go into focused, maintainable files#291

Merged
Dumbris merged 1 commit intomainfrom
refactor/split-connection-file
Feb 2, 2026
Merged

Refactor: Split connection.go into focused, maintainable files#291
Dumbris merged 1 commit intomainfrom
refactor/split-connection-file

Conversation

@Dumbris
Copy link
Contributor

@Dumbris Dumbris commented Feb 2, 2026

Summary

Refactors the massive 3,587-line connection.go file into 7 focused, maintainable files, achieving a 92% reduction in the main file size while maintaining 100% test coverage and zero breaking changes.

Fixes #273

Changes

File Structure

File Lines Purpose
connection.go 275 (-92%) Main Connect() dispatcher, core types
connection_browser.go 95 Browser launching, GUI detection
connection_docker.go 145 Docker isolation setup and helpers
connection_stdio.go 451 Stdio transport and command building
connection_http.go 314 HTTP/SSE transports and auth strategies
connection_oauth.go 2,189 All OAuth flows and error handling
connection_lifecycle.go 243 Initialization and disconnect logic
Total 3,712

Key Improvements

  • Maintainability: Each file has a single, clear responsibility
  • Readability: Functions are grouped logically, easier to navigate
  • Testability: Related code is colocated with its tests
  • Scalability: Future changes can target specific files
  • No Breaking Changes: All public APIs preserved

Dependency Hierarchy

connection.go (dispatcher)
    ├─→ connection_stdio.go
    │       └─→ connection_docker.go
    ├─→ connection_http.go
    │       └─→ connection_oauth.go
    │               └─→ connection_browser.go
    └─→ connection_lifecycle.go

Testing

✅ All unit tests pass (100+ tests)
✅ Race detection clean (go test -race)
✅ Linter passes with no errors
✅ OAuth E2E tests pass
✅ No circular dependencies

Commits

Each phase of the extraction was committed separately for reviewability:

  1. Extract browser utilities (95 lines)
  2. Extract Docker isolation (145 lines)
  3. Extract stdio transport (451 lines)
  4. Extract OAuth flows (2,189 lines)
  5. Extract HTTP/SSE transport (314 lines)
  6. Extract lifecycle functions (243 lines)
  7. Final verification and documentation

Review Notes

  • All OAuth state fields remain in Client struct (in client.go)
  • No changes to function signatures or behavior
  • Test files remain in same package with full access
  • Constants are preserved in appropriate files

@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Feb 2, 2026

Deploying mcpproxy-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 384cc31
Status: ✅  Deploy successful!
Preview URL: https://40a87fa4.mcpproxy-docs.pages.dev
Branch Preview URL: https://refactor-split-connection-fi.mcpproxy-docs.pages.dev

View logs

Fixes #273

Split the massive 3,587-line connection.go into 7 focused, maintainable files:

- connection.go (275 lines) - Main Connect() dispatcher, core types
- connection_browser.go (95 lines) - Browser launching, GUI detection
- connection_docker.go (145 lines) - Docker isolation setup and helpers
- connection_stdio.go (451 lines) - Stdio transport and command building
- connection_http.go (314 lines) - HTTP/SSE transports and auth strategies
- connection_oauth.go (2,189 lines) - All OAuth flows and error handling
- connection_lifecycle.go (243 lines) - Initialization and disconnect logic

Key achievements:
- 92% reduction in main file size (3,587 → 275 lines)
- 100% test pass rate - All tests pass
- No race conditions - go test -race passes
- No linter errors - Clean code quality
- No breaking changes - All public APIs preserved
- No circular dependencies - Clean dependency flow

Testing verified:
- All unit tests pass (100+ tests)
- Race detection clean
- Linter passes
- OAuth tests pass
- No circular dependencies
@Dumbris Dumbris force-pushed the refactor/split-connection-file branch from 2f2f00e to 384cc31 Compare February 2, 2026 07:15
@github-actions
Copy link

github-actions bot commented Feb 2, 2026

📦 Build Artifacts

Workflow Run: View Run
Branch: refactor/split-connection-file

Available Artifacts

  • archive-darwin-amd64 (23 MB)
  • archive-darwin-arm64 (21 MB)
  • archive-linux-amd64 (12 MB)
  • archive-linux-arm64 (11 MB)
  • archive-windows-amd64 (23 MB)
  • archive-windows-arm64 (21 MB)
  • frontend-dist-pr (0 MB)
  • installer-dmg-darwin-amd64 (26 MB)
  • installer-dmg-darwin-arm64 (23 MB)

How to Download

Option 1: GitHub Web UI (easiest)

  1. Go to the workflow run page linked above
  2. Scroll to the bottom "Artifacts" section
  3. Click on the artifact you want to download

Option 2: GitHub CLI

gh run download 21580829458 --repo smart-mcp-proxy/mcpproxy-go

Note: Artifacts expire in 14 days.

@Dumbris Dumbris merged commit aabcbc9 into main Feb 2, 2026
23 checks passed
@Dumbris Dumbris deleted the refactor/split-connection-file branch February 2, 2026 13:06
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.

internal/upstream/core/connection.go: File content (34031 tokens) exceeds maximum allowed tokens (25000)

1 participant