find_and_replace_in_models
Efficiently find and replace text in Anki card templates, including front, back, and CSS, for specified models to streamline content updates.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| back | Yes | Whether to search in back templates | |
| css | Yes | Whether to search in CSS | |
| fieldText | Yes | Text to find | |
| front | Yes | Whether to search in front templates | |
| modelName | Yes | Name of the model to search in | |
| replaceText | Yes | Text to replace with |
Implementation Reference
- src/tools/model.ts:78-103 (handler)The handler function that executes the find and replace operation in Anki models using the ankiClient.async ({ modelName, fieldText, replaceText, front, back, css }) => { try { const count = await ankiClient.model.findAndReplaceInModels({ model: { modelName, fieldText, replaceText, front, back, css, }, }); return { content: [ { type: 'text', text: `Successfully replaced ${count} occurrences of "${fieldText}" with "${replaceText}" in model "${modelName}"`, }, ], }; } catch (error) { throw new Error( `Failed to find and replace in model "${modelName}": ${error instanceof Error ? error.message : String(error)}` ); } }
- src/tools/model.ts:70-77 (schema)Zod input schema defining parameters for the find_and_replace_in_models tool.{ modelName: z.string().describe('Name of the model to search in'), fieldText: z.string().describe('Text to find'), replaceText: z.string().describe('Text to replace with'), front: z.boolean().describe('Whether to search in front templates'), back: z.boolean().describe('Whether to search in back templates'), css: z.boolean().describe('Whether to search in CSS'), },
- src/tools/model.ts:68-104 (registration)Registration of the 'find_and_replace_in_models' tool on the MCP server, including name, schema, and handler.server.tool( 'find_and_replace_in_models', { modelName: z.string().describe('Name of the model to search in'), fieldText: z.string().describe('Text to find'), replaceText: z.string().describe('Text to replace with'), front: z.boolean().describe('Whether to search in front templates'), back: z.boolean().describe('Whether to search in back templates'), css: z.boolean().describe('Whether to search in CSS'), }, async ({ modelName, fieldText, replaceText, front, back, css }) => { try { const count = await ankiClient.model.findAndReplaceInModels({ model: { modelName, fieldText, replaceText, front, back, css, }, }); return { content: [ { type: 'text', text: `Successfully replaced ${count} occurrences of "${fieldText}" with "${replaceText}" in model "${modelName}"`, }, ], }; } catch (error) { throw new Error( `Failed to find and replace in model "${modelName}": ${error instanceof Error ? error.message : String(error)}` ); } } );