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;
    }
Behavior2/5

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

No annotations are provided, so the description carries full burden. While it mentions the tool is useful for debugging/troubleshooting, it doesn't disclose important behavioral traits like authentication requirements, rate limits, whether it's read-only or destructive, or what format/logs are returned. For a log retrieval tool with no annotation coverage, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

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

The description is appropriately concise with two sentences. The first sentence states the core purpose, and the second provides usage context. There's no unnecessary verbosity, though it could be slightly more structured.

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?

Given the tool's complexity (7 parameters, no output schema, no annotations), the description is incomplete. It doesn't explain what the tool returns (log format, structure), doesn't mention authentication or permission requirements, and provides minimal behavioral context. For a Kubernetes log retrieval tool, this leaves significant gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The schema description coverage is 100%, so all parameters are documented in the schema. The description doesn't add any parameter-specific information beyond what's in the schema. According to guidelines, when schema coverage is high (>80%), the baseline score is 3 even without parameter info in the description.

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 tool's purpose: 'Obtiene los logs de un pod específico en Kubernetes' (Gets the logs of a specific pod in Kubernetes). It specifies the verb ('obtiene' - gets) and resource ('logs de un pod'), but doesn't distinguish it from the sibling tool 'k8s.app_status' which likely serves a different purpose.

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 provides some usage context with 'Útil para debugging y troubleshooting' (Useful for debugging and troubleshooting), which implies when to use it. However, it doesn't explicitly state when NOT to use it or mention alternatives like the sibling tool 'k8s.app_status' for different monitoring needs.

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

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