Skip to content

fix(k8s): give the MCP server the settings of its cluster tools #7348

Done

Description

@dan-petty

Problem

Tools of the role planning of the deployed MCP server fail in the pod, because the server lacks the settings that they read. A client gets an error text and no data. The roadmap jobs use the same role endpoint.

Evidence

Read on 2026-11-26 at 22:25Z with an MCP client in the namespace llm (/planning/mcp, bearer value of the server, 28 tools listed, each with the read-only hint):

Tool Result
gh_rate_limit data
telemetry_status data
k8s_status Failed to query cluster: Kubernetes client configuration is not available.
k8s_pods (namespace llm) a table with one row Error: Kubernet...
argo_cd_apps_list ArgoCD URL not configured. Run: devops config set argocd.url <url>
grafana_dashboards_list Grafana URL not configured. Run: devops config set grafana.url <url>

The Deployment mcp-server sets a kube context name in its environment and mounts the ConfigMap of the stack. The pod holds no kubeconfig file, and the in-cluster service account is not used by the Kubernetes tools.

Acceptance criteria

  • In the deployed pod, each tool of the role tables either gives data or is not in the table. The record lists the 28 tools of planning with the result of one call each.
  • The Kubernetes tools use the service account of the pod when no kubeconfig exists, with a Role that gives the read verbs that the tools need and no more.
  • The Argo CD and Grafana tools read their URLs from the ConfigMap of the stack, and their bearer values from a Secret row, or they leave the role tables.
  • A check in the cluster (a Job or a probe run) calls one tool of each group and fails when a tool gives a settings error.

Alternatives check of 2026-11-26: in-use.
The repository already uses this tool.
Tool: kubernetes (https://pypi.org/project/kubernetes), Apache-2.0, last activity 2026-11-18, maintained.
Reason: Searches found no dedicated MCP cluster-settings tool; the Kubernetes Python client covers in-cluster service-account auth only, leaving Argo CD/Grafana settings, Secret wiring and the probe as project work.

Covers:

  • In-cluster service-account authentication via load_incluster_config
  • Kubernetes API reads for status, pods and namespaced resources
  • Namespaced Role with only get, list and watch

Lacks:

  • Argo CD and Grafana URL and bearer-value settings
  • MCP probe that calls one tool of each group
  • Deployment, ConfigMap and Secret wiring for the server

Proposed design

Problem statement

The planning role of the deployed MCP server returns settings errors for its Kubernetes, Argo CD and Grafana tools. The pod runs in namespace devops and holds no kubeconfig file, no service-account token and no API server egress. The pod also holds no Argo CD or Grafana URL and no bearer value. This change gives the server a dedicated ServiceAccount, a read-only ClusterRole, API server egress, and the URL and bearer settings. It adds a check that fails on a settings error.

Acceptance criteria

Requirement: Dedicated service account

The mcp-server Deployment SHALL use a dedicated ServiceAccount in namespace devops with automountServiceAccountToken: true.

Scenario: Manifest check

  • WHEN The change runs uv run devops ci --check --only k8s on the Deployment and ServiceAccount manifests.
  • THEN The check exits 0.

Requirement: Read-only cluster role

The ClusterRole of the mcp-server ServiceAccount SHALL grant only get, list and watch on nodes and pods.

Scenario: Manifest check

  • WHEN The change runs uv run devops ci --check --only k8s on the ClusterRole and ClusterRoleBinding manifests.
  • THEN The check exits 0.

Requirement: API server egress

The NetworkPolicy of mcp-server SHALL allow TCP 6443 egress to the Kubernetes API server.

Scenario: Manifest check

  • WHEN The change runs uv run devops ci --check --only k8s on k8s/devops/networkpolicy.yaml.
  • THEN The check exits 0.

Requirement: Argo CD and Grafana settings

The mcp-server Deployment SHALL set the Argo CD and Grafana URL settings from the stack ConfigMap and their bearer values from the Secret that devops k8s push-secrets writes, and SHALL NOT use an ExternalSecret for these values.

Scenario: Manifest check

  • WHEN The change runs uv run devops ci --check --only k8s on the Deployment manifest.
  • THEN The check exits 0.

Requirement: Cluster tool probe

The command devops k8s mcp-server-check SHALL call k8s_status, k8s_pods, argo_cd_apps_list and grafana_dashboards_list, and exit non-zero when one gives a settings error.

Scenario: Settings error

  • WHEN A test gives the check a settings error for grafana_dashboards_list and data for the other three tools.
  • THEN The check exits non-zero and prints the tool name and the error text.

Requirement: Cluster tool probe passes

The command devops k8s mcp-server-check SHALL exit 0 when each of the four tools returns data.

Scenario: All tools return data

  • WHEN A test gives the check data for k8s_status, k8s_pods, argo_cd_apps_list and grafana_dashboards_list.
  • THEN The check exits 0 and prints one line for each tool.

Requirement: Read-only service account

The command devops k8s mcp-server-check MUST exit non-zero when the service account of the pod can delete a pod in the devops namespace.

Scenario: Delete allowed

  • WHEN A test gives the check a fake authorization client that allows delete on pods.
  • THEN The check exits non-zero and prints delete and pods.

Requirement: Forbidden read names the permission

The command devops k8s mcp-server-check MUST exit non-zero and name the verb and the resource when a tool gets a forbidden error.

Scenario: Forbidden read

  • WHEN A test gives the check a tool result of Forbidden: cannot list resource "nodes".
  • THEN The check exits non-zero and prints list and nodes.

Requirement: Pending a person after the merge

The post-merge record MUST list one call to each of the 28 tools of the planning role after a person sets the bearer values and runs the cluster check.

Scenario: Planning role record

  • WHEN A person sets the Argo CD and Grafana bearer values in the keyring, runs uv run devops k8s push-secrets, runs uv run devops k8s mcp-server-check, and calls each of the 28 tools after the merge.
  • THEN The check exits 0, and the issue holds a table with one row for each of the 28 tools, and each row shows data or that the tool is not in the table.

Existing Tool Considered

The alternatives check in the issue body gives kubernetes (https://pypi.org/project/kubernetes) the verdict in-use, because the repository already uses it. Its Covers: and Lacks: lists hold what the tool gives and misses. This proposal does the lacks with project work. The stack ConfigMap holds the two URLs. The Secret that devops k8s push-secrets writes holds the bearer values. A dedicated ServiceAccount and ClusterRole wire the server. The devops k8s mcp-server-check command calls one tool of each group. The command costs about 2k tokens and one hour to build, keep and fix.

Key questions

  • In which namespace does the mcp-server Deployment run?: The mcp-server Deployment runs in namespace devops. The folder k8s/llm/ does not exist after refactor(k8s): delete the environment files from devops-cli #7317. [sources: k8s/devops/mcp-server/deployment.yaml, k8s/devops/networkpolicy.yaml]
  • Which Kubernetes authentication do the tools use when no kubeconfig file exists?: The existing KubernetesClientSource.connect falls back to InClusterConfigLoader when no kubeconfig context matches. The change enables the token on a dedicated ServiceAccount and adds no authentication code. (best practice) [sources: src/devops_cli/k8s/api.py:167-222, k8s/devops/mcp-server/deployment.yaml]
    • Chosen: In-cluster service account. The pod holds a service account and no kubeconfig file. The client needs no long-lived file.
    • Rejected: Mounted kubeconfig Secret. It adds a long-lived credential file and a Secret to rotate.
    • Rejected: Exec credential plugin. The pod holds no external identity provider.
  • Should the Kubernetes access use a namespaced Role or a ClusterRole?: Use a dedicated ServiceAccount and a ClusterRole with only get, list and watch on nodes and pods. A namespaced Role cannot grant list on the cluster-scoped nodes that k8s_status reads or the cross-namespace pod list that k8s_pods uses. (best practice) [sources: src/devops_cli/k8s/service.py:307-316, src/devops_cli/k8s/api.py, k8s/devops/mcp-server/deployment.yaml]
    • Chosen: ClusterRole on nodes and pods. It grants the cluster-scoped node read and the cross-namespace pod read that the tools need, with only read verbs.
    • Rejected: Namespaced Role. It cannot grant list on the cluster-scoped nodes or the cross-namespace pod list.
    • Rejected: Shared ServiceAccount devops-cli. It has automountServiceAccountToken: false and other pods use it.
  • How do the Argo CD and Grafana tools receive their URL and bearer value in the pod?: The URLs come from the stack ConfigMap. The bearer values come from the Secret that devops k8s push-secrets writes, as ADR 0033 requires for platform Secrets. The Deployment gives each value to the server in an environment variable. No bearer value goes into the ConfigMap or into git. (best practice) [sources: docs/adr/0033-service-secrets-come-from-external-secrets-operator.md:37-38, SECURITY.md, k8s/devops/mcp-server/deployment.yaml, src/devops_cli/argo/credentials.py, src/devops_cli/commands/grafana.py]
    • Chosen: URL from the ConfigMap and bearer value from the push-secrets Secret. The stack already holds the URLs. The Secret keeps the bearer values out of git and out of the ConfigMap, and ADR 0033 requires this method for platform Secrets.
    • Rejected: ExternalSecret for the bearer values. ADR 0033 uses devops k8s push-secrets for platform Secrets, not an ExternalSecret.
    • Rejected: URL and bearer value in the ConfigMap. It puts a secret in a ConfigMap and in git, which SECURITY.md forbids.
  • Does the mcp-server NetworkPolicy allow TCP 6443 egress to the Kubernetes API server?: No. k8s/devops/networkpolicy.yaml has no TCP 6443 egress. The change adds an egress rule to the Kubernetes API server. [sources: k8s/devops/networkpolicy.yaml]
  • Should the cluster check be a Job, a readiness probe or a devops k8s check command?: Use a devops k8s mcp-server-check command, in the form of the existing devops k8s searxng-check and devops k8s crawl4ai-check commands. Do not use a readiness probe, because a settings error would restart the pod and hide the result. (best practice) [sources: tests/commands/k8s/test_k8s_searxng_check.py, tests/commands/k8s/test_k8s_crawl4ai_check.py, tests/commands/k8s/test_k8s_probe.py]
    • Chosen: devops k8s mcp-server-check command. It follows the existing check commands, calls each tool group and prints one result for each.
    • Rejected: Readiness probe. A settings error would restart the pod and hide the tool result.
    • Rejected: One-off Job. It needs a new manifest and shares no command with the existing cluster checks.
  • Does the planning role table already name the Argo CD and Grafana tools?: Yes. The planning role lists 28 tools, and argo_cd_apps_list and grafana_dashboards_list are two of them. [sources: src/devops_cli/roadmap/tools.py, src/devops_cli/ai/tools/registry.py:107, docs/MCP_TOOLS.md, tests/ai/mcp/test_mcp_roles.py]
  • Which Secret method does ADR 0033 require for the platform Secrets?: ADR 0033 requires devops k8s push-secrets for platform Secrets. An ExternalSecret is for service Secrets, not for these platform Secrets. [sources: docs/adr/0033-service-secrets-come-from-external-secrets-operator.md:37-38, SECURITY.md]

Fit

Fits in one pull request.

Suspected block

None.

Dependencies

None.

Activity

  1. added
    type/bug
    scope/k8s
    source/agent
    status/new
    effort/medium
    value/high
    on Nov 26, 2026
  2. dan-petty commented on Nov 26, 2026

    @dan-petty
    OwnerAuthor
    • Priority: Cluster tools return errors in the live pod and the roadmap jobs that use this endpoint get incomplete data, causing increased error rates.
    • Related: feat(k8s): deploy MCP server manifests when entrypoint exists #3600, which asks for a different change. Both concern the MCP server deployment in k8s, but #3600 adds the manifests while the candidate fixes the tool settings inside the running pod.
  3. added
    priority/p1-high
    on Nov 26, 2026
  4. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    Next step: the alternatives check records a verdict. See the section Proposed design of the body.

  5. devops-cli-service commented on Nov 26, 2026

    @devops-cli-service
    Contributor

    The result in the alternatives block of the issue body changed. Before this check: no check. A person decides what the new result means for the item.

    Searches (3)

    Tools considered:

    Searches run:

    • kubernetes python client load_incluster_config service account, results: 5
    • python kubernetes client in-cluster configuration load_incluster_config documentation, results: 5
    • load_incluster_config, results: 5

    Sources:

  6. added
    status/ready
    and removed
    status/new
    on Nov 27, 2026
  7. devops-cli-service commented on Nov 27, 2026

    @devops-cli-service
    Contributor

    Next step: the stage job writes the plan of the item. See the section Proposed design of the body.

  8. added
    owner/service
    and removed
    owner/service
    on Nov 28, 2026
  9. 10 remaining items

  10. added
    owner/service
    and removed
    owner/service
    on Nov 28, 2026
  11. added
    owner/agent
    status/in-progress
    status/in-review
    and removed
    status/ready
    status/in-progress
    on Nov 28, 2026
  12. removed
    status/in-review
    owner/agent
    on Nov 28, 2026
  13. devops-cli-service commented on Nov 28, 2026

    @devops-cli-service
    Contributor

    Live since 2026-11-28 18:38 UTC

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    effort/mediumpriority/p1-highscope/k8ssource/agenttype/bugvalue/high

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions