A Model Context Protocol (MCP) server that provides tools for managing Anki flashcards through AnkiConnect. This server allows AI assistants to create, search, and manage Anki cards and decks programmatically.
- Card Management: Create new flashcards with front/back content
- Deck Operations: List, create, and manage Anki decks
- Search Functionality: Search cards using Anki's powerful search syntax
- Media Support: Add images and audio files to cards
- Model Support: Work with different note types/models
- Sync Integration: Trigger AnkiWeb synchronization
- Configurable: Customizable AnkiConnect URL
- Anki Desktop: Install Anki desktop application
- AnkiConnect: Install the AnkiConnect addon in Anki
- Go: Go 1.21 or later for building from source
git clone https://github.com/ezynda3/anki-mcp.git
cd anki-mcp
go build -o anki-mcp .
go install github.com/ezynda3/anki-mcp@latest
The server can be configured using environment variables:
ANKI_CONNECT_URL
: AnkiConnect server URL (default:http://localhost:8765
)
Add the following to your Claude Desktop configuration file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Windows: %APPDATA%\Claude\claude_desktop_config.json
{
"mcpServers": {
"anki": {
"command": "/path/to/anki-mcp",
"env": {
"ANKI_CONNECT_URL": "http://localhost:8765"
}
}
}
}
For development and testing:
# Install MCP Inspector
npm install -g @modelcontextprotocol/inspector
# Run with inspector
mcp-inspector /path/to/anki-mcp
# Start the server
./anki-mcp
# The server communicates via stdio using the MCP protocol
Check if AnkiConnect is available and responding.
Parameters: None
Example:
Use the ping tool to check if Anki is running.
List all available Anki decks.
Parameters: None
Example:
Show me all my Anki decks.
Create a new Anki deck.
Parameters:
deck_name
(required): Name of the deck to create
Example:
Create a new deck called "Spanish Vocabulary".
Create a new flashcard in a specified deck.
Parameters:
deck_name
(required): Name of the deck to add the card tofront
(required): Front side content of the cardback
(required): Back side content of the cardmodel_name
(optional): Note type to use (default: "Basic")tags
(optional): Array of tags to add to the card
Example:
Create a card in my "Spanish Vocabulary" deck with front "Hola" and back "Hello" with tags "greetings" and "basic".
Search for cards using Anki's search syntax.
Parameters:
query
(required): Search query using Anki search syntaxlimit
(optional): Maximum number of results to return (default: 10)
Examples:
Search for cards in the "Spanish Vocabulary" deck.
Find cards tagged with "difficult".
Search for cards containing "hello" in any field.
Search Syntax Examples:
deck:"Spanish Vocabulary"
- Cards in a specific decktag:difficult
- Cards with a specific tagfront:hello
- Cards with "hello" in the front fieldis:due
- Cards that are due for reviewadded:1
- Cards added in the last day
Add a media file to Anki's media collection.
Parameters:
filename
(required): Name of the media filedata
(required): Base64 encoded media file data
Example:
Add an audio file "pronunciation.mp3" to Anki's media collection.
Create a new flashcard with media attachments.
Parameters:
deck_name
(required): Name of the deck to add the card tofront
(required): Front side content of the cardback
(required): Back side content of the cardmodel_name
(optional): Note type to use (default: "Basic")tags
(optional): Array of tags to add to the cardaudio_filename
(optional): Audio filename to attachaudio_data
(optional): Base64 encoded audio dataimage_filename
(optional): Image filename to attachimage_data
(optional): Base64 encoded image data
Example:
Create a card with an image showing a Spanish flag and audio pronunciation.
Get all available note types/models in Anki.
Parameters: None
Example:
Show me all available note types in Anki.
Get field names for a specific note type/model.
Parameters:
model_name
(required): Name of the model to get fields for
Example:
What fields are available for the "Cloze" note type?
Trigger Anki to sync with AnkiWeb.
Parameters: None
Example:
Sync my Anki collection with AnkiWeb.
The server provides detailed error messages for common issues:
- AnkiConnect not available: Ensure Anki is running and AnkiConnect addon is installed
- Deck not found: Check deck name spelling and existence
- Invalid parameters: Verify required parameters are provided
- Media encoding errors: Ensure media data is properly base64 encoded
go build -v .
go test -v ./...
main.go
: MCP server implementation and tool handlersankiconnect.go
: AnkiConnect client wrappergo.mod
: Go module dependencies
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
MIT License - see LICENSE file for details.
- Built using MCP-Go
- Integrates with AnkiConnect
- Inspired by the go-anki-deck library
"AnkiConnect is not available"
- Ensure Anki desktop is running
- Verify AnkiConnect addon is installed and enabled
- Check that AnkiConnect is listening on the correct port (default: 8765)
"Failed to create deck/card"
- Verify deck names don't contain invalid characters
- Check that required fields are provided
- Ensure AnkiConnect permissions allow the operation
Media files not working
- Verify media data is properly base64 encoded
- Check file extensions are supported by Anki
- Ensure media files aren't too large
Set environment variable for verbose logging:
export MCP_DEBUG=1
./anki-mcp
For detailed information about the Model Context Protocol, see:
For AnkiConnect API details, see: