Skip to main content
Glama
awesimon

Elasticsearch MCP Server

create_index_template

Create or update an Elasticsearch index template to automatically apply settings, mappings, and aliases to new indices matching specified patterns.

Instructions

Create or update an Elasticsearch index template

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
nameYesName of the index template
indexPatternsYesArray of index patterns this template applies to
templateYesTemplate configuration including settings, mappings, and aliases
priorityNoOptional template priority - higher values have higher precedence
versionNoOptional template version number

Implementation Reference

  • The main handler function for createIndexTemplate tool. Takes esClient, name, indexPatterns, template, priority, version and calls esClient.indices.putIndexTemplate. Returns success/error response content.
    export async function createIndexTemplate(
      esClient: Client,
      name: string,
      indexPatterns: string[],
      template: Record<string, any>,
      priority?: number,
      version?: number
    ) {
      try {
        const body: Record<string, any> = {
          index_patterns: indexPatterns,
          template: {
            settings: template.settings || {},
            mappings: template.mappings || {},
            aliases: template.aliases || {}
          }
        };
    
        // Add optional parameters if provided
        if (priority !== undefined) {
          body.priority = priority;
        }
    
        if (version !== undefined) {
          body.version = version;
        }
    
        const response = await esClient.indices.putIndexTemplate({
          name,
          body
        });
    
        return {
          content: [
            {
              type: "text" as const,
              text: `Index template "${name}" created successfully.`
            },
            {
              type: "text" as const,
              text: `Index patterns: ${indexPatterns.join(", ")}`
            },
            {
              type: "text" as const,
              text: response.acknowledged 
                ? "Template was acknowledged by the cluster."
                : "Template was not acknowledged. Check cluster status."
            }
          ]
        };
      } catch (error) {
        console.error(`Create index template failed: ${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:226-259 (registration)
    Registration of the create_index_template tool on the MCP server using server.tool(). Defines the schema (name, indexPatterns, template, priority, version) using Zod validations and calls the handler.
    // Create or update an index template
    server.tool(
      "create_index_template",
      "Create or update an Elasticsearch index template",
      {
        name: z
          .string()
          .trim()
          .min(1, "Template name is required")
          .describe("Name of the index template"),
        
        indexPatterns: z
          .array(z.string())
          .min(1, "At least one index pattern is required")
          .describe("Array of index patterns this template applies to"),
        
        template: z
          .record(z.any())
          .describe("Template configuration including settings, mappings, and aliases"),
        
        priority: z
          .number()
          .optional()
          .describe("Optional template priority - higher values have higher precedence"),
        
        version: z
          .number()
          .optional()
          .describe("Optional template version number")
      },
      async ({ name, indexPatterns, template, priority, version }) => {
        return await createIndexTemplate(esClient, name, indexPatterns, template, priority, version);
      }
    );
  • Import and re-export of the createIndexTemplate function from the tools module.
    import { createIndexTemplate, getIndexTemplate, deleteIndexTemplate } from "./tools/createIndexTemplate.js";
    
    export { 
      listIndices, 
      getMappings, 
      search, 
      getClusterHealth, 
      createIndex, 
      createMapping, 
      bulk, 
      reindex, 
      createIndexTemplate,
      getIndexTemplate,
      deleteIndexTemplate
    }; 
  • Zod input validation schema for create_index_template: name (string), indexPatterns (string array), template (record), priority (optional number), version (optional number).
    {
      name: z
        .string()
        .trim()
        .min(1, "Template name is required")
        .describe("Name of the index template"),
      
      indexPatterns: z
        .array(z.string())
        .min(1, "At least one index pattern is required")
        .describe("Array of index patterns this template applies to"),
      
      template: z
        .record(z.any())
        .describe("Template configuration including settings, mappings, and aliases"),
      
      priority: z
        .number()
        .optional()
        .describe("Optional template priority - higher values have higher precedence"),
      
      version: z
        .number()
        .optional()
        .describe("Optional template version number")
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations provided. The description does not disclose whether the operation is idempotent, destructive, or has side effects on existing indices. Auth or rate limit information is absent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Single sentence is concise and front-loaded, but could include more useful details without becoming verbose. No wasted words.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

No output schema, no annotations. The description lacks information about return values or what 'update' entails. Given the complexity of index templates, the description is insufficient for an agent to understand full behavior.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Input schema has 100% description coverage, so the schema already documents parameters. The description adds no extra meaning beyond the schema, providing only a brief restatement.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb (create or update) and resource (Elasticsearch index template). It distinguishes from sibling tools like create_index (creates an index) and delete_index_template (deletes a template).

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance on when to use create vs update, or when this tool is appropriate over alternatives. The description does not specify prerequisites or context for use.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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

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