swap-indexes
Swap indexes in Meilisearch to reorganize data efficiently. Input a JSON array of index pairs to switch their positions, enabling flexible index management.
Instructions
Swap two or more indexes in Meilisearch
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| indexes | Yes | JSON array of index pairs to swap, e.g. [["movies", "movies_new"]] |
Implementation Reference
- src/tools/index-tools.ts:156-183 (registration)Full registration of the 'swap-indexes' MCP tool, including name, description, Zod input schema for 'indexes' parameter (JSON string of array of pairs), and the complete inline handler function that parses, validates, calls API, and responds.server.tool( 'swap-indexes', 'Swap two or more indexes in Meilisearch', { indexes: z.string().describe('JSON array of index pairs to swap, e.g. [["movies", "movies_new"]]'), }, async ({ indexes }: SwapIndexesParams) => { try { // Parse the indexes string to ensure it's valid JSON const parsedIndexes = JSON.parse(indexes); // Ensure indexes is an array of arrays if (!Array.isArray(parsedIndexes) || !parsedIndexes.every(pair => Array.isArray(pair) && pair.length === 2)) { return { isError: true, content: [{ type: 'text', text: 'Indexes must be a JSON array of pairs, e.g. [["movies", "movies_new"]]' }], }; } const response = await apiClient.post('/swap-indexes', parsedIndexes); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } } );
- src/tools/index-tools.ts:162-182 (handler)Executes the core logic of the swap-indexes tool: parses input JSON string into array of index pairs, validates structure, performs HTTP POST to '/swap-indexes' endpoint via apiClient, formats and returns JSON response or error.async ({ indexes }: SwapIndexesParams) => { try { // Parse the indexes string to ensure it's valid JSON const parsedIndexes = JSON.parse(indexes); // Ensure indexes is an array of arrays if (!Array.isArray(parsedIndexes) || !parsedIndexes.every(pair => Array.isArray(pair) && pair.length === 2)) { return { isError: true, content: [{ type: 'text', text: 'Indexes must be a JSON array of pairs, e.g. [["movies", "movies_new"]]' }], }; } const response = await apiClient.post('/swap-indexes', parsedIndexes); return { content: [{ type: 'text', text: JSON.stringify(response.data, null, 2) }], }; } catch (error) { return createErrorResponse(error); } }
- src/tools/index-tools.ts:37-39 (schema)TypeScript type definition for the input parameters of the swap-indexes tool, used for typing the handler function.interface SwapIndexesParams { indexes: string; }
- src/tools/index-tools.ts:159-160 (schema)Zod runtime validation schema for the tool's input parameter 'indexes': expects a string representing a JSON array of index name pairs to swap.{ indexes: z.string().describe('JSON array of index pairs to swap, e.g. [["movies", "movies_new"]]'),