Skip to main content
Glama
yanmxa

OCM MCP Server

by yanmxa

clusters

Retrieve Kubernetes managed clusters to view available resources and manage distributed container environments through the OCM MCP Server.

Instructions

Retrieves a list of Kubernetes clusters (also known as managed clusters or spoke clusters).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • Main handler function for the 'clusters' tool: lists ManagedCluster CRs from open-cluster-management.io API, formats as table with name, hub accepted, URL, joined, available, age.
    export async function listClusters({ }): Promise<CallToolResult> {
      const response = await client.list<k8s.KubernetesObject>("cluster.open-cluster-management.io/v1", "ManagedCluster")
      if (!response || response.items.length == 0) {
        console.warn("no managed clusters on the current cluster")
        return {
          content: [{
            type: "text",
            text: "no managed clusters available on the current cluster"
          }],
        }
      }
    
      clusterToServerAPIMap = new Map(
        response.items.map((item: any) => {
          const name: string = item.metadata?.name;
          const server: string = item.spec?.managedClusterClientConfigs?.[0]?.url;
          return [name, server];
        })
      );
    
      // Format table header
      let result = `NAME       HUB ACCEPTED   MANAGED CLUSTER URLS                                                            JOINED   AVAILABLE   AGE\n`;
    
      // Process each cluster and format the output
      response.items.forEach((item: any) => {
        const name: string = item.metadata?.name || "Unknown";
        const hubAccepted: string = item.spec?.hubAcceptsClient ? "true" : "false";
        const server: string = item.spec?.managedClusterClientConfigs?.[0]?.url || "N/A";
    
        // Extract conditions
        const joinedCondition = item.status?.conditions?.find((c: any) => c.type === "ManagedClusterJoined")?.status || "False";
        const availableCondition = item.status?.conditions?.find((c: any) => c.type === "ManagedClusterConditionAvailable")?.status || "False";
    
        // Calculate cluster age
        const creationTimestamp = item.metadata?.creationTimestamp;
        const age = creationTimestamp ? getClusterAge(creationTimestamp) : "N/A";
    
        // Append formatted row
        result += `${name.padEnd(10)} ${hubAccepted.padEnd(14)} ${server.padEnd(80)} ${joinedCondition.padEnd(8)} ${availableCondition.padEnd(10)} ${age}\n`;
      });
    
      return {
        content: [{
          type: "text",
          text: result
        }],
      }
    }
  • Description and empty Zod schema (args) for the 'clusters' tool.
    export const listClusterDesc = "Retrieves a list of Kubernetes clusters (also known as managed clusters or spoke clusters)."
    export const listClustersArgs = {}
  • src/index.ts:24-28 (registration)
    Registration of the 'clusters' tool in the TypeScript MCP server.
      "clusters",
      listClusterDesc,
      listClustersArgs, // should be a Zod schema, e.g., z.object({...})
      async (args, extra) => listClusters(args) // ensure listClusters matches (args, extra) => ...
    )
  • Python handler for the 'clusters' tool using MCP decorator: lists ManagedCluster resources and formats table.
    @mcp.tool(description="Retrieves a list of Kubernetes clusters (also known as managed clusters or spoke clusters).")
    def clusters() -> Annotated[str, Field(description="The managed clusters, also known as spoke clusters.")]:
        config.load_kube_config()
        dyn_client = DynamicClient(ApiClient())
    
        try:
            managed_cluster_res = dyn_client.resources.get(
                api_version="cluster.open-cluster-management.io/v1",
                kind="ManagedCluster"
            )
            response = managed_cluster_res.get()
            items = response.items
        except Exception as e:
            return f"Failed to list clusters: {e}"
    
        if not items:
            return "No managed clusters available on the current cluster"
    
        header = (
            f"{'NAME':<12} {'HUB ACCEPTED':<15} {'MANAGED CLUSTER URLS':<80} "
            f"{'JOINED':<8} {'AVAILABLE':<10} {'AGE'}"
        )
        result_lines = [header]
    
        for item in items:
            metadata = item.metadata
            spec = item.spec or {}
            status = item.status or {}
    
            name = metadata.name or "Unknown"
            hub_accepted = str(spec.get("hubAcceptsClient", False)).lower()
            server = spec.get("managedClusterClientConfigs", [{}])[0].get("url", "N/A")
    
            conditions = status.get("conditions", [])
            joined = next((c.get("status") for c in conditions if c.get("type") == "ManagedClusterJoined"), "False")
            available = next((c.get("status") for c in conditions if c.get("type") == "ManagedClusterConditionAvailable"), "False")
    
            creation_timestamp = metadata.creationTimestamp
            age = get_cluster_age(creation_timestamp) if creation_timestamp else "N/A"
    
            if generate_kubeconfig:
                try:
                      kubeconfig_path = setup_cluster_access(cluster=name)
                      cluster_kubeconfig_map[name] = kubeconfig_path
                except Exception as e:
                    logger.warning(f"Failed to setup access for cluster '{name}': {e}")
    
            result_lines.append(
                f"{name:<12} {hub_accepted:<15} {server:<80} {joined:<8} {available:<10} {age}"
            )
    
        return "\n".join(result_lines)
  • Import of the 'clusters' tool for registration in Python MCP server (registration via decorator in source file).
    from multicluster_mcp_server.tools.cluster import clusters
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It states 'retrieves a list' which implies a read-only operation, but doesn't mention authentication requirements, rate limits, pagination, or what the returned list includes (e.g., metadata fields). This leaves significant gaps for a tool that likely interacts with a complex system like Kubernetes.

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 a single, efficient sentence that front-loads the core purpose ('retrieves a list of Kubernetes clusters') and adds clarifying terminology without redundancy. Every word earns its place.

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

Completeness2/5

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

For a tool interacting with Kubernetes clusters (a complex domain) with no annotations and no output schema, the description is insufficient. It doesn't explain what information is returned (e.g., cluster names, statuses, regions), how results are formatted, or any behavioral constraints. The agent would lack critical context to use this tool effectively.

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 tool has 0 parameters with 100% schema description coverage, so the schema fully documents the absence of inputs. The description doesn't need to compensate for any parameter gaps, and it appropriately doesn't mention parameters. A baseline of 4 is appropriate for a zero-parameter tool.

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 ('retrieves') and resource ('list of Kubernetes clusters'), with specific terminology ('managed clusters or spoke clusters') that adds domain context. However, it doesn't explicitly differentiate from sibling tools like 'connect_cluster' or 'kubectl' which might also interact with clusters.

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 'connect_cluster' or 'kubectl'. The description implies a read-only listing operation but doesn't specify prerequisites, timing, or exclusions.

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/yanmxa/ocm-mcp-server'

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