delete_index_metadata
Remove metadata for a specific Elasticsearch index in Agent Knowledge MCP, ensuring clean and accurate index documentation management.
Instructions
Delete metadata documentation for an Elasticsearch index
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index_name | Yes | Name of the index to remove metadata for |
Implementation Reference
- Full implementation of the 'delete_index_metadata' tool handler, including @app.tool decorator for registration, input schema via Pydantic Annotated Field, and the complete async function logic that searches for and deletes index metadata from the 'index_metadata' Elasticsearch index.@app.tool( description="Delete metadata documentation for an Elasticsearch index", tags={"elasticsearch", "metadata", "delete", "cleanup"} ) async def delete_index_metadata( index_name: Annotated[str, Field(description="Name of the index to remove metadata for")] ) -> str: """Delete metadata documentation for an Elasticsearch index.""" try: es = get_es_client() metadata_index = "index_metadata" # Search for existing metadata search_body = { "query": { "term": { "index_name.keyword": index_name } }, "size": 1 } existing_result = es.search(index=metadata_index, body=search_body) if existing_result['hits']['total']['value'] == 0: return (f"β οΈ No metadata found for index '{index_name}'!\n\n" + f"π **Status**: Index metadata does not exist\n" + f" β **Good**: No cleanup required for metadata\n" + f" π§ **Safe**: You can proceed with 'delete_index' if needed\n" + f" π **Check**: Use 'list_indices' to see all documented indices\n\n" + f"π‘ **This is Normal If**:\n" + f" β’ Index was created before metadata system was implemented\n" + f" β’ Index was created without using 'create_index_metadata' first\n" + f" β’ Metadata was already deleted in a previous cleanup") # Get existing document details before deletion existing_doc = existing_result['hits']['hits'][0] existing_id = existing_doc['_id'] existing_data = existing_doc['_source'] # Delete the metadata document result = es.delete(index=metadata_index, id=existing_id) return (f"β Index metadata deleted successfully!\n\n" + f"ποΈ **Deleted Metadata for '{index_name}'**:\n" + f" π Document ID: {existing_id}\n" + f" π Description: {existing_data.get('description', 'No description')}\n" + f" π― Purpose: {existing_data.get('purpose', 'No purpose')}\n" + f" π Data Types: {', '.join(existing_data.get('data_types', [])) if existing_data.get('data_types') else 'None'}\n" + f" π€ Created By: {existing_data.get('created_by', 'Unknown')}\n" + f" π Created: {existing_data.get('created_date', 'Unknown')}\n\n" + f"β **Cleanup Complete**:\n" + f" ποΈ Metadata documentation removed from registry\n" + f" π§ You can now safely use 'delete_index' to remove the actual index\n" + f" π Use 'list_indices' to verify metadata removal\n\n" + f"π― **Next Steps**:\n" + f" 1. Proceed with 'delete_index {index_name}' to remove the actual index\n" + f" 2. Or use 'create_index_metadata' if you want to re-document this index\n" + f" 3. Clean up any related indices mentioned in metadata\n\n" + f"β οΈ **Important**: This only deleted the documentation, not the actual index") except Exception as e: error_message = "β Failed to delete index metadata:\n\n" error_str = str(e).lower() if "connection" in error_str or "refused" in error_str: error_message += "π **Connection Error**: Cannot connect to Elasticsearch server\n" error_message += f"π Check if Elasticsearch is running at the configured address\n" error_message += f"π‘ Try: Use 'setup_elasticsearch' tool to start Elasticsearch\n\n" elif ("not_found" in error_str or "not found" in error_str) and "index" in error_str: error_message += f"π **Index Error**: Metadata index 'index_metadata' does not exist\n" error_message += f"π The metadata system has not been initialized\n" error_message += f"π‘ This means no metadata exists to delete - you can proceed safely\n\n" else: error_message += f"β οΈ **Unknown Error**: {str(e)}\n\n" error_message += f"π **Technical Details**: {str(e)}" return error_message