swap-indexes
Swap two or more indexes in Meilisearch to reorganize search data without downtime or data loss.
Instructions
Swap two or more indexes in Meilisearch
Tool call template
Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.
{
"id": 1,
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"arguments": {
"indexes": "<indexes>"
},
"name": "swap-indexes"
}
}Input 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:162-182 (handler)The handler function that implements the core logic of the 'swap-indexes' tool: parses the JSON string input, validates it as an array of index pairs, calls the API, and returns the 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)Type definition for the input parameters of the swap-indexes tool.
interface SwapIndexesParams { indexes: string; } - src/tools/index-tools.ts:156-183 (registration)Registration of the 'swap-indexes' MCP tool using server.tool(), defining name, description, input schema with Zod, and inline handler.
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/index.ts:64-64 (registration)Top-level registration call to registerIndexTools on the main MCP server instance, which includes the swap-indexes tool.
registerIndexTools(server); - src/tools/index-tools.ts:159-161 (schema)Zod schema object for validating the input parameters of the swap-indexes tool.
{ indexes: z.string().describe('JSON array of index pairs to swap, e.g. [["movies", "movies_new"]]'), },