Repository navigation
Description
Part of the vMCP interface refactor (epic #5419).
Summary
Expose a public constructor that returns a live, Kubernetes-populated vmcp.BackendRegistry (a DynamicRegistry kept current by an internal BackendWatcher) plus a readiness/lifecycle handle, so an embedder gets dynamic backend discovery without importing pkg/vmcp/k8s or hand-wiring rest.InClusterConfig + NewBackendWatcher + the watcher goroutine. Scope is deliberately limited to the registry/discovery seam — not the full core/Serve assembly.
Motivation
Today an embedder that wants live discovery must replicate pkg/vmcp/cli/serve.go:210-248:
dynamicRegistry := vmcp.NewDynamicRegistry(backends)
restConfig, _ := rest.InClusterConfig()
backendWatcher, _ := k8s.NewBackendWatcher(restConfig, namespace, group, dynamicRegistry)
go backendWatcher.Start(ctx)That forces a direct pkg/vmcp/k8s (+ k8s.io/client-go/rest) import. Per THV-0076/D9 the K8s-watch substrate should stay internal to vMCP; the embedder should depend only on a public registry constructor.
Note: the watcher runs in the embedder's Pod, so controller-runtime/k8s.io remain compiled into the binary — expected and unchanged. This issue is about the Go import surface and one-call ergonomics, not removing transitive deps.
Proposed shape (illustrative; home/types maintainers' call)
// Lives outside pkg/vmcp/k8s so callers don't import it.
func NewKubernetesBackendRegistry(
ctx context.Context, namespace, group string, opts ...Option,
) (vmcp.BackendRegistry, server.Watcher, error)Bundles NewDynamicRegistry + watcher construction + Start, defaulting restConfig to in-cluster (overridable via opt). The registry may start empty — the watcher's initial informer sync populates it — so the constructor needs only pkg/vmcp/k8s, not the static-discovery path's pkg/groups / pkg/container/runtime. The returned handle satisfies server.Watcher for /readyz cache-sync gating.
Embedder usage — no pkg/vmcp/k8s, no rest:
reg, watcher, _ := vmcpreg.NewKubernetesBackendRegistry(ctx, ns, group)
core, _ := core.New(&core.Config{BackendRegistry: reg, /* ... */})
srv, _ := server.Serve(ctx, core, &server.ServerConfig{
BackendRegistry: reg, Watcher: watcher, /* ... */
})Scope of work
- Add the public constructor (registry + watcher + lifecycle), in-cluster
restConfigby default with an override option. - Start empty + populate via the watcher's initial sync (avoid the static path's groups/container-runtime deps).
- Optionally route
cli.Serve's dynamic branch through it to dedupecli/serve.go:210-248.
Acceptance criteria
- Integration: an example/test embedder builds a live registry and serves, importing the new constructor but not
pkg/vmcp/k8sork8s.io/client-go/rest. - Import-graph (enforced by test): the embedder package does not import
pkg/vmcp/k8s/k8s.io/client-go/rest. - Live updates: adding/removing an
MCPServerCR updates the registry's backends (parity with currentcli.Serve).
Out of scope
- The broader config-driven
Build()/ full core+Serveassembly — the embedder keeps wiring aggregator/router/client itself. - The
ListBackends/LookupBackendextension; the optimizer; anyvmcpconfig.Configschema change.
References
- RFC THV-0076: vMCP Core Interface.
- Epic vMCP interface refactor #5419; related phases Phase 3: Reduce server.New to wrapper + config split #5432 (Phase 3), Phase 4: Documentation + runnable decorator example #5433 (Phase 4).
- Code to factor:
pkg/vmcp/cli/serve.go:210-248;vmcp.NewDynamicRegistry(pkg/vmcp/registry.go);k8s.NewBackendWatcher(pkg/vmcp/k8s/manager.go).
Activity
[-]Config-driven vMCP assembly so embedders avoid importing pkg/vmcp/k8s[/-][+]Public constructor for a Kubernetes-backed dynamic BackendRegistry (no pkg/vmcp/k8s import for embedders)[/+]Add public Kubernetes-backed BackendRegistry constructor
Add public Kubernetes-backed dynamic BackendRegistry constructor (#5542)
Add vMCP assembly API in pkg/vmcp/app
Add vMCP assembly API in pkg/vmcp/app
Add vMCP assembly API in pkg/vmcp/app