K8s Port Forward Mcp

io.github.oijusti由 GitHub 帳號 oijusti 發布v0.0.8更新於 Oct 24, 2026

Kubernetes Port Forward — MCP Server: port-forward Kubernetes services with terminal integration

發布方自己的服務:Port

概覽

AI 產生的概覽

本機 MCP 伺服器,讓助理探索 Kubernetes 服務並啟動或停止 kubectl 連接埠轉送工作階段,可選擇開啟日誌視窗。

可以做什麼
  • 列出命名空間與服務,依短名稱與環境分組,可依命名空間篩選
  • 一次呼叫為單一或多個服務啟動連接埠轉送,各自指定命名空間、環境、本機與遠端連接埠
  • 可選擇為每個服務開啟跟隨模式的 kubectl 日誌視窗
  • 停止由此伺服器啟動的所有連接埠轉送
  • 回傳本機網址與實際執行的 kubectl 指令
適用情境
適合在面對 Kubernetes 叢集工作時,讓助理自動找到正確的服務並開啟本機連接埠,而不必手動輸入 kubectl port-forward 指令。同時執行多個服務或在 dev、qa、stg、prod 環境間切換時特別方便。
執行需求
以 stdio 方式在本機執行,通常透過 npx 啟動。需要 Node.js 18 或更新版本、已安裝並設定好叢集存取權限的 kubectl,以及 VS Code、Cursor、Windsurf、Claude Desktop 或 Cline 等 MCP 用戶端。未宣告任何 API 金鑰或環境變數。
安裝前請注意
它會在背景啟動真正的 kubectl 程序並佔用本機連接埠,會改變本機狀態;用完應停止工作階段並留意殘留程序。它可以存取 kubeconfig 允許的任意命名空間與環境,包括 prod,啟動前請確認目標。日誌會以獨立的系統終端機視窗開啟。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 K8s Port Forward Mcp,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

Kubernetes Port Forward MCP

A Model Context Protocol (MCP) server that provides tools for discovering Kubernetes services and running kubectl port-forward sessions (optionally with separate log windows). It is designed for MCP clients/LLMs that translate natural language into structured tool calls.

Kubernetes Port Forward MCP vs kubectl port-forward

This package provides an MCP interface on top of the standard kubectl workflow.

  • kubectl: Best when you already know exact namespace/pod/ports and prefer manual control.
  • MCP: Best when an agent should discover services and run one or many port-forwards via tool calls.

Key Features

  • Service discovery: list namespaces and infer services (short name → environments → namespace) from running pods.
  • Multi-service in one session: start multiple port-forwards with one tool call.
  • LLM-friendly API: start_k8s_port_forward accepts an array so each service can use different namespace, environment, localPort, and remotePort.
  • Optional logs: open kubectl logs -f in a separate OS-level terminal window per service.

Table of Contents

Requirements

  • Node.js 18 or newer
  • kubectl installed and configured with access to your cluster
  • VS Code, Cursor, Windsurf, Claude Desktop, Cline, or any other MCP client

Quick Start

  1. Add this server to your MCP client (use the config in Getting Started below).
  2. Ask your assistant: "List available Kubernetes services."
  3. Ask your assistant: "Run api service on local port 3002."
  4. Open the returned URL (for example http://localhost:3002).
  5. When finished, ask: "Stop all port-forwards."

Getting Started

First, install the Kubernetes Port Forward MCP server with your client.

Standard config works in most MCP clients:

js
{  "mcpServers": {    "k8s-port-forward": {      "command": "npx",      "args": ["-y", "k8s-port-forward-mcp@latest"]    }  }}

[Install in VS Code] [Install in VS Code Insiders]

Amp

Add via the Amp VS Code extension settings screen or by updating your settings.json file:

json
"amp.mcpServers": {  "k8s-port-forward": {    "command": "npx",    "args": [      "-y",      "k8s-port-forward-mcp@latest"    ]  }}

Amp CLI Setup:

Add via the amp mcp add command below:

bash
amp mcp add k8s-port-forward -- npx -y k8s-port-forward-mcp@latest
Antigravity

Add via the Antigravity settings or by updating your configuration file:

json
{  "mcpServers": {    "k8s-port-forward": {      "command": "npx",      "args": ["-y", "k8s-port-forward-mcp@latest"]    }  }}
Claude Code

Use the Claude Code CLI to add the Kubernetes Port Forward MCP server:

bash
claude mcp add k8s-port-forward npx -y k8s-port-forward-mcp@latest
Claude Desktop

Follow the MCP install guide, use the standard config above.

Cline

Follow the instruction in the section Configuring MCP Servers

Example: Local Setup

Add the following to your cline_mcp_settings.json file:

json
{  "mcpServers": {    "k8s-port-forward": {      "type": "stdio",      "command": "npx",      "timeout": 30,      "args": ["-y", "k8s-port-forward-mcp@latest"],      "disabled": false    }  }}
Codex

Use the Codex CLI to add the Kubernetes Port Forward MCP server:

bash
codex mcp add k8s-port-forward npx "-y" "k8s-port-forward-mcp@latest"

Alternatively, create or edit the configuration file ~/.codex/config.toml and add:

toml
[mcp_servers.k8s-port-forward]command = "npx"args = ["-y", "k8s-port-forward-mcp@latest"]

For more information, see the Codex MCP documentation.

Copilot

Use the Copilot CLI to interactively add the Kubernetes Port Forward MCP server:

bash
/mcp add

Alternatively, create or edit the configuration file ~/.copilot/mcp-config.json and add:

json
{  "mcpServers": {    "k8s-port-forward": {      "type": "local",      "command": "npx",      "tools": ["*"],      "args": ["-y", "k8s-port-forward-mcp@latest"]    }  }}

For more information, see the Copilot CLI documentation.

Cursor
Click the button to install:

[Install in Cursor]

Or install manually:

Go to Cursor Settings -> MCP -> Add new MCP Server. Name to your liking, use command type with the command npx -y k8s-port-forward-mcp@latest. You can also verify config or add command arguments via clicking Edit.

Factory

Use the Factory CLI to add the Kubernetes Port Forward MCP server:

bash
droid mcp add k8s-port-forward "npx -y k8s-port-forward-mcp@latest"

Alternatively, type /mcp within Factory droid to open an interactive UI for managing MCP servers.

For more information, see the Factory MCP documentation.

Gemini CLI

Follow the MCP install guide, use the standard config above.

Goose
Click the button to install:

[Install in Goose]

Or install manually:

Go to Advanced settings -> Extensions -> Add custom extension. Name to your liking, use type STDIO, and set the command to npx -y k8s-port-forward-mcp@latest. Click "Add Extension".

Kiro

Follow the MCP Servers documentation. For example in .kiro/settings/mcp.json:

json
{  "mcpServers": {    "k8s-port-forward": {      "command": "npx",      "args": ["-y", "k8s-port-forward-mcp@latest"]    }  }}
LM Studio
Click the button to install:

[Add MCP Server k8s-port-forward to LM Studio]

Or install manually:

Go to Program in the right sidebar -> Install -> Edit mcp.json. Use the standard config above.

opencode

Follow the MCP Servers documentation. For example in ~/.config/opencode/opencode.json:

json
{  "$schema": "https://opencode.ai/config.json",  "mcp": {    "k8s-port-forward": {      "type": "local",      "command": ["npx", "-y", "k8s-port-forward-mcp@latest"],      "enabled": true    }  }}
Qodo Gen

Open Qodo Gen chat panel in VSCode or IntelliJ -> Connect more tools -> + Add new MCP -> Paste the standard config above.

Click Save.

VS Code
Click the button to install:

[Install in VS Code] [Install in VS Code Insiders]

Or install manually:

Follow the MCP install guide, use the standard config above. You can also install the Kubernetes Port Forward MCP server using the VS Code CLI:

bash
# For VS Codecode --add-mcp '{"name":"k8s-port-forward","command":"npx","args":["-y","k8s-port-forward-mcp@latest"]}'

After installation, the Kubernetes Port Forward MCP server will be available for use with your GitHub Copilot agent in VS Code.

Warp

Go to Settings -> AI -> Manage MCP Servers -> + Add to add an MCP Server. Use the standard config above.

Alternatively, use the slash command /add-mcp in the Warp prompt and paste the standard config from above:

js
{  "mcpServers": {    "k8s-port-forward": {      "command": "npx",      "args": [        "-y",        "k8s-port-forward-mcp@latest"      ]    }  }}
Windsurf

Follow Windsurf MCP documentation. Use the standard config above.

Examples

Quick reference (natural language → tool calls)

  • "Run api and auth services on local ports 3002, 3003"
    → list_k8s_services({}) then start_k8s_port_forward({ services: [{ serviceName: "api", localPort: 3002 }, { serviceName: "auth", localPort: 3003 }] })

  • "Run order service from shared services namespace in local port 3000"
    → start_k8s_port_forward({ services: [{ serviceName: "order", namespace: "shared-services", localPort: 3000 }] })

  • "Run order service from shared services namespace and remote port 3000 in local port 3000"
    → start_k8s_port_forward({ services: [{ serviceName: "order", namespace: "shared-services", localPort: 3000, remotePort: 3000 }] })

  • "Run api service in qa environment on local port 3001"
    → start_k8s_port_forward({ services: [{ serviceName: "api", environment: "qa", localPort: 3001 }] })

  • "Run auth service in prod environment from production namespace on local port 3002"
    → start_k8s_port_forward({ services: [{ serviceName: "auth", environment: "prod", namespace: "production", localPort: 3002 }] })

  • "Stop all port-forwards"
    → stop_k8s_port_forward({})

Detailed workflow example

User: "Run the frontend service in qa on port 3001"

AI workflow:

  1. Call list_k8s_services({}) to find the exact service name.
  2. Receive list containing e.g. frontend: qa (ns: ...), dev (ns: ...).
  3. Call start_k8s_port_forward({ services: [{ serviceName: "frontend", environment: "qa", localPort: 3001 }] }).
  4. Result: port-forwards run in the MCP server process; if includeLogs is true, logs open in a separate window. The tool result includes http://localhost:3001 and the exact kubectl commands.

Tools

Service discovery
  • list_k8s_namespaces

    • Title: List namespaces
    • Description: List all available Kubernetes namespaces.
    • Parameters: None
    • Read-only: true
  • list_k8s_services

    • Title: List services
    • Description: List available services grouped by short name and environment.
    • Parameters:
      • namespace (string, optional): Filter results to a namespace.
    • Read-only: true
Port forwarding
  • start_k8s_port_forward

    • Title: Start port-forward
    • Description: Start port-forwarding for one or more services.
    • Parameters:
      • services (array, required): List of service configs.
        • serviceName (string, required): Short name of the service. (Call list_k8s_services first.)
        • localPort (number, required): Local port to bind (1-65535).
        • namespace (string, optional): Namespace to target.
        • remotePort (number, optional): Remote (cluster) port.
        • environment (string, optional): dev | qa | stg | prod.
        • includeLogs (boolean, optional): Whether to open logs in a separate window (default: true).
    • Read-only: false
  • stop_k8s_port_forward

    • Title: Stop port-forward
    • Description: Stop all active port-forward processes started by this MCP server.
    • Parameters: None
    • Read-only: false

Validation and Debugging

Since the MCP server spawns actual kubectl processes in the background, you may want to verify what's running and see the exact commands being executed.

Checking running kubectl processes

Windows (PowerShell):

powershell
# List all kubectl processestasklist /fi "imagename eq kubectl.exe"
# See the exact commands with process IDsGet-CimInstance Win32_Process -Filter "Name='kubectl.exe'" | Select-Object ProcessId,CommandLine

Linux/macOS:

bash
# List all kubectl processesps aux | grep kubectl
# See the exact commands with process IDsps -ef | grep kubectl

This helps you:

  • Verify port-forwards are actually running
  • See the exact namespaces and ports being used
  • Identify stuck processes that might need manual termination
  • Debug connectivity issues by examining the actual commands

Common failures and fixes

  • Port already in use: choose another local port or stop the conflicting process.
  • Connection refused: verify service name, namespace, and selected environment.
  • No logs window: set includeLogs: true in the port-forward request.
  • Stuck process: terminate by PID (taskkill /PID <pid> on Windows, kill <pid> on Linux/macOS).

來源:README.md,提交 6e3529b

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v0.0.8最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分

其他 Port 整合