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
| Name | Required | Description | Default |
|---|---|---|---|
| index | No | Optional 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) }`, }, ], }; } } );
- index.ts:650-702 (handler)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) }`, }, ], }; } }
- index.ts:644-649 (schema)Input schema for the tool: optional 'index' parameter of type string.{ index: z .string() .optional() .describe("Optional index name to get shard information for"), },