note_addNote
Add a new note to an Anki deck using specified fields, model, and tags. Enables structured flashcard creation with AnkiConnect integration.
Instructions
Creates a new note using the given deck, model, fields, and tags. Returns the ID of the created note or null if the note could not be created.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| note | Yes | A dictionary representing the note to add. Should include 'deckName', 'modelName', 'fields', and optionally 'tags', 'options', 'audio', 'video', 'picture'. |
Implementation Reference
- src/anki_mcp/note_service.py:43-55 (handler)Handler implementation for the 'note_addNote' tool. The @tool decorator registers it as 'addNote' in the note_mcp namespace (prefixed to 'note_addNote' upon import). It wraps AnkiConnect's 'addNote' API call.@note_mcp.tool( name="addNote", description="Creates a new note using the given deck, model, fields, and tags. Returns the ID of the created note or null if the note could not be created.", ) async def add_note_tool( note: Annotated[ Dict[str, Any], Field( description="A dictionary representing the note to add. Should include 'deckName', 'modelName', 'fields', and optionally 'tags', 'options', 'audio', 'video', 'picture'." ), ], ) -> Optional[int]: return await anki_call("addNote", note=note)
- src/anki_mcp/__init__.py:24-24 (registration)Registration of the note_mcp server under the 'note' prefix in the main AnkiConnectMCP, which prefixes all note tools (e.g., 'addNote' becomes 'note_addNote').await anki_mcp.import_server("note", note_mcp)
- src/anki_mcp/common.py:8-23 (helper)Helper function used by the note_addNote handler to make asynchronous HTTP POST requests to the AnkiConnect server at http://127.0.0.1:8765, handling errors and returning results.async def anki_call(action: str, **params: Any) -> Any: async with httpx.AsyncClient() as client: payload = {"action": action, "version": 6, "params": params} result = await client.post(ANKICONNECT_URL, json=payload) result.raise_for_status() result_json = result.json() error = result_json.get("error") if error: raise Exception(f"AnkiConnect error for action '{action}': {error}") response = result_json.get("result") if "result" in result_json: return response return result_json