k8s-mcp-server

k8s-mcp-server

k8s-mcp-server

Category
访问服务器

README

Kubernetes MCP Server

A Kubernetes Model Context Protocol (MCP) server that provides tools for interacting with Kubernetes clusters through a standardized interface.

Features

  • API Resource Discovery: Get all available API resources in your Kubernetes cluster
  • Resource Listing: List resources of any type with optional namespace and label filtering
  • Resource Details: Get detailed information about specific Kubernetes resources
  • Resource Description: Get comprehensive descriptions of Kubernetes resources
  • Pod Logs: Retrieve logs from specific pods
  • Node Metrics: Get resource usage metrics for specific nodes
  • Pod Metrics: Get CPU and Memory metrics for specific pods
  • Event Listing: List events within a namespace or for a specific resource.
  • Resource Creation: Create new Kubernetes resources from a manifest.
  • Standardized Interface: Uses the MCP protocol for consistent tool interaction
  • Flexible Configuration: Supports different Kubernetes contexts and resource scopes

Prerequisites

  • Go 1.20 or later
  • Access to a Kubernetes cluster
  • kubectl configured with appropriate cluster access

Installation

  1. Clone the repository:
git clone https://github.com/reza-gholizade/k8s-mcp-server.git
cd k8s-mcp-server
  1. Install dependencies:
go mod download
  1. Build the server:
go build -o k8s-mcp-server main.go

Usage

Starting the Server

Run the server:

./k8s-mcp-server

The server will start and listen on stdin/stdout for MCP protocol messages.

Available Tools

1. getAPIResources

Retrieves all available API resources in the Kubernetes cluster.

Parameters:

  • includeNamespaceScoped (boolean): Whether to include namespace-scoped resources (defaults to true)
  • includeClusterScoped (boolean): Whether to include cluster-scoped resources (defaults to true)

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getAPIResources",
  "params": {
    "arguments": {
      "includeNamespaceScoped": true,
      "includeClusterScoped": true
    }
  }
}

2. listResources

Lists all instances of a specific resource type.

Parameters:

  • Kind (string, required): The kind of resource to list (e.g., "Pod", "Deployment")
  • namespace (string): The namespace to list resources from (if omitted, lists across all namespaces for namespaced resources)
  • labelSelector (string): Filter resources by label selector

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "listResources",
  "params": {
    "arguments": {
      "Kind": "Pod",
      "namespace": "default",
      "labelSelector": "app=nginx"
    }
  }
}

3. getResource

Retrieves detailed information about a specific resource.

Parameters:

  • kind (string, required): The kind of resource to get (e.g., "Pod", "Deployment")
  • name (string, required): The name of the resource to get
  • namespace (string): The namespace of the resource (if it's a namespaced resource)

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getResource",
  "params": {
    "arguments": {
      "kind": "Pod",
      "name": "nginx-pod",
      "namespace": "default"
    }
  }
}

4. describeResource

Describes a resource in the Kubernetes cluster based on given kind and name, similar to kubectl describe.

Parameters:

  • Kind (string, required): The kind of resource to describe (e.g., "Pod", "Deployment")
  • name (string, required): The name of the resource to describe
  • namespace (string): The namespace of the resource (if it's a namespaced resource)

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "describeResource",
  "params": {
    "arguments": {
      "Kind": "Pod",
      "name": "nginx-pod",
      "namespace": "default"
    }
  }
}

5. getPodsLogs

Retrieves the logs of a specific pod in the Kubernetes cluster.

Parameters:

  • Name (string, required): The name of the pod to get logs from.
  • namespace (string): The namespace of the pod (if it's a namespaced resource).

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getPodsLogs",
  "params": {
    "arguments": {
      "Name": "my-app-pod-12345",
      "namespace": "production"
    }
  }
}

6. getNodeMetrics

Retrieves resource usage metrics for a specific node in the Kubernetes cluster.

Parameters:

  • Name (string, required): The name of the node to get metrics from.

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getNodeMetrics",
  "params": {
    "arguments": {
      "Name": "worker-node-1"
    }
  }
}

7. getPodMetrics

Retrieves CPU and Memory metrics for a specific pod in the Kubernetes cluster.

Parameters:

  • namespace (string, required): The namespace of the pod.
  • podName (string, required): The name of the pod.

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getPodMetrics",
  "params": {
    "arguments": {
      "namespace": "default",
      "podName": "my-app-pod-67890"
    }
  }
}

8. getEvents

Retrieves events for a specific namespace or resource in the Kubernetes cluster.

Parameters:

  • namespace (string): The namespace to get events from. If omitted, events from all namespaces are considered (if permitted by RBAC).
  • resourceName (string): The name of a specific resource (e.g., a Pod name) to filter events for.
  • resourceKind (string): The kind of the specific resource (e.g., "Pod") if resourceName is provided.

Example (Namespace Events):

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getEvents",
  "params": {
    "arguments": {
      "namespace": "default"
    }
  }
}

Example (Resource Events):

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "getEvents",
  "params": {
    "arguments": {
      "namespace": "production",
      "resourceName": "my-app-pod-12345",
      "resourceKind": "Pod"
    }
  }
}

9. createorUpdateResource

Creates a new resource in the Kubernetes cluster from a YAML or JSON manifest.

Parameters:

  • manifest (string, required): The YAML or JSON manifest of the resource to create.
  • namespace (string, optional): The namespace in which to create the resource. If the manifest contains a namespace, this parameter can be omitted or used to override it (behavior might depend on server implementation).

Example:

{
  "jsonrpc": "2.0",
  "id": 1,
  "method": "createResource",
  "params": {
    "arguments": {
      "namespace": "default",
      "manifest": "apiVersion: v1\nkind: Pod\nmetadata:\n  name: my-new-pod\nspec:\n  containers:\n  - name: nginx\n    image: nginx:latest"
    }
  }
}

Development

Project Structure

.
├── handlers/         # Tool handlers
│   └── handlers.go   # Implementation of MCP tools
├── pkg/             # Internal packages
│   └── k8s/         # Kubernetes client implementation
├── main.go          # Server entry point
├── go.mod           # Go module definition
└── go.sum           # Go module checksums

Adding New Tools

To add a new tool:

  1. Create a new tool definition function (e.g., MyNewTool() mcp.Tool) in handlers/handlers.go
  2. Implement the tool handler function (e.g., MyNewHandler(client *k8s.Client) func(...)) in handlers/handlers.go
  3. Register the tool and its handler in main.go using s.AddTool()

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for details on how to contribute to this project.

License

gholizade.net@gmail.com

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

<a href="https://glama.ai/mcp/servers/@reza-gholizade/k8s-mcp-server"> <img width="380" height="200" src="https://glama.ai/mcp/servers/@reza-gholizade/k8s-mcp-server/badge" />

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

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

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

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

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选