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
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes |
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)}")]
- src/opensearch_mcp_server/tools/index.py:25-41 (registration)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)}")]
- src/opensearch_mcp_server/server.py:36-36 (registration)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)