Skip to main content
Glama

k8s_get_events

Retrieve Kubernetes cluster events filtered by namespace and type (Normal/Warning) to monitor and troubleshoot infrastructure issues.

Instructions

List cluster events filtered by namespace and type (Normal/Warning)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceNoKubernetes namespace (default: 'default')
typeNoEvent type: 'Normal' or 'Warning'
field_selectorNoField selector for filtering
limitNoMax number of events (default: 50)

Implementation Reference

  • Implementation of the k8s_get_events tool logic using the Kubernetes client to list events.
    export async function getEvents(args: Record<string, unknown>): Promise<string> {
      const api = getCoreV1Api();
      const namespace = (args.namespace as string) || "default";
      const type = args.type as string | undefined; // Normal, Warning
      const fieldSelector = args.field_selector as string | undefined;
      const limit = (args.limit as number) || 50;
    
      let selector = fieldSelector;
      if (type) {
        selector = selector ? `${selector},type=${type}` : `type=${type}`;
      }
    
      const response = await api.listNamespacedEvent(
        namespace,
        undefined,
        undefined,
        undefined,
        selector
      );
    
      const events = response.body.items
        .sort((a, b) => {
          const aTime = a.lastTimestamp || a.metadata?.creationTimestamp;
          const bTime = b.lastTimestamp || b.metadata?.creationTimestamp;
          return new Date(bTime || 0).getTime() - new Date(aTime || 0).getTime();
        })
        .slice(0, limit);
    
      if (events.length === 0) {
        return `No events found in namespace '${namespace}'${type ? ` of type '${type}'` : ""}.`;
      }
    
      const headers = ["LAST SEEN", "TYPE", "REASON", "OBJECT", "MESSAGE"];
      const rows = events.map((e) => [
        e.lastTimestamp ? formatAge(e.lastTimestamp) : "?",
        e.type || "Normal",
        e.reason || "",
        `${e.involvedObject.kind}/${e.involvedObject.name}`,
        (e.message || "").substring(0, 80),
      ]);
    
      return `Events in namespace '${namespace}':\n\n${formatTable(headers, rows)}`;
    }
  • Definition of the k8s_get_events tool schema.
      name: "k8s_get_events",
      description: "List cluster events filtered by namespace and type (Normal/Warning)",
      inputSchema: {
        type: "object" as const,
        properties: {
          namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" },
          type: { type: "string", description: "Event type: 'Normal' or 'Warning'" },
          field_selector: { type: "string", description: "Field selector for filtering" },
          limit: { type: "number", description: "Max number of events (default: 50)" },
        },
      },
    },
  • Routing k8s_get_events tool call to the handler function in index.ts.
    case "k8s_get_events": return getEvents(a);

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/batu-sonmez/infraclaude'

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