Skip to main content
Glama
rishab2404

Elasticsearch MCP Server

by rishab2404

get_mappings

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

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 for the get_mappings tool. It fetches the mappings for the specified Elasticsearch index using esClient.indices.getMapping and returns a formatted text response with the mappings or an error message.
    async ({ index }) => {
      console.error("[DEBUG] get_mappings tool called", index);
      try {
        const mappingResponse = await esClient.indices.getMapping({
          index,
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Mappings for index: ${index}`,
            },
            {
              type: "text" as const,
              text: `Mappings for index ${index}: ${JSON.stringify(
                mappingResponse[index]?.mappings || {},
                null,
                2
              )}`,
            },
          ],
        };
      } catch (error) {
        console.error(
          `Failed to get mappings: ${
            error instanceof Error ? error.message : String(error)
          }`
        );
        return {
          content: [
            {
              type: "text" as const,
              text: `Error: ${
                error instanceof Error ? error.message : String(error)
              }`,
            },
          ],
        };
      }
    }
  • Input schema for the get_mappings tool, which validates that the 'index' parameter is a non-empty trimmed string.
    {
      index: z
        .string()
        .trim()
        .min(1, "Index name is required")
        .describe("Name of the Elasticsearch index to get mappings for"),
    },
  • index.ts:178-228 (registration)
    Registration of the get_mappings tool using server.tool(), including name, description, input schema, and handler function.
      "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 }) => {
        console.error("[DEBUG] get_mappings tool called", index);
        try {
          const mappingResponse = await esClient.indices.getMapping({
            index,
          });
    
          return {
            content: [
              {
                type: "text" as const,
                text: `Mappings for index: ${index}`,
              },
              {
                type: "text" as const,
                text: `Mappings for index ${index}: ${JSON.stringify(
                  mappingResponse[index]?.mappings || {},
                  null,
                  2
                )}`,
              },
            ],
          };
        } catch (error) {
          console.error(
            `Failed to get mappings: ${
              error instanceof Error ? error.message : String(error)
            }`
          );
          return {
            content: [
              {
                type: "text" as const,
                text: `Error: ${
                  error instanceof Error ? error.message : String(error)
                }`,
              },
            ],
          };
        }
      }
    );
Install Server

Other 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/rishab2404/mcp_es'

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