gabornyergesX/kubernetes-mcp-server
If you are the rightful owner of kubernetes-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
A Kubernetes Model Context Protocol (MCP) server that provides programmatic access to Kubernetes resources through a standardized interface.
Kubernetes MCP Server
A Kubernetes Model Context Protocol (MCP) server that provides programmatic access to Kubernetes resources through a standardized interface.
Overview
This project implements a comprehensive MCP server for Kubernetes that enables applications to interact with Kubernetes clusters through a well-defined protocol. It supports a wide range of Kubernetes resources including pods, services, deployments, webhooks, and more.
Features
- Comprehensive Resource Support: Pods, Services, Ingresses, IngressClasses, Deployments, DaemonSets, StatefulSets, ReplicaSets, Jobs, CronJobs, ConfigMaps, Secrets, ResourceQuotas, LimitRanges, HPAs, PriorityClasses, RuntimeClasses, Leases, and Webhooks
- Full CRUD Operations: Create, Read, Update, Delete operations for all supported resources
- Real-time Watch: Event streaming for resource changes
- Multiple Transport Protocols: HTTP/JSON-RPC and Server-Sent Events (SSE)
- Comprehensive Testing: Extensive test coverage for all functionality
- Production Ready: Proper error handling, logging, and monitoring
Test Coverage
The project maintains comprehensive test coverage across all components:
- Overall Coverage: 25.4% (target: 80%+)
- Core Components: High coverage on critical paths
- Handler Coverage: All 23 resource handlers tested
- Transport Layer: HTTP and stdio transport tested
- Validation: Input validation and RBAC validation tested
- Utilities: Core utilities and helper functions tested
Coverage Reports
- HTML Report: Generated as
coverage.html
after runningmake test-coverage
- Detailed Report: Use
make test-coverage-detailed
for package-by-package analysis - CI Integration: Coverage reports uploaded to Codecov on every PR
- Coverage Badge: Real-time coverage status in repository badges
Coverage Goals
- Short-term: Achieve 50% overall coverage
- Medium-term: Achieve 70% overall coverage
- Long-term: Achieve 80%+ overall coverage
- Critical Paths: Maintain 90%+ coverage on core functionality
Quick Start
Prerequisites
- Go 1.21 or later
- Kubernetes cluster access (kubeconfig)
jq
for JSON processing (for test scripts)
Installation
# Clone the repository
git clone <repository-url>
cd kubernetes-mcp-server
# Build the server
make build
# Run the server
./kubernetes-mcp-server -transport sse -port 8080
Usage
The server exposes the following endpoints:
- MCP Endpoint:
http://localhost:8080/mcp
- Main MCP protocol endpoint - SSE Endpoint:
http://localhost:8080/sse
- Server-Sent Events endpoint - Health Endpoint:
http://localhost:8080/health
- Health check endpoint
Example API Call
# List all pods in the default namespace
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list_pods",
"arguments": {
"namespace": "default"
}
}
}'
Project Structure
kubernetes-mcp-server/
āāā cmd/ # Application entry points
ā āāā kubernetes-mcp-server/ # Main application
ā āāā main.go # Application entry point
āāā internal/ # Private application code
ā āāā kubernetes/ # Kubernetes client implementations
ā ā āāā client.go # Base client interface and implementation
ā ā āāā pod_client.go # Pod operations
ā ā āāā service_client.go # Service operations
ā ā āāā connection_pool.go # Connection pooling
ā ā āāā ... # 23 focused client implementations
ā āāā mcp/ # MCP protocol handlers
ā ā āāā core/ # Core MCP functionality
ā ā ā āāā server.go # Main server logic
ā ā ā āāā handler.go # Base handler interface
ā ā ā āāā handler_utils.go # Common utilities
ā ā āāā handlers/ # Resource-specific handlers
ā ā ā āāā pod/ # Pod operations
ā ā ā āāā service/ # Service operations
ā ā ā āāā deployment/ # Deployment operations
ā ā ā āāā ... # 20+ other resource types
ā ā āāā tools/ # Tool schema definitions
ā ā ā āāā pod_tools.go # Pod tool schemas
ā ā ā āāā service_tools.go # Service tool schemas
ā ā ā āāā ... # 23 resource tool files
ā ā āāā utils/ # Resource-specific utilities
ā ā āāā pod_utils.go # Pod utilities
ā ā āāā service_utils.go # Service utilities
ā ā āāā ... # Resource utility files
ā āāā config/ # Configuration management
ā āāā logger/ # Structured logging
ā āāā health/ # Health checks
ā āāā transport/ # Transport layer implementations
ā āāā http.go # HTTP/SSE transport
ā āāā stdio.go # Stdio transport
āāā pkg/ # Public libraries
ā āāā types/ # Shared type definitions
āāā docs/ # Documentation
ā āāā README.md # Documentation index
ā āāā API_DOCUMENTATION.md # Complete API reference
ā āāā PROJECT_ORGANIZATION.md # Project structure guide
ā āāā ... # Implementation guides
āāā tests/ # Test files
ā āāā scripts/ # Test scripts
āāā logs/ # Log files
āāā go.mod # Go module definition
āāā go.sum # Go module checksums
āāā Makefile # Build and development tasks
āāā README.md # This file
Supported Resources
Core Resources
- Pods: Container orchestration and management
- Services: Network service abstraction
- Ingresses: External traffic routing and load balancing
- IngressClasses: Ingress controller configuration and defaults
- Namespaces: Resource isolation and organization
Workload Resources
- Deployments: Declarative updates for Pods and ReplicaSets
- DaemonSets: Ensures all nodes run a copy of a Pod
- StatefulSets: Manages stateful applications
- ReplicaSets: Maintains a stable set of replica Pods
- Jobs: Creates one or more Pods and tracks their completion
- CronJobs: Creates Jobs on a time-based schedule
Configuration Resources
- ConfigMaps: Stores non-confidential configuration data
- Secrets: Stores sensitive configuration data
- ResourceQuotas: Provides constraints that limit resource consumption
- LimitRanges: Provides constraints that limit resource consumption per namespace
Advanced Resources
- HorizontalPodAutoscalers: Automatically scales the number of Pods
- PriorityClasses: Indicates the relative importance of Pods
- RuntimeClasses: Selects the container runtime configuration
- Leases: Distributed locking mechanism
- Webhooks: Admission control and validation
API Reference
For comprehensive API documentation, see .
Quick Overview
The server provides 23 resource types with comprehensive CRUD operations:
Core Resources (5)
- Pods: Container orchestration and management
- Services: Network service abstraction
- Namespaces: Resource isolation and organization
- ConfigMaps: Non-confidential configuration data
- Secrets: Sensitive configuration data
Workload Resources (6)
- Deployments: Declarative updates for Pods and ReplicaSets
- DaemonSets: Ensures all nodes run a copy of a Pod
- StatefulSets: Manages stateful applications
- ReplicaSets: Maintains a stable set of replica Pods
- Jobs: Creates one or more Pods and tracks their completion
- CronJobs: Creates Jobs on a time-based schedule
Networking Resources (4)
- Ingresses: External traffic routing and load balancing
- IngressClasses: Ingress controller configuration and defaults
- Endpoints: Network endpoints for services
- NetworkPolicies: Network traffic control
Configuration Resources (3)
- ResourceQuotas: Provides constraints that limit resource consumption
- LimitRanges: Provides constraints that limit resource consumption per namespace
- HorizontalPodAutoscalers: Automatically scales the number of Pods
Advanced Resources (5)
- PriorityClasses: Indicates the relative importance of Pods
- RuntimeClasses: Selects the container runtime configuration
- Leases: Distributed locking mechanism
- Webhooks: Admission control and validation
- ReplicationControllers: Legacy replication controller
Available Operations
Each resource supports these operations:
Operation | Description | Example Tool Name |
---|---|---|
list_* | List all resources in a namespace | list_pods |
get_* | Get detailed information about a specific resource | get_pod |
create_* | Create a new resource | create_pod |
update_* | Update an existing resource | update_pod |
patch_* | Patch a resource | patch_pod |
delete_* | Delete a resource | delete_pod |
watch_* | Watch for resource changes | watch_pods |
scale_* | Scale a resource (Deployments, StatefulSets, etc.) | scale_deployment |
exec_* | Execute commands in pods | exec_pod |
Quick Example
# List all pods in the default namespace
curl -X POST http://localhost:8080/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "list_pods",
"arguments": {
"namespace": "default"
}
}
}'
Development
Building
# Build the server
make build
# Build with specific flags
go build -o kubernetes-mcp-server ./cmd/kubernetes-mcp-server
Testing
# Run unit tests
make test
# Run specific test scripts
./tests/scripts/test_service.sh
./tests/scripts/test_comprehensive.sh
Running Tests
The project includes comprehensive test scripts for all functionality:
# Test service functionality
./tests/scripts/test_service.sh
# Test comprehensive functionality
./tests/scripts/test_comprehensive.sh
# Test specific resources
./tests/scripts/test_lease.sh
./tests/scripts/test_webhook.sh
Configuration
Environment Variables
Variable | Description | Default |
---|---|---|
K8S_MCP_SERVER_HOST | Server host | localhost |
K8S_MCP_SERVER_PORT | Server port | 8080 |
K8S_MCP_SERVER_TRANSPORT | Transport type (http , sse , stdio ) | sse |
K8S_MCP_SERVER_LOG_LEVEL | Log level (debug , info , warn , error ) | info |
K8S_MCP_SERVER_LOG_FORMAT | Log format (json , text ) | json |
K8S_MCP_SERVER_LOG_OUTPUT | Log output path | stdout |
K8S_MCP_SERVER_HEALTH_ENDPOINT | Health check endpoint | /health |
K8S_MCP_SERVER_READY_ENDPOINT | Readiness probe endpoint | /ready |
K8S_MCP_SERVER_LIVE_ENDPOINT | Liveness probe endpoint | /live |
KUBECONFIG | Path to kubeconfig file | ~/.kube/config |
Command Line Flags
-transport
: Transport protocol (http
,sse
, orstdio
, default:sse
)-port
: Server port (default:8080
)-host
: Server host (default:localhost
)-log-level
: Logging level (default:info
)-log-format
: Log format (default:json
)
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests for new functionality
- Ensure all tests pass
- Submit a pull request
License
[Add your license information here]
Documentation
For comprehensive documentation, see the directory:
Core Documentation
- - Complete API reference with examples
- - Project structure and architecture guide