Skip to main content
Glama
awesimon

Elasticsearch MCP Server

get_mappings

Retrieve field mappings for an Elasticsearch index to understand data structure and field types for querying and analysis.

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 handler function that fetches Elasticsearch index mappings using the Elasticsearch client and returns formatted text content with the mappings or error message.
    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:56-69 (registration)
    The registration of the 'get_mappings' tool on the MCP server, including description, input schema, and handler invocation.
    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);
      }
    );
  • Zod schema for the input parameter 'index' of the 'get_mappings' tool.
      index: z
        .string()
        .trim()
        .min(1, "Index name is required")
        .describe("Name of the Elasticsearch index to get mappings for"),
    },

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