add_notes
Add notes to Anki decks using specified models, fields, and tags. Streamline card creation with structured input for efficient study material organization.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| notes | Yes | Array of notes to add |
Implementation Reference
- src/tools/notes.ts:52-93 (registration)Registration of the 'add_notes' MCP tool, including input schema (array of notes with deck/model/fields/tags) and handler that formats and calls ankiClient.note.addNotes in batch, reporting success/failure counts.server.tool( 'add_notes', { notes: z .array( z.object({ deckName: z.string().describe('Name of the deck to add the note to'), modelName: z.string().describe('Name of the note model/type'), 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'), }) ) .describe('Array of notes to add'), }, async ({ notes }) => { try { const formattedNotes = notes.map((note) => ({ ...note, tags: note.tags || [], })); const results = await ankiClient.note.addNotes({ notes: formattedNotes }); const successCount = results?.filter((result) => result !== null).length || 0; const failureCount = (results?.length || 0) - successCount; return { content: [ { type: 'text', text: `Batch note addition completed. Successfully added: ${successCount} notes, Failed: ${failureCount} notes. Results: ${JSON.stringify(results)}`, }, ], }; } catch (error) { throw new Error( `Failed to add notes: ${error instanceof Error ? error.message : String(error)}` ); } }
- src/tools/notes.ts:54-66 (schema)Input schema definition for the add_notes tool using Zod.{ notes: z .array( z.object({ deckName: z.string().describe('Name of the deck to add the note to'), modelName: z.string().describe('Name of the note model/type'), 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'), }) ) .describe('Array of notes to add'),
- src/tools/notes.ts:68-93 (handler)The handler function for add_notes: processes input notes array, ensures tags, calls underlying ankiClient batch add, computes stats, returns formatted response.async ({ notes }) => { try { const formattedNotes = notes.map((note) => ({ ...note, tags: note.tags || [], })); const results = await ankiClient.note.addNotes({ notes: formattedNotes }); const successCount = results?.filter((result) => result !== null).length || 0; const failureCount = (results?.length || 0) - successCount; return { content: [ { type: 'text', text: `Batch note addition completed. Successfully added: ${successCount} notes, Failed: ${failureCount} notes. Results: ${JSON.stringify(results)}`, }, ], }; } catch (error) { throw new Error( `Failed to add notes: ${error instanceof Error ? error.message : String(error)}` ); } }