Skip to main content
Glama
cr7258

Elasticsearch MCP Server

index_document

Add or update documents in an Elasticsearch index to store and manage data for search and analysis.

Instructions

        Creates or updates a document in the index.
        
        Args:
            index: Name of the index
            document: Document data
            id: Optional document ID
        

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexYes
documentYes
idNo

Implementation Reference

  • The core handler function for the 'index_document' MCP tool. It is decorated with @mcp.tool() and delegates the indexing operation to the search client.
    @mcp.tool()
    def index_document(index: str, document: Dict, id: Optional[str] = None) -> Dict:
        """
        Creates or updates a document in the index.
        
        Args:
            index: Name of the index
            document: Document data
            id: Optional document ID
        """
        return self.search_client.index_document(index=index, id=id, document=document)
  • Supporting method in DocumentClient that performs the actual document indexing, handling differences between Elasticsearch and OpenSearch clients.
    def index_document(self, index: str, document: Dict, id: Optional[str] = None) -> Dict:
        """Creates a new document in the index."""
        # Handle parameter name differences between Elasticsearch and OpenSearch
        if self.engine_type == "elasticsearch":
            # For Elasticsearch: index(index, document, id=None, ...)
            if id is not None:
                return self.client.index(index=index, document=document, id=id)
            else:
                return self.client.index(index=index, document=document)
        else:
            # For OpenSearch: index(index, body, id=None, ...)
            if id is not None:
                return self.client.index(index=index, body=document, id=id)
            else:
                return self.client.index(index=index, body=document)
  • src/server.py:43-53 (registration)
    Registration point where DocumentTools (containing index_document) is included in the list of tool classes and registered via ToolsRegister.register_all_tools.
    # Define all tool classes to register
    tool_classes = [
        IndexTools,
        DocumentTools,
        ClusterTools,
        AliasTools,
        DataStreamTools,
        GeneralTools,
    ]        
    # Register all tools
    register.register_all_tools(tool_classes)
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool 'creates or updates,' implying mutation, but doesn't clarify permissions, idempotency, error handling, or response format. For a mutation tool with zero annotation coverage, this is insufficient, though it at least hints at the action.

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

Conciseness4/5

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

The description is appropriately sized and front-loaded, with the purpose stated first followed by parameter details. It avoids unnecessary words, though the 'Args' section could be more integrated. Overall, it's efficient but not perfectly structured.

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

Completeness2/5

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

Given the tool's complexity (mutation with 3 parameters, no annotations, no output schema, and nested objects), the description is incomplete. It lacks details on behavior, error cases, return values, and how it differs from siblings, making it inadequate for safe and effective use by an agent.

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 includes an 'Args' section listing parameters (index, document, id) with brief notes, adding meaning beyond the input schema, which has 0% description coverage. However, it doesn't explain parameter formats, constraints, or examples (e.g., what 'document data' entails), leaving gaps in understanding.

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: 'Creates or updates a document in the index.' This specifies the verb (creates/updates) and resource (document in index), making it easy to understand what the tool does. However, it doesn't explicitly differentiate from sibling tools like 'create_data_stream' or 'create_index,' which prevents a perfect score.

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 when to choose 'index_document' over 'create_data_stream' or 'create_index,' nor does it explain prerequisites or exclusions. This lack of context leaves the agent without usage direction.

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/cr7258/elasticsearch-mcp-server'

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