kubectl-ai can run as an MCP (Model Context Protocol) server, exposing kubectl-ai tools to other MCP clients. The server can run in two modes:
- Built-in tools only: Exposes only kubectl-ai's native tools
- External tool discovery: Additionally discovers and exposes tools from other MCP servers
Start the MCP server with only kubectl-ai's built-in tools:
kubectl-ai --mcp-serverStart the MCP server with external MCP tool discovery enabled:
kubectl-ai --mcp-server --external-toolsRun the server with the streamable HTTP transport to serve compatible MCP clients (including kubectl-ai MCP client mode) over HTTP:
kubectl-ai --mcp-server --mcp-server-mode streamable-http --http-port 9080This listens on http://localhost:9080/mcp by default.
When --external-tools is enabled, the enhanced MCP server will automatically discover and expose tools from configured MCP servers. You can configure MCP servers using the standard MCP client configuration file.
Create ~/.config/kubectl-ai/mcp.yaml:
servers:
filesystem:
command: "npx"
args:
[
"-y",
"@modelcontextprotocol/server-filesystem",
"/path/to/allowed/files",
]
brave-search:
command: "npx"
args: ["-y", "@modelcontextprotocol/server-brave-search"]
env:
BRAVE_API_KEY: "your-api-key"When external tool discovery is enabled with --external-tools, the kubectl-ai MCP server acts as a tool aggregator, providing:
- All kubectl-ai built-in tools (kubectl, cluster analysis, etc.)
- Tools from external MCP servers (filesystem, web search, etc.)
- Unified interface for all tools through a single MCP endpoint
The server handles external MCP connection failures gracefully:
- If external MCP servers are unavailable, the server continues with built-in tools only
- Individual tool failures don't affect the overall server operation
- Clear logging for troubleshooting connection issues
Configure Claude Desktop to use kubectl-ai as an MCP server:
Basic usage (built-in tools only):
{
"mcpServers": {
"kubectl-ai": {
"command": "kubectl-ai",
"args": ["--mcp-server"]
}
}
}Enhanced usage (with external tools):
{
"mcpServers": {
"kubectl-ai": {
"command": "kubectl-ai",
"args": ["--mcp-server", "--external-tools"]
}
}
}kubectl-ai provides the following native tools:
bash: Executes a bash command. Use this tool only when you need to execute a shell command.kubectl: Executes a kubectl command against the user's Kubernetes cluster. Use this tool only when you need to query or modify the state of the user's Kubernetes cluster.
Additional tools are available depending on the configured MCP servers:
- Filesystem tools: Read/write files, list directories
- Web search tools: Search the internet for information
- Database tools: Query databases
- API tools: Interact with external APIs
- Custom tools: Any MCP-compatible tools
| Flag | Default | Description |
|---|---|---|
--mcp-server |
false |
Run in MCP server mode |
--external-tools |
false |
Discover and expose external MCP tools (requires --mcp-server) |
--kubeconfig |
~/.kube/config |
Path to kubeconfig file |
--mcp-server-mode |
stdio |
Transport for the MCP server (stdio or streamable-http) |
--http-port |
9080 |
Port for the HTTP endpoint when using streamable-http modes |
┌─────────────────┐ ┌───────────────────┐ ┌─────────────────┐
│ MCP Client │───▶│ kubectl-ai Server │───▶│ External Tools │
│ (Claude, etc.) │ │ │ │ (filesystem, │
│ │ │ ┌───────────────┐ │ │ web search, │
│ │ │ │ Built-in │ │ │ etc.) │
│ │ │ │ kubectl tools │ │ │ │
│ │ │ └───────────────┘ │ │ │
└─────────────────┘ └───────────────────┘ └─────────────────┘The kubectl-ai MCP server acts as both:
- An MCP Server (exposing tools to clients)
- An MCP Client (consuming tools from other servers, when
--external-toolsis enabled)
This creates a powerful tool aggregation pattern where kubectl-ai becomes a central hub for both Kubernetes operations and general-purpose tools.
If external tools aren't appearing:
- Ensure you're using both
--mcp-serverand--external-toolsflags - Check MCP configuration file exists and is valid
- Verify external MCP servers are working independently
- Check kubectl-ai logs for connection errors
- Try running with external tools disabled to isolate issues
- Tool discovery adds startup time (usually 2-3 seconds) when
--external-toolsis enabled - Each external tool call has network overhead
- Consider running without
--external-toolsfor faster startup if external tools aren't needed
Enable verbose logging to troubleshoot:
kubectl-ai --mcp-server --external-tools -v=2This will show:
- MCP server connection attempts
- Tool discovery results
- Tool call routing decisions