Refactor duplicated MCP handler config setup in transport and routed server paths#6753
Merged
Merged
Conversation
Closed
6 tasks
Copilot
AI
changed the title
[WIP] Refactor duplicate buildMCPHandler setup in transport.go and routed.go
Refactor duplicated MCP handler config setup in transport and routed server paths
May 30, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR refactors MCP HTTP server setup by centralizing construction of the common mcpHandlerConfig used by both unified (transport) and routed server modes, reducing duplicated config wiring in multiple call paths.
Changes:
- Added
buildDefaultHandlerConfig(...)to construct sharedmcpHandlerConfigfields in one place. - Updated unified and routed server creation paths to use the new helper.
- Added a focused unit test to validate config field mapping.
Show a summary per file
| File | Description |
|---|---|
| internal/server/transport.go | Replaces inline mcpHandlerConfig{...} construction with buildDefaultHandlerConfig(...) for unified mode. |
| internal/server/routed.go | Replaces inline mcpHandlerConfig{...} construction with buildDefaultHandlerConfig(...) per backend in routed mode. |
| internal/server/middleware.go | Introduces the shared buildDefaultHandlerConfig(...) helper that returns an mcpHandlerConfig. |
| internal/server/middleware_test.go | Adds TestBuildDefaultHandlerConfig to assert field mapping from helper inputs to config fields. |
Copilot's findings
Tip
Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Files reviewed: 4/4 changed files
- Comments generated: 1
Comment on lines
+34
to
+42
| func buildDefaultHandlerConfig(unifiedServer *UnifiedServer, apiKey, hmacSecret string, sessionTimeout time.Duration, handlerLog *logger.Logger, logTag string) mcpHandlerConfig { | ||
| return mcpHandlerConfig{ | ||
| handlerLog: handlerLog, | ||
| sessionTimeout: sessionTimeout, | ||
| logTag: logTag, | ||
| unifiedServer: unifiedServer, | ||
| apiKey: apiKey, | ||
| hmacSecret: hmacSecret, | ||
| } |
Collaborator
|
@copilot address review feedback |
Contributor
Author
Addressed in commit |
This was referenced May 30, 2026
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.
CreateHTTPServerForMCPandCreateHTTPServerForRoutedModewere each assembling nearly identicalmcpHandlerConfigvalues before callingbuildMCPHandler, creating a small but recurring maintenance seam. This change centralizes that shared config construction while preserving the per-mode server-factory behavior.Shared config construction
buildDefaultHandlerConfig(...)ininternal/server/middleware.goto build the commonmcpHandlerConfigfields (sessionTimeout,unifiedServer) plus caller-provided options (handlerLog,logTag,apiKey,hmacSecret).defaultHandlerConfigOptionsso string fields are passed by name instead of positional arguments.Call-site deduplication
internal/server/transport.goto use the helper for unified mode (logTag: "unified").internal/server/routed.goto use the helper inside the backend loop (logTag: "routed:"+backendID).Focused coverage
TestBuildDefaultHandlerConfigininternal/server/middleware_test.goto validate field mapping and keep future config-field additions centralized.