Skip to content

mikebz/py-mcp-kubectl

Repository files navigation

mcp-kubectl

A simple implementation of the Model Context Protocol for kubectl operations in Kubernetes environments. This tool allows AI assistants like Claude to interact directly with your Kubernetes clusters to perform operations and gather information.

Features

  • Execute kubernetes commands directly through an AI assistant
  • Get information about pods, services, deployments and other Kubernetes resources
  • Update resources using natural language instructions

Prerequisites

Installation

  1. Clone the repository:
git clone <repository_url>
cd mcp-kubectl
  1. Install the required Python packages:
uv run kube.py

Usage

  1. Update the MCP config for Caude desktop

Create/edit ~/Library/Application\ Support/Claude/claude_desktop_config.json

Example file:

{
    "mcpServers": {
        "kubectl": {
            "command": "uv",
            "args": [
                "--directory",
                "/Users/mikebz/src/mcp-kubectl",
                "run",
                "kube.py"
            ],
            "env": {
                "PATH": "/Users/mikebz/google-cloud-sdk/bin:/Users/mikebz/bin:/usr/local/bin:/usr/bin:/bin:/usr/local/sbin:/usr/sbin:/sbin:/usr/local/go/bin"
            }
        }
    }
}

After that you can use Claud Desktop https://claude.ai/download to use the tool

  1. Interact with the server using the MCP inspector.

tutorial for installing and using the inspector

    npx @modelcontextprotocol/inspector \
    uv \
    --directory /Users/mikebz/src/mcp-kubectl \
    run \
    kube.py

Development

  • The main logic is in kube.py.
  • The MCP server is initialized and run at the end of kube.py.
  • New tools can be added by creating new functions and decorating them with @mcp.tool.

Testing

Testing is done using pytest

uv run pytest

Linting

Linting is done using pylint

uv run pylint $(git ls-files '*.py')

You might also find https://code.visualstudio.com/docs/python/linting useful

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages