How containers/kubernetes-mcp-server works
1. Primary runtime is a Go MCP server
- The core product is the kubernetes-mcp-server Go binary.
- cmd/kubernetes-mcp-server/main.go and pkg/kubernetes-mcp-server/cmd/root.go are the main entrypoints.
- The server speaks Model Context Protocol and can run in direct stdio-style mode or in HTTP/SSE mode on a port.
2. The main architectural boundary is “MCP surface” vs “cluster adapters”
- pkg/mcp owns the MCP protocol layer: tool registration, prompts, resource exposure, middleware, reload behavior, and MCP-specific validation/mutation.
- Below that, the domain adapters translate MCP operations into concrete backend calls:
- pkg/kubernetes for Kubernetes/OpenShift API access
- pkg/helm for Helm release and chart operations
- pkg/kiali for Kiali/Istio observability APIs
- pkg/kubevirt for VM lifecycle and guest-agent access
- pkg/kcp for kcp workspace support
- pkg/tekton under pkg/toolsets for pipeline/task actions
3. Toolsets are the feature composition mechanism
- pkg/toolsets is the main productization layer that groups capabilities into enable/disable sets such as core, config, helm, kcp, kiali, kubevirt, and tekton.
- Each toolset exposes MCP tools and sometimes prompts, and the server can limit exposure through configuration.
- This is important architecturally because the server is not one monolith of commands; it is a dynamically assembled capability set.
4. Kubernetes access is centralized and policy-aware
- pkg/kubernetes contains the cluster-facing logic for pods, nodes, namespaces, resources, events, scaling, exec, logs, watches, and Kubernetes-specific validation.
- There are provider abstractions for different cluster sources and modes: kubeconfig, in-cluster, single-cluster, token exchange, registry, and watch support.
- The implementation is intentionally direct API-based rather than shelling out to kubectl.
5. Configuration is a first-class subsystem
- pkg/config models CLI/TOML/environment-driven configuration, including TLS, telemetry, HTTP settings, toolset selection, cluster provider strategy, and denied resources.
- pkg/config/state.go and watcher-related code indicate runtime reload/update behavior, especially around kubeconfig/config changes.
- The config layer controls safety flags like read-only and destructive-operation blocking.
6. Authentication and HTTP-mode authorization are separate concerns
- pkg/http handles HTTP server behavior, authorization, middleware, and well-known endpoints for MCP over HTTP.
- pkg/tokenexchange and pkg/oauth support OIDC-style flows and token exchange, including Keycloak and Entra ID pathways.
- This means transport/auth concerns are isolated from the Kubernetes domain logic.
7. Observability is embedded, not bolted on
- pkg/metrics, pkg/telemetry, and pkg/logging provide metrics, OpenTelemetry integration, structured logs, and redaction.
- The README’s /stats endpoint and OTEL docs match this design: the server exposes operational telemetry about itself in addition to cluster data.
- pkg/mcplog appears to bridge Kubernetes errors and sensitive-data-safe log emission into MCP clients.
8. MCP semantics include prompts, resources, and tool mutation
- pkg/prompts and prompt-related code in pkg/mcp manage reusable prompt templates and serialization.
- pkg/mcp/tool_filter.go, tool_mutator.go, and prompt_mutator.go suggest the server dynamically filters or rewrites exposed capabilities based on config, mode, or cluster context.
- This is a key architectural point for diagramming: the exposed MCP catalog is computed, not static.
9. Domain-specific subsystems are independent extensions
- pkg/kiali wraps observability sources such as Istio/Kiali, Prometheus-style metrics, logs, traces, and mesh status.
- pkg/kubevirt handles VM creation, lifecycle, cloning, and guest-agent inspection.
- pkg/toolsets/tekton maps Tekton CRDs into pipeline/task start/restart/log workflows.
- Each extension is its own backend integration rather than a variation of the core Kubernetes resource layer.
10. Multi-cluster support is a structural feature
- The README and config options make multi-cluster support default behavior unless disabled.
- Context selection flows from kubeconfig/config providers into tool execution, and many tools accept a context or equivalent cluster identifier.
- This means the server sits between AI clients and potentially multiple Kubernetes clusters, not just a single target.
11. Packaging and deployment are multi-language, but the Go server is canonical
- Dockerfile and charts/kubernetes-mcp-server provide container and Helm deployment paths.
- npm/ and python/ directories package thin launchers/wrappers for ecosystem integration.
- These are distribution surfaces around the same server binary, not separate implementations.
12. Validation and safety are heavily test-driven
- The repository has extensive unit and integration-style tests across config, Kubernetes adapters, MCP behavior, and toolsets.
- internal/test provides shared test harnesses and mocks.
- The evals/ tree is a separate quality system for task-based behavioral evaluation, especially for Kubernetes, Helm, Kiali, KubeVirt, and Tekton scenarios.
13. Operational/deployment assets are part of the architecture
- charts/, dev/config/, and .github/workflows/ show the project is built for repeatable deployment, release automation, and local cluster bootstrapping.
- dev/config includes example cluster, ingress, Keycloak, and cert-manager assets, indicating that auth-enabled HTTP deployments are a supported operational mode.
- This matters for diagramming because the server often runs inside a Kubernetes cluster with external identity and ingress dependencies.
14. Overall request flow
- MCP client sends a tool/prompt/resource request.
- pkg/mcp resolves the request through the configured toolset and middleware.
- The relevant adapter (pkg/kubernetes, pkg/helm, pkg/kiali, pkg/kubevirt, pkg/tekton, or pkg/kcp) performs the action against the cluster or service.
- Results are normalized back into MCP-compatible outputs, with logging, redaction, and optional telemetry emitted along the way.
Main entry points: mcp MCP core · toolsets Toolsets · root.go Root cmd · http HTTP mode
Components 20
Runtime
Go server entrypoints and transport/runtime wiring.
MCP Surface
Protocol layer that assembles and serves tools, prompts, and resources.
Cluster Adapters
Backend integrations translated from MCP operations.
- Kubernetes · Direct Kubernetes and OpenShift API access for resources, exec, logs, watches, scaling, and validation.
pkg/kubernetes - Helm · Helm release and chart operations.
pkg/helm - Kiali · Istio and observability integration for topology, metrics, logs, traces, and mesh status.
pkg/kiali - KubeVirt · Virtual machine lifecycle, cloning, and guest-agent access.
pkg/kubevirt - kcp · Workspace and multi-cluster context support for kcp.
pkg/kcp - Tekton · Pipeline, task, and pipelinerun workflows exposed through toolsets.
pkg/toolsets/tekton
Platform
Configuration, auth, telemetry, logging, and output support.
- Config · CLI, TOML, env, TLS, HTTP, telemetry, providers, toolset selection, and safety policy.
pkg/config - HTTP mode · HTTP/SSE transport, authorization, middleware, and well-known endpoints.
pkg/http - Token exchange · OIDC-style token exchange and provider support.
pkg/tokenexchange - OAuth state · Browser or HTTP auth state handling for login flows.
pkg/oauth - Metrics · Server metrics and stats collection.
pkg/metrics - Telemetry · OpenTelemetry wiring and export hooks.
pkg/telemetry - Logging · Structured logging and redaction-safe sinks.
pkg/logging - Output · Normalizes results for MCP client responses.
pkg/output
Delivery
Packaging, deployment, and evaluation assets.
- Delivery · Container, chart, wrappers, workflows, and eval harnesses.
Connections 26
- Main → Root cmd: starts · Main delegates CLI and server bootstrapping to the root command.
- Root cmd → Config: loads · Startup reads runtime configuration and provider strategy.
- Root cmd → HTTP mode: selects · Chooses stdio/direct mode or HTTP/SSE transport.
- Root cmd → MCP core: serves · Initializes the MCP protocol surface.
- MCP core → Toolsets: assembles · Computes the exposed capability set from enabled toolsets.
- Toolsets → Kubernetes: includes · Core toolsets bind Kubernetes operations.
- Toolsets → Helm: includes · Helm toolset exposes release and chart actions.
- Toolsets → Kiali: includes · Kiali toolset exposes mesh and observability actions.
- Toolsets → KubeVirt: includes · KubeVirt toolset exposes VM operations.
- Toolsets → kcp: includes · kcp toolset exposes workspace-aware operations.
- Toolsets → Tekton: includes · Tekton toolset exposes pipeline/task workflows.
- MCP core → Prompts: publishes · Prompts are exposed as part of the MCP catalog.
- MCP core → Kubernetes: routes to · Core resource requests are dispatched into the cluster adapter.
- MCP core → Helm: routes to · Helm-related MCP tools delegate to the Helm adapter.
- MCP core → Kiali: routes to · Observability tools delegate to the Kiali adapter.
- MCP core → KubeVirt: routes to · VM tools delegate to the KubeVirt adapter.
- MCP core → kcp: routes to · Workspace tools delegate to the kcp adapter.
- MCP core → Tekton: routes to · Pipeline tools delegate to the Tekton adapter.
- HTTP mode → Token exchange: uses · HTTP auth may rely on token exchange flows.
- HTTP mode → OAuth state: tracks · Login state is maintained separately from cluster logic.
- MCP core → Metrics: emits · MCP runtime contributes operational metrics.
- MCP core → Telemetry: emits · Tracing and OTEL hooks are integrated into request handling.
- MCP core → Logging: logs · Structured logs and redaction-safe error handling accompany requests.
- MCP core → Output: formats · Adapter results are normalized into MCP-compatible outputs.
- Root cmd → Delivery: packages · The binary is delivered through containers, charts, wrappers, and workflows.
- Delivery → HTTP mode: deploys · Helm and container assets support HTTP deployments.