Skip to main content
Glama
awesimon

Elasticsearch MCP Server

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
NameRequiredDescriptionDefault
indexYesName of the Elasticsearch index to get mappings for

Implementation Reference

  • 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) }`, }, ], }; } }
  • 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); } );

Other Tools

Related 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/awesimon/elasticsearch-mcp'

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