Kubernetes MCP Server

Kubernetes MCP Server

A lightweight MCP server that provides natural language processing and API access to Kubernetes clusters, combining both kubectl commands and Kubernetes Python client.

ductnn

开发者工具
访问服务器

README

Kubernetes MCP Server

Python Version License

A lightweight MCP server that provides natural language processing and API access to Kubernetes clusters, combining both kubectl commands and Kubernetes Python client.

https://github.com/user-attachments/assets/48e061cd-3e85-40ff-ab04-a1a2b9bbd152

✨ Features

  • Natural Language Interface: Convert plain English queries to kubectl commands
    • List pods and deployments across all namespaces
    • Fallback to general resource listing for unsupported queries
  • Full CRUD Operations:
    • 🆕 Create/Delete namespaces, pods, and deployments via API endpoints
    • 🔍 Inspect cluster resources
    • ✏️ Modify labels, annotations, and deployment configurations
    • 🗑️ Graceful deletion
    • 📊 Scale deployments
  • Dual Execution Mode:
    • kubectl command integration
    • Kubernetes Python client (official SDK)
  • Advanced Capabilities:
    • Namespace validation (DNS-1123 compliant)
    • Label filtering
    • Grace period control
    • Automatic command fallback
    • Resource management (CPU, memory)
    • Environment variable configuration

📦 Installation

Prerequisites

  • Python 3.11+
  • Kubernetes cluster access
  • kubectl configured locally
  • UV installed
# Clone repository
git clone https://github.com/ductnn/mcp-kubernetes-server.git 
cd mcp-kubernetes-server

# Create virtual environment
uv venv .venv

# Activate (Unix)
source .venv/bin/activate

# Install dependencies
uv pip install -r requirements.txt

🚀 Usage

Natural Language Processing

The server supports basic natural language queries for listing resources:

# List all pods
result = nl_processor.process("Show me all pods")

# List all deployments
result = nl_processor.process("Show me all deployments")

# Query with namespace
result = nl_processor.process("Show me all resources", "kube-system")

For more complex operations, use the dedicated API endpoints:

# Create a pod
pod_service.create_pod(
    name="my-pod",
    namespace="default",
    image="nginx:latest",
    labels={"app": "my-app"}
)

# Create a deployment
deployment_service.create_deployment(
    name="my-deployment",
    namespace="default",
    image="nginx:latest",
    replicas=3
)

# Delete a namespace
namespace_service.delete("my-namespace", force=True)

API Endpoints

The server provides RESTful endpoints for all operations:

  • /api/pods - Pod operations
  • /api/deployments - Deployment operations
  • /api/namespaces - Namespace operations
  • /api/cluster - Cluster operations
  • /api/nlp - Natural language processing

🤖 Usage with AI Assistants

Claude Desktop

  • Open your Claude Desktop and choose Settings -> choose mode Developer -> Edit config and open file claude_desktop_config.json and edit:
{
    "mcpServers": {
        "kubernetes": {
            "command": "/path-to-your-uv/uv",
            "args": [
                "--directory",
                "/path-you-project/", // Example for me /Users/ductn/mcp-kubernetes-server
                "run",
                "main.py"
            ]
        }
    }
}
  • Then, restart your Claude Desktop and play :)

🧪 Testing

Run the test suite:

# Run all tests
pytest

# Run specific test file
pytest tests/unit/test_pod_service.py

# Run with coverage
pytest --cov=.

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

推荐服务器

Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
MCP Package Docs Server

MCP Package Docs Server

促进大型语言模型高效访问和获取 Go、Python 和 NPM 包的结构化文档,通过多语言支持和性能优化来增强软件开发。

精选
本地
TypeScript
Claude Code MCP

Claude Code MCP

一个实现了 Claude Code 作为模型上下文协议(Model Context Protocol, MCP)服务器的方案,它可以通过标准化的 MCP 接口来使用 Claude 的软件工程能力(代码生成、编辑、审查和文件操作)。

精选
本地
JavaScript
@kazuph/mcp-taskmanager

@kazuph/mcp-taskmanager

用于任务管理的模型上下文协议服务器。它允许 Claude Desktop(或任何 MCP 客户端)在基于队列的系统中管理和执行任务。

精选
本地
JavaScript
mermaid-mcp-server

mermaid-mcp-server

一个模型上下文协议 (MCP) 服务器,用于将 Mermaid 图表转换为 PNG 图像。

精选
JavaScript
Jira-Context-MCP

Jira-Context-MCP

MCP 服务器向 AI 编码助手(如 Cursor)提供 Jira 工单信息。

精选
TypeScript
Linear MCP Server

Linear MCP Server

一个模型上下文协议(Model Context Protocol)服务器,它与 Linear 的问题跟踪系统集成,允许大型语言模型(LLM)通过自然语言交互来创建、更新、搜索和评论 Linear 问题。

精选
JavaScript
Sequential Thinking MCP Server

Sequential Thinking MCP Server

这个服务器通过将复杂问题分解为顺序步骤来促进结构化的问题解决,支持修订,并通过完整的 MCP 集成来实现多条解决方案路径。

精选
Python
Curri MCP Server

Curri MCP Server

通过管理文本笔记、提供笔记创建工具以及使用结构化提示生成摘要,从而实现与 Curri API 的交互。

官方
本地
JavaScript