Skip to main content
Glama

k8s_get_pod_logs

Fetch Kubernetes pod logs with options for tail lines, time range, and container selection to troubleshoot and monitor application performance.

Instructions

Fetch logs from a pod with options for tail lines, time range, and container selection

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesPod name
namespaceNoKubernetes namespace (default: 'default')
containerNoContainer name (for multi-container pods)
tailNoNumber of lines from the end (default: 100)
sinceNoTime duration (e.g., '5m', '1h', '2d')
previousNoGet logs from previous container instance

Implementation Reference

  • The actual implementation of the tool that interacts with the Kubernetes API to fetch pod logs.
    export async function getPodLogs(args: Record<string, unknown>): Promise<string> {
      const api = getCoreV1Api();
      const namespace = (args.namespace as string) || "default";
      const name = args.name as string;
      const container = args.container as string | undefined;
      const tail = (args.tail as number) || 100;
      const since = args.since as string | undefined;
      const previous = (args.previous as boolean) || false;
    
      if (!name) throw new Error("Pod name is required");
    
      let sinceSeconds: number | undefined;
      if (since) {
        const match = since.match(/^(\d+)([smhd])$/);
        if (match) {
          const value = parseInt(match[1]);
          const unit = match[2];
          const multipliers: Record<string, number> = { s: 1, m: 60, h: 3600, d: 86400 };
          sinceSeconds = value * (multipliers[unit] || 1);
        }
      }
    
      const response = await api.readNamespacedPodLog(
        name,
        namespace,
        container,
        undefined,
        undefined,
        undefined,
        undefined,
        previous,
        sinceSeconds,
        tail
      );
    
      const logs = response.body;
      if (!logs || logs.trim().length === 0) {
        return `No logs found for pod '${name}'${container ? ` container '${container}'` : ""} in namespace '${namespace}'.`;
      }
    
      const header = `Logs for pod '${name}'${container ? ` (container: ${container})` : ""} in '${namespace}' (last ${tail} lines):`;
      return `${header}\n\n${logs}`;
    }
  • Schema definition for k8s_get_pod_logs.
      name: "k8s_get_pod_logs",
      description: "Fetch logs from a pod with options for tail lines, time range, and container selection",
      inputSchema: {
        type: "object" as const,
        properties: {
          name: { type: "string", description: "Pod name" },
          namespace: { type: "string", description: "Kubernetes namespace (default: 'default')" },
          container: { type: "string", description: "Container name (for multi-container pods)" },
          tail: { type: "number", description: "Number of lines from the end (default: 100)" },
          since: { type: "string", description: "Time duration (e.g., '5m', '1h', '2d')" },
          previous: { type: "boolean", description: "Get logs from previous container instance" },
        },
        required: ["name"],
      },
    },
  • Tool registration/routing for k8s_get_pod_logs.
    case "k8s_get_pod_logs": return getPodLogs(a);
Behavior2/5

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

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It mentions options like tail lines and time range but doesn't disclose critical traits: whether this is a read-only operation, potential rate limits, authentication requirements, output format (e.g., text stream), or error conditions (e.g., if the pod doesn't exist).

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 action ('fetch logs') and lists key options without unnecessary words. Every part earns its place, making it easy to scan and understand quickly.

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 with 6 parameters, no annotations, and no output schema, the description is incomplete. It lacks context on behavioral aspects (e.g., safety, errors), usage guidelines, and output details, which are crucial for an AI agent to invoke this tool correctly in a Kubernetes environment.

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?

Schema description coverage is 100%, so the schema fully documents all 6 parameters. The description adds marginal value by summarizing key options ('tail lines, time range, and container selection'), but doesn't provide additional semantics beyond what's in the schema, such as usage examples or constraints not captured in schema descriptions.

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 ('fetch logs') and resource ('from a pod'), making the purpose evident. However, it doesn't explicitly differentiate from sibling tools like 'docker_container_logs' or 'system_logs', which also fetch logs from different sources, leaving some ambiguity about when to choose this specific Kubernetes tool.

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?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention prerequisites (e.g., needing Kubernetes cluster access), compare it to sibling tools like 'k8s_describe_pod' for debugging, or specify scenarios where fetching logs is appropriate versus other diagnostic tools.

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

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