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"),
    },

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observed

TDQS

C2.9/5.0
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: whether this is a read-only operation, what format the shard information returns, potential performance implications, or any limitations. The description is functional but lacks operational context.

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 extremely concise - a single sentence that efficiently communicates the core functionality. It's front-loaded with the main purpose and includes the scope clarification. Every word serves a purpose with no redundancy or unnecessary elaboration.

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 insufficiently complete. While concise, it doesn't explain what 'shard information' includes, the format of the response, or how to interpret the results. Given the complexity of shard management in search systems and the lack of structured documentation elsewhere, the description should provide more operational context.

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%, with the single parameter 'index' clearly documented in the schema. The description adds minimal value beyond the schema by mentioning 'all or specific indices' which implies the optional nature of the index parameter, but doesn't provide additional context about valid index names, patterns, or special cases.

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'), with scope clarification ('for all or specific indices'). It distinguishes this as a retrieval operation rather than a mutation, but doesn't explicitly differentiate from similar sibling tools like 'get_mappings' or 'get_aliases' that also retrieve metadata.

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?

No explicit guidance on when to use this tool versus alternatives. The description mentions 'all or specific indices' which provides some context about scope, but doesn't indicate when to prefer this over other metadata retrieval tools like 'get_cluster_health' or 'list_indices', nor does it mention prerequisites or typical use cases.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools