K8sGPT provides a Model Context Protocol (MCP) server that exposes Kubernetes cluster operations as standardized tools, resources, and prompts for AI assistants like Claude, ChatGPT, and other MCP-compatible clients.
- What is MCP?
- Quick Start
- Server Modes
- Available Tools
- Available Resources
- Available Prompts
- Usage Examples
- Integration with AI Assistants
- HTTP API Reference
The Model Context Protocol (MCP) is an open standard that enables AI assistants to securely connect to external data sources and tools. K8sGPT's MCP server exposes Kubernetes operations through this standardized interface, allowing AI assistants to:
- Analyze cluster health and issues
- Query Kubernetes resources
- Access pod logs and events
- Get troubleshooting guidance
- Manage analyzer filters
Stdio mode (for local AI assistants):
k8sgpt serve --mcpHTTP mode (for network access):
k8sgpt serve --mcp --mcp-http --mcp-port 8089curl -X POST http://localhost:8089/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list"
}'Used by local AI assistants like Claude Desktop:
k8sgpt serve --mcpConfigure in your MCP client (e.g., Claude Desktop's claude_desktop_config.json):
{
"mcpServers": {
"k8sgpt": {
"command": "k8sgpt",
"args": ["serve", "--mcp"]
}
}
}Used for network access and webhooks:
k8sgpt serve --mcp --mcp-http --mcp-port 8089The server runs in stateless mode, so no session management is required. Each request is independent.
The MCP server exposes 12 tools for Kubernetes operations:
analyze
- Analyze Kubernetes resources for issues and problems
- Parameters:
namespace(optional): Namespace to analyzeexplain(optional): Get AI explanations for issuesfilters(optional): Comma-separated list of analyzers to use
cluster-info
- Get Kubernetes cluster information and version
list-resources
- List Kubernetes resources of a specific type
- Parameters:
resourceType(required): Type of resource (pods, deployments, services, nodes, jobs, cronjobs, statefulsets, daemonsets, replicasets, configmaps, secrets, ingresses, pvcs, pvs)namespace(optional): Namespace to querylabelSelector(optional): Label selector for filtering
get-resource
- Get detailed information about a specific Kubernetes resource
- Parameters:
resourceType(required): Type of resourcename(required): Resource namenamespace(optional): Namespace
list-namespaces
- List all namespaces in the cluster
get-logs
- Get logs from a pod container
- Parameters:
podName(required): Name of the podnamespace(optional): Namespacecontainer(optional): Container nametail(optional): Number of lines to showprevious(optional): Show logs from previous container instancesinceSeconds(optional): Show logs from last N seconds
list-events
- List Kubernetes events for debugging
- Parameters:
namespace(optional): Namespace to queryinvolvedObjectName(optional): Filter by object nameinvolvedObjectKind(optional): Filter by object kind
list-filters
- List all available and active analyzers/filters
add-filters
- Add filters to enable specific analyzers
- Parameters:
filters(required): Comma-separated list of analyzer names
remove-filters
- Remove filters to disable specific analyzers
- Parameters:
filters(required): Comma-separated list of analyzer names
list-integrations
- List available integrations (Prometheus, AWS, Keda, Kyverno, etc.)
config
- Configure K8sGPT settings including custom analyzers and cache
Resources provide read-only access to cluster information:
cluster-info
- URI:
cluster-info - Get information about the Kubernetes cluster
namespaces
- URI:
namespaces - List all namespaces in the cluster
active-filters
- URI:
active-filters - Get currently active analyzers/filters
Prompts provide guided troubleshooting workflows:
troubleshoot-pod
- Interactive pod debugging workflow
- Arguments:
podName(required): Name of the pod to troubleshootnamespace(required): Namespace of the pod
troubleshoot-deployment
- Interactive deployment debugging workflow
- Arguments:
deploymentName(required): Name of the deploymentnamespace(required): Namespace of the deployment
troubleshoot-cluster
- General cluster troubleshooting workflow
curl -X POST http://localhost:8089/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "analyze",
"arguments": {
"namespace": "production",
"explain": "true"
}
}
}'curl -X POST http://localhost:8089/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 2,
"method": "tools/call",
"params": {
"name": "list-resources",
"arguments": {
"resourceType": "pods",
"namespace": "default"
}
}
}'curl -X POST http://localhost:8089/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 3,
"method": "tools/call",
"params": {
"name": "get-logs",
"arguments": {
"podName": "nginx-abc123",
"namespace": "default",
"tail": "100"
}
}
}'curl -X POST http://localhost:8089/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 4,
"method": "resources/read",
"params": {
"uri": "namespaces"
}
}'curl -X POST http://localhost:8089/mcp \
-H "Content-Type: application/json" \
-d '{
"jsonrpc": "2.0",
"id": 5,
"method": "prompts/get",
"params": {
"name": "troubleshoot-pod",
"arguments": {
"podName": "nginx-abc123",
"namespace": "default"
}
}
}'Add to claude_desktop_config.json:
{
"mcpServers": {
"k8sgpt": {
"command": "k8sgpt",
"args": ["serve", "--mcp"]
}
}
}Restart Claude Desktop and you'll see k8sgpt tools available in the tool selector.
Any MCP-compatible client can connect to the k8sgpt server. For HTTP-based clients:
- Start the server:
k8sgpt serve --mcp --mcp-http --mcp-port 8089 - Connect to:
http://localhost:8089/mcp - Use standard MCP protocol methods:
tools/list,tools/call,resources/read,prompts/get
POST http://localhost:8089/mcp
Content-Type: application/json
All requests follow the JSON-RPC 2.0 format:
{
"jsonrpc": "2.0",
"id": 1,
"method": "method_name",
"params": {
...
}
}List Tools
{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}List Resources
{"jsonrpc": "2.0", "id": 2, "method": "resources/list"}List Prompts
{"jsonrpc": "2.0", "id": 3, "method": "prompts/list"}{
"jsonrpc": "2.0",
"id": 4,
"method": "tools/call",
"params": {
"name": "tool_name",
"arguments": {
"arg1": "value1",
"arg2": "value2"
}
}
}{
"jsonrpc": "2.0",
"id": 5,
"method": "resources/read",
"params": {
"uri": "resource_uri"
}
}{
"jsonrpc": "2.0",
"id": 6,
"method": "prompts/get",
"params": {
"name": "prompt_name",
"arguments": {
"arg1": "value1"
}
}
}Successful responses:
{
"jsonrpc": "2.0",
"id": 1,
"result": {
...
}
}Error responses:
{
"jsonrpc": "2.0",
"id": 1,
"error": {
"code": -32600,
"message": "Error description"
}
}k8sgpt serve --mcp --mcp-http --mcp-port 9000k8sgpt serve --mcp --backend openaik8sgpt serve --mcp --kubeconfig ~/.kube/configVerify the server is running:
curl http://localhost:8089/mcpEnsure your kubeconfig has appropriate cluster access:
kubectl cluster-infoList available tools to verify names:
curl -X POST http://localhost:8089/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc": "2.0", "id": 1, "method": "tools/list"}'