Kubernetes MCP Server
Enables secure Kubernetes operations with configurable security modes, supporting core Kubernetes resources, Istio service mesh, and Helm chart management through natural language.
README
Kubernetes MCP Server
A comprehensive Model Context Protocol (MCP) server for secure Kubernetes operations with configurable security modes.

š Features
- š Security-First: Multiple security modes (Non-destructive, Read-only, Custom, Full access)
- š¦ Modular Architecture: Clean separation of concerns with dedicated modules
- š³ Docker Ready: Production-ready containerized deployment
- ā” FastMCP Integration: Built on FastMCP 2.11.3 framework
- šÆ Comprehensive Coverage: Support for all major Kubernetes and Istio resources
- š¾ Backup Operations: Safe backup-before-delete functionality
- š§ Helm Support: Complete Helm chart lifecycle management
š Prerequisites
- Python 3.12+
- Docker (for containerized deployment)
- Kubernetes cluster access
- kubectl configured
- Helm 3.x (optional, for Helm operations)
š ļø Installation
Option 1: Docker Deployment (Recommended)
# Build the Docker image
docker build -t kubectl-mcp-server:latest .
# Run with non-destructive security mode
docker run -d \
--name kubectl-mcp-server \
-p 8000:8000 \
-v ~/.kube:/root/.kube:ro \
-e KUBECONFIG=/root/.kube/config \
-e ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true \
kubectl-mcp-server:latest
Option 2: Local Development
# Install dependencies
pip install -r requirements.txt
# Run the server
python run_server.py --transport stdio
š Security Modes
1. Non-Destructive Mode (Recommended for Production)
export ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true
- ā Allows: All read operations, create, scale, backup
- ā Blocks: Delete operations, Helm uninstalls
2. Read-Only Mode (Monitoring/Observability)
export ALLOW_ONLY_READONLY_TOOLS=true
- ā Allows: Get/list operations, logs, health checks
- ā Blocks: All write operations
3. Custom Mode (Granular Control)
export ALLOWED_TOOLS="get_pods,get_deployments,get_services"
- ā Allows: Only specified tools
- ā Blocks: Everything else
4. Full Access Mode (Development Only)
# No environment variables set
- ā Allows: All operations
- ā ļø Warning: Use only in development environments
šÆ Supported Resources
Core Kubernetes Resources
- Workloads: Pods, Deployments, ReplicaSets, StatefulSets, DaemonSets
- Services: Services, Endpoints, Ingresses
- Configuration: ConfigMaps, Secrets
- Storage: PersistentVolumes, PersistentVolumeClaims, StorageClasses
- RBAC: Roles, ClusterRoles, RoleBindings, ClusterRoleBindings, ServiceAccounts
- Networking: NetworkPolicies
- Cluster: Namespaces, Nodes, Events
Istio Service Mesh
- Traffic Management: VirtualServices, DestinationRules, Gateways
- Security: ServiceEntries
Helm Operations
- Chart Management: Install, upgrade, uninstall
- Release Operations: List, status, values
- Repository Management: Add, list repositories
š§ Configuration
Environment Variables
| Variable | Description | Default | Example |
|---|---|---|---|
ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS |
Enable non-destructive mode | false |
true |
ALLOW_ONLY_READONLY_TOOLS |
Enable read-only mode | false |
true |
ALLOWED_TOOLS |
Custom tool whitelist | "" |
"get_pods,get_services" |
KUBECONFIG |
Kubernetes config path | ~/.kube/config |
/path/to/config |
TRANSPORT |
MCP transport method | stdio |
stdio or sse |
Windsurf Integration
Add to your Windsurf MCP configuration (~/.codeium/windsurf/mcp_config.json):
{
"mcpServers": {
"kubectl-safe": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"-v", "/Users/yourusername/.kube:/root/.kube:ro",
"-e", "KUBECONFIG=/root/.kube/config",
"-e", "ALLOW_ONLY_NON_DESTRUCTIVE_TOOLS=true",
"-e", "TRANSPORT=stdio",
"kubectl-mcp-server:latest",
"python", "run_server.py", "--transport", "stdio"
]
}
}
}
š Usage Examples
Basic Operations
# List all pods
python run_server.py --transport stdio
# Then use MCP client to call: get_pods_tool
# Get deployments in specific namespace
# MCP call: get_deployments_tool(namespace="production")
# Scale a deployment
# MCP call: scale_deployment_tool(name="myapp", replicas=3, namespace="default")
Backup Operations
# Backup a resource before deletion
# MCP call: backup_resource_tool(name="myapp", resource_type="deployment", namespace="default")
# Safe delete (backup + delete)
# MCP call: backup_and_delete_resource_tool(name="myapp", resource_type="deployment")
Helm Operations
# Install a Helm chart
# MCP call: install_helm_chart_tool(name="myapp", chart="nginx", namespace="default")
# List Helm releases
# MCP call: list_helm_releases_tool(namespace="default")
šļø Architecture
kubectl-mcp-server/
āāā run_server.py # Main entry point
āāā kubectl_mcp_tool/
ā āāā mcp_server.py # MCP server implementation
ā āāā tools/ # Modular tool implementations
ā āāā kubectl_get.py # Read operations
ā āāā kubectl_operations.py # Utility operations
ā āāā kubectl_delete.py # Destructive operations
ā āāā kubectl_backup.py # Backup operations
ā āāā helm_operations.py # Helm chart operations
āāā Dockerfile # Container configuration
āāā requirements.txt # Python dependencies
š Security Best Practices
- Use Non-Destructive Mode in production environments
- Mount kubeconfig read-only in containers
- Regularly backup critical resources
- Monitor logs for security events
- Use least-privilege RBAC policies
- Validate configurations before deployment
š Troubleshooting
Common Issues
Authentication Errors
# Check kubeconfig
kubectl config current-context
# Verify cluster access
kubectl get nodes
Container Issues
# Check container logs
docker logs kubectl-mcp-server
# Verify volume mounts
docker exec -it kubectl-mcp-server ls -la /root/.kube/
MCP Connection Issues
# Test server directly
python run_server.py --transport stdio --debug
# Validate JSON configuration
cat ~/.codeium/windsurf/mcp_config.json | python3 -m json.tool
š Monitoring
Health Checks
- Server startup logs indicate security mode
- Failed operations are logged with details
- Resource access attempts are audited
Metrics
- Operation success/failure rates
- Security mode violations
- Resource access patterns
š¤ Contributing
- Fork the repository
- Create a feature branch
- Add tests for new functionality
- Ensure security modes work correctly
- Submit a pull request
š License
This project is licensed under the MIT License - see the LICENSE file for details.
š Support
For issues and questions:
- Check the troubleshooting section
- Review container logs
- Validate Kubernetes connectivity
- Verify MCP configuration
š Version History
- v1.0.0: Initial release with security modes and comprehensive Kubernetes support
- FastMCP 2.11.3 integration
- Docker containerization
- Windsurf integration
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.