create-index
Create a new Meilisearch index by specifying a unique identifier and optional primary key to organize searchable data.
Instructions
Create a new Meilisearch index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indexUid | Yes | Unique identifier for the new index | |
| primaryKey | No | Primary key for the index |
Input Schema (JSON Schema)
{
"$schema": "http://json-schema.org/draft-07/schema#",
"additionalProperties": false,
"properties": {
"indexUid": {
"description": "Unique identifier for the new index",
"type": "string"
},
"primaryKey": {
"description": "Primary key for the index",
"type": "string"
}
},
"required": [
"indexUid"
],
"type": "object"
}
Implementation Reference
- src/tools/index-tools.ts:99-111 (handler)The handler function for the 'create-index' tool. It sends a POST request to the Meilisearch /indexes endpoint with the index uid and optional primaryKey, then returns the JSON response or an error response.async ({ indexUid, primaryKey }: CreateIndexParams) => { try { const response = await apiClient.post('/indexes', { uid: indexUid, primaryKey, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } }
- src/tools/index-tools.ts:95-98 (schema)Zod input schema for the 'create-index' tool defining parameters indexUid (required string) and primaryKey (optional string).{ indexUid: z.string().describe('Unique identifier for the new index'), primaryKey: z.string().optional().describe('Primary key for the index'), },
- src/tools/index-tools.ts:92-112 (registration)Direct registration of the 'create-index' tool using server.tool() within the registerIndexTools function.server.tool( 'create-index', 'Create a new Meilisearch index', { indexUid: z.string().describe('Unique identifier for the new index'), primaryKey: z.string().optional().describe('Primary key for the index'), }, async ({ indexUid, primaryKey }: CreateIndexParams) => { try { const response = await apiClient.post('/indexes', { uid: indexUid, primaryKey, }); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } );
- src/tools/index-tools.ts:23-26 (schema)TypeScript interface defining the parameters for the create-index tool, used for type safety in the handler.interface CreateIndexParams { indexUid: string; primaryKey?: string; }
- src/index.ts:64-64 (registration)Invocation of registerIndexTools on the main MCP server instance, which registers the create-index tool among others.registerIndexTools(server);