-
Notifications
You must be signed in to change notification settings - Fork 6
feat: refactor backend architecture with interface pattern and trusted proxy support #72
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: refactor backend architecture with interface pattern and trusted proxy support #72
Conversation
…d proxy support - Extract backend interface for better separation of concerns - Split monolithic backend.go into separate proxy and transparent backends - Add trusted proxy configuration support with IP/CIDR validation - Implement transparent backend for HTTP/HTTPS proxy targets - Add comprehensive test coverage for new backend implementations - Maintain backward compatibility with existing proxy functionality
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Uncommented the SetTrustedProxies call to properly configure trusted proxies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors the backend architecture to introduce an interface pattern for better abstraction and adds trusted proxy support for enhanced security when running behind reverse proxies. The changes maintain backward compatibility while providing better separation of concerns.
- Extracted a
Backendinterface to abstract proxy implementations - Split the monolithic backend into separate proxy and transparent implementations
- Added trusted proxy configuration with IP/CIDR validation for secure header handling
Reviewed Changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| pkg/backend/interface.go | Defines the new Backend interface with Run, Wait, and Close methods |
| pkg/backend/proxy.go | Updates ProxyBackend to implement the Backend interface |
| pkg/backend/transparent.go | New TransparentBackend implementation for HTTP/HTTPS proxying with trusted proxy support |
| pkg/backend/transparent_test.go | Comprehensive test coverage for the transparent backend functionality |
| pkg/backend/proxy_test.go | Enhanced test coverage for proxy backend context handling |
| pkg/backend/main_test.go | Test setup configuration for the backend package |
| pkg/mcp-proxy/main.go | Integration of trusted proxy support and backend interface usage |
| main.go | Command-line flag addition for trusted proxy configuration |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| if p.ctx == nil { | ||
| return nil | ||
| } | ||
| <-p.ctx.Done() |
Copilot
AI
Aug 24, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The Wait() method accesses p.ctx without proper synchronization. Consider using the ctxLock mutex to safely read p.ctx, similar to how it's protected in the Run() method.
| if p.ctx == nil { | |
| return nil | |
| } | |
| <-p.ctx.Done() | |
| p.ctxLock.Lock() | |
| ctx := p.ctx | |
| p.ctxLock.Unlock() | |
| if ctx == nil { | |
| return nil | |
| } | |
| <-ctx.Done() |
Summary
This PR refactors the backend architecture to use an interface pattern, providing better separation of concerns and extensibility. It introduces trusted proxy support for enhanced security when running behind reverse proxies.
Type of Change
Related Issues
Changes Made
Backendinterface for better abstractionbackend.gointo separate implementations:proxy.go: Handles MCP server execution and proxyingtransparent.go: Handles HTTP/HTTPS URL proxying with trusted proxy supportTesting