MKP - Model Kontext Protocol Server for Kubernetes
以下摘录自该仓库的 README(片段) · 在 GitHub 读完整 README →
MKP is a Model Context Protocol (MCP) server for Kubernetes that allows
LLM-powered applications to interact with Kubernetes clusters. It provides tools
for listing and applying Kubernetes resources through the MCP protocol.
Features
- List resources supported by the Kubernetes API server
- List clustered resources
- List namespaced resources
- Get resources and their subresources (including status, scale, logs, etc.)
- Apply (create or update) clustered resources
- Apply (create or update) namespaced resources
- Execute commands in pods with timeout control
- Generic and pluggable implementation using API Machinery's unstructured client
- Built-in rate limiting for protection against excessive API calls
Why MKP?
MKP offers several key advantages as a Model Context Protocol server for
Kubernetes:
Native Go Implementation
- Built with the same language as Kubernetes itself
- Excellent performance characteristics for server applications
- Strong type safety and concurrency support
- Seamless integration with Kubernetes libraries
Direct API Integration
- Uses Kubernetes API machinery directly without external dependencies
- No reliance on kubectl, helm, or other CLI tools
- Communicates directly with the Kubernetes API server
- Reduced overhead and improved reliability
Universal Resource Support
- Works with any Kubernetes resource type through the unstructured client
- No hardcoded resource schemas or specialized handlers needed
- Automatically supports Custom Resource Definitions (CRDs)
- Future-proof for new Kubernetes resources
Minimalist Design
- Focused on core Kubernetes resource operations
- Clean, maintainable codebase with clear separation of concerns
- Lightweight with minimal dependencies
- Easy to understand, extend, and contribute to
Production-Ready Architecture
- Designed for reliability and performance in production environments
- Proper error handling and resource management
- Built-in rate limiting to protect against excessive API calls
- Testable design with comprehensive unit tests
- Follows Kubernetes development best practices
Prerequisites
- Go 1.24 or later
- Kubernetes cluster and kubeconfig
- Task for running tasks
Installation
1. Clone the repository:
2. Install dependencies:
3. Build the server:
Usage
Running the server
To run the server with the default kubeconfig:
To run the server with a specific kubeconfig:
To run the server on a specific port:
Running with ToolHive
MKP can be run as a Model Context Protocol (MCP) server using
ToolHive, which simplifies the
deployment and management of MCP servers.
See the
ToolHive documentation for
detailed instructions on how to set up MKP with the ToolHive UI, CLI, or
Kubernetes operator.
MCP Tools
The MKP server provides the following MCP tools:
get_resource
Get a Kubernetes resource or its subresource.
Parameters:
- resource_type (required): Type of resource to get (clustered or namespaced)
- group: API group (e.g., apps, networking.k8s.io)
- version (required): API version (e.g., v1, v1beta1)
- resource (required): Resource name (e.g., deployments, services)
- namespace: Namespace (required for namespaced resources)
- name (required): Name of the resource to get
- subresource: Subresource to get (e.g., status, scale, logs)
- parameters: Optional parameters for the request (see examples below)
Example:
Example of getting logs from a specific container with parameters:
Available parameters for pod logs:
- container: Specify which container to get logs from
- previous: Get logs from previous container instance (true/false)
- sinceSeconds: Only return logs newer than a relative duration in seconds
- sinceTime: Only return logs after a specific time (RFC3339 format)
- timestamps: Include timestamps on each line (true/false)
- limitBytes: Maximum number of bytes to return