get_logs
Retrieve logs from a specific Kubernetes pod by specifying its name, namespace, and log tail length. Simplify log management within clusters using MCP Kubernetes Server.
Instructions
Get the logs of a specific pod
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | Yes | ||
| namespace | No | default | |
| tail | No |
Implementation Reference
- kubernetes.py:158-167 (handler)The handler function that implements the 'get_logs' tool logic. It retrieves the last 'tail' number of lines from the logs of a pod named 'name' in the specified 'namespace' using the 'kubectl logs' command.@mcp.tool() async def get_logs(name: str, namespace: str = "default", tail: int = 1000) -> dict: """Get the logs of a specific pod""" try: cmd = ["kubectl", "logs", name, "-n", namespace, "--tail", str(tail)] result = subprocess.run(cmd, capture_output=True, text=True, check=True) return {"logs": result.stdout} except subprocess.CalledProcessError as e: return {"error": f"Failed to get logs: {str(e)}"}