Skip to main content
Glama
itshare4u

Agent Knowledge MCP

create_index_metadata

Generate metadata documentation for Elasticsearch indices to ensure proper governance, data management, and clear documentation of index purpose, content, and usage patterns.

Instructions

Create metadata documentation for an Elasticsearch index to ensure proper governance and documentation

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
index_nameYesName of the index to document
descriptionYesDetailed description of the index purpose and content
purposeYesPrimary purpose and use case for this index
data_typesNoTypes of data stored in this index (e.g., 'documents', 'logs', 'metrics')
usage_patternNoHow the index is accessed (e.g., 'read-heavy', 'write-heavy', 'mixed')mixed
retention_policyNoData retention policy and lifecycle managementNo specific policy
related_indicesNoNames of related or dependent indices
tagsNoTags for categorizing and organizing indices
created_byNoTeam or person responsible for this indexUnknown

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary handler implementation for the 'create_index_metadata' tool. Uses FastMCP @app.tool decorator for registration and schema definition via Annotated parameters. Handles metadata index creation/check, existing metadata check, and new metadata document insertion into Elasticsearch.
    @app.tool(
        description="Create metadata documentation for an Elasticsearch index to ensure proper governance and documentation",
        tags={"elasticsearch", "metadata", "documentation", "governance"}
    )
    async def create_index_metadata(
            index_name: Annotated[str, Field(description="Name of the index to document")],
            description: Annotated[str, Field(description="Detailed description of the index purpose and content")],
            purpose: Annotated[str, Field(description="Primary purpose and use case for this index")],
            data_types: Annotated[List[str], Field(
                description="Types of data stored in this index (e.g., 'documents', 'logs', 'metrics')")] = [],
            usage_pattern: Annotated[
                str, Field(description="How the index is accessed (e.g., 'read-heavy', 'write-heavy', 'mixed')")] = "mixed",
            retention_policy: Annotated[
                str, Field(description="Data retention policy and lifecycle management")] = "No specific policy",
            related_indices: Annotated[List[str], Field(description="Names of related or dependent indices")] = [],
            tags: Annotated[List[str], Field(description="Tags for categorizing and organizing indices")] = [],
            created_by: Annotated[str, Field(description="Team or person responsible for this index")] = "Unknown"
    ) -> str:
        """Create comprehensive metadata documentation for an Elasticsearch index."""
        try:
            es = get_es_client()
    
            # Check if metadata index exists
            metadata_index = "index_metadata"
            try:
                es.indices.get(index=metadata_index)
            except Exception:
                # Create metadata index if it doesn't exist
                metadata_mapping = {
                    "properties": {
                        "index_name": {"type": "keyword"},
                        "description": {"type": "text"},
                        "purpose": {"type": "text"},
                        "data_types": {"type": "keyword"},
                        "created_by": {"type": "keyword"},
                        "created_date": {"type": "date"},
                        "usage_pattern": {"type": "keyword"},
                        "retention_policy": {"type": "text"},
                        "related_indices": {"type": "keyword"},
                        "tags": {"type": "keyword"},
                        "last_updated": {"type": "date"},
                        "updated_by": {"type": "keyword"}
                    }
                }
    
                try:
                    es.indices.create(index=metadata_index, body={"mappings": metadata_mapping})
                except Exception as create_error:
                    if "already exists" not in str(create_error).lower():
                        return f"❌ Failed to create metadata index: {str(create_error)}"
    
            # Check if metadata already exists for this index
            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:
                existing_doc = existing_result['hits']['hits'][0]
                existing_id = existing_doc['_id']
                existing_data = existing_doc['_source']
    
                return (f"⚠️ Index metadata already exists for '{index_name}'!\n\n" +
                        f"πŸ“‹ **Existing Metadata** (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', []))}\n" +
                        f"   πŸ‘€ Created By: {existing_data.get('created_by', 'Unknown')}\n" +
                        f"   πŸ“… Created: {existing_data.get('created_date', 'Unknown')}\n\n" +
                        f"πŸ’‘ **Options**:\n" +
                        f"   πŸ”„ **Update**: Use 'update_index_metadata' to modify existing documentation\n" +
                        f"   πŸ—‘οΈ **Replace**: Use 'delete_index_metadata' then 'create_index_metadata'\n" +
                        f"   βœ… **Keep**: Current metadata is sufficient, proceed with 'create_index'\n\n" +
                        f"🚨 **Note**: You can now create the index '{index_name}' since metadata exists")
    
            # Create new metadata document
            current_time = datetime.now().isoformat()
    
            metadata_doc = {
                "index_name": index_name,
                "description": description,
                "purpose": purpose,
                "data_types": data_types,
                "created_by": created_by,
                "created_date": current_time,
                "usage_pattern": usage_pattern,
                "retention_policy": retention_policy,
                "related_indices": related_indices,
                "tags": tags,
                "last_updated": current_time,
                "updated_by": created_by
            }
    
            # Generate a consistent document ID
            metadata_id = f"metadata_{index_name}"
    
            result = es.index(index=metadata_index, id=metadata_id, body=metadata_doc)
    
            return (f"βœ… Index metadata created successfully!\n\n" +
                    f"πŸ“‹ **Metadata Details**:\n" +
                    f"   🎯 Index: {index_name}\n" +
                    f"   πŸ“ Description: {description}\n" +
                    f"   🎯 Purpose: {purpose}\n" +
                    f"   πŸ“‚ Data Types: {', '.join(data_types) if data_types else 'None specified'}\n" +
                    f"   πŸ”„ Usage Pattern: {usage_pattern}\n" +
                    f"   πŸ“… Retention: {retention_policy}\n" +
                    f"   πŸ”— Related Indices: {', '.join(related_indices) if related_indices else 'None'}\n" +
                    f"   🏷️ Tags: {', '.join(tags) if tags else 'None'}\n" +
                    f"   πŸ‘€ Created By: {created_by}\n" +
                    f"   πŸ“… Created: {current_time}\n\n" +
                    f"βœ… **Next Steps**:\n" +
                    f"   πŸ”§ You can now use 'create_index' to create the actual index '{index_name}'\n" +
                    f"   πŸ“Š Use 'list_indices' to see this metadata in the index listing\n" +
                    f"   πŸ”„ Use 'update_index_metadata' if you need to modify this documentation\n\n" +
                    f"🎯 **Benefits Achieved**:\n" +
                    f"   β€’ Index purpose is clearly documented\n" +
                    f"   β€’ Team collaboration is improved through shared understanding\n" +
                    f"   β€’ Future maintenance is simplified with proper context\n" +
                    f"   β€’ Index governance and compliance are maintained")
    
        except Exception as e:
            error_message = "❌ Failed to create 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"
            else:
                error_message += f"⚠️ **Unknown Error**: {str(e)}\n\n"
    
            error_message += f"πŸ” **Technical Details**: {str(e)}"
            return error_message
  • TOOL_DISTRIBUTION mapping registers the sub-server containing 'create_index_metadata' tool, indicating 3 tools including this one.
    "elasticsearch_index_metadata": 3, # create_index_metadata, update_index_metadata, delete_index_metadata
  • Input schema defined using Pydantic Annotated fields with descriptions for tool parameters.
    index_name: Annotated[str, Field(description="Name of the index to document")],
    description: Annotated[str, Field(description="Detailed description of the index purpose and content")],
    purpose: Annotated[str, Field(description="Primary purpose and use case for this index")],
    data_types: Annotated[List[str], Field(
        description="Types of data stored in this index (e.g., 'documents', 'logs', 'metrics')")] = [],
    usage_pattern: Annotated[
        str, Field(description="How the index is accessed (e.g., 'read-heavy', 'write-heavy', 'mixed')")] = "mixed",
    retention_policy: Annotated[
        str, Field(description="Data retention policy and lifecycle management")] = "No specific policy",
    related_indices: Annotated[List[str], Field(description="Names of related or dependent indices")] = [],
    tags: Annotated[List[str], Field(description="Tags for categorizing and organizing indices")] = [],
    created_by: Annotated[str, Field(description="Team or person responsible for this index")] = "Unknown"
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It states the tool creates metadata documentation but doesn't describe what happens during executionβ€”whether it overwrites existing metadata, requires specific permissions, returns confirmation or error details, or has side effects like indexing changes. This leaves significant gaps for a creation tool.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, well-structured sentence that efficiently conveys the core purpose without unnecessary words. It's front-loaded with the main action and context, making it easy to parse and understand quickly.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's complexity (9 parameters, creation operation) and the presence of an output schema, the description is minimally adequate. It states what the tool does but lacks behavioral details, usage context, and output expectations. With no annotations and a creation operation, more completeness would be beneficial, but the output schema mitigates some gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds no parameter-specific information beyond what the input schema provides. Since schema description coverage is 100%, the baseline score is 3. The description doesn't explain parameter relationships, dependencies, or usage examples, so it doesn't compensate for any gaps but doesn't need to given the comprehensive schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Create metadata documentation for an Elasticsearch index to ensure proper governance and documentation.' It specifies the verb ('create'), resource ('metadata documentation'), and context ('Elasticsearch index'), but doesn't explicitly differentiate from sibling tools like 'update_index_metadata' or 'delete_index_metadata'.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention sibling tools like 'update_index_metadata' for modifying existing metadata or 'delete_index_metadata' for removal, nor does it specify prerequisites or appropriate contexts for creation versus other operations.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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

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