Kubectl MCP Tool

by rohitg00
Verified

local-only server

The server can only run on the client’s local machine because it depends on local resources.

Integrations

  • Supports Helm v3 operations for package management in Kubernetes, enabling installation, upgrades, and uninstallation of Helm charts through natural language commands.

  • Provides comprehensive access to Kubernetes functionality including resource management, deployment scaling, pod operations, security configuration, diagnostics, and monitoring through natural language.

  • Allows installation of the MCP tool directly from PyPI, with support for version-specific installations and development versions.

Kubectl MCP ツール

Claude、Cursor などの AI アシスタントが自然言語を通じて Kubernetes クラスターと対話できるようにする、Kubernetes 用の Model Context Protocol (MCP) サーバー。

⚠️ 既知の問題

現在、サーバー上でJSON解析の問題が発生しています。このため、以下の環境でMCPの実行に支障が生じています。

  • クロード
  • カーソル
  • ウィンドサーフィン

これらの問題の解決に積極的に取り組んでいます。トラブルシューティングは私が単独で行っているため、各サービスごとに詳細なテストを実施しているため、解決には時間がかかる可能性があります。これらの問題をデバッグできる場合は、お気軽にプルリクエストを送信してください。

この期間中、皆様のご理解と継続的なご支援に心より感謝申し上げます。🙏

ご理解いただきありがとうございます!

特徴

コアKubernetesオペレーション

  • [x] Kubernetesクラスターに接続する
  • [x] ポッド、サービス、デプロイメント、ノードの一覧表示と管理
  • [x] ポッドやその他のリソースの作成、削除、説明
  • [x] ポッドログとKubernetesイベントを取得する
  • [x] Helm v3 操作のサポート(インストール、アップグレード、アンインストール)
  • [x] kubectl explainとapi-resourcesのサポート
  • [x] 次のコマンドの名前空間を選択する(メモリの永続性)
  • [x] ポッドへのポート転送
  • [x] スケールデプロイメントとステートフルセット
  • [x] コンテナ内でコマンドを実行する
  • [x] ConfigMapとシークレットの管理
  • [x] 以前のバージョンへのロールバック
  • [x] イングレスとネットワークポリシー管理
  • [x] クラスター間のコンテキスト切り替え

自然言語処理

  • [x] kubectl操作のための自然言語クエリを処理する
  • [x] 以前の操作を記憶するコンテキスト認識コマンド
  • [x] Kubernetesの概念を人間に分かりやすく説明
  • [x] 意図に基づいたインテリジェントなコマンド構築
  • [x] 専用ツールが利用できない場合はkubectlにフォールバックする
  • [x] オフライン/テストシナリオ用の模擬データのサポート
  • [x] 名前空間を考慮したクエリ処理

監視

  • [x] クラスターのヘルスモニタリング
  • [x] リソース使用率の追跡
  • [x] ポッドのステータスとヘルスチェック
  • [x] イベント監視とアラート
  • [x] ノード容量と割り当て分析
  • [x] 過去のパフォーマンスの追跡
  • [x] kubectl top によるリソース使用統計
  • [x] コンテナの準備状況と生存追跡

安全

  • [x] RBACの検証と検証
  • [x] セキュリティコンテキスト監査
  • [x] Kubernetes APIへの安全な接続
  • [x] 資格情報管理
  • [x] ネットワークポリシー評価
  • [x] コンテナセキュリティスキャン
  • [x] セキュリティのベストプラクティスの実施
  • [x] ロールとクラスタロールの管理
  • [x] ServiceAccountの作成とバインド
  • [x] PodSecurityPolicy分析
  • [x] RBAC権限監査
  • [x] セキュリティコンテキストの検証

診断

  • [x] クラスタの診断とトラブルシューティング
  • [x] 構成の検証
  • [x] エラー分析と回復の提案
  • [x] 接続状態の監視
  • [x] ログ分析とパターン検出
  • [x] リソース制約の識別
  • [x] ポッドヘルスチェック診断
  • [x] 一般的なエラーパターンの識別
  • [x] 構成ミスのリソース検証
  • [x] 詳細な生存性および準備プローブの検証

高度な機能

  • [x] 複数のトランスポートプロトコルのサポート(stdio、SSE)
  • [x] 複数のAIアシスタントとの統合
  • [x] 拡張可能なツールフレームワーク
  • [x] カスタムリソース定義のサポート
  • [x] 名前空間間の操作
  • [x] 複数のリソースに対するバッチ操作
  • [x] インテリジェントなリソース関係マッピング
  • [x] エラーの説明と回復の提案
  • [x] ボリューム管理と識別

建築

モデルコンテキストプロトコル(MCP)統合

Kubectl MCPツールはモデルコンテキストプロトコル(MCP)を実装し、AIアシスタントが標準化されたインターフェースを介してKubernetesクラスターと対話できるようにします。アーキテクチャは以下の要素で構成されています。

  1. MCP サーバー: MCP クライアント (AI アシスタント) からのリクエストを処理する準拠サーバー
  2. ツールレジストリ: Kubernetes 操作をスキーマ付きの MCP ツールとして登録します
  3. トランスポート層: stdio、SSE、HTTP トランスポート方式をサポート
  4. コアオペレーション: ツール呼び出しをKubernetes APIオペレーションに変換する
  5. レスポンスフォーマッタ:KubernetesレスポンスをMCP準拠のレスポンスに変換します

リクエストフロー

デュアルモード操作

このツールは次の 2 つのモードで動作します。

  1. CLI モード: Kubernetes 操作を実行するための直接コマンドライン インターフェース
  2. サーバーモード: AIアシスタントからのリクエストを処理するMCPサーバーとして実行

インストール

詳細なインストール手順については、インストール ガイドを参照してください。

kubectl-mcp-tool を PyPI から直接インストールできます。

pip install kubectl-mcp-tool

特定のバージョンの場合:

pip install kubectl-mcp-tool==1.1.0

このパッケージは PyPI で入手できます: https://pypi.org/project/kubectl-mcp-tool/1.1.0/

前提条件

  • Python 3.9以上
  • kubectl CLI がインストールおよび設定されている
  • Kubernetes クラスターへのアクセス
  • pip (Python パッケージ マネージャー)

グローバルインストール

# Install latest version from PyPI pip install kubectl-mcp-tool # Or install development version from GitHub pip install git+https://github.com/rohitg00/kubectl-mcp-server.git

ローカル開発インストール

# Clone the repository git clone https://github.com/rohitg00/kubectl-mcp-server.git cd kubectl-mcp-server # Install in development mode pip install -e .

インストールの確認

インストール後、ツールが正しく動作していることを確認します。

# Check CLI mode kubectl-mcp --help

注: このツールは、AIアシスタントが接続するMCPサーバーとして機能するように設計されており、kubectlの直接的な代替としてではありません。MCPサーバーを起動する主なコマンドはkubectl-mcp serveです。

AIアシスタントとの使用

クロードデスクトップ

~/.config/claude/mcp.json (Windows: %APPDATA%\Claude\mcp.json ) の Claude Desktop 構成に以下を追加します。

{ "mcpServers": { "kubernetes": { "command": "python", "args": ["-m", "kubectl_mcp_tool.minimal_wrapper"], "env": { "KUBECONFIG": "/path/to/your/.kube/config" } } } }

カーソルAI

新しいグローバル MCP サーバーを追加して、MCP の下の Cursor AI 設定に以下を追加します。

{ "mcpServers": { "kubernetes": { "command": "python", "args": ["-m", "kubectl_mcp_tool.minimal_wrapper"], "env": { "KUBECONFIG": "/path/to/your/.kube/config", "PATH": "/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/homebrew/bin" } } } }

グローバル設定のために、この構成を~/.cursor/mcp.jsonに保存します。

: /path/to/your/.kube/configを、実際の kubeconfig ファイルへのパスに置き換えてください。ほとんどのシステムでは、これは~/.kube/configです。

ウィンドサーフィン

~/.config/windsurf/mcp.json (Windows: %APPDATA%\WindSurf\mcp.json ) の Windsurf 構成に以下を追加します。

{ "mcpServers": { "kubernetes": { "command": "python", "args": ["-m", "kubectl_mcp_tool.minimal_wrapper"], "env": { "KUBECONFIG": "/path/to/your/.kube/config" } } } }

自動構成

サポートされているすべての AI アシスタントを自動的に構成するには、提供されているインストール スクリプトを実行します。

bash install.sh

このスクリプトは次のことを行います。

  1. 必要な依存関係をインストールする
  2. Claude、Cursor、WindSurf の設定ファイルを作成する
  3. 正しいパスと環境変数を設定する
  4. Kubernetes接続をテストする

前提条件

  1. kubectl がインストールされ、PATH に含まれている
  2. 有効なkubeconfigファイル
  3. Kubernetes クラスターへのアクセス
  4. Helm v3 (オプション、Helm 操作用)

ポッドの一覧

List all pods in the default namespace

アプリケーションをデプロイする

Create a deployment named nginx-test with 3 replicas using the nginx:latest image

ポッドログを確認する

Get logs from the nginx-test pod

ポート転送

Forward local port 8080 to port 80 on the nginx-test pod

発達

# Clone the repository git clone https://github.com/rohitg00/kubectl-mcp-server.git cd kubectl-mcp-server # Install dependencies pip install -r requirements.txt # Install in development mode pip install -e . # Run tests python -m python_tests.test_all_features

プロジェクト構造

├── kubectl_mcp_tool/ # Main package │ ├── __init__.py # Package initialization │ ├── cli.py # CLI entry point │ ├── mcp_server.py # MCP server implementation │ ├── mcp_kubectl_tool.py # Main kubectl MCP tool implementation │ ├── natural_language.py # Natural language processing │ ├── diagnostics.py # Diagnostics functionality │ ├── core/ # Core functionality │ ├── security/ # Security operations │ ├── monitoring/ # Monitoring functionality │ ├── utils/ # Utility functions │ └── cli/ # CLI functionality components ├── python_tests/ # Test suite │ ├── run_mcp_tests.py # Test runner script │ ├── mcp_client_simulator.py # MCP client simulator for mock testing │ ├── test_utils.py # Test utilities │ ├── test_mcp_core.py # Core MCP tests │ ├── test_mcp_security.py # Security tests │ ├── test_mcp_monitoring.py # Monitoring tests │ ├── test_mcp_nlp.py # Natural language tests │ ├── test_mcp_diagnostics.py # Diagnostics tests │ └── mcp_test_strategy.md # Test strategy documentation ├── docs/ # Documentation │ ├── README.md # Documentation overview │ ├── INSTALLATION.md # Installation guide │ ├── integration_guide.md # Integration guide │ ├── cursor/ # Cursor integration docs │ ├── windsurf/ # Windsurf integration docs │ └── claude/ # Claude integration docs ├── compatible_servers/ # Compatible MCP server implementations │ ├── cursor/ # Cursor-compatible servers │ ├── windsurf/ # Windsurf-compatible servers │ ├── minimal/ # Minimal server implementations │ └── generic/ # Generic MCP servers ├── requirements.txt # Python dependencies ├── setup.py # Package setup script ├── pyproject.toml # Project configuration ├── MANIFEST.in # Package manifest ├── LICENSE # MIT License ├── CHANGELOG.md # Version history ├── .gitignore # Git ignore file ├── install.sh # Installation script ├── publish.sh # PyPI publishing script └── start_mcp_server.sh # Server startup script

貢献

貢献を歓迎します!お気軽にプルリクエストを送信してください。

  1. リポジトリをフォークする
  2. 機能ブランチを作成します( git checkout -b feature/amazing-feature
  3. 変更をコミットします ( git commit -m 'Add some amazing feature' )
  4. ブランチにプッシュする ( git push origin feature/amazing-feature )
  5. プルリクエストを開く

ライセンス

このプロジェクトは MIT ライセンスに基づいてライセンスされています - 詳細についてはLICENSEファイルを参照してください。

ID: e0r1dfpk7e