Skip to main content
Glama
seohyunjun

OpenSearch MCP Server

by seohyunjun

search_documents

Search documents in an OpenSearch index using custom queries to find specific information within your data.

Instructions

Search documents in an opensearch index with a custom query

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexYes
bodyYes

Implementation Reference

  • The handler function that executes the search_documents tool. It queries the OpenSearch index with the given body, defaults size to 20 if not set, formats the response including hits and aggregations, and returns a list of TextContent.
    async def search_documents(index: str, body: dict) -> list[TextContent]:
        """
        Search documents in a specified opensearch index using a custom query.
        
        Args:
            index: Name of the index to search
            body: Opensearch query DSL. If size is not specified, defaults to 20 results.
        """
        # Ensure reasonable default size limit is set
        if 'size' not in body:
            body['size'] = 20
        self.logger.info(f"Searching in index: {index} with query: {body}")
        try:
            response = self.es_client.search(index=index, body=body)
            # Extract and format relevant information
            formatted_response = {
                'total_hits': response['hits']['total']['value'],
                'max_score': response['hits']['max_score'],
                'hits': []
            }
    
            # Process each hit
            for hit in response['hits']['hits']:
                hit_data = {
                    '_id': hit['_id'],
                    '_score': hit['_score'],
                    'source': hit['_source']
                }
                formatted_response['hits'].append(hit_data)
    
            # Include aggregations if present
            if 'aggregations' in response:
                formatted_response['aggregations'] = response['aggregations']
    
            return [TextContent(type="text", text=json.dumps(formatted_response, indent=2))]
        except Exception as e:
            self.logger.error(f"Error searching documents: {e}")
            return [TextContent(type="text", text=f"Error: {str(e)}")]
  • Registers the DocumentTools instance (containing search_documents) with the MCP server by calling its register_tools method.
    document_tools.register_tools(self.mcp)
  • The @mcp.tool decorator registers the search_documents function with the MCP server, providing the tool description.
    @mcp.tool(description="Search documents in an opensearch index with a custom query")
  • Type hints (index: str, body: dict -> list[TextContent]) and docstring describing parameters serve as the tool schema for MCP.
    async def search_documents(index: str, body: dict) -> list[TextContent]:
        """
        Search documents in a specified opensearch index using a custom query.
        
        Args:
            index: Name of the index to search
            body: Opensearch query DSL. If size is not specified, defaults to 20 results.
        """
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 mentions 'custom query' but fails to describe key traits such as authentication needs, rate limits, pagination behavior, or what happens on errors (e.g., invalid index). This leaves significant gaps in understanding the tool's operation and constraints.

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 with zero wasted words, front-loading the core action and context. It is appropriately sized for the tool's complexity, making it easy to parse quickly.

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 (search with custom queries), lack of annotations, no output schema, and low schema coverage, the description is incomplete. It omits details on return values, error handling, and operational constraints, making it insufficient for an agent to use the tool effectively without additional context.

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

Parameters2/5

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

Schema description coverage is 0%, so the description must compensate for undocumented parameters. It only vaguely references 'custom query' without explaining what 'index' and 'body' parameters represent, their formats, or examples. This adds minimal value beyond the schema, failing to clarify parameter meanings adequately.

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 verb ('search') and resource ('documents'), and specifies the context ('in an opensearch index with a custom query'), making the purpose evident. However, it does not explicitly differentiate from siblings like 'list_indices' or 'get_mapping', which focus on metadata rather than document content, so it falls short of 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 lacks information on prerequisites (e.g., index existence), exclusions (e.g., when not to use it), or comparisons to sibling tools like 'list_indices' for browsing indices, leaving the agent without contextual usage cues.

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/seohyunjun/opensearch-mcp-server'

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