io.github.oijusti/k8s-port-forward-mcp
平台与服务by oijusti
Kubernetes Port Forward 的 MCP Server,支持结合终端对 Kubernetes 服务进行端口转发。
什么是 io.github.oijusti/k8s-port-forward-mcp?
Kubernetes Port Forward 的 MCP Server,支持结合终端对 Kubernetes 服务进行端口转发。
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_forwardaccepts an array so each service can use differentnamespace,environment,localPort, andremotePort. - Optional logs: open
kubectl logs -fin a separate OS-level terminal window per service.
Table of Contents
- Requirements
- Quick Start
- Getting Started
- Examples
- Tools
- Output and Logs
- Configuration
- Validation and Debugging
Requirements
- Node.js 18 or newer
kubectlinstalled and configured with access to your cluster- VS Code, Cursor, Windsurf, Claude Desktop, Cline, or any other MCP client
Quick Start
- Add this server to your MCP client (use the config in Getting Started below).
- Ask your assistant: "List available Kubernetes services."
- Ask your assistant: "Run api service on local port 3002."
- Open the returned URL (for example
http://localhost:3002). - 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:
{
"mcpServers": {
"k8s-port-forward": {
"command": "npx",
"args": ["-y", "k8s-port-forward-mcp@latest"]
}
}
}
<img src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Server&color=0098FF" alt="Install in VS Code"> <img alt="Install in VS Code Insiders" src="https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Server&color=24bfa5">
<details> <summary>Amp</summary>Add via the Amp VS Code extension settings screen or by updating your settings.json file:
"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:
amp mcp add k8s-port-forward -- npx -y k8s-port-forward-mcp@latest
Add via the Antigravity settings or by updating your configuration file:
{
"mcpServers": {
"k8s-port-forward": {
"command": "npx",
"args": ["-y", "k8s-port-forward-mcp@latest"]
}
}
}
Use the Claude Code CLI to add the Kubernetes Port Forward MCP server:
claude mcp add k8s-port-forward npx -y k8s-port-forward-mcp@latest
Follow the MCP install guide, use the standard config above.
</details> <details> <summary>Cline</summary>Follow the instruction in the section Configuring MCP Servers
Example: Local Setup
Add the following to your cline_mcp_settings.json file:
{
"mcpServers": {
"k8s-port-forward": {
"type": "stdio",
"command": "npx",
"timeout": 30,
"args": ["-y", "k8s-port-forward-mcp@latest"],
"disabled": false
}
}
}
Use the Codex CLI to add the Kubernetes Port Forward MCP server:
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:
[mcp_servers.k8s-port-forward]
command = "npx"
args = ["-y", "k8s-port-forward-mcp@latest"]
For more information, see the Codex MCP documentation.
</details> <details> <summary>Copilot</summary>Use the Copilot CLI to interactively add the Kubernetes Port Forward MCP server:
/mcp add
Alternatively, create or edit the configuration file ~/.copilot/mcp-config.json and add:
{
"mcpServers": {
"k8s-port-forward": {
"type": "local",
"command": "npx",
"tools": ["*"],
"args": ["-y", "k8s-port-forward-mcp@latest"]
}
}
}
For more information, see the Copilot CLI documentation.
</details> <details> <summary>Cursor</summary>Click the button to install:
<img src="https://cursor.com/deeplink/mcp-install-dark.svg" alt="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.
Use the Factory CLI to add the Kubernetes Port Forward MCP server:
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.
</details> <details> <summary>Gemini CLI</summary>Follow the MCP install guide, use the standard config above.
</details> <details> <summary>Goose</summary>Click the button to install:
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".
Follow the MCP Servers documentation. For example in .kiro/settings/mcp.json:
{
"mcpServers": {
"k8s-port-forward": {
"command": "npx",
"args": ["-y", "k8s-port-forward-mcp@latest"]
}
}
}
Click the button to install:
Or install manually:
Go to Program in the right sidebar -> Install -> Edit mcp.json. Use the standard config above.
Follow the MCP Servers documentation. For example in ~/.config/opencode/opencode.json:
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"k8s-port-forward": {
"type": "local",
"command": ["npx", "-y", "k8s-port-forward-mcp@latest"],
"enabled": true
}
}
}
Open Qodo Gen chat panel in VSCode or IntelliJ -> Connect more tools -> + Add new MCP -> Paste the standard config above.
Click <code>Save</code>.
</details> <details> <summary>VS Code</summary>Click the button to install:
<img src="https://img.shields.io/badge/VS_Code-VS_Code?style=flat-square&label=Install%20Server&color=0098FF" alt="Install in VS Code"> <img alt="Install in VS Code Insiders" src="https://img.shields.io/badge/VS_Code_Insiders-VS_Code_Insiders?style=flat-square&label=Install%20Server&color=24bfa5">
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:
# For VS Code
code --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.
</details> <details> <summary>Warp</summary>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:
{
"mcpServers": {
"k8s-port-forward": {
"command": "npx",
"args": [
"-y",
"k8s-port-forward-mcp@latest"
]
}
}
}
Follow Windsurf MCP documentation. Use the standard config above.
</details>Examples
Quick reference (natural language → tool calls)
-
"Run api and auth services on local ports 3002, 3003"
→list_k8s_services({})thenstart_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:
- Call
list_k8s_services({})to find the exact service name. - Receive list containing e.g.
frontend: qa (ns: ...), dev (ns: ...). - Call
start_k8s_port_forward({ services: [{ serviceName: "frontend", environment: "qa", localPort: 3001 }] }). - Result: port-forwards run in the MCP server process; if
includeLogsis true, logs open in a separate window. The tool result includeshttp://localhost:3001and the exact kubectl commands.
Tools
<details> <summary><b>Service discovery</b></summary>-
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
-
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. (Calllist_k8s_servicesfirst.)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):
# List all kubectl processes
tasklist /fi "imagename eq kubectl.exe"
# See the exact commands with process IDs
Get-CimInstance Win32_Process -Filter "Name='kubectl.exe'" | Select-Object ProcessId,CommandLine
Linux/macOS:
# List all kubectl processes
ps aux | grep kubectl
# See the exact commands with process IDs
ps -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: truein the port-forward request. - Stuck process: terminate by PID (
taskkill /PID <pid>on Windows,kill <pid>on Linux/macOS).
常见问题
io.github.oijusti/k8s-port-forward-mcp 是什么?
Kubernetes Port Forward 的 MCP Server,支持结合终端对 Kubernetes 服务进行端口转发。
相关 Skills
Slack动图
by anthropics
面向Slack的动图制作Skill,内置emoji/消息GIF的尺寸、帧率和色彩约束、校验与优化流程,适合把创意或上传图片快速做成可直接发送的Slack动画。
✎ 帮你快速做出适配 Slack 的动图,内置约束规则和校验工具,少踩上传与播放坑,做表情包和演示都更省心。
MCP构建
by anthropics
聚焦高质量 MCP Server 开发,覆盖协议研究、工具设计、错误处理与传输选型,适合用 FastMCP 或 MCP SDK 对接外部 API、封装服务能力。
✎ 想让 LLM 稳定调用外部 API,就用 MCP构建:从 Python 到 Node 都有成熟指引,帮你更快做出高质量 MCP 服务器。
接口测试套件
by alirezarezvani
扫描 Next.js、Express、FastAPI、Django REST 的 API 路由,自动生成覆盖鉴权、参数校验、错误码、分页、上传与限流场景的 Vitest 或 Pytest 测试套件。
✎ 帮你把API与集成测试自动化跑顺,减少回归漏测;能力全面,尤其适合复杂接口场景的QA团队。
相关 MCP Server
Slack 消息
编辑精选by Anthropic
Slack 是让 AI 助手直接读写你的 Slack 频道和消息的 MCP 服务器。
✎ 这个服务器解决了团队协作中需要 AI 实时获取 Slack 信息的痛点,特别适合开发团队让 Claude 帮忙汇总频道讨论或发送通知。不过,它目前只是参考实现,文档有限,不建议在生产环境直接使用——更适合开发者学习 MCP 如何集成第三方服务。
by netdata
io.github.netdata/mcp-server 是让 AI 助手实时监控服务器指标和日志的 MCP 服务器。
✎ 这个工具解决了运维人员需要手动检查系统状态的痛点,最适合 DevOps 团队让 Claude 自动分析性能数据。不过,它依赖 NetData 的现有部署,如果你没用过这个监控平台,得先花时间配置。
by d4vinci
Scrapling MCP Server 是专为现代网页设计的智能爬虫工具,支持绕过 Cloudflare 等反爬机制。
✎ 这个工具解决了爬取动态网页和反爬网站时的头疼问题,特别适合需要批量采集电商价格或新闻数据的开发者。不过,它依赖外部浏览器引擎,资源消耗较大,不适合轻量级任务。