Skip to main content
Glama

list_namespace_resources

List Kubernetes resources like pods, services, and deployments within a specified namespace to monitor and manage cluster components.

Instructions

List resources (pods, services, deployments, etc.) in a namespace.

Args: context_name: The Kubernetes context name namespace: The name of the namespace

Returns: JSON string containing a summary of resources in the namespace

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
context_nameYes
namespaceYes

Implementation Reference

  • The handler function for the 'list_namespace_resources' tool, decorated with @mcp.tool(). It lists various Kubernetes resources (pods, services, deployments, statefulsets, daemonsets, configmaps, secrets, PVCs) in the given namespace, provides counts and some details, and returns a JSON summary.
    @mcp.tool()
    @use_current_context
    def list_namespace_resources(context_name: str, namespace: str):
        """
        List resources (pods, services, deployments, etc.) in a namespace.
    
        Args:
            context_name: The Kubernetes context name
            namespace: The name of the namespace
    
        Returns:
            JSON string containing a summary of resources in the namespace
        """
        from kubernetes.client import AppsV1Api
    
        core_v1: CoreV1Api = get_api_clients(context_name)["core"]
        apps_v1 = get_api_clients(context_name).get("apps", AppsV1Api(get_api_clients(context_name)["api_client"]))
    
        try:
            # Check if namespace exists
            try:
                core_v1.read_namespace(namespace)
            except ApiException as e:
                if e.status == 404:
                    return json.dumps({"error": f"Namespace '{namespace}' not found"})
                else:
                    return json.dumps({"error": f"API error: {str(e)}"})
    
            # Get pods
            pods = core_v1.list_namespaced_pod(namespace)
    
            # Get services
            services = core_v1.list_namespaced_service(namespace)
    
            # Get deployments
            deployments = apps_v1.list_namespaced_deployment(namespace)
    
            # Get stateful sets
            stateful_sets = apps_v1.list_namespaced_stateful_set(namespace)
    
            # Get daemon sets
            daemon_sets = apps_v1.list_namespaced_daemon_set(namespace)
    
            # Get config maps
            config_maps = core_v1.list_namespaced_config_map(namespace)
    
            # Get secrets
            secrets = core_v1.list_namespaced_secret(namespace)
    
            # Get persistent volume claims
            pvcs = core_v1.list_namespaced_persistent_volume_claim(namespace)
    
            result = {
                "namespace": namespace,
                "resource_counts": {
                    "pods": len(pods.items),
                    "services": len(services.items),
                    "deployments": len(deployments.items),
                    "statefulSets": len(stateful_sets.items),
                    "daemonSets": len(daemon_sets.items),
                    "configMaps": len(config_maps.items),
                    "secrets": len(secrets.items),
                    "persistentVolumeClaims": len(pvcs.items)
                },
                "pods": [{"name": pod.metadata.name, "status": pod.status.phase} for pod in pods.items],
                "services": [{"name": svc.metadata.name, "type": svc.spec.type, "cluster_ip": svc.spec.cluster_ip} for svc
                             in services.items],
                "deployments": [{"name": deploy.metadata.name, "replicas": deploy.spec.replicas} for deploy in
                                deployments.items]
            }
    
            return json.dumps(result)
        except ApiException as e:
            return json.dumps({"error": f"Failed to list namespace resources: {str(e)}"})
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the return format ('JSON string containing a summary'), which is helpful, but lacks critical behavioral details: whether this is a read-only operation, if it requires specific permissions, how it handles errors, or if it's paginated. For a Kubernetes tool with no annotations, this is a significant gap in safety and operational context.

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 well-structured with clear sections (purpose, args, returns) and uses minimal sentences. The first sentence states the core purpose, followed by parameter and return details. There's no redundant information, though the 'Args' and 'Returns' labels could be more integrated into natural language.

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

Completeness3/5

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

Given the tool's moderate complexity (listing resources in Kubernetes), no annotations, no output schema, and 2 parameters, the description is minimally adequate. It covers what the tool does and its parameters, but lacks behavioral context, error handling, and output details beyond 'JSON string'. For a tool in a critical environment like Kubernetes, more completeness is warranted.

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

Parameters3/5

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

Schema description coverage is 0%, but the description includes an 'Args' section that documents both parameters ('context_name' and 'namespace') with brief explanations. This compensates partially for the schema gap, though it doesn't provide format examples or constraints. With 2 parameters fully listed, it meets the baseline for adequate parameter documentation.

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

Purpose4/5

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

The description clearly states the verb ('List') and resource ('resources in a namespace'), with examples of resource types (pods, services, deployments). It distinguishes from siblings like 'list_namespaces' or 'pod_list' by focusing on namespace-scoped aggregation. However, it doesn't explicitly differentiate from 'get_namespace_details', which might overlap in purpose.

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

Usage Guidelines2/5

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

No guidance is provided on when to use this tool versus alternatives like 'pod_list', 'service_list', or 'get_namespace_details'. The description implies it aggregates multiple resource types, but doesn't specify use cases, prerequisites, or exclusions, leaving the agent to infer usage from the tool name alone.

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/bourbonkk/k8s-pilot'

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