Skip to main content
Glama
BenedatLLC

Kubernetes Tools MCP Server

by BenedatLLC

get_pod_spec

Retrieve the specification for a Kubernetes pod in a namespace to inspect its configuration, including containers, volumes, and scheduling details.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pod_nameYes
namespaceNodefault

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Core handler function for the 'get_pod_spec' tool. Fetches the pod object from Kubernetes API and returns its spec as a dictionary.
    def get_pod_spec(pod_name: str, namespace: str = "default") -> dict[str,Any]:
        """
        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.
        """
        global K8S
        if K8S is None:
            K8S = _get_api_client()
            logging.info(f"get_pod_spec(pod_name={pod_name}, namespace={namespace})")
        try:
            # Get the pod object
            pod = K8S.read_namespaced_pod(name=pod_name, namespace=namespace)
            # Ensure pod is a V1Pod instance and has a spec
            if not isinstance(pod, client.V1Pod) or not hasattr(pod, "spec") or pod.spec is None:
                raise K8sApiError(f"Pod '{pod_name}' in namespace '{namespace}' did not return a valid spec.")
            return pod.spec.to_dict()
        except ApiException as e:
            if hasattr(e, "status") and e.status == 404:
                raise K8sApiError(
                    f"Pod '{pod_name}' not found in namespace '{namespace}'."
                ) from e
            else:
                raise K8sApiError(
                    f"Error getting pod '{pod_name}' in namespace '{namespace}': {e}"
                ) from e
        except Exception as e:
            raise K8sApiError(f"Unexpected error getting pod spec: {e}") from e
  • The TOOLS list in k8s_tools.py registers get_pod_spec among the available tools, which is imported into mcp_server.py for MCP tool setup.
    TOOLS = [
        get_namespaces,
        get_node_summaries,
        get_pod_summaries,
        get_pod_container_statuses,
        get_pod_events,
        get_pod_spec,
        get_logs_for_pod_and_container,
        get_deployment_summaries,
        get_service_summaries
    ]
  • MCP server registers the tools by wrapping functions from TOOLS (including get_pod_spec) into FastMCP Tool objects using Tool.from_function.
        from .k8s_tools import TOOLS
    else:
        from .mock_tools import TOOLS
        logging.warning(f"Using mock versions of the tools")
    wrapped_tools = [get_tool_for_function(fn) for fn in TOOLS]
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden and does so well by detailing return values, key fields, and error conditions (K8SConfigError, K8sApiError). It explains that the spec is converted from V1PodSpec to a dictionary and lists common values for fields like restart_policy and dns_policy, adding valuable behavioral context beyond basic functionality.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is appropriately sized and front-loaded with the core purpose, followed by structured sections for Args, Returns, and Raises. Every sentence adds value, such as detailing return fields and errors, though the Returns section is somewhat lengthy but necessary for clarity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (retrieving detailed pod specs) and the presence of an output schema (implied by the detailed Returns section), the description is complete enough. It covers purpose, parameters, return semantics with key fields, and error handling, providing all necessary context for an AI agent to use the tool effectively without redundancy.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate, which it does by explaining both parameters: pod_name as 'the name of the pod' and namespace as 'the namespace the pod belongs to (defaults to "default")'. This adds clear meaning beyond the schema's titles, though it doesn't elaborate on format constraints or examples.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'retrieves' and the resource 'spec for a given pod in a specific namespace', making the purpose specific and unambiguous. It distinguishes this tool from siblings like get_pod_summaries or get_pod_events by focusing on the detailed spec object rather than summaries or events.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage by specifying it retrieves a pod's spec, but it does not explicitly state when to use this tool versus alternatives like get_pod_summaries for high-level info or get_pod_container_statuses for container states. No explicit exclusions or prerequisites are provided, leaving usage context inferred rather than guided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/BenedatLLC/k8stools'

If you have feedback or need assistance with the MCP directory API, please join our Discord server