create_model
Build custom Anki flashcards by defining model names, field order, card templates, CSS, and cloze type using the create_model tool in Anki MCP.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cardTemplates | Yes | Array of card templates with Front and Back content | |
| css | No | Custom CSS styling for the model | |
| inOrderFields | Yes | Array of field names in order | |
| isCloze | No | Whether the model should be a cloze type | |
| modelName | Yes | Name of the model to create |
Implementation Reference
- src/tools/model.ts:28-64 (handler)Handler function that processes inputs, prepares parameters including optional CSS and cloze settings, invokes ankiClient.model.createModel, and responds with success message containing the new model ID or propagates errors.async ({ modelName, inOrderFields, cardTemplates, css, isCloze }) => { try { const modelParams: { modelName: string; inOrderFields: string[]; cardTemplates: { [key: string]: string; Back: string; Front: string }[]; css?: string; isCloze?: boolean; } = { modelName, inOrderFields, cardTemplates, }; if (css !== undefined) { modelParams.css = css; } if (isCloze !== undefined) { modelParams.isCloze = isCloze; } const result = await ankiClient.model.createModel(modelParams); return { content: [ { type: 'text', text: `Successfully created model "${modelName}" with ID: ${result.id}`, }, ], }; } catch (error) { throw new Error( `Failed to create model "${modelName}": ${error instanceof Error ? error.message : String(error)}` ); } }
- src/tools/model.ts:12-27 (schema)Zod input schema validating modelName (required string), inOrderFields (array of strings), cardTemplates (array of template objects with Front/Back and additional properties), optional css and isCloze.{ modelName: z.string().describe('Name of the model to create'), inOrderFields: z.array(z.string()).describe('Array of field names in order'), cardTemplates: z .array( z .object({ Front: z.string().describe('Front template content'), Back: z.string().describe('Back template content'), }) .and(z.record(z.string())) ) .describe('Array of card templates with Front and Back content'), css: z.string().optional().describe('Custom CSS styling for the model'), isCloze: z.boolean().optional().describe('Whether the model should be a cloze type'), },
- src/tools/model.ts:10-65 (registration)Registration of the 'create_model' tool on the MCP server using server.tool(), including name, input schema, and handler function.server.tool( 'create_model', { modelName: z.string().describe('Name of the model to create'), inOrderFields: z.array(z.string()).describe('Array of field names in order'), cardTemplates: z .array( z .object({ Front: z.string().describe('Front template content'), Back: z.string().describe('Back template content'), }) .and(z.record(z.string())) ) .describe('Array of card templates with Front and Back content'), css: z.string().optional().describe('Custom CSS styling for the model'), isCloze: z.boolean().optional().describe('Whether the model should be a cloze type'), }, async ({ modelName, inOrderFields, cardTemplates, css, isCloze }) => { try { const modelParams: { modelName: string; inOrderFields: string[]; cardTemplates: { [key: string]: string; Back: string; Front: string }[]; css?: string; isCloze?: boolean; } = { modelName, inOrderFields, cardTemplates, }; if (css !== undefined) { modelParams.css = css; } if (isCloze !== undefined) { modelParams.isCloze = isCloze; } const result = await ankiClient.model.createModel(modelParams); return { content: [ { type: 'text', text: `Successfully created model "${modelName}" with ID: ${result.id}`, }, ], }; } catch (error) { throw new Error( `Failed to create model "${modelName}": ${error instanceof Error ? error.message : String(error)}` ); } } );