Repository navigation
Description
Description
Introduce deriveCoreConfig and deriveServerConfig to split the in-memory-only
server.Config into the core Config (collaborators + workflowDefs + Authz for the
admission seam + the cross-cutting TelemetryProvider/AuditConfig) and a transport-only
ServerConfig. This is the first half of RFC Phase 3 (the config decomposition); it sets up
the data shapes that #5445 then feeds into the Serve(ctx, New(deriveCoreConfig(cfg, …)), deriveServerConfig(cfg)) wrapper. ServerConfig carries no AuthzMiddleware field
(authz now lives in the core admission seam from Phase 1). The AuthzMiddleware field on
server.Config itself is kept (not removed in this epic): cli/serve.go sets it at
serve.go:~374, and the "cli/serve.go unchanged" constraint forbids touching that
assignment — so the field stays as a vestigial input the new path ignores.
deriveServerConfig simply omits it; the core admission seam derives its authorizer from
the Authz config instead. (The now-redundant HTTP authz/annotation blocks are deleted
as cleanup in #5445 once server.New routes through Serve — but the field itself
remains, so cli/serve.go needs no change.)
Context
By the time this task runs, Phase 1 has produced the VMCP core (New(cfg) -> VMCP with the
admission and elicitation seams) and Phase 2 has re-homed every transport concern under
Serve(ctx, VMCP, *ServerConfig) -> *Server — but server.New does not yet call Serve.
This task adds the two derivation helpers that map the existing single server.Config onto
the core/transport pair, without changing server.New's body or observable behavior yet
(that is #5445/P3.2).
The split is not a clean partition (Risk R3, architecture.md lines 483-487): the
cross-cutting fields TelemetryProvider, AuditConfig, and the health view are consumed on
both sides — the core decorates the backend client with telemetry and runs the workflow
auditor; the transport adds telemetry/audit middleware and owns the health monitor — so they
are passed to both deriveCoreConfig and deriveServerConfig. The field-by-field
placement is given in the research.md Config table (lines 144-167) and architecture.md
"ServerConfig" (lines 243-274). This is an in-memory-only change: vmcpconfig.Config, the
CRD/YAML model, and the wire/storage format are all unchanged inputs to New.
Parent Story: #5432
Dependencies: #5439, #5440, #5441, #5442, #5443 (all of Phase 2 complete — the ServerConfig type and the relocated transport wiring must exist)
Blocks: #5445
Acceptance Criteria
-
deriveCoreConfig(cfg, …)andderiveServerConfig(cfg)produce, respectively, the core
Configand the transportServerConfigfrom the existingserver.Config. - The core
Configcarries the collaborators (aggregator/router/backendClient/
backendRegistry/discovery, relocated fromserver.Newparams),workflowDefs, and the
Authzconfig for the admission seam. - The cross-cutting fields
TelemetryProvider,AuditConfig, and the health view are
populated on both the coreConfigand theServerConfig(not a clean partition, R3). - All transport-only fields (
Host,Port,EndpointPath,SessionTTL,
AuthMiddleware,AuthInfoHandler,AuthServer,StatusReportingInterval,Watcher,
StatusReporter,SessionFactory,SessionStorage,OptimizerFactory,
OptimizerConfig) land onServerConfig. - Health monitor (A2): the monitor is built at the composition root (P3.2 Reduce server.New body to the wrapper #5445) from
HealthMonitorConfig;deriveServerConfigplaces the built*health.Monitoron
ServerConfig.HealthMonitor(lifecycle) andderiveCoreConfigplaces the same instance's
health.StatusProvideron the coreConfig(filtering).HealthMonitorConfigis consumed
at the root, not carried verbatim ontoServerConfig. -
ServerConfigcarries noAuthzMiddlewarefield (authz lives in the core admission
seam). TheAuthzMiddlewarefield onserver.Configis kept (not removed in this
epic):cli/serve.gostill sets it and must stay unchanged, so it remains a vestigial input
the new path ignores (deriveServerConfigomits it; the core seam uses theAuthzconfig).
Only the redundant HTTP authz/annotation blocks are deleted later (P3.2 Reduce server.New body to the wrapper #5445). - No serialized/wire/CRD/YAML format change — the change is in-memory only;
vmcpconfig.Configis unchanged. - PR is ≤ 400 LOC and ≤ 10 files changed (excluding tests/docs/generated)
-
server.Newsignature and observable behavior unchanged - All tests pass (
task test); lint clean (task lint-fix) - Code reviewed and approved
Technical Approach
Recommended Implementation
Add two unexported derivation helpers in pkg/vmcp/server (alongside New/Serve):
deriveServerConfig(cfg *Config) *ServerConfig— a pure projection of the transport-only
fields out of the existingserver.Config, plus the two cross-cutting fields. Per the
go-style "Copy Before Mutating Caller Input" rule, treatcfgas read-only and construct a
freshServerConfig; do not mutatecfg.deriveCoreConfig(cfg *Config, …)— assembles the coreConfigfrom the cross-cutting
fields oncfg(TelemetryProvider,AuditConfig, health view), theAuthzconfig that
feeds the admission seam,workflowDefs, and the collaborators that today arrive as
separateserver.Newparameters (router, backendClient, discovery manager, backendRegistry,
aggregator). The exact extra parameters mirror theNewcore constructor signature
established in Phase 1 — pass the collaborators through rather than reaching back into
cfg.
Keep the defaulting logic that server.New applies today (Host/EndpointPath/Name/
Version/SessionTTL at server.go:310-327) flowing into the derived configs so that derived
values are post-default — either derive after defaults are applied, or apply the same defaults
inside the helpers.
Do not remove the AuthzMiddleware field from server.Config — in this task or any
other. cli/serve.go (the composition root, serve.go:~374) assigns it, and the
"cli/serve.go unchanged" constraint forbids editing that assignment, so the field stays as a
vestigial input the new path ignores. deriveServerConfig simply does not propagate
AuthzMiddleware onto ServerConfig (which never had the field); the core admission seam
derives its authorizer from the Authz config instead. The two consumer blocks
(server.go:606-609, :611-617) still run on the legacy server.New path in this task
(#5441 left them inert only on the Serve path); they become dead and are deleted in
#5445 once server.New routes through Serve — the field itself remains.
For A2, the health monitor is built at the composition root (in #5445's wrapper, or a test
harness), so the derivers receive the built *health.Monitor and thread it: the *Monitor
onto ServerConfig.HealthMonitor (lifecycle, owned by Serve) and its StatusProvider onto
the core Config (filtering). The derivers do not call health.NewMonitor themselves.
This task only introduces the helpers and the field move; it does not yet rewire
server.New's body to call them through Serve (that is #5445). Wire the helpers so they
can be unit-tested in isolation against a representative server.Config.
Patterns & Frameworks
- Decompose the top-level config at the composition root into small, focused config types —
the core takes only what it needs, the transport takes only what it needs (counters
anti-pattern Figure out ergonomics for exposing directories #6, "Configuration Object Passed Everywhere"). The cross-cutting overlap is the
documented R3 exception. - Routing authz through the core admission seam (and deleting the dead HTTP authz/annotation
blocks in P3.2 Reduce server.New body to the wrapper #5445 — theAuthzMiddlewarefield onserver.Configis kept vestigial)
avoids "middleware overuse" (anti-pattern Implement secret store #4) and keeps the SDK/transport boundary clean
(anti-pattern Implement secret injection #5). - Treat
cfgas read-only; build fresh derived structs (.claude/rules/go-style.md"Copy
Before Mutating Caller Input"). - Avoid parallel types that drift:
ServerConfigalready exists from P2.1 Serve skeleton + ServerConfig #5439; reuse it
rather than defining a second transport config (.claude/rules/go-style.md"Interface
Design"). - stdlib
testing.T+ testify inpkg/vmcp/server; no Ginkgo. SPDX header on any new.go
file. - Conventions:
.claude/rules/go-style.md,.claude/rules/vmcp-anti-patterns.md,
.claude/rules/security.md.
Code Pointers
pkg/vmcp/server/server.go:92-185— theConfigstruct being split. Field-by-field
placement is inresearch.md(lines 144-167) andarchitecture.md"ServerConfig"
(lines 243-274).pkg/vmcp/server/server.go:121-125—AuthzMiddleware func(http.Handler) http.Handler;
kept, not removed (in this task or any other) —cli/serve.gosets it and must stay
unchanged, so it remains a vestigial input.deriveServerConfigomits it; the core seam
uses theAuthzconfig instead.pkg/vmcp/server/server.go:606-609,:611-617— the twos.config.AuthzMiddleware
consumer blocks; left intact (inert on theServepath via nilAuthzMiddleware, per
P2.3 Move middleware chain under Serve; remove authz + annotation mw #5441) and physically removed in P3.2 Reduce server.New body to the wrapper #5445.pkg/vmcp/server/server.go:136-147— the cross-cutting fieldsTelemetryProviderand
AuditConfiggo to both derived configs.HealthMonitorConfigis consumed at the
composition root (P3.2 Reduce server.New body to the wrapper #5445) to build the*health.Monitor; the built monitor (not the
config) is then threaded —*Monitor→ServerConfig.HealthMonitor,StatusProvider→
coreConfig(A2).pkg/vmcp/server/server.go:301-327—server.New(7-param signature; stays stable). Its
defaulting block (310-327) and its collaborator parameters (router, backendClient,
discoveryMgr, backendRegistry, workflowDefs) are the inputsderiveCoreConfigassembles.architecture.md"ServerConfig" (243-274) — the targetServerConfigshape and the core
Configcontents.architecture.md"Cross-cutting config not a clean partition (R3)" (483-487) — why
TelemetryProvider/AuditConfig/health go to both sides.pkg/vmcp/server/server_test.go— existingpkg/vmcp/serverunit-test patterns to mirror
for the derivation-helper tests.
Component Interfaces
The shape, not the full implementation. ServerConfig is the type established in #5439
(architecture.md 250-267); the core Config is the Phase 1 core constructor input.
// deriveServerConfig projects the transport-only fields out of the in-memory server.Config,
// plus the two cross-cutting fields shared with the core (R3), plus the already-built health
// monitor (A2). cfg is treated as read-only. healthMon is built at the composition root.
func deriveServerConfig(cfg *Config, healthMon *health.Monitor) *ServerConfig {
return &ServerConfig{
Name: cfg.Name, Version: cfg.Version, GroupRef: cfg.GroupRef,
Host: cfg.Host, Port: cfg.Port, EndpointPath: cfg.EndpointPath, SessionTTL: cfg.SessionTTL,
AuthMiddleware: cfg.AuthMiddleware,
AuthInfoHandler: cfg.AuthInfoHandler,
AuthServer: cfg.AuthServer,
HealthMonitor: healthMon, // built at the composition root (A2); nil => disabled
StatusReportingInterval: cfg.StatusReportingInterval,
StatusReporter: cfg.StatusReporter,
Watcher: cfg.Watcher,
SessionFactory: cfg.SessionFactory,
SessionStorage: cfg.SessionStorage,
OptimizerFactory: cfg.OptimizerFactory,
OptimizerConfig: cfg.OptimizerConfig,
// Cross-cutting (also on core Config) — R3, not a clean partition:
TelemetryProvider: cfg.TelemetryProvider,
AuditConfig: cfg.AuditConfig,
}
// NOTE: ServerConfig has no AuthzMiddleware field — authz flows through the core admission
// seam (Phase 1 / R1). The AuthzMiddleware field on server.Config is KEPT (vestigial;
// cli/serve.go sets it and stays unchanged); only the dead HTTP blocks that read it are
// deleted in #5445 (with the wrapper routing). deriveServerConfig simply omits it.
}
// deriveCoreConfig assembles the core Config from cfg's cross-cutting + admission inputs, the
// injected health StatusProvider (A2), and the collaborators that arrive as separate
// server.New parameters today.
func deriveCoreConfig(
cfg *Config,
rt router.Router,
backendClient vmcp.BackendClient,
discoveryMgr discovery.Manager,
backendRegistry vmcp.BackendRegistry,
workflowDefs map[string]*composer.WorkflowDefinition,
healthProvider health.StatusProvider, // the same monitor built at the root (A2); nil => no filtering
) *coreConfig { // coreConfig = the Phase 1 core constructor input type
// collaborators + workflowDefs + Authz (admission seam) + cross-cutting Telemetry/Audit +
// HealthStatusProvider = healthProvider
}Testing Strategy
Unit Tests
-
deriveServerConfigcopies every transport-only field from a fully-populated
server.Configonto the returnedServerConfig(table-style assertion over each field). -
deriveServerConfigcarries the cross-cuttingTelemetryProviderandAuditConfig
(and the built*health.Monitor) onto theServerConfig, and does not project an
AuthzMiddlewarefield —ServerConfighas none, and theserver.Configfield is
retained (vestigial) and simply not projected. -
deriveCoreConfigpopulates the coreConfigwith the passed collaborators,
workflowDefs, theAuthzconfig, and the same cross-cutting fields. - Neither helper mutates the input
cfg(assertcfgis unchanged after the call).
Integration / Behavioral Parity Tests
- Existing
pkg/vmcp/servertests stay green: becauseserver.Newis not yet rewired to
call the helpers in this task, its observable behavior is unchanged (the parity gate over
theserver.Newwrapper is exercised end-to-end in P3.2 Reduce server.New body to the wrapper #5445).
Edge Cases
- Nil/zero cross-cutting fields (
TelemetryProvider == nil,AuditConfig == nil,
HealthMonitorConfig == nil) propagate as nil to both sides — derivation must not panic or
substitute a default for a deliberately-disabled subsystem. - Default-applied scalars (
Host/EndpointPath/Name/Version/SessionTTL) are
reflected post-default in the derivedServerConfig(derive after defaults, or apply the
same defaults in the helper).
Out of Scope
- Reducing
server.New's body toServe(ctx, New(deriveCoreConfig(cfg, …)), deriveServerConfig(cfg, healthMon))and removing the two//nolint:gocyclo— that is
P3.2 Reduce server.New body to the wrapper #5445/P3.2, which this task blocks. - Deleting the now-dead authz/annotation HTTP blocks and physically retiring the discovery
middleware/seam + thes.core == nilguard — deferred to P3.2 Reduce server.New body to the wrapper #5445 (done atomically with the
wrapper routing so the legacy path never loses authz/aggregation). TheAuthzMiddleware
field onserver.Configis kept (vestigial) throughout, to preservecli/serve.go
unchanged. Building the*health.Monitorat the composition root is likewise P3.2 Reduce server.New body to the wrapper #5445; this
task only threads it through the derivers. - Any change to
vmcpconfig.Config, the CRD/YAML model, or the wire/storage format. - Building the admission seam itself or relocating any transport wiring — those landed in
Phases 1 and 2 (P1.1 Define VMCP interface + core Config #5434..105, P2.1 Serve skeleton + ServerConfig #5439..205). - Changing the
server.New7-param signature or its observable behavior.
References
- RFC THV-0076: /Users/trey/Documents/GitHub/stacklok/toolhive-rfcs/rfcs/THV-0076-vmcp-core-interface.md
- Parent story: Phase 3: Reduce server.New to wrapper + config split #5432
- Epic: vMCP interface refactor #5419
Activity
Add vMCP core/server config derivation helpers
Add vMCP core/server config derivation helpers (#5513)