list_logs
Retrieve logs from Oracle Cloud Infrastructure log groups to monitor activity, analyze retention settings, and manage log data for troubleshooting and compliance.
Instructions
List all logs in a log group.
Args:
log_group_id: OCID of the log group
Returns:
List of logs with their types, retention, and enabled state
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| log_group_id | Yes |
Implementation Reference
- Core implementation of the list_logs tool handler. Fetches all logs in a specified log group using OCI pagination and returns formatted log details.def list_logs(logging_client: oci.logging.LoggingManagementClient, log_group_id: str) -> List[Dict[str, Any]]: """ List all logs in a log group. Args: logging_client: OCI Logging Management client log_group_id: OCID of the log group Returns: List of logs with their details """ try: logs_response = oci.pagination.list_call_get_all_results( logging_client.list_logs, log_group_id ) logs = [] for log in logs_response.data: logs.append({ "id": log.id, "log_group_id": log.log_group_id, "display_name": log.display_name, "log_type": log.log_type, "lifecycle_state": log.lifecycle_state, "is_enabled": log.is_enabled, "retention_duration": log.retention_duration, "compartment_id": log.compartment_id, "time_created": str(log.time_created), "time_last_modified": str(log.time_last_modified), }) logger.info(f"Found {len(logs)} logs in log group {log_group_id}") return logs except Exception as e: logger.exception(f"Error listing logs: {e}") raise
- mcp_server_oci/mcp_server.py:1748-1764 (registration)MCP tool registration for 'list_logs'. Decorates the wrapper handler with @mcp.tool(name="list_logs"), adds logging/error handling, and delegates to the core list_logs implementation.@mcp.tool(name="list_logs") @mcp_tool_wrapper( start_msg="Listing logs in log group {log_group_id}...", error_prefix="Error listing logs" ) async def mcp_list_logs(ctx: Context, log_group_id: str) -> List[Dict[str, Any]]: """ List all logs in a log group. Args: log_group_id: OCID of the log group Returns: List of logs with their types, retention, and enabled state """ return list_logs(oci_clients["logging"], log_group_id)
- mcp_server_oci/mcp_server.py:104-113 (helper)Import statement that brings the list_logs helper function from monitoring.py into the MCP server for tool registration.from mcp_server_oci.tools.monitoring import ( list_alarms, get_alarm, get_alarm_history, list_metrics, query_metric_data, search_logs, list_log_groups, list_logs, )