Anki Model Context Protocol (MCP) Server
This server lets AI assistants directly manage an Anki collection (flashcards, decks, notetypes, tags, media, and search) via MCP, using file-based I/O to keep responses compact.
Deck management: list, create, rename, delete, and move cards between decks.
Notetype management: list notetypes and inspect their schemas/fields.
Note/flashcard operations: add single notes, cloze notes, batch-add notes, fetch, update, and delete notes.
Card state control: suspend or unsuspend cards by IDs, note IDs, search query, or JSON file.
Search & discovery: search notes and cards using Anki query syntax, with results written to disk.
Tag management: list all tags, add/remove tags in bulk from notes.
Media handling: store image/audio files from disk into Anki's media storage.
Export: export decks to .apkg, .colpkg, or structured JSON files.
Collection stats: get overview statistics including notes, cards, due counts, and deck breakdown.
Provides tools for managing Anki flashcards, decks, notetypes, tags, media, and searches, including batch card creation, deck hierarchy management, note retrieval and updates, tag operations, and deck export.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Anki Model Context Protocol (MCP) Server Create a deck called 'Spanish Vocabulary' and add the batch of cards from /tmp/spanish_cards.json"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
Anki Model Context Protocol (MCP) Server
A high-performance Model Context Protocol (MCP) server enabling AI assistants (Claude Desktop, Claude Code, Antigravity, Codex, Cursor, etc.) to directly manage Anki flashcards, decks, notetypes, tags, media, and searches.
⚡ Universal File-Based I/O Architecture
Modern flashcards (especially with HTML markup, syntax-highlighted code blocks, and LaTeX math formulas) are large payloads. Streaming these through JSON-RPC tool parameters or returning full card content directly to the model causes token exhaustion, truncated outputs, and context window saturation.
This server implements Universal File-Based Input and Output (File-Based I/O):
Zero In-Band Token Bloat: Flashcard mutations, queries, searches, and schema introspections accept input JSON file paths and write full structured output to disk.
Compact Telemetry Responses: Every tool call returns bounded metadata summaries ($< 150$ tokens) with status, IDs, affected counts, and the resolved
output_filepath.Atomic Batch Ingestion: Hundreds of cards can be written to a single JSON payload and ingested in an atomic SQLite transaction in milliseconds.
Cross-Platform Temp Storage: Outputs default to the OS temporary directory (
%TEMP%\anki_mcpon Windows,/tmp/anki_mcpon Linux/macOS) and can be overridden viaANKI_MCP_OUTPUT_DIR.
Related MCP server: Anki MCP Server
Features
⚡ Fast Direct Bridge: Interacts directly with Anki's collection database (
collection.anki2) via the officialankiPython engine with zero HTTP overhead.🔒 Non-Blocking Connection Lifecycle: Uses per-request open/close context management (~2.7ms) so database locks are immediately released and Anki Desktop is not locked out.
🪟 Cross-Platform: Native support for Windows, macOS, and Linux, with automatic collection discovery in standard OS locations.
🗂️ Hierarchical Decks: Full support for nested deck creation (e.g.
Computer Science::Algorithms::Trees).📝 Rich Card Formats: Supports Standard/Basic cards, Cloze deletions (
{{c1::...}}), custom fields, and LaTeX math formulas ($...$and$$...$$).🔍 Query Engine: Full support for Anki's search syntax (
deck:Languages tag:grammar,is:due,added:7,"Recursion").🏷️ Tag Management: Hierarchical tagging and bulk tag additions/removals.
📦 Batch Creation: High-throughput batch card addition in single atomic operations via JSON payloads.
💾 Deck Export: Native packaging to
.apkg,.colpkg, and.json.💡 MCP Prompts & Resources: Built-in resources (
anki://decks,anki://stats) and structured card generation prompt (flashcard_generator).
Installation & Setup
This project uses uv for fast, reproducible Python environment management.
Clone and Install
git clone https://github.com/debnath-d/anki-mcp-server.git
cd anki-mcp-server
uv syncRun Server
uv run anki-mcp-serverClient Configurations
1. Claude Desktop
Add the server to your Claude Desktop configuration file:
Windows:
%APPDATA%\Claude\claude_desktop_config.jsonmacOS:
~/Library/Application Support/Claude/claude_desktop_config.jsonLinux:
~/.config/Claude/claude_desktop_config.json
Windows Configuration
{
"mcpServers": {
"anki": {
"command": "uv",
"args": [
"--directory",
"C:\\path\\to\\anki-mcp-server",
"run",
"anki-mcp-server"
]
}
}
}macOS / Linux Configuration
{
"mcpServers": {
"anki": {
"command": "uv",
"args": [
"--directory",
"/path/to/anki-mcp-server",
"run",
"anki-mcp-server"
]
}
}
}2. Google Antigravity
Add to your Antigravity MCP configuration (~/.gemini/config/mcp_config.json):
{
"mcpServers": {
"anki": {
"command": "uv",
"args": [
"--directory",
"/path/to/anki-mcp-server",
"run",
"anki-mcp-server"
]
}
}
}3. Claude Code / Codex / CLI Clients
Start Claude Code with the MCP server:
claude --mcp-server "uv --directory '/path/to/anki-mcp-server' run anki-mcp-server"🧠 Bundled Anki Agent Skill
This repository includes a production-ready Agent Skill (skills/anki) designed for AI coding assistants and agents (such as Google Antigravity, Claude Code, and other agents supporting the Agent Skills standard).
While the MCP server provides the mechanism (tools, file-based I/O, database access), the agent skill provides the policy and methodology (spaced-repetition knowledge formulation, card authoring heuristics, and multi-step runbooks).
What the Skill Provides
Evolutionary Card Lifecycle: Rejects rigid academic dogma that forces complete pre-comprehension. Cards can start directly in Anki as rich problem statements (e.g. 150 NeetCode problems) or reading excerpts, evolving into atomic cards as you study.
Token-Efficient Ingestion: Guides agents to assemble bulk payloads via scripts directly in the OS temporary directory (
tempfile.gettempdir() / 'anki_mcp') without burning LLM context tokens analyzing each card upfront.Pragmatic Knowledge Formulation: Operationalized rules distilled from SuperMemo:
Atomicity (Minimum Information Principle) as an evolutionary target during review/refactoring.
Pragmatic allowances for small sets (2–4 items) and short sequences.
Contrastive pairing for confusable concepts to combat memory interference.
Context prefixes (e.g.
[Python],[NeetCode]) and hierarchical tags.Strict formatting for LaTeX (
$...$,$$...$$) and code blocks (<pre><code>...</code></pre>).
Execution Playbooks: Step-by-step runbooks for bulk script ingestion, interactive generation, leech triage (
prop:lapses>=4), and deck restructuring.Query Cheatsheet: Quick reference for Anki search syntax (
is:due,prop:lapses,tag:,deck:).
Installing the Skill
The skill adheres to the open Agent Skills standard and can be linked globally or per-project across your preferred agent environments:
1. Claude Code
Global Install:
Linux / macOS:
mkdir -p ~/.claude/skills ln -s "$(pwd)/skills/anki" ~/.claude/skills/ankiWindows (PowerShell):
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.claude\skills" New-Item -ItemType SymbolicLink -Path "$env:USERPROFILE\.claude\skills\anki" -Target "$PWD\skills\anki"
Project-Specific Install: Link or copy directly into your repository's
.claude/skills/:mkdir -p .claude/skills ln -s "$(pwd)/skills/anki" .claude/skills/anki
2. Google Antigravity
Global Install:
Linux / macOS:
mkdir -p ~/.gemini/config/skills ln -s "$(pwd)/skills/anki" ~/.gemini/config/skills/ankiWindows (PowerShell):
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.gemini\config\skills" New-Item -ItemType SymbolicLink -Path "$env:USERPROFILE\.gemini\config\skills\anki" -Target "$PWD\skills\anki"
Project-Specific Install: Link into
.agents/skills/:mkdir -p .agents/skills ln -s "$(pwd)/skills/anki" .agents/skills/anki
3. Universal .agents/skills (Cursor, Codex, OpenHands)
Global Install:
Linux / macOS:
mkdir -p ~/.agents/skills ln -s "$(pwd)/skills/anki" ~/.agents/skills/ankiWindows (PowerShell):
New-Item -ItemType Directory -Force -Path "$env:USERPROFILE\.agents\skills" New-Item -ItemType SymbolicLink -Path "$env:USERPROFILE\.agents\skills\anki" -Target "$PWD\skills\anki"
Project-Specific Install:
mkdir -p .agents/skills ln -s "$(pwd)/skills/anki" .agents/skills/anki
Available MCP Tools
1. Deck Management
Tool | Parameters | Description |
|
| Lists all decks with names, IDs, and card counts. Writes hierarchy to disk and returns summary. |
|
| Creates a new deck or subdeck (e.g. |
|
| Renames an existing deck and updates all nested subdeck prefixes. |
|
| Deletes a deck and its cards. |
|
| Moves cards across decks by IDs, query, or input file. |
2. Notetypes (Models)
Tool | Parameters | Description |
|
| Lists all available notetypes (e.g. |
|
| Returns detailed schema, fields, and templates for a notetype to disk. |
3. Flashcard & Note Ingestion & Mutation (File-Based)
Tool | Parameters | Description |
|
| Ingests one or more notes (single note, cloze deletion, or batch array) atomically from a JSON payload. |
|
| Fetches a note by ID with fields, tags, notetype, and cards to disk. |
|
| Updates fields or tags on an existing note from a JSON payload. |
|
| Deletes notes and their cards by ID list or JSON file. |
4. Media, State Control & Export
Tool | Parameters | Description |
|
| Copies an image/diagram directly from disk into Anki's media storage and returns embed tags. |
|
| Sets card review queue state ( |
|
| Exports a deck to |
5. Search & Discovery
Tool | Parameters | Description |
|
| Searches notes using Anki search syntax ( |
|
| Searches cards and returns review queue, intervals, and due dates to disk. |
6. Tag Management & Stats
Tool | Parameters | Description |
|
| Lists all unique tags across the collection to disk. |
|
| Adds or removes tags in bulk across notes specified directly or within a JSON file. |
|
| Returns summary statistics (total notes, cards, new/due cards, deck breakdown). |
Testing
Run the automated test suite and linter:
ruff check .
uv run python -m unittest discover -s testsImportant Notes & Troubleshooting
SQLite Database Lock: Anki uses exclusive file locks. The Anki desktop GUI application must be closed while the MCP server executes write operations to prevent
anki.errors.DBErrorlocks.Collection Path Auto-Discovery:
Windows: Automatically detected in
%APPDATA%\Anki2\<Profile>\collection.anki2or%LOCALAPPDATA%\Anki2\<Profile>\collection.anki2.macOS: Automatically detected in
~/Library/Application Support/Anki2/<Profile>/collection.anki2.Linux: Automatically detected in
~/.local/share/Anki2/<Profile>/collection.anki2.To use a custom location, set the
ANKI_COLLECTION_PATHenvironment variable.
Output Cache: Tool outputs are stored in your OS temporary directory (
%TEMP%\anki_mcpor/tmp/anki_mcp) by default. SetANKI_MCP_OUTPUT_DIRto use a custom directory.
Available Tools
23 toolsadd_cloze_noteC
Create a Cloze deletion flashcard (fill-in-the-blank style) from a JSON file payload.
Inputs: input_file (required), deck_name, output_file. Returns: object
add_noteC
Create a new flashcard note from a JSON file payload.
Inputs: input_file (required), deck_name, output_file. Returns: object
add_notes_batchC
Add multiple flashcard notes in a single high-throughput batch operation from a JSON file.
Inputs: input_file (required), output_file. Returns: object
add_tags_to_notesC
Add one or more tags in bulk to notes from argument lists or a JSON file.
Inputs: tags, note_ids, input_file, output_file. Returns: object
change_deckB
Move cards to a target deck by card IDs, note IDs, search query, or input file.
Inputs: query, card_ids, note_ids, input_file, +2 more. Returns: object
create_deckB
Create a new deck or subdeck (e.g. 'Computer Science::Algorithms').
Inputs: deck_name (required), output_file. Returns: object
delete_deckA
Delete a deck and all cards contained within it by deck ID or deck name.
Inputs: deck_id, deck_name, output_file. Returns: object
delete_notesB
Delete notes (and all cards generated from them) by their Note IDs or from a JSON file list.
Inputs: note_ids, input_file, output_file. Returns: object
export_deckA
Export a deck to an Anki package (.apkg), full collection package (.colpkg), or structured JSON file.
Inputs: deck_name (required), target_path (required), format, include_media. Returns: object
get_collection_statsC
Get collection statistics (total notes, cards, new/due cards, deck breakdown).
Inputs: output_file. Returns: object
get_noteC
Retrieve complete information about a note by its ID.
Inputs: note_id (required), output_file. Returns: object
get_notetype_infoC
Get detailed schema information about a specific notetype.
Inputs: notetype_name (required), output_file. Returns: object
list_decksB
List all decks in the Anki collection with their IDs and card counts.
Inputs: output_file. Returns: object
list_notetypesC
List all available notetypes (models) in the collection, their fields, and types.
Inputs: output_file. Returns: object
list_tagsA
List all unique tags across the collection, writing full tag array to disk.
Inputs: output_file. Returns: object
remove_tags_from_notesC
Remove one or more tags in bulk from notes from argument lists or a JSON file.
Inputs: tags, note_ids, input_file, output_file. Returns: object
rename_deckB
Rename an existing deck (and its child subdecks) by deck ID.
Inputs: deck_id (required), new_name (required), output_file. Returns: object
search_cardsC
Search cards using Anki browser syntax, returning card queue status, due dates, and intervals to disk.
Inputs: query (required), limit, output_file. Returns: object
search_notesB
Search notes using Anki browser syntax, writing full matched cards/fields to disk.
Inputs: query (required), limit, output_file. Returns: object
store_media_fileC
Store a media file (image, diagram, audio) directly from local disk into Anki's media storage.
Inputs: source_path (required), target_name. Returns: object
suspend_cardsB
Suspend cards from active review queues by card IDs, note IDs, search query, or input file.
Inputs: query, card_ids, note_ids, input_file, +1 more. Returns: object
unsuspend_cardsA
Unsuspend cards back into active review queues by card IDs, note IDs, search query, or input file.
Inputs: query, card_ids, note_ids, input_file, +1 more. Returns: object
update_noteB
Update fields and/or tags of an existing note from a JSON file.
Inputs: note_id (required), input_file (required), output_file. Returns: object
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 23 tools
Each tool targets a distinct resource and action. Even similar tools like search_notes vs search_cards are clearly differentiated by what they return (full notes vs card scheduling info). Operations like add_note, add_cloze_note, and add_notes_batch serve clearly different use cases without ambiguity.
All 23 tool names follow a consistent verb_noun pattern with snake_case: list_decks, create_deck, delete_deck, rename_deck, change_deck, store_media_file, suspend_cards, unsuspend_cards, list_notetypes, get_notetype_info, add_note, add_cloze_note, add_notes_batch, get_note, update_note, delete_notes, search_notes, search_cards, list_tags, add_tags_to_notes, remove_tags_from_notes, get_collection_stats, export_deck. No style mixing or irregular verbs.
With 23 tools, the surface is on the heavier side but still well-scoped for a comprehensive Anki integration. The tool count covers all major workflows (deck management, note/card CRUD, tagging, media, export, statistics) without feeling bloated. It slightly exceeds the ideal range but remains purposeful.
The toolset provides complete lifecycle coverage: decks can be listed, created, deleted, renamed, and used for moving cards; notes can be added (single, cloze, batch), retrieved, updated, deleted, and searched; cards can be searched and suspended/unsuspended; tags can be listed and bulk-added/removed; media import, collection stats, and export are available. No obvious dead ends or missing critical operations.
Maintenance
Related MCP Connectors
Turn text, files, URLs, or photos into Anki flashcard decks from your AI assistant.
Spaced-repetition flashcards in Markdown: create cards, manage decks and study with FSRS.
Build and study spaced-repetition flashcards with your agent.
Language flashcards in your AI assistant: build decks, edit cards and review what's due in the chat.
Related MCP Servers
- AlicenseBqualityDmaintenanceEnables AI assistants to manage Anki flashcard decks and cards through natural language, supporting deck creation, card additions (basic and cloze types), and review queue management.66 npm2MIT
- AlicenseNot gradedqualityDmaintenanceEnables interaction with the Anki desktop flashcard application through the Anki-Connect plugin. Supports managing decks, cards, notes, and models, allowing AI assistants to create and query flashcards through natural language.10 npm1ISC
- AlicenseAqualityDmaintenanceEnables AI assistants to manage Anki flashcard collections by creating, searching, and updating cards through a standardized interface. It supports media handling, batch operations, and review scheduling via the AnkiConnect add-on.62MIT
- AlicenseAqualityDmaintenanceEnables AI tools to manage Anki flashcards, including deck management, card search, creation, editing, deletion, and statistics.1030 npm3Apache 2.0