MCP HubMCP Hub
strowk

mcp-k8s-go

by: strowk

MCP server connecting to Kubernetes

246created 01/12/2024
Visit
Kubernetes

πŸ“ŒOverview

Purpose: The MCP K8S Go framework serves as a Golang-based server that connects to Kubernetes, facilitating seamless Kubernetes management and resource access.

Overview: MCP K8S Go is designed to simplify interactions with Kubernetes environments through a set of command-line tools and prompts, enhancing the efficiency of managing Kubernetes resources.

Key Features:

  • Kubernetes Context Management: Access and list Kubernetes contexts directly from kubeconfig configurations, allowing users to efficiently navigate multiple clusters.

  • Resource Management Tools: A suite of commands to list namespaces, nodes, resources, and events in specified contexts, as well as to retrieve logs from pods, tailoring resource management to user needs.


Golang-based MCP server connecting to Kubernetes

MCP K8S Go


Features

MCP πŸ’¬ prompt πŸ—‚οΈ resource πŸ€– tool

  • πŸ—‚οΈπŸ€– List Kubernetes contexts
  • πŸ’¬πŸ€– List Kubernetes namespaces
  • πŸ€– List and get any Kubernetes resources
    • includes custom mappings for resources like pods, services, deployments, but any resource can be listed and retrieved
  • πŸ€– List Kubernetes nodes
  • πŸ’¬ List Kubernetes pods
  • πŸ€– Get Kubernetes events
  • πŸ€– Get Kubernetes pod logs
  • πŸ€– Run command in Kubernetes pod

Browse With Inspector

To use latest published version with Inspector you can run this:

npx @modelcontextprotocol/inspector npx @strowk/mcp-k8s

Use With Claude

Demo Usage

Following chat with Claude Desktop demonstrates how it looks when selected particular context as a resource and then asked to check pod logs for errors in kube-system namespace:

To use this MCP server with Claude Desktop (or any other client) you might need to choose which way of installation to use.

You have multiple options:

Smitherymcp-getPre-built NPMPre-built in GithubFrom sourcesUsing Docker
Claude SetupAutoAutoManualManualManualManual
PrerequisiteNode.jsNode.jsNode.jsNoneGolangDocker

Using Smithery

To install MCP K8S Go for Claude Desktop automatically via Smithery:

npx -y @smithery/cli install @strowk/mcp-k8s --client claude

Using mcp-get

To install MCP K8S Go for Claude Desktop automatically via mcp-get:

npx @michaellatman/mcp-get@latest install @strowk/mcp-k8s

Manually with prebuilt binaries

Prebuilt from npm

Use this if you have npm installed and want to use pre-built binaries:

npm install -g @strowk/mcp-k8s

Then check version by running mcp-k8s --version and if this printed installed version, you can proceed to add configuration to claude_desktop_config.json file:

{
  "mcpServers": {
    "mcp_k8s": {
      "command": "mcp-k8s",
      "args": []
    }
  }
}

Or using npx with any client:

npx @strowk/mcp-k8s

For example for Claude:

{
  "mcpServers": {
    "mcp_k8s": {
      "command": "npx",
      "args": [
        "@strowk/mcp-k8s"
      ]
    }
  }
}

From GitHub releases

Head to GitHub releases and download the latest release for your platform.

Unpack the archive, which would contain binary named mcp-k8s-go, put that binary somewhere in your PATH and then add the following configuration to the claude_desktop_config.json file:

{
  "mcpServers": {
    "mcp_k8s": {
      "command": "mcp-k8s-go",
      "args": []
    }
  }
}

Building from source

You would need Golang installed to build this project:

go get github.com/strowk/mcp-k8s-go
go install github.com/strowk/mcp-k8s-go

Then add the following configuration to the claude_desktop_config.json file:

{
  "mcpServers": {
    "mcp_k8s_go": {
      "command": "mcp-k8s-go",
      "args": []
    }
  }
}

Using Docker

This server is built and published to Docker Hub since 0.3.1-beta.2 release with multi-arch images available for linux/amd64 and linux/arm64 architectures.

You can use latest tag for example like this:

docker run -i -v ~/.kube/config:/home/nonroot/.kube/config --rm mcpk8s/server:latest

Windows users might need to replace ~/.kube/config with //c/Users/<username>/.kube/config at least in Git Bash.

For Claude:

{
  "mcpServers": {
    "mcp_k8s_go": {
      "command": "docker",
      "args": [
        "run",
        "-i",
        "-v",
        "~/.kube/config:/home/nonroot/.kube/config",
        "--rm",
        "mcpk8s/server:latest"
      ]
    }
  }
}

Environment Variables and Command-line Options

The following environment variables are used by the MCP server:

  • KUBECONFIG: Path to your Kubernetes configuration file (optional, defaults to ~/.kube/config)

The following command-line options are supported:

  • --allowed-contexts=<ctx1,ctx2,...>: Comma-separated list of allowed Kubernetes contexts that users can access. If not specified, all contexts are allowed.
  • --help: Display help information
  • --version: Display version information