add_note
Add a note to a specified Anki deck using a chosen note type, input fields, and optional tags for organized learning.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deckName | Yes | Name of the deck to add the note to | |
| fields | Yes | Object with field names as keys and field content as values | |
| modelName | Yes | Name of the note model/type (e.g., "Basic", "Cloze") | |
| tags | No | Array of tags to add to the note |
Implementation Reference
- src/tools/notes.ts:20-48 (handler)The handler function for the 'add_note' tool that constructs a note and calls ankiClient.note.addNote to add it to Anki, returning success message or throwing error.async ({ deckName, modelName, fields, tags }) => { try { const note = { deckName, modelName, fields, tags: tags || [], }; const noteId = await ankiClient.note.addNote({ note }); if (noteId === null) { throw new Error('Failed to add note - possibly a duplicate or invalid fields'); } return { content: [ { type: 'text', text: `Successfully added note with ID: ${noteId}. Deck: "${deckName}", Model: "${modelName}", Tags: [${tags?.join(', ') || 'none'}]`, }, ], }; } catch (error) { throw new Error( `Failed to add note: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/tools/notes.ts:12-19 (schema)Zod input schema for the 'add_note' tool defining parameters: deckName, modelName, fields, and optional tags.{ deckName: z.string().describe('Name of the deck to add the note to'), modelName: z.string().describe('Name of the note model/type (e.g., "Basic", "Cloze")'), fields: z .record(z.string()) .describe('Object with field names as keys and field content as values'), tags: z.array(z.string()).optional().describe('Array of tags to add to the note'), },
- src/tools/notes.ts:11-49 (registration)Registration of the 'add_note' tool within the registerNoteTools function using server.tool(name, schema, handler). Note: This register function is exported but not called in the main server setup, which uses consolidated tools instead.'add_note', { deckName: z.string().describe('Name of the deck to add the note to'), modelName: z.string().describe('Name of the note model/type (e.g., "Basic", "Cloze")'), fields: z .record(z.string()) .describe('Object with field names as keys and field content as values'), tags: z.array(z.string()).optional().describe('Array of tags to add to the note'), }, async ({ deckName, modelName, fields, tags }) => { try { const note = { deckName, modelName, fields, tags: tags || [], }; const noteId = await ankiClient.note.addNote({ note }); if (noteId === null) { throw new Error('Failed to add note - possibly a duplicate or invalid fields'); } return { content: [ { type: 'text', text: `Successfully added note with ID: ${noteId}. Deck: "${deckName}", Model: "${modelName}", Tags: [${tags?.join(', ') || 'none'}]`, }, ], }; } catch (error) { throw new Error( `Failed to add note: ${error instanceof Error ? error.message : String(error)}` ); } } );