get_mappings
Retrieve field mappings for a specified Elasticsearch index to understand its structure and data organization within the Elasticsearch MCP Server environment.
Instructions
Get field mappings for a specific Elasticsearch index
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| index | Yes | Name of the Elasticsearch index to get mappings for |
Implementation Reference
- src/tools/getMappings.ts:3-42 (handler)The main handler function that retrieves the mappings for the specified Elasticsearch index and formats the response as MCP content blocks, handling errors gracefully.export async function getMappings(esClient: Client, index: string) { try { const mappingResponse = await esClient.indices.getMapping({ index, }); return { content: [ { type: "text" as const, text: `Index mapping: ${index}`, }, { type: "text" as const, text: `Index ${index} mapping: ${JSON.stringify( mappingResponse[index]?.mappings || {}, null, 2 )}`, }, ], }; } catch (error) { console.error( `Failed to get mapping: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text" as const, text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/server.ts:60-64 (schema)Input schema using Zod for validating the 'index' parameter required by the get_mappings tool.index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to get mappings for"),
- src/server.ts:56-69 (registration)MCP server tool registration for 'get_mappings', including name, description, input schema, and execution handler.server.tool( "get_mappings", "Get field mappings for a specific Elasticsearch index", { index: z .string() .trim() .min(1, "Index name is required") .describe("Name of the Elasticsearch index to get mappings for"), }, async ({ index }) => { return await getMappings(esClient, index); } );