Skip to main content
Glama
itshare4u

Agent Knowledge MCP

delete_index_metadata

Remove metadata documentation for Elasticsearch indexes to manage and organize search data effectively.

Instructions

Delete metadata documentation for an Elasticsearch index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
index_nameYesName of the index to remove metadata for

Implementation Reference

  • The main handler function for the 'delete_index_metadata' tool. It uses @app.tool decorator for registration in FastMCP, includes input schema via Annotated Field, searches for existing metadata in 'index_metadata' index, deletes the document if found, and provides detailed success/error messages.
    @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

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/itshare4u/AgentKnowledgeMCP'

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