Sponsored by Deepsite.site

Kubernetes Mcp

Created By
HSn09189 months ago
Content

🚀 Kubernetes-MCP

English | 中文

✨ A Model Capable Protocol (MCP) server implementation designed with Go for interacting with Kubernetes clusters. This server allows MCP-compatible clients to perform Kubernetes operations through defined tools.

📌 Core Features

🔹 MCP Server: Implements the mcp-go library to provide MCP functionality 🔹 Kubernetes Interaction: Uses controller-runtime client to interact with clusters 🔹 Transport Methods: Supports standard I/O (stdio) or Server-Sent Events (sse) 🔹 Data Model: Uses dedicated models package for standardized data structures 🔹 Response Format: All tools provide human-readable text and structured JSON output

🛠️ Resource Management Tools

📊 Implemented API Groups

🔸 Core API Group (v1)

  • List, get, describe, create, update, delete operations
  • Cluster-scoped: list namespaces, list nodes
  • Get Pod logs functionality

🔸 Apps API Group (apps/v1)

  • Full support for Deployment, ReplicaSet, StatefulSet, DaemonSet

🔸 Batch API Group (batch/v1)

  • Full support for Job, CronJob

🔸 Networking API Group (networking.k8s.io/v1)

  • Full support for Ingress, NetworkPolicy

🔸 RBAC API Group (rbac.authorization.k8s.io/v1)

  • Full support for Role, RoleBinding, ClusterRole, ClusterRoleBinding

🔸 Storage API Group (storage.k8s.io/v1)

  • Full support for StorageClass, VolumeAttachment

🔸 Policy API Group (policy/v1beta1)

  • Full support for PodSecurityPolicy, PodDisruptionBudget

🔸 API Extensions API Group (apiextensions.k8s.io/v1)

  • Full support for CustomResourceDefinition

🔸 Autoscaling API Group (autoscaling/v1)

  • Full support for HorizontalPodAutoscaler

📋 Requirements

📌 Go 1.24 📌 Kubernetes cluster access (via kubeconfig or in-cluster service account)

📦 Key Dependencies

🧩 Core Libraries:

  • github.com/mark3labs/mcp-go - MCP protocol implementation
  • sigs.k8s.io/controller-runtime - Kubernetes client
  • k8s.io/client-go - Core Kubernetes libraries
  • github.com/spf13/cobra - CLI structure
  • go.uber.org/zap - Logging
  • sigs.k8s.io/yaml - YAML processing

🔨 Build Methods

📥 Build from Source

git clone https://github.com/HSn0918/kubernetes-mcp.git
cd kubernetes-mcp
go build -o kubernetes-mcp ./cmd/kubernetes-mcp
./kubernetes-mcp server --transport=sse --port 8080

🐳 Docker Build

# Build image
docker build -t kubernetes-mcp:latest \
  --build-arg VERSION=$(git describe --tags --always) \
  --build-arg COMMIT=$(git rev-parse HEAD) \
  --build-arg BUILD_DATE=$(date -u +"%Y-%m-%dT%H:%M:%SZ") .

# Run with stdio transport (default)
docker run -v ~/.kube:/root/.kube kubernetes-mcp:latest

# Run with SSE transport
docker run -p 8080:8080 -v ~/.kube:/root/.kube kubernetes-mcp:latest server --transport=sse

# View version info
docker run kubernetes-mcp:latest version

# Specify custom kubeconfig
docker run -v /path/to/config:/config kubernetes-mcp:latest server --kubeconfig=/config

🚀 Usage

🔄 Starting the Server

# Using standard I/O (default)
./kubernetes-mcp server

# Using SSE (Server-Sent Events)
./kubernetes-mcp server --transport sse --port 8080

# Specifying Kubeconfig
./kubernetes-mcp server --kubeconfig /path/to/your/kubeconfig

# View version
./kubernetes-mcp version

⚙️ Configuration Options

🔧 Transport: --transport (stdio/sse) 🔧 Port: --port (default 8080, SSE mode) 🔧 Config file: --kubeconfig (path) 🔧 Log level: --log-level (debug/info/warn/error) 🔧 Log format: --log-format (console/json)

🧩 Advanced Features

📝 Structured Tools

🔍 GET_CLUSTER_INFO: Get cluster information and version details 🔍 GET_API_RESOURCES: List available API resources in the cluster 🔍 SEARCH_RESOURCES: Search across namespaces and resource types 🔍 EXPLAIN_RESOURCE: Get resource structure and field details 🔍 APPLY_MANIFEST: Apply YAML manifests to the cluster 🔍 VALIDATE_MANIFEST: Validate YAML manifest format 🔍 DIFF_MANIFEST: Compare YAML with existing cluster resources 🔍 GET_EVENTS: Get events related to specific resources

💡 Prompt System

🔖 KUBERNETES_YAML_PROMPT: Generate standard Kubernetes YAML 🔖 KUBERNETES_QUERY_PROMPT: Kubernetes operation guidance 🔖 TROUBLESHOOT_PODS_PROMPT: Pod troubleshooting guide 🔖 TROUBLESHOOT_NODES_PROMPT: Node troubleshooting guide

🔄 Standard Resource Operations

Each API group supports the following operations:

  • List resources: Get resource lists, filterable by namespace and labels
  • Get resource: Retrieve specific resources in YAML format
  • Describe resource: Get detailed readable descriptions of resources
  • Create resource: Create new resources from YAML
  • Update resource: Update existing resources using YAML
  • Delete resource: Remove specific resources

🌟 Core API Group Special Operations

  • Get Pod logs: Retrieve logs from specific Pod containers
  • List namespaces: View all available namespaces in the cluster
  • List nodes: View all nodes and their status in the cluster

Server Config

{
  "mcpServers": {
    "kubernetes-mcp": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "--rm",
        "-p",
        "8080:8080",
        "-v",
        "~/.kube:/root/.kube",
        "kubernetes-mcp:latest",
        "server",
        "--transport=sse"
      ],
      "env": {
        "KUBECONFIG": "/root/.kube/config"
      }
    }
  }
}
Recommend Servers
TraeBuild with Free GPT-4.1 & Claude 3.7. Fully MCP-Ready.
Baidu Map百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Jina AI MCP ToolsA Model Context Protocol (MCP) server that integrates with Jina AI Search Foundation APIs.
Tavily Mcp
EdgeOne Pages MCPAn MCP service designed for deploying HTML content to EdgeOne Pages and obtaining an accessible public URL.
DeepChatYour AI Partner on Desktop
Zhipu Web SearchZhipu Web Search MCP Server is a search engine specifically designed for large models. It integrates four search engines, allowing users to flexibly compare and switch between them. Building upon the web crawling and ranking capabilities of traditional search engines, it enhances intent recognition capabilities, returning results more suitable for large model processing (such as webpage titles, URLs, summaries, site names, site icons, etc.). This helps AI applications achieve "dynamic knowledge acquisition" and "precise scenario adaptation" capabilities.
MiniMax MCPOfficial MiniMax Model Context Protocol (MCP) server that enables interaction with powerful Text to Speech, image generation and video generation APIs.
Serper MCP ServerA Serper MCP Server
CursorThe AI Code Editor
Playwright McpPlaywright MCP server
WindsurfThe new purpose-built IDE to harness magic
Howtocook Mcp基于Anduin2017 / HowToCook (程序员在家做饭指南)的mcp server,帮你推荐菜谱、规划膳食,解决“今天吃什么“的世纪难题; Based on Anduin2017/HowToCook (Programmer's Guide to Cooking at Home), MCP Server helps you recommend recipes, plan meals, and solve the century old problem of "what to eat today"
Context7Context7 MCP Server -- Up-to-date code documentation for LLMs and AI code editors
BlenderBlenderMCP connects Blender to Claude AI through the Model Context Protocol (MCP), allowing Claude to directly interact with and control Blender. This integration enables prompt assisted 3D modeling, scene creation, and manipulation.
TimeA Model Context Protocol server that provides time and timezone conversion capabilities. This server enables LLMs to get current time information and perform timezone conversions using IANA timezone names, with automatic system timezone detection.
MCP AdvisorMCP Advisor & Installation - Use the right MCP server for your needs
Amap Maps高德地图官方 MCP Server
ChatWiseThe second fastest AI chatbot™
Visual Studio Code - Open Source ("Code - OSS")Visual Studio Code
AiimagemultistyleA Model Context Protocol (MCP) server for image generation and manipulation using fal.ai's Stable Diffusion model.