Skip to main content
Glama

delete_document

Remove a specific document by its ID from a collection in Typesense databases to manage and maintain accurate data storage and organization.

Instructions

Deletes a single document by its ID from a specific collection. Args: ctx (Context): The MCP context. collection_name (str): The name of the collection. document_id (str): The ID of the document to delete. Returns: dict | str: The deleted document dictionary or an error message string.

Input Schema

NameRequiredDescriptionDefault
collection_nameYes
document_idYes

Input Schema (JSON Schema)

{ "properties": { "collection_name": { "title": "Collection Name", "type": "string" }, "document_id": { "title": "Document Id", "type": "string" } }, "required": [ "collection_name", "document_id" ], "title": "delete_documentArguments", "type": "object" }

Implementation Reference

  • main.py:704-736 (handler)
    The handler function for the 'delete_document' tool, decorated with @mcp.tool() which also serves as registration. It deletes a document by ID from a Typesense collection using the client, with error handling for not found cases and other exceptions.
    @mcp.tool() async def delete_document(ctx: Context, collection_name: str, document_id: str) -> dict | str: """ Deletes a single document by its ID from a specific collection. Args: ctx (Context): The MCP context. collection_name (str): The name of the collection. document_id (str): The ID of the document to delete. Returns: dict | str: The deleted document dictionary or an error message string. """ if not collection_name: return "Error: collection_name parameter is required." if not document_id: return "Error: document_id parameter is required." try: client: typesense.Client = ctx.request_context.lifespan_context.client # NOTE: Assuming document delete is synchronous based on collection delete pattern. deleted_doc = client.collections[collection_name].documents[document_id].delete() return deleted_doc except typesense.exceptions.ObjectNotFound: # Could be collection or document not found return f"Error: Collection '{collection_name}' or Document ID '{document_id}' not found." except typesense.exceptions.TypesenseClientError as e: print(f"Error deleting document '{document_id}' from '{collection_name}': {e}") return f"Error deleting document '{document_id}' from '{collection_name}': {e}" except Exception as e: print(f"An unexpected error occurred while deleting document '{document_id}' from '{collection_name}': {e}") return f"An unexpected error occurred: {e}"

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/avarant/typesense-mcp-server'

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