Repository navigation
Description
Summary
Several "config" CRD controllers in the operator force their consuming MCPServer to re-reconcile by writing a hash annotation onto the MCPServer (a cross-controller spec mutation). This is an anti-pattern: a config controller should not mutate another controller's primary resource. The correct mechanism is a controller-runtime Watches(...) on the consuming side, which enqueues reconciliation automatically with no poking.
An audit of every config CRD → consumer pair (see matrix below) shows the operator is mostly already on the watch pattern. There are exactly three remaining annotation pokes, all targeting MCPServer. Two are purely redundant (a watch already covers them); one is currently load-bearing because the corresponding watch is missing.
Severity: SHOULD FIX
Area: Controller Design
Breaking: No
The anti-pattern
A config controller reaches over and writes a hash annotation onto every referencing MCPServer purely to bump its resourceVersion and force a reconcile, e.g.:
// config controller, looping over referencing MCPServers:
annotations["toolhive.stacklok.dev/<config>-hash"] = referencedConfig.Status.ConfigHash
ctrlutil.MutateAndPatchSpec(ctx, r.Client, &mcpServer, ...) // writes a FOREIGN primary resourceThe annotation value is write-only — nothing ever reads it. The real change detection happens by comparing config.Status.ConfigHash against the MCPServer's own Status.<Config>Hash during the MCPServer's reconcile. So the annotation's only job is to trigger that reconcile — which a Watches(...) already does, correctly and without the cross-controller write.
(Note: the original report described time.Now()-based annotation values defeating idempotent reconciliation. The code has since moved to a stable Status.ConfigHash value, gated behind a hashChanged check, so that specific concern no longer applies. The remaining issue is purely the cross-controller mutation / double reconcile.)
Audit: every config CRD → consumer
Good examples to copy: MCPRemoteProxy and VirtualMCPServer are watch-only across the board.
| Config CRD | Consumer | Watch present? | Annotation poke? | Verdict |
|---|---|---|---|---|
| MCPExternalAuthConfig | MCPServer | ✅ mcpserver_controller.go:2743 |
mcpexternalauthconfig_controller.go:367-382 |
REDUNDANT |
| MCPToolConfig | MCPServer | ❌ none | toolconfig_controller.go:160-173 |
BROKEN IF REMOVED |
| MCPWebhookConfig | MCPServer | ✅ mcpserver_controller.go:2746 |
mcpwebhookconfig_controller.go:166-194 |
REDUNDANT |
| MCPExternalAuthConfig | MCPRemoteProxy / VirtualMCPServer | ✅ | no | CORRECT |
| MCPToolConfig | MCPRemoteProxy / VirtualMCPServer | ✅ | no | CORRECT |
| MCPOIDCConfig | MCPServer / MCPRemoteProxy / VirtualMCPServer | ✅ | no | CORRECT |
| MCPTelemetryConfig | MCPServer / MCPRemoteProxy / VirtualMCPServer | ✅ | no | CORRECT |
| VirtualMCPCompositeToolDefinition | VirtualMCPServer | ✅ | no | CORRECT |
| MCPAuthzConfig | all | n/a (ref-tracked only) | no | OK — see note |
MCPAuthzConfig note: AuthzConfigRef is currently only reference-tracked for status (ReferencingWorkloads) — it is not yet resolved into runtime config, so consumers correctly do not re-reconcile on its content. When ref-resolution lands, add a consumer-side Watches(&MCPAuthzConfig{}) from the start — do not introduce an annotation poke.
What we want to change
Goal: every config CRD → consumer pair is watch-only, with zero cross-controller annotation writes.
-
MCPExternalAuthConfig — REDUNDANT, safe to remove.
Delete the annotation-poke loop atmcpexternalauthconfig_controller.go:367-382. The MCPServer watch (:2743) already triggers reconcile. Keep thefindReferencingMCPServers/Status.ReferencingWorkloadsstatus bookkeeping. -
MCPWebhookConfig — REDUNDANT, safe to remove.
Delete the annotation-poke loop atmcpwebhookconfig_controller.go:166-194. The MCPServer watch (:2746) already triggers reconcile. KeepupdateReferencingWorkloads+ status write. (This was not in the original report — same anti-pattern, found during the audit.) -
MCPToolConfig — must add the watch FIRST, then remove the poke.
MCPServer has no watch on MCPToolConfig, so the poke attoolconfig_controller.go:160-173is currently the only trigger. Order matters:- Add
Watches(&mcpv1beta1.MCPToolConfig{}, <toolConfigHandler>)toMCPServerReconciler.SetupWithManager(mcpserver_controller.go:2739), mirroring the existing handler inmcpremoteproxy_controller.go:1652. - Only then delete the poke loop.
Removing the poke before the watch exists would silently stop MCPServers from reacting to MCPToolConfig edits.
- Add
-
Tests / docs.
- Update the annotation assertion in
mcpexternalauthconfig_controller_test.go(~lines 693-702) once the poke is gone, and the equivalent webhook-config test if present. - Add integration coverage for MCPToolConfig → MCPServer change propagation (currently only MCPRemoteProxy's ToolConfig propagation is covered).
- Update the annotation assertion in
-
Leave alone: MCPOIDCConfig, MCPTelemetryConfig, VirtualMCPCompositeToolDefinition (already correct), and MCPAuthzConfig (deferred until ref-resolution lands).
Suggested PR scoping
The two pure deletions (ExternalAuth, Webhook) are independent and low-risk. The ToolConfig change adds a watch + test and carries the ordering risk, so it may be cleaner as its own PR. Either one combined PR ("Replace annotation pokes with watches in config controllers") or a 2-PR split is acceptable.
Activity
Sanskarzz commentedon Jun 19, 2026
@ChrisJBurns I'd like to work on this issue. Please assign me.
ChrisJBurns commentedon Jun 19, 2026
@Sanskarzz Yep assigned. I've modified the description with a bit more info.