🧠 Anki MCP
Transform your Anki flashcard experience with AI! This MCP (Model Context Protocol) server bridges your Anki flashcard collection with AI assistants like Claude, enabling natural conversations about your study materials.
🚀 What Can You Do?
Imagine having an AI tutor that knows your entire flashcard collection and can:
📚 Interactive Learning
- "Quiz me on Japanese vocabulary I haven't seen in 3 days"
- "Test me on challenging cards from my medical deck"
- "Show me cards I've been struggling with recently"
✨ Smart Content Creation
- "Create flashcards about photosynthesis with diagrams"
- "Turn this PDF chapter into spaced repetition cards"
- "Generate cloze deletion cards from my lecture notes"
🔍 Powerful Analytics
- "Which topics am I struggling with most?"
- "Show me my study patterns for the last month"
- "What's my retention rate for different card types?"
🎯 Bulk Operations
- "Tag all my chemistry cards with 'exam-prep'"
- "Move cards with low retention to an intensive review deck"
- "Find and fix duplicate cards across my decks"
🎯 Features
- 🎯 Smart Tool Design: Intuitive, high-level tools designed specifically for AI agents
- 💬 Natural Conversations: Talk to Claude about your flashcards like you would a study buddy
- ⚡ Lightning Fast: Efficient operations that don't bog down your AI assistant
- 📦 Bulk Operations: Update thousands of cards at once with simple commands
- 📊 Study Insights: Deep analytics on your learning progress and patterns
- 🎨 Rich Media: Full support for images, audio, and other media in your cards
- 🔍 Powerful Search: Leverage Anki's advanced search syntax through natural language
- 🔒 Rock Solid: Fully typed TypeScript with comprehensive error handling
🛠 Technical Stack
- Node.js: Runtime environment (20+ required)
- TypeScript: Type safety and developer experience
- MCP SDK: Model Context Protocol implementation
- yanki-connect: 🙏 Fully-typed, isomorphic AnkiConnect API client
- tsup: Fast TypeScript bundler
- PNPM: Efficient package manager
Special thanks to the yanki-connect library for providing the robust AnkiConnect interface that powers this integration!
📋 Prerequisites
1. Install Anki and Node.js
Download and install Anki if you haven't already, plus Node.js 20 or newer.
2. Install AnkiConnect Plugin
- Open Anki
- Go to Tools → Add-ons
- Click Get Add-ons...
- Enter code:
2055492159
- Restart Anki
📋 Version Requirements: This server requires AnkiConnect version 25.2.25.0 or newer (released 2025-02-25) for full compatibility. Most features work with older versions, but we recommend updating for the best experience.
3. Configure AnkiConnect (Optional)
AnkiConnect works out of the box, but you can customize settings:
- Go to Tools → Add-ons
- Select AnkiConnect and click Config
- Default settings should work fine for most users
🚀 Quick Start
Option 1: Use with Claude Desktop (Recommended)
-
Configure Claude Desktop
Edit your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
Add this configuration (npx downloads and runs the latest release):
{
"mcpServers": {
"anki": {
"command": "npx",
"args": ["-y", "@arielbk/anki-mcp"]
}
}
}
-
Or install globally if you prefer a fixed version on your machine:
npm install -g @arielbk/anki-mcp
and use "command": "anki-mcp" with "args": [] in the config above.
-
Restart Claude Desktop
-
Start using it!
- Make sure Anki is running with AnkiConnect enabled
- Ask Claude: "Show me my Anki decks" or "Quiz me with 5 cards"
💡 Pro Tip: You can test your setup by asking Claude simple questions like "How many Anki decks do I have?" or "What's in my largest deck?"
Use with Claude Code
claude mcp add --scope user anki -- npx -y @arielbk/anki-mcp
The tools only appear in a newly started Claude Code session; /clear is not enough. Run /mcp to check that anki is connected.
Option 2: Development Setup
-
Clone the repository
git clone https://github.com/arielbk/anki-mcp.git
cd anki-mcp
-
Install dependencies
pnpm install
-
Build the project
pnpm build
-
Test the server
# Use the MCP inspector to test functionality
pnpm inspect
Option 3: Use with Other MCP Clients
This server works with any MCP-compatible client. You can also use it with:
- MCP Inspector: Interactive debugging tool
- Cline: VS Code extension for AI coding
- Custom MCP clients: Build your own using the MCP SDK
For stdio transport, run:
node dist/index.js
For localhost HTTP (Streamable HTTP) transport, run:
node dist/index.js --http --host=127.0.0.1 --port=3000
# The MCP endpoint will be at http://127.0.0.1:3000/mcp
Clients that support Streamable HTTP can connect directly. Legacy SSE clients may still work via client-side fallback.
HTTP mode is stateless: every POST /mcp is answered by a fresh server instance, no Mcp-Session-Id is issued, and GET/DELETE /mcp (2025 session operations) return 405 Method Not Allowed.
Protocol versions. Both transports serve the stateless 2026-07-28 revision (server/discover plus the per-request _meta envelope) and the 2025-era revisions via the initialize handshake (2025-11-25, 2025-06-18, 2025-03-26 and 2024-11-05), so existing clients keep working unchanged.
When bound to a loopback address (the default), the HTTP server rejects requests whose Host header is not localhost, 127.0.0.1 or [::1], and requests carrying a browser Origin header from another host (DNS rebinding protection). Clients that send no Origin header, such as desktop and CLI MCP clients, are unaffected. If you bind to another interface, set ALLOWED_HOSTS to a comma-separated list of hostnames to keep the Host check.
Option 4: Container
The repository includes a Dockerfile. It works with any OCI-compatible container tool, such as Podman or Rancher Desktop with the docker/nerdctl CLI:
podman build -t anki-mcp .
podman run -i --rm anki-mcp
AnkiConnect must be reachable from inside the container for tool calls to work. Listing tools and resources works without it.
🎮 Usage Examples
Once configured with Claude Desktop, you can have natural conversations like:
📖 Study Sessions
You: "I have a Japanese exam tomorrow. Can you quiz me on Hiragana cards I haven't reviewed in a week?"
Claude: I'll find your Hiragana cards that need review and start a quiz session...
📝 Content Creation
You: "Create flashcards for the major battles of World War II with dates and significance"
Claude: I'll create comprehensive flashcards covering the key WWII battles...
📊 Study Analytics
You: "How am I doing with my medical terminology deck? Show me my weak areas."
Claude: Let me analyze your performance on the medical terminology deck...
🏷️ Organization
You: "Tag all cards about cardiovascular system with 'cardiology' and move them to my MCAT prep deck"
Claude: I'll help you organize those cards...
🔧 Available Tools
The server provides 8 high-level tools. Each takes an operation parameter, so a handful of tools covers the whole AnkiConnect API:
📝 Manage Flashcards (manage_flashcards)
Create, update, delete, and search your flashcards. Perfect for content creation, bulk updates, and organization.
Batch creation (create_batch)
- Defaults: top-level
deckName, modelName and tags apply to every note. A note's own deckName/modelName override the defaults; its tags are added to the default tags.
- Chunking: notes are sent one chunk at a time (
chunkSize, default 10, max 50) with a short pause between chunks, so large imports don't overload Anki.
- Per-note results: every note is reported as
#n "first 40 chars of the first field" with its new note ID or the reason it failed (duplicate in the collection or earlier in the same batch, unknown note type, wrong field names, empty first field, ...). Field names match case-insensitively (front works for Front).
- Partial failure: if Anki stops responding partway, the batch stops and reports which notes were saved, which chunk may or may not have been saved, and which notes to resend.
- Duplicates:
allowDuplicate: true allows notes whose first field already exists; duplicateScope: "deck" checks for duplicates only in the target deck (default: whole collection).
- Dry run:
dryRun: true validates every note (note type, field names, duplicates) without writing anything.
Import from a file
Instead of notes, pass filePath (an absolute path or ~/...; relative paths are rejected because the server's working directory is usually not your project) to a .json, .csv or .tsv file. An agent can draft cards to a file for you to review, then import them in one call without sending every card through the conversation.
- JSON: an array of notes, same shape as
notes: [{ "fields": { "Front": "...", "Back": "..." }, "tags": ["x"] }]
- CSV / TSV: the header row holds the field names. Optional
tags (space-separated), deck and model columns set those per row. Quoted fields may contain commas, tabs, newlines and "" for a literal quote. Anki text-export header lines (#separator:, #html:, #columns:, #deck:, #notetype:, #tags:) are understood; #columns: replaces the header row.
Front,Back,tags
"What does <code>Array.prototype.map</code> return?",A new array,js arrays
Capital of France,Paris,geography
{
"operation": "create_batch",
"filePath": "/Users/me/cards.csv",
"deckName": "Interview prep",
"modelName": "Basic",
"dryRun": true
}
🎯 Study Sessions (study_session)
Run interactive quiz sessions, manage card scheduling, and track which cards need review.
📚 Manage Decks (manage_decks)
Create and organize decks, move cards around, and configure deck settings.
Per-deck daily limits
Decks usually share an options preset (e.g. "Default"), so changing it changes every deck that uses it. To give one deck its own limits, use create with newPerDay / reviewsPerDay, or set_limits on an existing deck:
{ "operation": "set_limits", "deckName": "Interview prep", "newPerDay": 15 }
If the deck uses a shared preset, it is cloned into a new preset named after the deck, assigned to that deck only, and then changed. Other decks are not affected.
📊 Get Analytics (get_analytics)
Dive into your study statistics, review history, and learning patterns.
🎨 Manage Models (manage_models)
Customize note types, add fields, modify templates, and style your cards. list shows each note type's field names, so agents don't have to guess Front/Back.
🔧 Anki Operations (anki_operations)
Handle sync, media files, imports/exports, and other utility operations.
🖼️ Get Media File (get_media_file)
Retrieve media files (images, audio, etc.) from your Anki collection. AI assistants can analyze images directly (though they won't display in the UI).
🖥️ Anki GUI (anki_gui)
Drive the Anki desktop app: open the Card Browser with a search, open pre-filled Add Cards or Edit dialogs, start a deck review and answer cards on screen, or read the current card and the browser selection. These operations change what is shown in Anki (and exit_anki quits it), so prefer the other tools for anything that doesn't need the UI.
Upgrading from 0.5.x: the separate gui_* tools were merged into anki_gui. gui_browse is now anki_gui with operation: "browse", and so on.
📚 Resources
The server also exposes read-only MCP resources under anki:/// (deck names, note types, card and note details, review statistics) for clients that support resources.
✍️ Prompt: writing good flashcards
The server also provides an MCP prompt, writing_good_flashcards (optional topic argument), with guidelines for effective cards: the minimum information principle, one fact per card, no yes/no questions, several angles on one idea, one cloze per list item in a fixed order, and only making cards for material you already understand. It is based on Andy Matuschak's How to write good prompts and SuperMemo's Twenty rules of formulating knowledge. In Claude Code it is available as a slash command (/mcp__anki__writing_good_flashcards).
💡 Pro Tip: Many operations support pagination to prevent overwhelming your context window. Use limit and offset parameters when working with large result sets.
🛠 Development
# Run in development mode with auto-reloading
pnpm dev
# Type-check, lint and check formatting (what CI runs)
pnpm typecheck
pnpm lint
pnpm format:check
# Run unit tests (AnkiConnect is mocked; tests never touch your collection)
pnpm test
# Format the code
pnpm format
# Test with MCP inspector
pnpm inspect
🔧 Configuration
AnkiConnect Settings
The server connects to AnkiConnect on localhost:8765 by default. If you've customized your AnkiConnect configuration, you may need to adjust the connection settings.
Important: Make sure Anki is running and AnkiConnect is installed before using the MCP server. The server will fail to connect if AnkiConnect is not accessible.
💡 Note: The underlying yanki-connect library supports auto-launching Anki on macOS, but this feature is not currently exposed in the MCP server configuration. You'll need to start Anki manually.
Claude Desktop Advanced Configuration
For advanced users, you can pass additional parameters:
{
"mcpServers": {
"anki": {
"command": "anki-mcp",
"args": ["--verbose"],
"env": {
"ANKI_CONNECT_HOST": "localhost",
"ANKI_CONNECT_PORT": "8765"
}
}
}
}
Troubleshooting
Common Issues:
- "Failed to connect to AnkiConnect": Ensure Anki is running and AnkiConnect plugin is installed
- "Couldn't reach AnkiConnect at http://127.0.0.1:8765. Is Anki running?": Anki is not running or quit during the last operation. Restart it; if a
create_batch was interrupted, its result lists which notes were saved and which to resend.
- "No decks found": Make sure you have at least one deck in Anki
- Claude doesn't respond: Restart Claude Desktop after configuration changes
- Permission errors: Check that the global npm install worked correctly with
npm list -g @arielbk/anki-mcp
🤝 Contributing
We welcome contributions! Please: