Skip to main content
Glama

Container logs

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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the action ('Get logs') but doesn't describe what 'logs' include (e.g., stdout/stderr, timestamps), whether this works for stopped containers, authentication needs, rate limits, or error conditions. For a tool with zero annotation coverage, this leaves significant behavioral gaps.

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 with zero waste. It's front-loaded with the core action and resource, making it easy to parse. Every word earns its place, achieving ideal conciseness for a simple tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (reading logs), lack of annotations, and presence of an output schema (which handles return values), the description is minimally adequate. It states what the tool does but misses behavioral details and usage context. With an output schema, it doesn't need to explain returns, but other gaps keep it at a baseline level.

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%, with clear documentation for both parameters (container name/ID and tail lines). The description adds no additional parameter semantics beyond what the schema provides, such as format examples or constraints. This meets the baseline of 3 when the schema does the heavy lifting.

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 ('Get') and resource ('logs from a container'), making the purpose immediately understandable. It distinguishes from siblings like container_info (metadata) or exec_container (execute commands), though it doesn't explicitly mention these distinctions. The description is specific but lacks explicit sibling differentiation for a perfect score.

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., container must be running), exclusions, or comparisons to siblings like container_stats (performance metrics) or list_containers (enumeration). Without any usage context, the agent must infer when this tool is appropriate.

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

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