get_mapping
Retrieve index mappings from an OpenSearch cluster using this tool. Specify the index to fetch detailed schema and field definitions for efficient data management and query optimization.
Instructions
Get index mapping
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes |
Implementation Reference
- The get_mapping tool handler, decorated with @mcp.tool for registration. Fetches the index mapping from OpenSearch and returns it as TextContent.@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)Calls register_tools on the IndexTools instance to register the get_mapping tool (and other index tools) with the MCP server.index_tools.register_tools(self.mcp)
- Defines the tool schema: input 'index' as string, output list[TextContent], with description and Args docstring.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 """
- src/opensearch_mcp_server/server.py:28-28 (registration)Instantiates the IndexTools class which contains the get_mapping tool implementation.index_tools = IndexTools(self.logger)