Kubernetes资源交互工具

一个实现Model Context Protocol服务器的工具,提供与Kubernetes资源交互的简单方式。

  • by cola-io
  • Go
  • 混合部署
  • 更新于
在 GitHub 查看 cola-io/koffee

使用说明

用于实现模型上下文协议服务器的工具。它提供了一种与Kubernetes资源交互的简单方法。

特性

  • 列出本地kube上下文,如 kubectl config get-contexts
  • 切换kube上下文,如下所示 kubectl config use-context <context>
  • 获取集群版本,如 kubectl get --raw /version
  • 获取集群资源,例如 kubectl api-resources
  • 获取资源详细信息,如 kubectl get <kind> <name> -n <namespace> -oyaml
  • 使用指定的清单文件应用资源,如 kubectl apply -f <file>
  • 删除具有指定种类、名称和命名空间的资源,如 kubectl delete <kind> <name> -n <namespace>
  • 记录指定pod和容器的pod,如 kubectl logs <pod> -n <namespace>
  • 在指定的pod和容器中运行命令,如下所示 kubectl exec <pod> -n <namespace> -c <container> -- <command>

开始

构建本地二进制文件

# execute the following command to build the local binary.
~ » make all
~ » bin/koffee -h
A tool for implementing the Model Context Protocol server. It provides a simple way to interact with Kubernetes resources.

Usage:
  koffee [flags]

Koffee flags:

  -k, --kubeconfig string
                Path to Kubernetes configuration file (uses default config if not specified)
  -p, --port int
                Port to use for communicating with server, required when using --transport=sse and must be between 1 and 65535 (default 8888)
  -t, --transport string
                Transport protocol to use (stdio, sse) (default "stdio")
  -v, --v int
                Setting the slog level, default is info level
  -V, --version
                Print version information and quits

Global flags:

  -h, --help
                help for koffee

构建docker镜像

# execute the following command to build the docker image.
make docker-build

配置

STDIO模式

在stdio模式下,koffee通过标准输入/输出流与客户端通信。

# Run in stdio mode, it is default mode.
"mcp": {
  "servers": {
    "Kubernetes": {
      "command": "/path/to/koffee",
      "args": [
        "--kubeconfig",
        "/path/to/kubeconfig"
      ]
    }
  }
}

SSE模式

在SSE模式下,koffee通过服务器发送事件与客户端通信。

# Run in SSE mode.
/path/to/koffee --kubeconfig /path/to/kubeconfig --transport sse --port 8888
# Run in sse mode.
"mcp": {
  "servers": {
    "Kubernetes": {
      "url": "http://localhost:8888/sse",
      "args": []
    }
  }
}

用法

如果您使用VS Code作为MCP客户端,可以参考本文档中的介绍, VS代码MCP介绍.

列出本地kube上下文

全部

切换kube上下文

全部

获取集群版本

全部

获取集群资源

全部

获取资源详细信息

全部

将指定的清单应用于集群

全部

删除指定的资源

全部

用于指定吊舱和容器的吊舱

全部

在指定的pod和容器中运行命令

全部