Skip to main content
Glama
itshare4u

Agent Knowledge MCP

update_index_metadata

Modify metadata documentation for Elasticsearch indices to maintain accurate records of data purpose, structure, and policies.

Instructions

Update existing metadata documentation for an Elasticsearch index

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
index_nameYesName of the index to update metadata for
descriptionNoUpdated description of the index purpose and content
purposeNoUpdated primary purpose and use case
data_typesNoUpdated types of data stored in this index
usage_patternNoUpdated access pattern
retention_policyNoUpdated data retention policy
related_indicesNoUpdated related or dependent indices
tagsNoUpdated tags for categorization
updated_byNoPerson or team making this updateUnknown

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Registers the 'update_index_metadata' tool with FastMCP app using @app.tool decorator, providing description and tags.
    @app.tool(
        description="Update existing metadata documentation for an Elasticsearch index",
        tags={"elasticsearch", "metadata", "update", "documentation"}
    )
  • Defines the input schema using Annotated parameters with pydantic Field descriptions for validation and documentation.
    async def update_index_metadata(
            index_name: Annotated[str, Field(description="Name of the index to update metadata for")],
            description: Annotated[
                Optional[str], Field(description="Updated description of the index purpose and content")] = None,
            purpose: Annotated[Optional[str], Field(description="Updated primary purpose and use case")] = None,
            data_types: Annotated[
                Optional[List[str]], Field(description="Updated types of data stored in this index")] = None,
            usage_pattern: Annotated[Optional[str], Field(description="Updated access pattern")] = None,
            retention_policy: Annotated[Optional[str], Field(description="Updated data retention policy")] = None,
            related_indices: Annotated[
                Optional[List[str]], Field(description="Updated related or dependent indices")] = None,
            tags: Annotated[Optional[List[str]], Field(description="Updated tags for categorization")] = None,
            updated_by: Annotated[str, Field(description="Person or team making this update")] = "Unknown"
    ) -> str:
  • Executes the tool logic: retrieves ES client, searches for existing metadata, applies partial updates to specified fields, fetches updated data, generates change summary, and returns formatted response. Includes detailed error handling for connection issues and missing indices.
    """Update existing 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"🚨 **Missing Metadata**: Cannot update non-existent documentation\n" +
                    f"   πŸ’‘ **Solution**: Use 'create_index_metadata' to create documentation first\n" +
                    f"   πŸ“‹ **Required**: Provide description, purpose, and data types\n" +
                    f"   βœ… **Then**: Use this update tool for future modifications\n\n" +
                    f"πŸ” **Alternative**: Use 'list_indices' to see all documented indices")
    
        # Get existing document
        existing_doc = existing_result['hits']['hits'][0]
        existing_id = existing_doc['_id']
        existing_data = existing_doc['_source']
    
        # Prepare update data - only update provided fields
        update_data = {
            "last_updated": datetime.now().isoformat(),
            "updated_by": updated_by
        }
    
        if description is not None:
            update_data["description"] = description
        if purpose is not None:
            update_data["purpose"] = purpose
        if data_types is not None:
            update_data["data_types"] = data_types
        if usage_pattern is not None:
            update_data["usage_pattern"] = usage_pattern
        if retention_policy is not None:
            update_data["retention_policy"] = retention_policy
        if related_indices is not None:
            update_data["related_indices"] = related_indices
        if tags is not None:
            update_data["tags"] = tags
    
        # Update the document
        result = es.update(index=metadata_index, id=existing_id, body={"doc": update_data})
    
        # Get updated document to show changes
        updated_result = es.get(index=metadata_index, id=existing_id)
        updated_data = updated_result['_source']
    
        # Build change summary
        changes_made = []
        if description is not None:
            changes_made.append(f"   πŸ“ Description: {existing_data.get('description', 'None')} β†’ {description}")
        if purpose is not None:
            changes_made.append(f"   🎯 Purpose: {existing_data.get('purpose', 'None')} β†’ {purpose}")
        if data_types is not None:
            old_types = ', '.join(existing_data.get('data_types', []))
            new_types = ', '.join(data_types)
            changes_made.append(f"   πŸ“‚ Data Types: {old_types or 'None'} β†’ {new_types}")
        if usage_pattern is not None:
            changes_made.append(f"   πŸ”„ Usage Pattern: {existing_data.get('usage_pattern', 'None')} β†’ {usage_pattern}")
        if retention_policy is not None:
            changes_made.append(f"   πŸ“… Retention: {existing_data.get('retention_policy', 'None')} β†’ {retention_policy}")
        if related_indices is not None:
            old_related = ', '.join(existing_data.get('related_indices', []))
            new_related = ', '.join(related_indices)
            changes_made.append(f"   πŸ”— Related: {old_related or 'None'} β†’ {new_related}")
        if tags is not None:
            old_tags = ', '.join(existing_data.get('tags', []))
            new_tags = ', '.join(tags)
            changes_made.append(f"   🏷️ Tags: {old_tags or 'None'} β†’ {new_tags}")
    
        return (f"βœ… Index metadata updated successfully!\n\n" +
                f"πŸ“‹ **Updated Metadata for '{index_name}'**:\n" +
                (f"πŸ”„ **Changes Made**:\n" + '\n'.join(changes_made) + "\n\n" if changes_made else "") +
                f"πŸ“Š **Current Metadata**:\n" +
                f"   πŸ“ Description: {updated_data.get('description', 'No description')}\n" +
                f"   🎯 Purpose: {updated_data.get('purpose', 'No purpose')}\n" +
                f"   πŸ“‚ Data Types: {', '.join(updated_data.get('data_types', [])) if updated_data.get('data_types') else 'None'}\n" +
                f"   πŸ”„ Usage Pattern: {updated_data.get('usage_pattern', 'Unknown')}\n" +
                f"   πŸ“… Retention: {updated_data.get('retention_policy', 'Not specified')}\n" +
                f"   πŸ”— Related Indices: {', '.join(updated_data.get('related_indices', [])) if updated_data.get('related_indices') else 'None'}\n" +
                f"   🏷️ Tags: {', '.join(updated_data.get('tags', [])) if updated_data.get('tags') else 'None'}\n" +
                f"   πŸ‘€ Last Updated By: {updated_by}\n" +
                f"   πŸ“… Last Updated: {update_data['last_updated']}\n\n" +
                f"βœ… **Benefits**:\n" +
                f"   β€’ Index documentation stays current and accurate\n" +
                f"   β€’ Team has updated context for index usage\n" +
                f"   β€’ Change history is tracked with timestamps\n" +
                f"   β€’ Governance and compliance are maintained")
    
    except Exception as e:
        error_message = "❌ Failed to update 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"πŸ’‘ Try: Use 'create_index_metadata' to set up metadata system\n\n"
        else:
            error_message += f"⚠️ **Unknown Error**: {str(e)}\n\n"
    
        error_message += f"πŸ” **Technical Details**: {str(e)}"
        return error_message
Behavior2/5

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

No annotations are provided, so the description carries full burden. It states 'Update' implying a mutation, but doesn't disclose behavioral traits like required permissions, whether changes are reversible, rate limits, or what the output contains. The description adds minimal context beyond the basic action.

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, efficient sentence that front-loads the core action and resource. There is zero waste or redundancy, making it appropriately concise for the tool's complexity.

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 mutation nature, 9 parameters, and no annotations, the description is incompleteβ€”it lacks behavioral context and usage guidance. However, the presence of an output schema reduces the need to explain return values, and the schema covers parameters well, making it minimally adequate but with clear 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?

Schema description coverage is 100%, so the schema fully documents all 9 parameters. The description adds no additional meaning about parameters beyond implying metadata fields can be updated, which is already clear from the schema. Baseline 3 is appropriate when schema does the heavy lifting.

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 action ('Update') and resource ('existing metadata documentation for an Elasticsearch index'), making the purpose evident. It distinguishes from siblings like 'create_index_metadata' by specifying 'existing' metadata, but doesn't explicitly contrast with other update tools like 'update_config'.

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 prerequisites (e.g., needing an existing index), exclusions, or compare with siblings like 'create_index_metadata' for new metadata or 'update_config' for different settings.

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