
Kubernetes Tools MCP Server
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.
Tools
get_namespaces
Return a summary of the namespaces for this Kubernetes cluster, similar to that returned by `kubectl get namespace`. Parameters ---------- None This function does not take any parameters. Returns ------- list of NamespaceSummary List of namespace summary objects. Each NamespaceSummary has the following fields: name : str Name of the namespace. status : str Status phase of the namespace. age : datetime.timedelta Age of the namespace (current time minus creation timestamp). Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to list namespaces fails.
get_node_summaries
Return a summary of the nodes for this Kubernetes cluster, similar to that returned by `kubectl get nodes -o wide`. Parameters ---------- None This function does not take any parameters. Returns ------- list of NodeSummary List of node summary objects. Each NodeSummary has the following fields: name : str Name of the node. status : str Status of the node (Ready, NotReady, etc.). roles : list[str] List of roles for the node (e.g., ['control-plane', 'master']). age : datetime.timedelta Age of the node (current time minus creation timestamp). version : str Kubernetes version running on the node. internal_ip : Optional[str] Internal IP address of the node. external_ip : Optional[str] External IP address of the node (if available). os_image : Optional[str] Operating system image running on the node. kernel_version : Optional[str] Kernel version of the node. container_runtime : Optional[str] Container runtime version on the node. Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to list nodes fails.
get_pod_summaries
Retrieves a list of PodSummary objects for pods in a given namespace or all namespaces. Parameters ---------- namespace : Optional[str], default=None The specific namespace to list pods from. If None, lists pods from all namespaces. Returns ------- list of PodSummary A list of PodSummary objects, each providing a summary of a pod's status with the following fields: name : str Name of the pod. namespace : str Namespace in which the pod is running. total_containers : int Total number of containers in the pod. ready_containers : int Number of containers currently in ready state. restarts : int Total number of restarts for all containers in the pod. last_restart : Optional[datetime.timedelta] Time since the container last restart (None if never restarted). age : datetime.timedelta Age of the pod (current time minus creation timestamp). ip : Optional[str] Pod IP address (None if not assigned). node : Optional[str] Name of the node where the pod is running (None if not scheduled). Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to list pods fails.
get_pod_container_statuses
Get the status for all containers in a specified Kubernetes pod. Parameters ---------- pod_name : str Name of the pod to retrieve container statuses for. namespace : str, optional Namespace of the pod (default is "default"). Returns ------- list of ContainerStatus List of container status objects for the specified pod. Each ContainerStatus has the following fields: pod_name : str Name of the pod. namespace : str Namespace of the pod. container_name : str Name of the container. image : str Image name. ready : bool Whether the container is currently passing its readiness check. The value will change as readiness probes keep executing. restart_count : int Number of times the container has restarted. started : Optional[bool] Started indicates whether the container has finished its postStart lifecycle hook and passed its startup probe. stop_signal : Optional[str] Stop signal for the container. state : Optional[ContainerState] Current state of the container. last_state : Optional[ContainerState] Last state of the container. volume_mounts : list[VolumeMountStatus] Status of volume mounts for the container resource_requests : dict[str, str] Describes the minimum amount of compute resources required. If Requests is omitted for a container, it defaults to Limits if that is explicitly specified, otherwise to an implementation-defined value. Requests cannot exceed Limits. resource_limits : dict[str, str] Describes the maximum amount of compute resources allowed. allocated_resources : dict[str, str] Compute resources allocated for this container by the node. Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to read the pod fails.
get_pod_events
Get events for a specific Kubernetes pod. This is equivalent to the kubectl command: `kubectl get events -n NAMESPACE --field-selector involvedObject.name=POD_NAME,involvedObject.kind=Pod` Parameters ---------- pod_name : str Name of the pod to retrieve events for. namespace : str, optional Namespace of the pod (default is "default"). Returns ------- list of EventSummary List of events associated with the specified pod. Each EventSummary has the following fields: last_seen : Optional[datetime.datetime] Timestamp of the last occurrence of the event (if available). type : str Type of the event. reason : str Reason for the event. object : str The object this event applies to. message : str Message describing the event. Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to list events fails.
get_pod_spec
Retrieves the spec for a given pod in a specific namespace. Args: pod_name (str): The name of the pod. namespace (str): The namespace the pod belongs to (defaults to "default"). Returns ------- dict[str, Any] The pod's spec object, containing its desired state. It is converted from a V1PodSpec to a dictionary. Key fields include: containers : list of kubernetes.client.V1Container List of containers belonging to the pod. Each container defines its image, ports, environment variables, resource requests/limits, etc. init_containers : list of kubernetes.client.V1Container, optional List of initialization containers belonging to the pod. volumes : list of kubernetes.client.V1Volume, optional List of volumes mounted in the pod and the sources available for the containers. node_selector : dict, optional A selector which must be true for the pod to fit on a node. Keys and values are strings. restart_policy : str Restart policy for all containers within the pod. Common values are "Always", "OnFailure", "Never". service_account_name : str, optional Service account name in the namespace that the pod will use to access the Kubernetes API. dns_policy : str DNS policy for the pod. Common values are "ClusterFirst", "Default". priority_class_name : str, optional If specified, indicates the pod's priority_class via its name. node_name : str, optional NodeName is a request to schedule this pod onto a specific node. Raises ------ K8SConfigError If unable to initialize the K8S API K8sApiError If the pod is not found, configuration fails, or any other API error occurs.
get_logs_for_pod_and_container
Retrieves logs from a Kubernetes pod and container. Args: namespace (str): The namespace of the pod. pod_name (str): The name of the pod. container_name (str, optional): The name of the container within the pod. If None, defaults to the first container. Returns: str, optional: Log content if any found for this pod/container, or None otherwise Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to fetch logs fails or an unexpected error occurs.
get_deployment_summaries
Retrieves a list of DeploymentSummary objects for deployments in a given namespace or all namespaces. Similar to `kubectl get deployements`. Parameters ---------- namespace : Optional[str], default=None The specific namespace to list deployments from. If None, lists deployments from all namespaces. Returns ------- list of DeploymentSummary A list of DeploymentSummary objects, each providing a summary of a deployment's status with the following fields: name : str Name of the deployment. namespace : str Namespace in which the deployment is running. total_replicas : int Total number of replicas desired for this deployment. ready_replicas : int Number of replicas that are currently ready. up_to_date_replicas : int Number of replicas that are up to date. available_replicas : int Number of replicas that are available. age : datetime.timedelta Age of the deployment (current time minus creation timestamp). Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to list deployments fails.
get_service_summaries
Retrieves a list of ServiceSummary objects for services in a given namespace or all namespaces. Similar to `kubectl get services`. Parameters ---------- namespace : Optional[str], default=None The specific namespace to list services from. If None, lists services from all namespaces. Returns ------- list of ServiceSummary A list of ServiceSummary objects, each providing a summary of a service's status with the following fields: name : str Name of the service. namespace : str Namespace in which the service is running. type : str Type of the service (ClusterIP, NodePort, LoadBalancer, ExternalName). cluster_ip : Optional[str] Cluster IP address assigned to the service (None for ExternalName services). external_ip : Optional[str] External IP address if applicable (for LoadBalancer services). ports : list[PortInfo] List of ports (and their protocols) exposed by the service. age : datetime.timedelta Age of the service (current time minus creation timestamp). Raises ------ K8sConfigError If unable to initialize the K8S API. K8sApiError If the API call to list services fails.
README
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
:
pip install k8stools
Via uv
:
uv add k8stools
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:
from pydantic_ai.agent import Agent
from k8stools.k8s_tools import TOOLS
agent = Agent(
model="openai:gpt-4.1",
system_prompt=SYSTEM_PROMPT,
tools=TOOLS
)
result = agent.run_sync("What is the status of the pods in my cluster?")
print(result.output)
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:
usage: k8s-mcp-server [-h] [--transport {streamable-http,stdio}] [--host HOST] [--port PORT]
[--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}] [--debug]
Run the MCP server.
options:
-h, --help show this help message and exit
--transport {streamable-http,stdio}
Transport to use for MCP server [default: stdio]
--host HOST Hostname for HTTP service [default: 127.0.0.1]
--port PORT Port for HTTP service [default: 8000]
--log-level {DEBUG,INFO,WARNING,ERROR,CRITICAL}
Log level [default: INFO]
--debug Enable debug mode [default: False]
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:
{
"servers": {
"k8stools-stdio": {
"command": "${workspaceFolder}/.venv/bin/k8s-mcp-server",
"args": [
],
"envFile": "${workspaceFolder}/.envrc"
}
}
}
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:
# start the server
$ k8s-mcp-server --transport=streamable-http
[07/21/25 19:55:13] INFO Starting with 6 tools on transport streamable-http mcp_server.py:59
INFO: Started server process [6649]
INFO: Waiting for application startup.
INFO StreamableHTTP session manager started streamable_http_manager.py:111
INFO: Application startup complete.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
# Now, open another terminal window and test it
$ curl -v \
-H "Content-Type: application/json" \
-H "Accept: application/json, text/event-stream" \
-d '{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/list",
"params": {}
}' \
http://127.0.0.1:8000/mcp
* Trying 127.0.0.1:8000...
* Connected to 127.0.0.1 (127.0.0.1) port 8000
> POST /mcp HTTP/1.1
> Host: 127.0.0.1:8000
> User-Agent: curl/8.7.1
> Content-Type: application/json
> Accept: application/json, text/event-stream
> Content-Length: 120
>
* upload completely sent off: 120 bytes
< HTTP/1.1 200 OK
< date: Tue, 22 Jul 2025 02:56:25 GMT
< server: uvicorn
< cache-control: no-cache, no-transform
< connection: keep-alive
< content-type: text/event-stream
< x-accel-buffering: no
< Transfer-Encoding: chunked
<
event: message
data: {"jsonrpc":"2.0","id":1,"result":{"tools":[.... long text elided ...]}}
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.
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.

VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.

E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.