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

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