delete_collection
Remove a specific collection from a Typesense database using its name. This tool permanently deletes the collection schema and all associated data for efficient management of your search infrastructure.
Instructions
Deletes a specific collection.
Args:
ctx (Context): The MCP context.
collection_name (str): The name of the collection to delete.
Returns:
dict | str: The deleted collection schema dictionary or an error message string.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection_name | Yes |
Input Schema (JSON Schema)
{
"properties": {
"collection_name": {
"title": "Collection Name",
"type": "string"
}
},
"required": [
"collection_name"
],
"title": "delete_collectionArguments",
"type": "object"
}
Implementation Reference
- main.py:487-514 (handler)The core handler function for the 'delete_collection' tool, decorated with @mcp.tool() for automatic registration. It deletes the specified collection using the Typesense client and handles various errors, returning the result or an error message.@mcp.tool() async def delete_collection(ctx: Context, collection_name: str) -> dict | str: """ Deletes a specific collection. Args: ctx (Context): The MCP context. collection_name (str): The name of the collection to delete. Returns: dict | str: The deleted collection schema dictionary or an error message string. """ if not collection_name: return "Error: collection_name parameter is required." try: client: typesense.Client = ctx.request_context.lifespan_context.client # NOTE: Assuming delete is synchronous based on pattern with retrieve/export/search. deleted_info = client.collections[collection_name].delete() return deleted_info except typesense.exceptions.ObjectNotFound: return f"Error: Collection '{collection_name}' not found." except typesense.exceptions.TypesenseClientError as e: print(f"Error deleting collection '{collection_name}': {e}") return f"Error deleting collection '{collection_name}': {e}" except Exception as e: print(f"An unexpected error occurred while deleting collection '{collection_name}': {e}") return f"An unexpected error occurred: {e}"
- main.py:487-487 (registration)The @mcp.tool() decorator registers the delete_collection function as an MCP tool.@mcp.tool()