Skip to main content
Glama
seohyunjun

OpenSearch MCP Server

by seohyunjun

get_shard_allocation

Retrieve shard allocation distribution for an OpenSearch index to monitor data distribution and optimize cluster performance.

Instructions

Get index shard allocation distribution

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latest_indexYes

Implementation Reference

  • The core handler function for the 'get_shard_allocation' tool. It queries the OpenSearch cluster's shard allocation using the '_cat/shards' endpoint, processes the data to count shards per node, and returns a formatted response as TextContent.
    @mcp.tool(description="Get index shard allocation distribution")
    async def get_shard_allocation(latest_index: str) -> list[TextContent]:
        """
        Get the current index shard allocation distribution across nodes.
        Returns index name, shard number, primary/replica status, and node assignment.
        This helps understand how shards are distributed across the cluster.
    
        Args:
        latest_index: The most recent index of interest.
        """
        self.logger.info("Fetching shard allocation...")
        try:
            response = self.es_client.transport.perform_request(
                'GET',
                '/_cat/shards',
                params={'h': 'index,shard,prirep,node', 'format': 'json'}
            )
            # Count shards per node
            shard_counts = {}
            for shard in response:
                if shard['node'] not in shard_counts:
                    shard_counts[shard['node']] = 0
                shard_counts[shard['node']] += 1
            
            # Format the response with both raw data and counts
            formatted_response = {
                'shard_distribution': response,
                'shards_per_node': shard_counts
            }
            return [TextContent(type="text", text=str(formatted_response))]
        except Exception as e:
            self.logger.error(f"Error fetching shard allocation: {e}")
            return [TextContent(type="text", text=f"Error: {str(e)}")]
  • Registers all tools from AdminIndexTools, including 'get_shard_allocation', by calling its register_tools method on the MCP instance.
    admin_index_tools.register_tools(self.mcp)
  • Instantiates the AdminIndexTools class instance which provides the 'get_shard_allocation' tool.
    admin_index_tools = AdminIndexTools(self.logger)
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 tool 'gets' information, implying a read-only operation, but does not specify permissions, rate limits, side effects, or response format. For a tool with zero annotation coverage, this leaves significant gaps in understanding its 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, efficient sentence with no wasted words. It is front-loaded and directly states the tool's purpose, making it easy to parse and understand quickly.

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

Completeness2/5

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

Given the lack of annotations, no output schema, and low schema description coverage, the description is incomplete. It does not compensate for these gaps by explaining parameters, return values, or behavioral details, making it inadequate for a tool with one required parameter and no structured context.

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

Parameters2/5

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

The input schema has 1 parameter with 0% description coverage, and the tool description does not mention any parameters. It fails to explain what 'latest_index' means or how it affects the shard allocation distribution, leaving the parameter semantics undocumented and unclear.

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 as 'Get index shard allocation distribution,' specifying the action ('Get') and resource ('index shard allocation distribution'). It distinguishes from siblings like 'get_cluster_health' or 'list_indices' by focusing on shard allocation, but does not explicitly differentiate in the description text.

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 does not mention prerequisites, context, or exclusions, leaving the agent to infer usage from the purpose alone without explicit direction.

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