drop_index
Remove specified fields from a collection's query index to manage database indexing and optimize query performance.
Instructions
Remove field(s) from a query index
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| collection | Yes | Collection name | |
| index | Yes | Field(s) to remove from query index |
Implementation Reference
- src/index.ts:103-106 (schema)Zod schema for drop_index input validation: requires 'collection' (string) and 'index' (string) fields.
const dropIndexSchema = z.object({ collection: z.string().describe("Collection name"), index: z.string().describe("Field(s) to remove from query index"), }); - src/index.ts:315-327 (registration)Tool registration for 'drop_index' in the tools array with name, description, and inputSchema.
{ name: "drop_index", description: "Remove field(s) from a query index", schema: dropIndexSchema, inputSchema: { type: "object", properties: { collection: { type: "string", description: "Collection name" }, index: { type: "string", description: "Field(s) to remove from query index" } }, required: ["collection", "index"] } }, - src/index.ts:958-977 (handler)Handler for drop_index tool. Extracts collection and index args, then executes 'coho removeindex --project ... --space ... <collection> <index>' CLI command.
case "drop_index": { const { collection, index } = args as DropIndexArgs; const dropIndexArgs = [ 'removeindex', '--project', config.projectId, '--space', config.space, collection, index ]; const result = await executeCohoCommand(dropIndexArgs); return { content: [ { type: "text", text: result } ], isError: false }; } - src/index.ts:529-564 (helper)Helper function executeCohoCommand that runs the coho CLI with sanitized admin token. Used by the drop_index handler to execute the removeindex command.
async function executeCohoCommand(args: string[]): Promise<string> { const safeArgs = ['coho', ...args, '--admintoken', '***']; console.error(`Executing command: ${safeArgs.join(' ')}`); try { const { stdout, stderr } = await execFile('coho', [...args, '--admintoken', config.adminToken], { timeout: 120000 // 2 minutes timeout for CLI operations }); if (stderr) { // Sanitize stderr before logging to avoid token exposure const safeSterr = stderr.replace(new RegExp(config.adminToken, 'g'), '***'); console.error(`Command output to stderr:`, safeSterr); } console.error(`Command successful`); const result = stdout || stderr; // Sanitize result to ensure admin token is not exposed return result ? result.replace(new RegExp(config.adminToken, 'g'), '***') : result; } catch (error: any) { // Comprehensive sanitization of all error properties to avoid admin token exposure const sanitizeText = (text: string): string => text ? text.replace(new RegExp(config.adminToken, 'g'), '***') : text; const sanitizedMessage = sanitizeText(error?.message || 'Unknown error'); const sanitizedCmd = sanitizeText(error?.cmd || ''); const sanitizedStdout = sanitizeText(error?.stdout || ''); const sanitizedStderr = sanitizeText(error?.stderr || ''); // Log sanitized error details console.error(`Command failed: ${sanitizedMessage}`); if (sanitizedCmd) console.error(`Command: ${sanitizedCmd}`); if (sanitizedStdout) console.error(`Stdout: ${sanitizedStdout}`); if (sanitizedStderr) console.error(`Stderr: ${sanitizedStderr}`); // Return sanitized error message const errorDetails = [sanitizedMessage, sanitizedStderr].filter(Boolean).join(' - '); throw new McpError(ErrorCode.InvalidRequest, `Command failed: ${errorDetails}`); } }