get_templates
Retrieve index templates from Elasticsearch, optionally filtered by name, to manage and organize data structure configurations efficiently.
Instructions
Get index templates from Elasticsearch
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| name | No | Optional template name filter |
Implementation Reference
- src/index.ts:1084-1110 (handler)The handler function for the 'get_templates' tool. It calls esService.getIndexTemplates(name), formats the templates as JSON text response, and handles errors.async ({ name }) => { try { const templates = await esService.getIndexTemplates(name); return { content: [ { type: "text", text: `Index Templates:` }, { type: "text", text: JSON.stringify(templates, null, 2) }, ], }; } catch (error) { console.error( `Failed to get templates: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } }
- src/index.ts:1081-1083 (schema)Input schema for the 'get_templates' tool, defining an optional 'name' string parameter to filter templates.{ name: z.string().optional().describe("Optional template name filter"), },
- src/index.ts:1078-1111 (registration)Registration of the 'get_templates' tool using server.tool(), specifying name, description, input schema, and handler.server.tool( "get_templates", "Get index templates from Elasticsearch", { name: z.string().optional().describe("Optional template name filter"), }, async ({ name }) => { try { const templates = await esService.getIndexTemplates(name); return { content: [ { type: "text", text: `Index Templates:` }, { type: "text", text: JSON.stringify(templates, null, 2) }, ], }; } catch (error) { console.error( `Failed to get templates: ${ error instanceof Error ? error.message : String(error) }` ); return { content: [ { type: "text", text: `Error: ${ error instanceof Error ? error.message : String(error) }`, }, ], }; } } );
- Helper method in ElasticsearchService that performs the actual Elasticsearch API call to retrieve index templates using client.indices.getIndexTemplate.async getIndexTemplates(name?: string): Promise<any> { return await this.client.indices.getIndexTemplate({ name, }); }