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
| Name | Required | Description | Default |
|---|---|---|---|
| namespace | No | Kubernetes namespace (default: 'default') | |
| type | No | Event type: 'Normal' or 'Warning' | |
| field_selector | No | Field selector for filtering | |
| limit | No | Max number of events (default: 50) |
Implementation Reference
- src/tools/kubernetes/events.ts:4-46 (handler)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)}`; } - src/tools/kubernetes/index.ts:64-75 (registration)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)" }, }, }, }, - src/tools/kubernetes/index.ts:200-200 (handler)Routing k8s_get_events tool call to the handler function in index.ts.
case "k8s_get_events": return getEvents(a);