Skip to main content
Glama

container_logs

Retrieve container logs to monitor application output and troubleshoot issues. Specify container name/ID and optionally set the number of log lines to display from the end.

Instructions

Get logs from a container.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
containerYesContainer name or ID
tailNoNumber of lines to show from end of log

Implementation Reference

  • The main handler function for the 'container_logs' tool. It extracts container name/ID and optional tail lines from args, runs 'podman logs --tail <n> <container>', and returns the output or error.
    async def container_logs(self, args: Dict[str, Any]) -> Dict[str, Any]:
        container = args.get("container")
        tail = args.get("tail", 100)
        result = run_podman(["logs", "--tail", str(tail), container])
        return {"output": result["stdout"] if result["success"] else f"Error: {result['stderr']}"}
  • Input schema definition for the container_logs tool, defining required 'container' string and optional 'tail' integer.
    Tool(
        name="container_logs",
        description="Get logs from a container",
        inputSchema={
            "type": "object",
            "properties": {
                "container": {
                    "type": "string",
                    "description": "Container name or ID"
                },
                "tail": {
                    "type": "integer",
                    "description": "Number of lines to show from end of log",
                    "default": 100
                }
            },
            "required": ["container"]
        }
    ),
  • main_b.py:459-472 (registration)
    Registration of tool handlers in the handle_tools_call method, mapping 'container_logs' to self.container_logs function.
    tool_handlers = {
        "list_containers": self.list_containers,
        "container_info": self.container_info,
        "start_container": self.start_container,
        "stop_container": self.stop_container,
        "restart_container": self.restart_container,
        "container_logs": self.container_logs,
        "run_container": self.run_container,
        "remove_container": self.remove_container,
        "exec_container": self.exec_container,
        "list_images": self.list_images,
        "pull_image": self.pull_image,
        "container_stats": self.container_stats,
    }
  • main.py:191-197 (handler)
    Alternative handler for 'container_logs' using FastMCP decorator, similar logic running podman logs.
    @mcp.tool(title="Container logs", description="Get logs from a container.")
    def container_logs(
        container: str = Field(..., description="Container name or ID"),
        tail: int = Field(100, description="Number of lines to show from end of log"),
    ) -> str:
        result = run_podman(["logs", "--tail", str(tail), container])
        return result["stdout"] if result["success"] else f"Error: {result['stderr']}"
  • Helper function used by all tools including container_logs to execute podman commands and return structured results.
    def run_podman(args: List[str]) -> Dict[str, Any]:
        """Run a podman command and capture output"""
        try:
            cmd = ["podman"] + args
            logger.info(f"Running command: {' '.join(cmd)}")
            result = subprocess.run(
                cmd,
                capture_output=True,
                text=True,
                timeout=30
            )
            return {
                "success": result.returncode == 0,
                "stdout": result.stdout.strip(),
                "stderr": result.stderr.strip(),
                "returncode": result.returncode,
            }
        except subprocess.TimeoutExpired:
            logger.error("Command timed out")
            return {"success": False, "stdout": "", "stderr": "Command timed out", "returncode": -1}
        except Exception as e:
            logger.error(f"Command error: {e}")
            return {"success": False, "stdout": "", "stderr": str(e), "returncode": -1}

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/kunwarmahen/podman-mcp-server'

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