Skip to main content
Glama
Octodet

octodet-elasticsearch-mcp

get_shards

Retrieve shard details for all or specified indices in the octodet-elasticsearch-mcp server to monitor and manage Elasticsearch cluster data distribution.

Instructions

Get shard information for all or specific indices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexNoOptional index name to get shard information for

Implementation Reference

  • The MCP tool handler function for 'get_shards' that calls the Elasticsearch service method and formats the response as MCP-compliant content.
    async ({ index }) => {
      try {
        const shardsInfo = await esService.getShards(index);
    
        return {
          content: [
            {
              type: "text",
              text: `Found ${shardsInfo.length} shards${
                index ? ` for index ${index}` : ""
              }`,
            },
            {
              type: "text",
              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",
              text: `Error: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
  • Core helper function in ElasticsearchService that executes the cat.shards API and maps results to ShardInfo array.
    async getShards(index?: string): Promise<ShardInfo[]> {
      const response = await this.client.cat.shards({
        index,
        format: "json",
      });
    
      return response.map((shard: any) => ({
        index: shard.index,
        shard: shard.shard,
        prirep: shard.prirep,
        state: shard.state,
        docs: shard.docs,
        store: shard.store,
        ip: shard.ip,
        node: shard.node,
      }));
    }
  • TypeScript interface defining the structure of individual shard information objects returned by the getShards function.
    export interface ShardInfo {
      index: string;
      shard: string;
      prirep: string;
      state: string;
      docs: string;
      store: string;
      ip: string;
      node: string;
  • src/index.ts:368-413 (registration)
    Registration of the 'get_shards' tool on the MCP server, including name, description, input schema, and handler reference.
    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 }) => {
        try {
          const shardsInfo = await esService.getShards(index);
    
          return {
            content: [
              {
                type: "text",
                text: `Found ${shardsInfo.length} shards${
                  index ? ` for index ${index}` : ""
                }`,
              },
              {
                type: "text",
                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",
                text: `Error: ${
                  error instanceof Error ? error.message : String(error)
                }`,
              },
            ],
          };
        }
      }
    );
  • Zod schema for the input parameter 'index' of the get_shards tool.
    {
      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: 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.

Install Server

Other Tools

Related 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/Octodet/elasticsearch-mcp'

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