New: K8sGPT MCP Server with AI Integration!

Back to Documentation

Model Context Protocol (MCP) Server

K8sGPT MCP Server - Kubernetes operations as standardized tools for AI assistants

What is MCP?

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 like Claude to:

  • Analyze cluster health and issues
  • Query Kubernetes resources
  • Access pod logs and events
  • Get troubleshooting guidance
  • Manage analyzer filters

Quick Start

Start the MCP Server - Stdio Mode

For local AI assistants like Claude Desktop:

k8sgpt serve --mcp

Start the MCP Server - HTTP Mode

For network access and webhooks:

k8sgpt serve --mcp --mcp-http --mcp-port 8089

Server Modes

Stdio Mode (Default)

Used by local AI assistants like Claude Desktop for direct process communication.

Configuration Example:

{
  "mcpServers": {
    "k8sgpt": {
      "command": "k8sgpt",
      "args": ["serve", "--mcp"]
    }
  }
}

HTTP Mode

Used for network access and webhook integrations. The server runs in stateless mode with independent requests.

Command:

k8sgpt serve --mcp --mcp-http --mcp-port 8089

Available Tools

The MCP server exposes 12+ tools for Kubernetes operations:

Cluster Analysis

analyze

Analyze Kubernetes resources for issues and problems with optional AI explanations.

Parameters:

  • namespace (optional): Namespace to analyze
  • explain (optional): Get AI explanations for issues
  • filters (optional): Comma-separated list of analyzers to use

cluster-info

Get Kubernetes cluster information and version details.

Resource Management

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 query
  • labelSelector (optional): Label selector for filtering

get-resource

Get detailed information about a specific Kubernetes resource.

Parameters:

  • resourceType (required): Type of resource
  • name (required): Resource name
  • namespace (optional): Namespace

list-namespaces

List all namespaces in the cluster.

Debugging and Troubleshooting

get-logs

Get logs from a pod container.

Parameters:

  • podName (required): Name of the pod
  • namespace (optional): Namespace
  • container (optional): Container name
  • tail (optional): Number of lines to show
  • previous (optional): Show logs from previous container instance
  • sinceSeconds (optional): Show logs from last N seconds

list-events

List Kubernetes events for debugging.

Parameters:

  • namespace (optional): Namespace to query
  • involvedObjectName (optional): Filter by object name
  • involvedObjectKind (optional): Filter by object kind

Analyzer Management

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

Integration & Configuration

list-integrations

List available integrations (Prometheus, AWS, Keda, Kyverno, etc.)

config

Configure K8sGPT settings including custom analyzers and cache.

Available Resources

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

Available Prompts

Prompts provide guided troubleshooting workflows:

troubleshoot-pod

Interactive pod debugging workflow

Arguments: podName (required), namespace (required)

troubleshoot-deployment

Interactive deployment debugging workflow

Arguments: deploymentName (required), namespace (required)

troubleshoot-cluster

General cluster troubleshooting workflow

Integration with AI Assistants

Claude Desktop

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.

Custom MCP Clients

Any MCP-compatible client can connect to the k8sgpt server:

  1. Start the server: k8sgpt serve --mcp --mcp-http --mcp-port 8089
  2. Connect to: http://localhost:8089/mcp
  3. Use standard MCP protocol methods: tools/list, tools/call, resources/read, prompts/get

Advanced Configuration

Custom Port

k8sgpt serve --mcp --mcp-http --mcp-port 9000

With Specific Backend

k8sgpt serve --mcp --backend openai

With Kubeconfig

k8sgpt serve --mcp --kubeconfig ~/.kube/config

Troubleshooting

Connection Issues

Verify the server is running:

curl http://localhost:8089/mcp

Permission Issues

Ensure your kubeconfig has appropriate cluster access:

kubectl cluster-info

Tool Errors

List 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"}'

Learn More