Skip to main content
Glama
Octodet

octodet-elasticsearch-mcp

delete_document

Remove a specific document from an Elasticsearch index by providing the index name and document ID for precise data management.

Instructions

Delete a document from a specific Elasticsearch index

Input Schema

NameRequiredDescriptionDefault
idYesDocument ID to delete
indexYesName of the Elasticsearch index

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "id": { "description": "Document ID to delete", "minLength": 1, "type": "string" }, "index": { "description": "Name of the Elasticsearch index", "minLength": 1, "type": "string" } }, "required": [ "index", "id" ], "type": "object" }

Implementation Reference

  • The main handler function for the "delete_document" MCP tool. It receives index and id parameters, calls the esService.deleteDocument helper, and returns a structured response with success or error message in MCP format.
    async ({ index, id }) => { try { await esService.deleteDocument(index, id); return { content: [ { type: "text", text: `Document with ID '${id}' deleted from index '${index}'.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error deleting document: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
  • Zod-based input schema defining the required 'index' and 'id' string parameters with validation and descriptions for the delete_document tool.
    { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index"), id: z .string() .min(1, "Document ID is required") .describe("Document ID to delete"), },
  • src/index.ts:504-542 (registration)
    The server.tool registration call for the "delete_document" tool, specifying name, description, input schema, and handler function.
    server.tool( "delete_document", "Delete a document from a specific Elasticsearch index", { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index"), id: z .string() .min(1, "Document ID is required") .describe("Document ID to delete"), }, async ({ index, id }) => { try { await esService.deleteDocument(index, id); return { content: [ { type: "text", text: `Document with ID '${id}' deleted from index '${index}'.`, }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error deleting document: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
  • Supporting helper method in ElasticsearchService class that performs the actual document deletion using the Elasticsearch client.
    async deleteDocument(index: string, id: string): Promise<any> { return await this.client.delete({ index, id }); }

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