Skip to main content
Glama
rishab2404

Elasticsearch MCP Server

by rishab2404

get_shards

Retrieve detailed shard information for all or specific indices in an Elasticsearch database, enabling efficient index management and monitoring.

Instructions

Get shard information for all or specific indices

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexNoOptional index name to get shard information for

Implementation Reference

  • Handler function that retrieves shard information from Elasticsearch using esClient.cat.shards, formats it into a structured array, and returns metadata and JSON stringified 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) }`, }, ], }; } }
  • Zod schema defining the optional 'index' parameter as a string for specifying the Elasticsearch index.
    index: z .string() .optional() .describe("Optional index name to get shard information for"), },
  • index.ts:641-703 (registration)
    Full registration of the 'get_shards' tool using McpServer.tool method, specifying name, description, input 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) }`, }, ], }; } } );

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

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