Skip to main content
Glama
BenedatLLC

Kubernetes Tools MCP Server

by BenedatLLC

get_namespaces

Retrieve a list of all Kubernetes namespaces in your cluster, showing name, status, and age for each namespace.

Instructions

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.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The handler function implementing the core logic of the get_namespaces tool. It uses the Kubernetes CoreV1Api to list namespaces, calculates their age, and returns a list of NamespaceSummary pydantic models.
    def get_namespaces() -> list[NamespaceSummary]:
        """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.
        """
        global K8S
        if K8S is None:
            K8S = _get_api_client()
        logging.info(f"get_namespaces()")
        namespaces = K8S.list_namespace().items
        now = datetime.datetime.now(datetime.timezone.utc)
        return [
            NamespaceSummary(name=namespace.metadata.name,
                            status=namespace.status.phase,
                            age=now-namespace.metadata.creation_timestamp)
            for namespace in namespaces
        ]
  • Pydantic model defining the output schema for each namespace returned by get_namespaces.
    class NamespaceSummary(BaseModel):
        """Summary information about a namespace, like returned by `kubectl get namespace`"""
        name: str
        status: str
        age: datetime.timedelta
  • Code in the MCP server that imports the TOOLS list (including get_namespaces) from k8s_tools or mock_tools, wraps each function into a FastMCP Tool object, and registers them in the FastMCP server instance.
    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]
    
    mcp = FastMCP(
        name="k8stools-"+args.transport,
        tools=wrapped_tools,
        streamable_http_path="/mcp",
        stateless_http=(args.transport == 'streamable-http'),
        host=args.host,
        port=args.port,
        log_level=args.log_level,
        debug=args.debug
    )
    logging.debug(f"Settings are: {mcp.settings}")
    logging.info(f"Starting with {len(wrapped_tools)} tools on transport {args.transport}")
    # this starts the uvicorn server
  • The TOOLS list that collects all tool handler functions, including get_namespaces, for use in MCP server 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
    ]
  • Helper function that converts a tool handler function into an MCP-compatible Tool object using FastMCP's Tool.from_function, enabling schema inference and structured output.
    def get_tool_for_function(fn) -> Tool:
        tool = Tool.from_function(fn, structured_output=True)
        #return_type = fn.__annotations__['return']
        return tool
Behavior4/5

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

With no annotations provided, the description carries full burden and does well by disclosing the return format (list of NamespaceSummary objects with specific fields), error conditions (K8sConfigError, K8sApiError), and behavioral aspects like what happens on API failure. It doesn't mention rate limits, authentication needs, or pagination behavior, but provides substantial 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.

Conciseness5/5

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

The description is well-structured with clear sections (Parameters, Returns, Raises), front-loaded with the core purpose, and every sentence earns its place by providing essential information about behavior, output format, and error conditions without redundancy.

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 has no parameters, has an output schema (implied by the detailed Returns section), and no annotations, the description provides complete context: clear purpose, detailed return format with field descriptions, specific error conditions, and operational behavior. Nothing essential appears missing for this type of read-only listing tool.

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?

With 0 parameters and 100% schema coverage, the baseline would be 4. The description explicitly states 'This function does not take any parameters' in the Parameters section, which adds clarity beyond what the empty schema alone conveys, confirming this is a parameterless operation.

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 tool's purpose with specific verb ('Return') and resource ('summary of the namespaces for this Kubernetes cluster'), and distinguishes it from siblings by specifying it returns namespace summaries rather than deployments, pods, services, etc. The kubectl analogy provides helpful context.

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 context through the kubectl analogy and by specifying what it returns (namespace summaries), but doesn't explicitly state when to use this tool versus alternatives like get_pod_summaries or get_service_summaries. No explicit when-not-to-use guidance or prerequisite information is provided.

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