Skip to main content
Glama
seohyunjun

OpenSearch MCP Server

by seohyunjun

get_recovery_status

Check recovery status and estimated completion time for OpenSearch cluster operations to monitor progress and plan next steps.

Instructions

Get recovery status and estimated completion time

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault

No arguments

Implementation Reference

  • The main handler function for the 'get_recovery_status' tool. It fetches active shard recoveries from OpenSearch using cat.recovery API, calculates progress (files and bytes percentage), recovery rate (MB/sec), and estimates remaining time. If no active recoveries, falls back to cluster health summary. Returns formatted text output as list[TextContent].
    async def get_recovery_status() -> list[TextContent]:
        """
        Get recovery status for shards that are currently being recovered.
        Includes progress percentage and estimated time remaining based on current recovery rate.
        """
        self.logger.info("Fetching recovery status...")
        try:
            # Get active recoveries with detailed stats
            response = self.es_client.cat.recovery(format='json', active_only=True, v=True)
            
            if not response:
                # Get cluster health to show overall shard status if no active recoveries
                health = self.es_client.cluster.health()
                total_shards = health['active_shards'] + health['unassigned_shards'] + health['initializing_shards']
                active_pct = (health['active_shards'] / total_shards) * 100 if total_shards > 0 else 100
                
                status_msg = (
                    f"No active recoveries. Cluster status: {health['status']}\n"
                    f"Active shards: {health['active_shards']}/{total_shards} ({active_pct:.1f}%)\n"
                    f"Initializing: {health['initializing_shards']}\n"
                    f"Unassigned: {health['unassigned_shards']}"
                )
                return [TextContent(type="text", text=status_msg)]
    
            # Process active recoveries
            summary = []
            for recovery in response:
                index = recovery['index']
                shard = recovery['shard']
                stage = recovery.get('stage', 'unknown')
                
                # Calculate progress and time remaining
                files_pct = float(recovery.get('files_percent', '0').rstrip('%'))
                bytes_pct = float(recovery.get('bytes_percent', '0').rstrip('%'))
                total_bytes = int(recovery.get('total_bytes', 0))
                bytes_recovered = int(recovery.get('recovered_in_bytes', 0))
                
                # Parse time value which can be in format like "1.2s" or "3m" or "2.5h"
                time_str = recovery.get('time', '0s')
                try:
                    # Convert time string to milliseconds
                    if time_str.endswith('ms'):
                        time_spent_ms = float(time_str[:-2])
                    elif time_str.endswith('s'):
                        time_spent_ms = float(time_str[:-1]) * 1000
                    elif time_str.endswith('m'):
                        time_spent_ms = float(time_str[:-1]) * 60 * 1000
                    elif time_str.endswith('h'):
                        time_spent_ms = float(time_str[:-1]) * 60 * 60 * 1000
                    else:
                        time_spent_ms = 0
                except ValueError:
                    time_spent_ms = 0
                
                # Calculate recovery rate and estimated time remaining
                if bytes_recovered > 0 and time_spent_ms > 0:
                    rate_mb_sec = (bytes_recovered / 1024 / 1024) / (time_spent_ms / 1000)
                    remaining_bytes = total_bytes - bytes_recovered
                    est_seconds_remaining = (remaining_bytes / 1024 / 1024) / rate_mb_sec if rate_mb_sec > 0 else 0
                    
                    # Format time remaining in a human-readable way
                    if est_seconds_remaining < 60:
                        time_remaining = f"{est_seconds_remaining:.0f} seconds"
                    elif est_seconds_remaining < 3600:
                        time_remaining = f"{est_seconds_remaining/60:.1f} minutes"
                    else:
                        time_remaining = f"{est_seconds_remaining/3600:.1f} hours"
                    
                    recovery_info = (
                        f"Index: {index}, Shard: {shard}\n"
                        f"Stage: {stage}\n"
                        f"Progress: files={files_pct:.1f}%, bytes={bytes_pct:.1f}%\n"
                        f"Rate: {rate_mb_sec:.1f} MB/sec\n"
                        f"Est. time remaining: {time_remaining}\n"
                    )
                else:
                    recovery_info = (
                        f"Index: {index}, Shard: {shard}\n"
                        f"Stage: {stage}\n"
                        f"Progress: files={files_pct:.1f}%, bytes={bytes_pct:.1f}%\n"
                        "Rate: calculating...\n"
                    )
                
                summary.append(recovery_info)
            
            return [TextContent(type="text", text="\n".join(summary))]
            
        except Exception as e:
            self.logger.error(f"Error fetching recovery status: {e}")
            return [TextContent(type="text", text=f"Error: {str(e)}")]
  • Calls register_tools on AdminClusterTools instance, which registers the get_recovery_status tool (along with others) via its @mcp.tool decorators.
    admin_cluster_tools.register_tools(self.mcp)
  • Instantiates the AdminClusterTools class containing the get_recovery_status tool implementation.
    admin_cluster_tools = AdminClusterTools(self.logger)
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions retrieving 'recovery status and estimated completion time', which implies a read-only operation, but fails to detail aspects like authentication requirements, rate limits, error conditions, or what specific 'recovery' refers to (e.g., cluster recovery, index recovery). This leaves significant gaps in understanding the tool's behavior.

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, clear sentence with no wasted words, making it highly concise and front-loaded. Every part of the sentence directly contributes to explaining the tool's purpose, earning its place without unnecessary elaboration.

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 complexity is low (0 parameters, no output schema, no annotations), the description is minimally adequate but incomplete. It states what the tool retrieves but lacks context on the recovery process, output format, or how it integrates with sibling tools like 'get_cluster_health'. This leaves the agent with insufficient information for fully informed usage.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters4/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The tool has 0 parameters, and the schema description coverage is 100%, so there are no parameters to document. The description does not need to add parameter semantics beyond the schema, and it appropriately avoids mentioning any. A baseline of 4 is applied for zero-parameter tools, as there is no missing information to compensate for.

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 tool's purpose with a specific verb ('Get') and resource ('recovery status and estimated completion time'), making it immediately understandable. However, it doesn't distinguish this tool from potential sibling tools that might also retrieve status information, such as 'get_cluster_health' or 'get_cluster_stats', which prevents 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 like 'get_cluster_health' or 'get_cluster_stats', nor does it mention any prerequisites or context for usage. It merely states what the tool does without indicating appropriate scenarios or exclusions.

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/seohyunjun/opensearch-mcp-server'

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