Skip to main content
Glama
seohyunjun

OpenSearch MCP Server

by seohyunjun

get_mapping

Retrieve index mapping details from OpenSearch to understand data structure and field definitions for effective querying and analysis.

Instructions

Get index mapping

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexYes

Implementation Reference

  • The handler function that implements the 'get_mapping' tool logic. It retrieves the mapping for the specified index using the OpenSearch client's indices.get_mapping method and returns it as a list of TextContent.
    async def get_mapping(index: str) -> list[TextContent]: """ Get the mapping for an index. It is important to always check the mappings to understand the exact field names and types before constructing queries or URLs. Args: index: Name of the index """ self.logger.info(f"Getting mapping for index: {index}") try: response = self.es_client.indices.get_mapping(index=index) return [TextContent(type="text", text=str(response))] except Exception as e: self.logger.error(f"Error getting mapping: {e}") return [TextContent(type="text", text=f"Error: {str(e)}")]
  • The tool is registered within the IndexTools.register_tools method using the @mcp.tool decorator, providing the description and implicitly defining the schema from the function signature.
    @mcp.tool(description="Get index mapping") async def get_mapping(index: str) -> list[TextContent]: """ Get the mapping for an index. It is important to always check the mappings to understand the exact field names and types before constructing queries or URLs. Args: index: Name of the index """ self.logger.info(f"Getting mapping for index: {index}") try: response = self.es_client.indices.get_mapping(index=index) return [TextContent(type="text", text=str(response))] except Exception as e: self.logger.error(f"Error getting mapping: {e}") return [TextContent(type="text", text=f"Error: {str(e)}")]
  • In the OpensearchMCPServer, an IndexTools instance is created and its register_tools method is called to register all tools from that module, including 'get_mapping', to the MCP server.
    index_tools.register_tools(self.mcp)

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