Request and Response Lifecycle
The two binaries implement the same lifecycle, with slightly different internal helper packages.
1. Process startup
cmd/kubestellar-ops/main.gocallspkg/cmd.Execute().cmd/kubestellar-deploy/main.gocallspkg/deploy/cmd.Execute().- The root Cobra command checks
--mcp-server. - MCP mode creates a server instance (
pkg/mcp/server.NewServerorpkg/deploy/mcp.NewServer).
2. MCP handshake
Once started, the server reads JSON-RPC messages from stdin.
initializereturns protocol version, server name and version, and tool capability metadata.tools/listreturns the tool catalog and JSON schema for each tool.initializedandnotifications/initializedare accepted as notifications without a response.
In kubestellar-ops, the stdio loop lives in pkg/mcp/server/server.go and uses bufio.Reader.ReadBytes('\n').
In kubestellar-deploy, the loop is in pkg/deploy/mcp/server.go and uses a bufio.Scanner with a larger buffer for larger payloads.
3. Tool dispatch
When Claude Code invokes tools/call:
- The server unmarshals the tool name and arguments.
handleToolsCallorhandleToolCallswitches on the tool name.- The selected handler validates input and performs the operation.
Examples:
- ops handlers commonly call
getClientForCluster()orcluster.Discoverer. - deploy handlers commonly use
multicluster.ClientManager,Executor, andSelector. - GitOps handlers call into
pkg/gitops.
4. Kubernetes work
Handlers then execute the real operation:
- Read-only diagnostics call Kubernetes list and get APIs.
- Multi-cluster operations fan out across all discovered contexts.
- Deploy workflows aggregate per-cluster results.
- GitOps workflows load manifests, compare desired state, and optionally apply changes.
5. Response encoding
Finally the server wraps the result into an MCP tools/call response and writes one JSON line to stdout.
There is one important implementation difference:
kubestellar-opshandlers usually return(string, bool)where the string is preformatted human-readable output and the boolean marks error state.kubestellar-deployhandlers usually return structured Go values thatserver.gomarshals into formatted JSON text for the MCP response body.