delete_index
Remove a specific Elasticsearch index by specifying its name, ensuring streamlined data management and storage optimization.
Instructions
Delete an Elasticsearch index
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes | Name of the Elasticsearch index to delete |
Implementation Reference
- src/index.ts:1001-1026 (handler)The handler function for the 'delete_index' MCP tool. It takes the index name, calls the esService.deleteIndex helper, and returns a success or error message in the expected MCP content format.async ({ index }) => { try { await esService.deleteIndex(index); return { content: [ { type: "text", text: `Index '${index}' deleted successfully.` }, ], }; } catch (error) { console.error( `Failed to delete index: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/index.ts:994-1000 (schema)Zod schema defining the input parameters for the 'delete_index' tool: a required trimmed string 'index' name.{ index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to delete"), },
- src/index.ts:991-1027 (registration)Registration of the 'delete_index' tool using server.tool(), including name, description, input schema, and handler function.server.tool( "delete_index", "Delete an Elasticsearch index", { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to delete"), }, async ({ index }) => { try { await esService.deleteIndex(index); return { content: [ { type: "text", text: `Index '${index}' deleted successfully.` }, ], }; } catch (error) { console.error( `Failed to delete index: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- Supporting helper method in the ElasticsearchService class that deletes the specified index using the Elasticsearch client.async deleteIndex(index: string): Promise<any> { return await this.client.indices.delete({ index, }); }