get-logs
Retrieve container logs from Docker to monitor application behavior and troubleshoot issues by specifying the container name.
Instructions
Retrieve the latest logs for a specified Docker container
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| container_name | Yes |
Implementation Reference
- src/docker_mcp/handlers.py:165-181 (handler)Implements the core logic for the 'get-logs' tool: extracts container_name from arguments, fetches the last 100 logs using docker_client.container.logs, and returns formatted text content with logs or error.@staticmethod async def handle_get_logs(arguments: Dict[str, Any]) -> List[TextContent]: debug_info = [] try: container_name = arguments.get("container_name") if not container_name: raise ValueError("Missing required container_name") debug_info.append(f"Fetching logs for container '{ container_name}'") logs = await asyncio.to_thread(docker_client.container.logs, container_name, tail=100) return [TextContent(type="text", text=f"Logs for container '{container_name}':\n{logs}\n\nDebug Info:\n{chr(10).join(debug_info)}")] except Exception as e: debug_output = "\n".join(debug_info) return [TextContent(type="text", text=f"Error retrieving logs: {str(e)}\n\nDebug Information:\n{debug_output}")]
- src/docker_mcp/server.py:128-138 (registration)Registers the 'get-logs' tool in the MCP server's list_tools() method, including its description and input schema requiring 'container_name'.types.Tool( name="get-logs", description="Retrieve the latest logs for a specified Docker container", inputSchema={ "type": "object", "properties": { "container_name": {"type": "string"} }, "required": ["container_name"] } ),
- src/docker_mcp/server.py:160-161 (handler)Dispatches 'get-logs' tool calls to the DockerHandlers.handle_get_logs implementation.elif name == "get-logs": return await DockerHandlers.handle_get_logs(arguments)
- src/docker_mcp/server.py:131-137 (schema)Defines the input schema for the 'get-logs' tool: object with required 'container_name' string property.inputSchema={ "type": "object", "properties": { "container_name": {"type": "string"} }, "required": ["container_name"] }