Purpose
mcp-openshift is a Model Context Protocol (MCP) server used to let AI agents safely explore and operate OpenShift / Kubernetes clusters. It starts in read-only mode by default, and higher-capability tools are only registered after the mode is raised.
Main capabilities
Resources accessible to agents include: projects, Pods and logs, Deployments and DeploymentConfigs, Routes, Services, Builds, ImageStreams, and arbitrary resources by kind. In higher modes, it can also scale workloads, restart Deployments, apply manifests, and delete resources.
Authentication methods
Requires the cluster's API URL and credentials. The authentication mode can be selected automatically, or overridden with OPENSHIFT_AUTH:
- token: uses OPENSHIFT_TOKEN (bearer). It can be obtained from the web console: click the username in the upper right corner → Copy login command → Display Token, copy the value after --token= (sha256~…) and the URL after --server=; it can also be obtained with oc whoami -t. Console tokens have a short validity period and must be obtained again after expiration.
- password: uses OPENSHIFT_USERNAME + OPENSHIFT_PASSWORD, connecting to the cluster's built-in OAuth server (HTPasswd / LDAP / any local IdP that supports challenge). The server performs the same token request flow as oc login -u … -p …, caches the token to ~/.mcp-openshift/token.json (permissions 0600), and automatically logs in again when it expires. The password is only sent to the cluster's OAuth endpoint and is not logged or written to disk. TLS: clusters usually use a private CA. You can set OPENSHIFT_CA_CERT to point to the CA certificate bundle, or use OPENSHIFT_INSECURE_TLS=true in development-only environments to skip verification.
Security mechanisms (secure by default)
Implemented by src/security.ts, providing defense in depth on top of the account's cluster RBAC:
- OPENSHIFT_MODE: read-only (default) → read-write → admin. Tools above the current mode are not registered.
- OPENSHIFT_NAMESPACE_ALLOWLIST / OPENSHIFT_PROTECTED_NAMESPACES: restrict writes to specified namespaces; system namespaces (kube-, openshift, openshift-, default) are readable but can never be modified.
- OPENSHIFT_ALLOW_APPLY: creating/updating resources requires this flag in addition to read-write mode, and requires human confirmation.
- OPENSHIFT_ALLOW_DELETE: deletion requires this flag in addition to admin mode, and requires human confirmation.
- OPENSHIFT_DRY_RUN: write operations are sent with Kubernetes dryRun=All, undergoing validation and admission checks, but are not persisted.
- Human in the loop: apply, delete, and scaling to zero pause and request human approval via MCP elicitation.
- OPENSHIFT_AUDIT_LOG: each protected operation outputs one line of JSON audit record to stderr; Secret values in all output are redacted.
Optional AI risk protection
After setting OPENSHIFT_GUARD_MODE=monitor|enforce, apply_resource / delete_resource consult the local laya-guard daemon (install: pipx install laya-guard && laya-guard), classifying the operation as allow/confirm/block before execution. This step runs after the apply/delete gate, only tightens and never loosens permissions, and fails closed.
Applicable scenarios
Suitable for scenarios that require AI agents to perform routine troubleshooting and operations on OpenShift / Kubernetes clusters, such as viewing projects and Pods, reading logs, checking Deployments and Routes, and service and build status, as well as performing operational actions such as scaling, restarting, applying manifests, and deletion under controlled conditions.
Usage
You need to provide the cluster API URL and credentials, and set the above environment variables as needed. The repository provides docs/CLIENTS.md (for Claude Code / Cursor / Codex / VS Code / Windsurf) and .env.example listing all variables. The repository includes the built-in skill openshift-safe-operations, used to teach agents how to authenticate (including obtaining credentials from the browser console), safety rules, and standard troubleshooting and operations workflows. See also SECURITY.md.
Limitations
Specific limitations and complete configuration details are not yet provided; refer to the documentation in the repository (docs/CLIENTS.md, SECURITY.md, .env.example) and the source code.