Skip to main content
Glama
BenedatLLC

Kubernetes Tools MCP Server

by BenedatLLC

get_deployment_summaries

Retrieve deployment summaries from Kubernetes clusters to monitor replica status and availability across namespaces.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Main tool handler: Queries Kubernetes AppsV1Api for deployments (namespaced or all), extracts summary fields like replicas and age, constructs DeploymentSummary pydantic models, returns list. Handles API init and errors.
    def get_deployment_summaries(namespace: Optional[str] = None) -> list[DeploymentSummary]:
        """
        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.
        """
        global APPS_V1_API
        
        # Load Kubernetes configuration and initialize client only once
        if APPS_V1_API is None:
            APPS_V1_API = _get_apps_v1_api_client()
    
        logging.info(f"get_deployment_summaries(namespace={namespace})")
        deployment_summaries: list[DeploymentSummary] = []
        
        try:
            if namespace:
                deployments = APPS_V1_API.list_namespaced_deployment(namespace=namespace)
            else:
                deployments = APPS_V1_API.list_deployment_for_all_namespaces()
        except client.ApiException as e:
            raise K8sApiError(f"Error fetching deployments: {e}") from e
        
        current_time_utc = datetime.datetime.now(datetime.timezone.utc)
        
        for deployment in deployments.items:
            deployment_name = deployment.metadata.name
            deployment_namespace = deployment.metadata.namespace
            
            # Extract replica counts from deployment status
            total_replicas = deployment.spec.replicas if deployment.spec.replicas is not None else 0
            ready_replicas = deployment.status.ready_replicas if deployment.status.ready_replicas is not None else 0
            up_to_date_replicas = deployment.status.updated_replicas if deployment.status.updated_replicas is not None else 0
            available_replicas = deployment.status.available_replicas if deployment.status.available_replicas is not None else 0
            
            # Calculate age
            age = datetime.timedelta(0)  # Default to 0 if creation_timestamp is missing
            if deployment.metadata.creation_timestamp:
                age = current_time_utc - deployment.metadata.creation_timestamp
            
            deployment_summary = DeploymentSummary(
                name=deployment_name,
                namespace=deployment_namespace,
                total_replicas=total_replicas,
                ready_replicas=ready_replicas,
                up_to_date_relicas=up_to_date_replicas,
                available_replicas=available_replicas,
                age=age
            )
            deployment_summaries.append(deployment_summary)
        
        return deployment_summaries
  • Pydantic model defining the output schema for deployment summaries, matching kubectl get deployments output fields.
    class DeploymentSummary(BaseModel):
        """A summary of a deployment's status like returned by `kubectl get deployments`"""
        name: str
        namespace: str
        total_replicas: int
        ready_replicas: int
        up_to_date_relicas: int
        available_replicas: int
        age: datetime.timedelta
  • Exported TOOLS list including get_deployment_summaries, imported by mcp_server for tool registration.
    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
    ]
  • Server code that imports TOOLS list and wraps each function (including get_deployment_summaries) into FastMCP Tool objects using Tool.from_function with structured_output=True.
    if not args.mock:
        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]
  • Mock implementation of the tool for testing, returns static data filtered by namespace, copies docstring from real handler.
    def get_deployment_summaries(namespace: Optional[str] = None) -> list[k8s_tools.DeploymentSummary]:
        """Mock implementation that returns static deployment data, filtered by namespace if specified"""
        deployments = _MOCK_DATA['deployments']
        
        if namespace is not None:
            return [deployment for deployment in deployments if deployment.namespace == namespace]
        return deployments
    
    get_deployment_summaries.__doc__ = k8s_tools.get_deployment_summaries.__doc__
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 disclosing behavioral traits: it specifies the kubectl-like behavior, lists potential errors (K8sConfigError, K8sApiError), and describes the return format. It does not mention rate limits or auth needs, but covers key operational aspects.

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

Conciseness5/5

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

The description is appropriately sized and front-loaded: the first sentence states the purpose clearly, followed by organized sections (Parameters, Returns, Raises) that add necessary detail without redundancy. Every sentence earns its place by providing essential information.

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 (1 parameter, no annotations, but with an output schema), the description is complete enough. It explains the purpose, parameter usage, return values in detail (though the output schema covers this, the description adds clarity), and error conditions, leaving no significant gaps for an AI agent.

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?

The description adds significant meaning beyond the input schema, which has 0% coverage. It explains the 'namespace' parameter's purpose (to list deployments from a specific namespace or all namespaces), default behavior (None for all namespaces), and semantics, compensating fully for the schema's lack of descriptions.

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 resource 'list of DeploymentSummary objects for deployments', specifying it works 'in a given namespace or all namespaces'. It distinguishes from siblings by focusing on deployments rather than pods, nodes, services, etc., and explicitly mentions the kubectl analogy for context.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (to get deployment summaries) and implies when not to use it (e.g., for pod or service summaries, as indicated by sibling tool names). However, it does not explicitly name alternatives or state exclusions, such as when to use get_pod_summaries instead.

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