Skip to main content
Glama

k8s.pod_logs

Retrieve container logs from Kubernetes pods to diagnose application issues and monitor runtime behavior in development clusters.

Instructions

Obtiene los logs de un pod específico en Kubernetes. Útil para debugging y troubleshooting.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
namespaceYesnamespace del pod
podNameYesnombre exacto del pod
tailNonúmero de líneas desde el final (default: 100)
previousNover logs del contenedor anterior (crashed)
containerNonombre del contenedor específico (si tiene múltiples)
sinceNologs desde hace X tiempo (e.g., '5m', '1h', '2d')
timestampsNoincluir timestamps en los logs

Implementation Reference

  • Core implementation of the tool logic: executes `kubectl logs` with dynamic arguments based on options to fetch and process Kubernetes pod logs.
    export async function getPodLogs( namespace: string, podName: string, options: PodLogsOptions = {} ): Promise<PodLogsResult> { const { tail = DEFAULT_TAIL, previous, container, since, timestamps } = options; const result: PodLogsResult = { namespace, podName, container, logs: "", lineCount: 0, truncated: false, }; // Helper para construir args condicionales sin ifs por todos lados const pushIf = (cond: any, ...args: string[]) => cond && argsList.push(...args); const argsList: string[] = ["logs", podName, "-n", namespace, `--tail=${tail}`]; pushIf(previous, "--previous"); pushIf(container, "-c", container!); pushIf(since, `--since=${since}`); pushIf(timestamps, "--timestamps"); try { const { stdout, stderr } = await execFileAsync("kubectl", argsList, { maxBuffer: MAX_BUFFER, }); if (stderr?.trim()) { // kubectl a veces escribe warnings en stderr aunque funcione console.warn("kubectl logs warning:", stderr.trim()); } result.logs = stdout.trim(); result.lineCount = result.logs ? result.logs.split("\n").length : 0; // "truncated" es básicamente: pedí N y me devolvió N líneas (o más) result.truncated = result.lineCount >= tail; } catch (err: any) { result.error = `Error executing kubectl logs: ${err?.message ?? String(err)}`; } return result; }
  • Zod input schema defining the parameters for the k8s.pod_logs tool, including namespace, podName, and various log options.
    inputSchema: z.object({ namespace: z.string().describe("namespace del pod"), podName: z.string().describe("nombre exacto del pod"), tail: z.number().optional().describe("número de líneas desde el final (default: 100)"), previous: z.boolean().optional().describe("ver logs del contenedor anterior (crashed)"), container: z.string().optional().describe("nombre del contenedor específico (si tiene múltiples)"), since: z.string().optional().describe("logs desde hace X tiempo (e.g., '5m', '1h', '2d')"), timestamps: z.boolean().optional().describe("incluir timestamps en los logs"), }),
  • src/index.ts:67-102 (registration)
    MCP server registration of the 'k8s.pod_logs' tool, including tool name, description, input schema, and thin handler wrapper that calls the core getPodLogs function.
    server.registerTool( "k8s.pod_logs", { description: "Obtiene los logs de un pod específico en Kubernetes. Útil para debugging y troubleshooting.", inputSchema: z.object({ namespace: z.string().describe("namespace del pod"), podName: z.string().describe("nombre exacto del pod"), tail: z.number().optional().describe("número de líneas desde el final (default: 100)"), previous: z.boolean().optional().describe("ver logs del contenedor anterior (crashed)"), container: z.string().optional().describe("nombre del contenedor específico (si tiene múltiples)"), since: z.string().optional().describe("logs desde hace X tiempo (e.g., '5m', '1h', '2d')"), timestamps: z.boolean().optional().describe("incluir timestamps en los logs"), }), }, async (args) => { const results = await getPodLogs( args.namespace, args.podName, { tail: args.tail, previous: args.previous, container: args.container, since: args.since, timestamps: args.timestamps, } ); return { content: [ { type: "text", text: JSON.stringify(results, null, 2), }, ], }; } )
  • TypeScript interface defining the options for pod logs retrieval, matching the tool's input schema.
    export interface PodLogsOptions { tail?: number; previous?: boolean; container?: string; since?: string; timestamps?: boolean; }
  • TypeScript interface defining the structure of the pod logs result returned by the handler.
    export interface PodLogsResult { namespace: string; podName: string; container?: string; logs: string; lineCount: number; truncated: boolean; error?: string; }

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/nicolasmosquerar/k8s-mcp-assistant'

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