The HTTP handlers in internal/api (servers.go, tools.go, prompts.go, resources.go) are free functions that each re-declare the shared dependencies they need — contracts.MCPClientAccessor on every server handler, MCPHealthMonitor on the health handlers, and now the tool-call timeout.
Those dependencies are pass-through variables. accessor and the RouteOptions are threaded through registration layers that never use them, only to hand them to the leaf:
RegisterRoutes(…clientManager, opts)
└─ RegisterServerRoutes(…accessor, options)
└─ RegisterToolRoutes(…accessor, options)
└─ handleServerToolCall(ctx, accessor, server, tool, data, options.ToolCallTimeout)
The visible symptom is handleServerToolCall, which grew from 4 to 6 parameters in #262 when ctx and timeout were added. The parameter count is the symptom; the pass-through threading and the shallow handler signatures are the underlying issue.
Proposed change
Introduce a handler type that holds the shared dependencies and config as fields, and convert the handlers to methods that take only per-call inputs:
type serverRoutes struct {
accessor contracts.MCPClientAccessor
toolCallTimeout time.Duration
}
func (s *serverRoutes) toolCall(ctx context.Context, server, tool string, args map[string]any) (*ToolCallResponse, error)
Registration constructs the struct once; the Register* functions stop threading accessor/options; each handler's signature narrows to what genuinely varies per call.
Scope
Do it consistently across the server handler family (servers.go, tools.go, prompts.go, resources.go) and the Register* signatures — a mix of free functions and methods would be worse than either. The health handlers (health.go) follow the same shape with MCPHealthMonitor and can move at the same time.
The HTTP handlers in
internal/api(servers.go,tools.go,prompts.go,resources.go) are free functions that each re-declare the shared dependencies they need —contracts.MCPClientAccessoron every server handler,MCPHealthMonitoron the health handlers, and now the tool-call timeout.Those dependencies are pass-through variables.
accessorand theRouteOptionsare threaded through registration layers that never use them, only to hand them to the leaf:The visible symptom is
handleServerToolCall, which grew from 4 to 6 parameters in #262 whenctxandtimeoutwere added. The parameter count is the symptom; the pass-through threading and the shallow handler signatures are the underlying issue.Proposed change
Introduce a handler type that holds the shared dependencies and config as fields, and convert the handlers to methods that take only per-call inputs:
Registration constructs the struct once; the
Register*functions stop threadingaccessor/options; each handler's signature narrows to what genuinely varies per call.Scope
Do it consistently across the server handler family (
servers.go,tools.go,prompts.go,resources.go) and theRegister*signatures — a mix of free functions and methods would be worse than either. The health handlers (health.go) follow the same shape withMCPHealthMonitorand can move at the same time.