Enables chat interactions with Kubernetes clusters via GitHub Copilot, allowing users to query cluster status, inspect resources, and retrieve logs through natural language conversation supported by custom instruction files.
Provides a collection of Kubernetes tools for querying and monitoring cluster resources, including namespaces, nodes, pods, deployments, and services. Enables agents to retrieve logs, inspect pod specifications, and check container statuses to support monitoring and root cause analysis use cases.
Provides mock tools that can simulate interactions with a Kubernetes cluster running OpenTelemetry Demo, useful for testing agents against realistic but static data without requiring a live cluster.
Kubernetes Tools
This package provides a collection of Kubernetes functions to be used by Agents. They can be passed directly to an agent as tools or placed behind an MCP server (included). Some use cases include:
- Chat with your kubernetes cluster via GitHub CoPilot or Cursor.
- Build agents to monitor your cluster or perform root cause analysis.
- Vibe-code a custom chat UI.
- Use in non-agentic automations.
Methodology
Our goal is to focus on quality over quantity -- providing well-documented and strongly typed tools. We believe that this is a critical in enabling agents to make effective use of tools, beyond simple demos.
These are built on top of the kubernetes Python API (https://github.com/kubernetes-client/python). There are three styles of tools provided here:
- There are tools that mimic the output of kubectl commands (e.g.
get_pod_summaries
, which is equivalent tokubectl get pods
). Strongly-typed Pydantic models are used for the return values of these tools. - There are tools that return strongly typed Pydantic models that attempt to match the associated Kubernetes
client types (see https://github.com/kubernetes-client/python/tree/master/kubernetes/docs).
Lesser used fields may be omitted from these models. An example of this case is
get_pod_container_statuses
. - In some cases we simply call
to_dict()
on the class returned by the API (defined in https://github.com/kubernetes-client/python/tree/master/kubernetes/client/models). The return type isdict[str,Any]
, but we document the fields in the function's docstring.get_pod_spec
is an example of this type of tool.
Currently, the priority is on functions that do not modify the state of the cluster. We want to focus first on the monitoring / RCA use cases. When we do add tools to address other use cases, they will be kept separate from the read-only tools so you can still build "safe" agents.
Installation
Via pip
:
Via uv
:
Current tools
These are the tools we define:
get_namespaces
- get a list of namespaces, likekubectl get namespace
get_node_summaries
- get a list of nodes, likekubectl get nodes -o wide
get_pod_summaries
- get a list of pods, likekubectl get pods -o wide
get_pod_container_statuses
- return the status for each of the container in a podget_pod_events
- return the events for a podget_pod_spec
- retrieves the spec for a given podget_logs_for_pod_and_container
- retrieves logs from a pod and containerget_deployment_summaries
- get a list of deployments, likekubectl get deployments
get_service_summaries
- get a list of services, likekubectl get services
We also define a set of associated "print_" functions that are helpful in debugging:
print_namespaces
print_node_summaries
print_pod_summaries
print_pod_container_statuses
print_pod_events
print_pod_spec
print_deployment_summaries
print_service_summaries
Using the tools
Directly use in an agent
The core tools are in k8stools.k8s_tools
. Here's an example usage in an agent:
Using via MCP
The script k8s-mcp-server
provides an MCP server for the same set of tools.
Here are the command line arguments for the server:
Use MCP with the stdio transport
The stdio transport is best for use with local Coding Agents, like GitHub CoPilot or Cursor.
It is the default, so you can run the k8s-mcp-server
script without arguments. Here's an example
mcp.json
configuration:
This assumes the following:
- The Python virtual environment is expected to be in
.venv
under the root of your VSCode workspace - You have installed the k8stools package into your workspace
- The environment file
.envrc
contains any variables you need defined. In particular, you may need to setKUBECONFIG
to point to yourkubectl
config file.
Use MCP with the streamable HTTP transport
The streamable http transport is enabled with the command line option --transport=streamable-http
. It will
start an HTTP server which listens on the specified address and port (defaulting to 127.0.0.1 and 8000, respectively).
This transport is best for cases where you want remote access to your MCP server.
Here's a short example that starts the server and then does a sanity test using curl
to get the tool information:
Mock tools
When building agents, it can be helpful to test them against mock versions that do
not go against a real cluster, but return static (but realistic) values. The module
k8stools.mock_tools
does just that. The data values were captured when running
against a real Minikube instance running the
Open Telemetry Demo
application. When running the MCP server, this may be enabled by using the
--mock
command line option.
Instruction files
GitHub CoPilot supports instruction files that can provide additional context to the CoPilot
Coding Agent. It can even analyze your project and create one for you. By default, this gets
saved to .github/copilot-instructions.md
. You can manually add instructions to customize
your agent for using your MCP tools. As an example, here's the additional content included
in this repository's copilot-instructions.md
:
MCP Integration
Run server:
k8s-mcp-server [--transport stdio|streamable-http]
Tools auto-registered viaTool.from_function()
inmcp_server.py
When answering questions about the user's kubernetes cluster, use the tools provided by this server, which is configured in
mcp.json
ask8stools-stdio
. Some other considerations when answering these questions:
- If the answer includes multiple, similar entries, format as a table if possible.
- When providing pod statuses, be sure to include the state of the pod.
- When providing a status, use an icon show quickly show if it is good or bad.
- If you are asked for the current status, and you haven't run a request in more than an minute, be sure to run the tool again to get the latest status.
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
Tools
Provides a set of read-only Kubernetes functions via an MCP server, enabling interaction with Kubernetes clusters through agents or coding assistants like GitHub Copilot.
Related Resources
Related MCP Servers
- -securityAlicense-qualityA read-only MCP server for Kubernetes that allows querying cluster information and diagnosing issues through natural language interfaces like Claude.Last updated -7PythonMIT License
- -securityAlicense-qualityAn MCP server that enables interaction with Kubernetes/Minikube clusters through natural language, allowing AI agents like Codename Goose to manage Kubernetes resources via the Model Context Protocol.Last updated -2PythonMIT License
- -securityAlicense-qualityProvides MCP multi-cluster Kubernetes management and operations, featuring a management interface, logging, and nearly 50 built-in tools covering common DevOps and development scenarios. Supports both standard and CRD resources.Last updated -590GoMIT License
- -securityAlicense-qualityProvides MCP multi-cluster Kubernetes management and operations. It can be integrated as an SDK into your own project and includes nearly 50 built-in tools covering common DevOps and development scenarios. Supports both standard and CRD resources.Last updated -122GoMIT License