Skip to main content
Glama
awesimon

Elasticsearch MCP Server

create_index

Create an Elasticsearch index with optional settings and mappings to define field types and index behavior.

Instructions

Create an Elasticsearch index, optionally configure settings and mappings

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
indexYesName of the Elasticsearch index to create
settingsNoIndex settings, such as number of shards and replicas
mappingsNoIndex mappings, defining field types, etc.

Implementation Reference

  • The handler function that executes the create_index tool's logic. It takes esClient, index, optional settings and mappings, calls esClient.indices.create() to create the Elasticsearch index, and returns a response with success/error text.
    export async function createIndex(
      esClient: Client,
      index: string,
      settings?: Record<string, any>,
      mappings?: Record<string, any>
    ) {
      try {
        const body: Record<string, any> = {};
        
        if (settings) {
          body.settings = settings;
        }
        
        if (mappings) {
          body.mappings = mappings;
        }
    
        const response = await esClient.indices.create({
          index,
          ...body
        });
    
        const content: { type: "text"; text: string }[] = [];
        
        if (response.acknowledged) {
          content.push({
            type: "text" as const,
            text: `索引 "${index}" 创建成功!\n分片数: ${response.shards_acknowledged ? '已确认' : '等待确认'}`
          });
        } else {
          content.push({
            type: "text" as const,
            text: `索引 "${index}" 创建请求已发送,但未得到确认。请检查集群状态。`
          });
        }
    
        return {
          content
        };
      } catch (error) {
        console.error(`创建索引失败: ${error instanceof Error ? error.message : String(error)}`);
        return {
          content: [
            {
              type: "text" as const,
              text: `错误: ${error instanceof Error ? error.message : String(error)}`
            }
          ]
        };
      }
    } 
  • src/server.ts:122-146 (registration)
    Registration of the 'create_index' tool on the MCP server via server.tool(), defining the schema with Zod for index (required string), settings (optional Record), and mappings (optional Record), and delegating to the createIndex handler.
    // Create an Elasticsearch index, optionally configure settings and mappings
    server.tool(
      "create_index",
      "Create an Elasticsearch index, optionally configure settings and mappings",
      {
        index: z
          .string()
          .trim()
          .min(1, "Index name is required")
          .describe("Name of the Elasticsearch index to create"),
        
        settings: z
          .record(z.any())
          .optional()
          .describe("Index settings, such as number of shards and replicas"),
        
        mappings: z
          .record(z.any())
          .optional()
          .describe("Index mappings, defining field types, etc.")
      },
      async ({ index, settings, mappings }) => {
        return await createIndex(esClient, index, settings, mappings);
      }
    );
  • Input parameter schemas for create_index: 'index' (required string, trimmed, min 1), 'settings' (optional Record<string, any>), 'mappings' (optional Record<string, any>).
    {
      index: z
        .string()
        .trim()
        .min(1, "Index name is required")
        .describe("Name of the Elasticsearch index to create"),
      
      settings: z
        .record(z.any())
        .optional()
        .describe("Index settings, such as number of shards and replicas"),
      
      mappings: z
        .record(z.any())
        .optional()
        .describe("Index mappings, defining field types, etc.")
    },
  • Import of the createIndex function from the tools/createIndex module.
    import { createIndex } from "./tools/createIndex.js";
Behavior2/5

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

With no annotations, the description must disclose behavior but only states the action. It does not explain what happens if the index already exists (e.g., error or overwrite), side effects, or authentication/rate limits. The optional settings and mappings are mentioned but no behavioral details.

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?

The description is a single concise sentence that front-loads the main action. It avoids unnecessary words, though slight expansion would improve clarity without losing conciseness.

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?

Despite moderate complexity (3 params, nested objects, no output schema), the description lacks crucial context such as error handling (e.g., index already exists), success response, and typical use cases. An agent would need additional information to use this tool correctly.

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?

Schema description coverage is 100%, with each parameter's purpose described in the schema. The description adds no extra meaning beyond the schema, so the baseline of 3 applies.

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 'Create an Elasticsearch index, optionally configure settings and mappings' uses a specific verb and resource, clearly distinguishing it from siblings like create_index_template or create_mapping. It is unambiguous and directly states the action.

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 is provided on when to use this tool versus alternatives (e.g., create_index_template for templates). There is no mention of prerequisites, such as Elasticsearch cluster availability or required permissions, nor any context for when to use settings vs. mappings.

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