Skip to content

Make MCPServer controller hands-off on replicas - #3955

Merged
rdimitrov merged 1 commit into
mainfrom
jaosorior/mcpserver-hands-off-replicas
Feb 26, 2026
Merged

rdimitrov merged 1 commit into
mainfrom
jaosorior/mcpserver-hands-off-replicas

Conversation

@JAORMX

@JAORMX JAORMX commented Feb 25, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Remove hardcoded replica enforcement: The controller no longer forces replicas=1 on every reconcile, allowing kubectl scale, HPAs, KEDA, and other autoscalers to manage replicas freely
  • Add stdio transport cap: stdio requires 1:1 proxy-to-backend connections, so the controller caps it at 1 replica while leaving SSE and streamable-http unconstrained
  • Template-only deployment updates: Config changes (image, env, etc.) now update only Spec.Template, Spec.Selector, labels, and annotations — preserving Spec.Replicas set by external tools
  • New status fields: ReadyReplicas reports actual running pod count; Stopped phase reports scale-to-zero state; Ready print column shows replica count in kubectl get mcpservers

Closes #3329

Test plan

  • Unit tests for replica behavior across all transports (SSE, streamable-http, stdio)
  • Unit test: stdio transport scaled to 3 → capped back to 1
  • Unit test: SSE/streamable-http scaled to 3/5 → replicas preserved
  • Unit test: scale-to-zero → status shows Stopped phase
  • Unit test: config update preserves externally-set replicas
  • Unit test: ReadyReplicas matches running pod count
  • Unit test: default creation starts with 1 replica
  • task operator-test passes
  • task lint passes (also fixes pre-existing goconst issue)
  • CRD manifests, reference docs, and CLI docs regenerated
  • Manual: deploy MCPServer, kubectl scale --replicas=3 (SSE), verify controller doesn't revert
  • Manual: kubectl scale --replicas=0, verify status shows Stopped
  • Manual: stdio MCPServer, kubectl scale --replicas=3, verify controller caps to 1

🤖 Generated with Claude Code

The MCPServer controller previously hardcoded replicas=1 and actively
reverted any external scaling, preventing kubectl scale, HPAs, KEDA,
and other autoscalers from working.

The controller is now hands-off for replica management, with one
exception: stdio transport is capped at 1 replica because it requires
1:1 proxy-to-backend connections. Non-stdio transports (SSE,
streamable-http) allow free scaling by external tools.

Key changes:
- Replace blanket replica enforcement with stdio-only cap
- Use template-only deployment updates to preserve Spec.Replicas
- Add Stopped phase and ReadyReplicas to MCPServer status
- Add Ready print column for kubectl get mcpservers
- Handle scale-to-zero by reporting Stopped phase

Closes #3329

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@github-actions github-actions Bot added the size/L Large PR: 600-999 lines changed label Feb 25, 2026
@codecov

codecov Bot commented Feb 26, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 83.33333% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 67.83%. Comparing base (3d54ad2) to head (20b9282).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
pkg/vmcp/workloads/k8s.go 0.00% 2 Missing ⚠️
...d/thv-operator/controllers/mcpserver_controller.go 93.75% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #3955      +/-   ##
==========================================
+ Coverage   67.64%   67.83%   +0.19%     
==========================================
  Files         438      438              
  Lines       44108    44123      +15     
==========================================
+ Hits        29835    29930      +95     
+ Misses      11938    11851      -87     
- Partials     2335     2342       +7     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@rdimitrov
rdimitrov merged commit dc06c9b into main Feb 26, 2026
47 of 50 checks passed
@rdimitrov
rdimitrov deleted the jaosorior/mcpserver-hands-off-replicas branch February 26, 2026 10:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L Large PR: 600-999 lines changed

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Operator reverts manual StatefulSet replica scaling back to 1

3 participants