get-logs
Retrieve log output from a Kubernetes pod to monitor application behavior, debug issues, and track pod activity. Specify the pod name and optionally set namespace, line count, or enable real-time log streaming.
Instructions
Get logs from a Kubernetes pod
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| follow | No | Follow the logs (stream new logs as they come in) | |
| lines | No | Number of lines to retrieve from the end of the logs (default: 100) | |
| namespace | No | The namespace of the pod (optional, defaults to current context namespace) | |
| pod | Yes | The name of the pod to get logs from |
Implementation Reference
- server.js:1588-1598 (handler)The core handler logic for the 'get-logs' tool. Constructs and executes a 'kubectl logs' command using the provided pod name, optional namespace, number of tail lines, follow flag, and container name, returning the log output.case "get-logs": { const { pod, namespace, lines = 100, follow = false, container } = args; const nsArg = namespace ? `-n ${namespace}` : ""; const followArg = follow ? "-f" : ""; const containerArg = container ? `-c ${container}` : ""; const cmd = `kubectl logs ${pod} ${nsArg} --tail=${lines} ${followArg} ${containerArg}`.trim(); const { stdout } = await execAsync(cmd); return { content: [{ type: "text", text: stdout || "No logs found" }] }; }
- server.js:284-312 (schema)The tool schema definition for 'get-logs', including input schema for validation, descriptions, and required parameters. Used for tool listing and input validation.name: "get-logs", description: "Get logs from a Kubernetes pod", inputSchema: { type: "object", properties: { pod: { type: "string", description: "The name of the pod to get logs from" }, namespace: { type: "string", description: "The namespace of the pod (optional, defaults to current context namespace)" }, lines: { type: "number", description: "Number of lines to retrieve from the end of the logs (default: 100)" }, follow: { type: "boolean", description: "Follow the logs (stream new logs as they come in)" }, container: { type: "string", description: "The container name to get logs from (if pod has multiple containers)" } }, required: ["pod"] } },