Skip to main content
Glama
rishab2404

Elasticsearch MCP Server

by rishab2404

get_shards

Retrieve shard details for Elasticsearch indices to monitor data distribution and cluster health. Use this tool to analyze index sharding patterns and optimize storage performance.

Instructions

Get shard information for all or specific indices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexNoOptional index name to get shard information for

Implementation Reference

  • index.ts:641-703 (registration)
    Registration of the 'get_shards' MCP tool, including schema and handler function.
    server.tool(
      "get_shards",
      "Get shard information for all or specific indices",
      {
        index: z
          .string()
          .optional()
          .describe("Optional index name to get shard information for"),
      },
      async ({ index }) => {
        console.error("[DEBUG] get_shards tool called", index);
        try {
          const response = await esClient.cat.shards({
            index,
            format: "json",
          });
    
          const shardsInfo = response.map((shard) => ({
            index: shard.index,
            shard: shard.shard,
            prirep: shard.prirep,
            state: shard.state,
            docs: shard.docs,
            store: shard.store,
            ip: shard.ip,
            node: shard.node,
          }));
    
          const metadataFragment = {
            type: "text" as const,
            text: `Found ${shardsInfo.length} shards${
              index ? ` for index ${index}` : ""
            }`,
          };
    
          return {
            content: [
              metadataFragment,
              {
                type: "text" as const,
                text: JSON.stringify(shardsInfo, null, 2),
              },
            ],
          };
        } catch (error) {
          console.error(
            `Failed to get shard information: ${
              error instanceof Error ? error.message : String(error)
            }`
          );
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: ${
                  error instanceof Error ? error.message : String(error)
                }`,
              },
            ],
          };
        }
      }
    );
  • Handler function that executes the tool logic: calls esClient.cat.shards, maps the response, and returns formatted content.
    async ({ index }) => {
      console.error("[DEBUG] get_shards tool called", index);
      try {
        const response = await esClient.cat.shards({
          index,
          format: "json",
        });
    
        const shardsInfo = response.map((shard) => ({
          index: shard.index,
          shard: shard.shard,
          prirep: shard.prirep,
          state: shard.state,
          docs: shard.docs,
          store: shard.store,
          ip: shard.ip,
          node: shard.node,
        }));
    
        const metadataFragment = {
          type: "text" as const,
          text: `Found ${shardsInfo.length} shards${
            index ? ` for index ${index}` : ""
          }`,
        };
    
        return {
          content: [
            metadataFragment,
            {
              type: "text" as const,
              text: JSON.stringify(shardsInfo, null, 2),
            },
          ],
        };
      } catch (error) {
        console.error(
          `Failed to get shard information: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
        return {
          content: [
            {
              type: "text" as const,
              text: `Error: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    }
  • Input schema for the tool: optional 'index' parameter of type string.
    {
      index: z
        .string()
        .optional()
        .describe("Optional index name to get shard information for"),
    },
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It states what the tool does but doesn't describe important behavioral aspects like whether this is a read-only operation, what format the shard information returns, whether it includes cluster health status, or any performance considerations for large indices.

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 that communicates the core functionality without unnecessary words. It's appropriately sized for a simple tool with one optional parameter.

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?

For a tool with no annotations and no output schema, the description is insufficient. It doesn't explain what shard information includes (primary/replica status, node assignments, size, etc.), doesn't mention error conditions, and provides no context about how this tool fits into broader index management workflows with the sibling tools.

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

Parameters3/5

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

Schema description coverage is 100%, so the schema already documents the optional 'index' parameter. The description adds minimal value by mentioning 'specific indices' which aligns with the parameter, but doesn't provide additional context about index naming conventions, wildcard support, or what happens when no index is specified.

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 action ('Get') and resource ('shard information'), and specifies scope options ('for all or specific indices'). It doesn't explicitly differentiate from sibling tools like get_mappings or list_indices, but the focus on shard information provides reasonable distinction.

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 list_indices or get_mappings. It mentions scope options but doesn't explain when to filter by index versus getting all indices, or how this tool relates to other index-related operations.

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/rishab2404/mcp_es'

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