MCP K8S Go

repository·main·Indexed 18 days ago

https://github.com/strowk/mcp-k8s-go

A Golang-based Model Context Protocol (MCP) server that enables LLMs to interact with Kubernetes clusters. It provides capabilities to browse contexts, namespaces, pods, and resources, as well as run commands and view logs. The server supports read-only mode, context restriction via the --allowed-contexts flag, and secret masking. It can be installed via npm, Smithery, mcp-get, Docker, or built from source.

Tokens
3.3K
Snippets
17
Records
23
Agent score
62%

What's inside mcp-k8s-go

  1. Capabilities of MCP K8S

    main

    The MCP K8S server provides the following capabilities through prompts, resources, and tools:

    • Contexts & Namespaces: List Kubernetes contexts and namespaces.
    • Resource Management: List, get, create, and modify any Kubernetes resources (includes custom mappings for pods, services, and deployments).
    • Cluster Inspection: List Kubernetes nodes and get Kubernetes events.
    • Pod Operations: List pods, get pod logs, and run commands in a Kubernetes pod.
  2. Browse MCP K8S Go with Inspector

    main

    To test and browse the capabilities of the latest published version of the MCP K8S Go server, you can use the Model Context Protocol Inspector by running the following command:

    npx @modelcontextprotocol/inspector npx @strowk/mcp-k8s
  3. Install MCP K8S Go via NPM

    main

    If you have npm installed, you can install the pre-built binaries globally:

    npm install -g @strowk/mcp-k8s

    To use it with Claude Desktop, add the following to your claude_desktop_config.json:

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

    Alternatively, you can use npx in your configuration:

    {
      "mcpServers": {
        "mcp_k8s": {
          "command": "npx",
          "args": [
            "@strowk/mcp-k8s"
          ]
        }
      }
    }
  4. Build MCP K8S Go from source

    main

    To build the server from source, you must have Golang installed. Run:

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

    Then, add this configuration to your claude_desktop_config.json:

    {
      "mcpServers": {
        "mcp_k8s_go": {
          "command": "mcp-k8s-go",
          "args": []
        }
      }
    }
  5. Configure MCP K8S for Claude Desktop

    main

    To use MCP K8S with Claude Desktop, add the server configuration to your claude_desktop_config.json file.

    By default, use the following configuration to allow access to all contexts with full permissions:

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

    Once configured, Claude Desktop can access Kubernetes contexts as resources and perform tasks like listing pods, events, or reading logs.

  6. Run MCP K8S Go using Docker

    main

    The server is available as a multi-arch Docker image (linux/amd64 and linux/arm64).

    To run it manually:

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

    Note: Windows users using Git Bash may need to use //c/Users/<username>/.kube/config for the volume mount.

    To use it with Claude Desktop, add this to claude_desktop_config.json:

    {
      "mcpServers": {
        "mcp_k8s_go": {
          "command": "docker",
          "args": [
            "run",
            "-i",
            "-v",
            "~/.kube/config:/home/nonroot/.kube/config",
            "--rm",
            "mcpk8s/server:latest"
          ]
        }
      }
    }
  7. Configure MCP K8S restrictions and context limits

    main

    You can restrict the MCP K8S server's capabilities and access scope by passing arguments in the args array of your claude_desktop_config.json.

    Common use cases include:

    • Restricting access to specific Kubernetes contexts.
    • Enabling a read-only mode to prevent accidental cluster modifications.

    Example configuration for a restricted environment (allowing only dev and prod contexts in read-only mode):

    {
        "mcpServers": {
            "mcp_k8s": {
                "command": "mcp-k8s",
                "args": [
                    "--allowed-contexts=dev,prod",
                    "--readonly"
                ]
            }
        }
    }
  8. Install MCP K8S Go from GitHub Releases

    main
    1. Download the latest release for your platform from GitHub releases.
    2. Unpack the archive containing the mcp-k8s-go binary.
    3. Place the binary in your PATH.
    4. Add the following to your claude_desktop_config.json:
    {
      "mcpServers": {
        "mcp_k8s": {
          "command": "mcp-k8s-go",
          "args": []
        }
      }
    }
  9. mcp-k8s Capabilities and Features

    main

    The mcp-k8s server exposes the following MCP capabilities:

    Tools

    The server provides tools to interact with your Kubernetes cluster. Depending on whether --readonly is enabled, the following categories of tools are available:

    • Inspection Tools: ListContextsTool, ListNamespacesTool, ListResourcesTool, GetResourceTool, ListNodesTool, ListEventsTool, ListPodsPrompt (via prompts), and PodLogsTool.
    • Write/Action Tools (Disabled in --readonly mode): ApplyK8sResourceTool and PodExecCommandTool.

    Prompts

    Pre-defined prompts to help guide LLM interactions, such as:

    • ListPodsPrompt
    • ListNamespacesPrompt

    Resources

    The server provides resource providers, such as ContextsResourceProvider, which allows the LLM to discover available Kubernetes contexts.