Skip to main content
Glama

list_snapshots

Retrieve detailed snapshots from an Elasticsearch repository to monitor backup status and manage data recovery processes efficiently.

Instructions

List all snapshots in an Elasticsearch repository with detailed information and status

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
repositoryNoRepository name to list snapshots frombackup_repository
verboseNoWhether to show detailed information for each snapshot

Implementation Reference

  • Full implementation of the 'list_snapshots' tool handler. This async function retrieves and formats a detailed list of snapshots from the specified Elasticsearch repository, including status, indices, timings, shards, and metadata. Handles errors with user-friendly messages.
    @app.tool( description="List all snapshots in an Elasticsearch repository with detailed information and status", tags={"elasticsearch", "snapshot", "list", "repository"} ) async def list_snapshots( repository: Annotated[str, Field(description="Repository name to list snapshots from")] = "backup_repository", verbose: Annotated[bool, Field(description="Whether to show detailed information for each snapshot")] = True ) -> str: """List all snapshots in an Elasticsearch repository.""" try: es = get_es_client() # Check if repository exists try: repo_info = es.snapshot.get_repository(repository=repository) except: return (f"❌ Repository '{repository}' not found!\n\n" + f"πŸ“‚ **Repository Error**: Cannot access snapshot repository\n" + f"πŸ“ **Possible Issues**:\n" + f" 1. Repository name is incorrect\n" + f" 2. Repository was not created yet\n" + f" 3. Elasticsearch path.repo configuration issue\n\n" + f"πŸ’‘ **Solutions**:\n" + f" β€’ Use 'create_snapshot' to create repository\n" + f" β€’ Check Elasticsearch configuration\n" + f" β€’ Verify repository permissions") # Get repository details repo_details = repo_info.get(repository, {}) repo_type = repo_details.get('type', 'unknown') repo_settings = repo_details.get('settings', {}) # List all snapshots try: snapshots_result = es.snapshot.get(repository=repository, snapshot="_all") snapshots = snapshots_result.get('snapshots', []) except: snapshots = [] if not snapshots: return (f"πŸ“‹ No snapshots found in repository '{repository}'\n\n" + f"πŸ“‚ **Repository Information**:\n" + f" πŸ“‹ Name: {repository}\n" + f" πŸ“Š Type: {repo_type}\n" + f" πŸ“ Location: {repo_settings.get('location', 'Not specified')}\n" + f" πŸ“Έ Snapshots: 0\n\n" + f"πŸ’‘ **Next Steps**:\n" + f" β€’ Use 'create_snapshot' to create your first backup\n" + f" β€’ Regular snapshots help protect against data loss\n" + f" β€’ Consider automated snapshot scheduling") # Sort snapshots by start time (newest first) snapshots.sort(key=lambda x: x.get('start_time_in_millis', 0), reverse=True) result_message = f"πŸ“Έ Found {len(snapshots)} snapshot(s) in repository '{repository}'\n\n" # Repository information result_message += (f"πŸ“‚ **Repository Information**:\n" + f" πŸ“‹ Name: {repository}\n" + f" πŸ“Š Type: {repo_type}\n" + f" πŸ“ Location: {repo_settings.get('location', 'Not specified')}\n" + f" πŸ“Έ Total Snapshots: {len(snapshots)}\n\n") # List snapshots result_message += f"πŸ“‹ **Available Snapshots**:\n\n" for i, snapshot in enumerate(snapshots, 1): name = snapshot.get('snapshot', 'Unknown') state = snapshot.get('state', 'UNKNOWN') # Status emoji based on state if state == 'SUCCESS': status_emoji = "βœ…" elif state == 'PARTIAL': status_emoji = "⚠️" elif state == 'FAILED': status_emoji = "❌" elif state == 'IN_PROGRESS': status_emoji = "πŸ”„" else: status_emoji = "❓" result_message += f"{status_emoji} **{i}. {name}**\n" result_message += f" πŸ“Š State: {state}\n" if verbose: # Detailed information indices = snapshot.get('indices', []) result_message += f" πŸ“¦ Indices: {len(indices)} ({', '.join(indices[:3])}{'...' if len(indices) > 3 else ''})\n" # Timestamps if snapshot.get('start_time'): result_message += f" πŸ•’ Started: {snapshot['start_time']}\n" if snapshot.get('end_time'): result_message += f" πŸ•’ Completed: {snapshot['end_time']}\n" # Duration if snapshot.get('start_time_in_millis') and snapshot.get('end_time_in_millis'): duration = (snapshot['end_time_in_millis'] - snapshot['start_time_in_millis']) / 1000 result_message += f" ⏱️ Duration: {duration:.2f} seconds\n" # Shards info if snapshot.get('shards'): shards = snapshot['shards'] total = shards.get('total', 0) successful = shards.get('successful', 0) failed = shards.get('failed', 0) result_message += f" πŸ”’ Shards: {successful}/{total} successful" if failed > 0: result_message += f" ({failed} failed)" result_message += "\n" # Metadata metadata = snapshot.get('metadata', {}) if metadata.get('description'): result_message += f" πŸ“ Description: {metadata['description']}\n" # Global state include_global_state = snapshot.get('include_global_state', False) result_message += f" 🌐 Global State: {'Included' if include_global_state else 'Excluded'}\n" result_message += "\n" # Usage instructions result_message += (f"πŸ”§ **Usage Instructions**:\n" + f" β€’ Use 'restore_snapshot <name>' to restore from any snapshot\n" + f" β€’ Use 'create_snapshot <name>' to create new backups\n" + f" β€’ Monitor storage space in repository location\n" + f" β€’ Clean up old snapshots periodically\n\n" + f"πŸ’Ύ **Backup Best Practices**:\n" + f" βœ… Regular automated snapshots (daily/weekly)\n" + f" βœ… Test restore procedures periodically\n" + f" βœ… Monitor snapshot success/failure status\n" + f" βœ… Keep snapshots in multiple locations if possible") return result_message except Exception as e: error_message = "❌ Failed to list snapshots:\n\n" error_str = str(e).lower() if "connection" in error_str or "refused" in error_str: error_message += "πŸ”Œ **Connection Error**: Cannot connect to Elasticsearch server\n" error_message += f"πŸ“ Check if Elasticsearch is running at the configured address\n" error_message += f"πŸ’‘ Try: Use 'setup_elasticsearch' tool to start Elasticsearch\n\n" elif "repository" in error_str and ("not found" in error_str or "missing" in error_str): error_message += f"πŸ“‚ **Repository Error**: Repository '{repository}' not found\n" error_message += f"πŸ“ Check repository configuration and permissions\n" error_message += f"πŸ’‘ Try: Create repository first or check Elasticsearch configuration\n\n" else: error_message += f"⚠️ **Unknown Error**: {str(e)}\n\n" error_message += f"πŸ” **Technical Details**: {str(e)}" return error_message
  • Registration of the elasticsearch_snapshots sub-server (containing list_snapshots tool) by importing its FastMCP app and mounting it into the main Elasticsearch server app, making the tool available in the unified interface.
    from .sub_servers.elasticsearch_snapshots import app as snapshots_app from .sub_servers.elasticsearch_index_metadata import app as index_metadata_app from .sub_servers.elasticsearch_document import app as document_app from .sub_servers.elasticsearch_index import app as index_app from .sub_servers.elasticsearch_search import app as search_app from .sub_servers.elasticsearch_batch import app as batch_app # Create unified FastMCP application app = FastMCP( name="AgentKnowledgeMCP-Elasticsearch", version="2.0.0", instructions="Unified Elasticsearch tools for comprehensive knowledge management via modular server mounting" ) # ================================ # SERVER MOUNTING - MODULAR ARCHITECTURE # ================================ print("πŸ—οΈ Mounting Elasticsearch sub-servers...") # Mount all sub-servers into unified interface app.mount(snapshots_app) # 3 tools: snapshot management
  • Pydantic schema definition via Annotated Fields for input parameters (repository, verbose) and @app.tool decorator providing description and tags for the list_snapshots tool.
    @app.tool( description="List all snapshots in an Elasticsearch repository with detailed information and status", tags={"elasticsearch", "snapshot", "list", "repository"} ) async def list_snapshots( repository: Annotated[str, Field(description="Repository name to list snapshots from")] = "backup_repository", verbose: Annotated[bool, Field(description="Whether to show detailed information for each snapshot")] = True ) -> str:

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/itshare4u/AgentKnowledgeMCP'

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