anki_add_note
Add a flashcard to a specified Anki deck by providing the deck name, front, and back content for the note. Integrates with Anki via the AnkiConnect plugin.
Instructions
Add a flashcard to an Anki deck
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| back | Yes | Back of the flashcard | |
| deckName | Yes | The target deck name | |
| front | Yes | Front of the flashcard |
Implementation Reference
- src/index.ts:169-172 (registration)Registration of the 'addNote' tool in the ListToolsRequestSchema handler, defining its name, description, and input schema.{ name: "addNote", description: "Create a single note", inputSchema: noteParameters,
- src/index.ts:112-136 (schema)Input schema definition (noteParameters) used by the 'addNote' tool for validating deckName, modelName, fields, and optional tags.const noteParameters = { type: "object", properties: { deckName: { type: "string", description: "Name of the deck to add note to", }, modelName: { type: "string", description: "Name of the note model/type to use", }, fields: { type: "object", description: "Map of fields to the value in the note model being used", }, tags: { type: "array", items: { type: "string", }, description: "Tags to apply to the note", }, }, required: ["deckName", "modelName", "fields"], };
- src/index.ts:232-239 (handler)Handler logic for the 'addNote' tool within the CallToolRequestSchema handler. It wraps arguments in {note: ...} and calls AnkiConnect's 'addNote' action via ankiRequest, returning the created note ID.case "addNote": const createdNoteId = await ankiRequest<number>( "addNote", { note: request.params.arguments }, ); return { toolResult: `Created note with the following ID: ${createdNoteId}`, };
- src/index.ts:36-47 (helper)Helper function 'ankiRequest' used by the 'addNote' handler to make API calls to AnkiConnect at localhost:8765.async function ankiRequest<T>(action: string, params: any = {}): Promise<T> { const response = await fetch("http://localhost:8765", { method: "POST", body: JSON.stringify({ action, version: 6, params, }), }); const { result } = (await response.json()) as AnkiRequestResult<T>; return result; }