Headless AnkiConnect-compatible REST API server with AnkiWeb sync
Project description
AnkiConnect Server
Headless AnkiConnect-compatible REST API server with AnkiWeb sync support and MCP server integration.
❓ Problem & Solution
Problem: Traditional AnkiConnect requires the Anki desktop app running, works only on localhost, and can't be deployed to servers.
Solution: This headless server provides direct collection access without Anki desktop, supports remote deployment, and includes automatic AnkiWeb sync.
✨ Features
- Server Deployment - Run on VPS, Raspberry Pi, or cloud without GUI
- AI Integration - MCP server for AI assistant access to your cards
- Full AnkiConnect API Compatibility - Version 6 API with all standard actions
- Headless Operation - No Qt/GUI required, perfect for servers and containers
- AnkiWeb Sync - Automatic synchronization with AnkiWeb (optional)
- Custom Sync Server - Support for self-hosted Anki sync servers
- MCP Server - Model Context Protocol integration for AI assistants
📋 Table of Contents
🔧 Requirements
- Python 3.12+
- uv package manager
- Anki collection file (
.anki21)
📦 Installation
Quick Install
# Clone the repository
git clone https://github.com/glechic/anki-connect-server.git
cd anki-connect-server
# Install with uv
uv pip install -e .
From PyPI
# Install the package
pip install anki-connect-server
# Or run directly with uvx (no installation needed)
uvx anki-connect-server
⚙️ Configuration
Set environment variables before running the server:
| Variable | Required | Default | Description |
|---|---|---|---|
ANKI_COLLECTION_PATH |
Yes | - | Path to your .anki21 collection file |
ANKICONNECT_PORT |
No | 8765 |
Server port |
ANKICONNECT_BIND |
No | 127.0.0.1 |
Bind address (use 0.0.0.0 for external access) |
ANKICONNECT_ANKIWEB_USER |
No | - | AnkiWeb username (required for sync) |
ANKICONNECT_ANKIWEB_PASS |
No | - | AnkiWeb password (required for sync) |
ANKIWEB_URL |
No | - | Custom sync server URL (optional) |
ANKICONNECT_FULL_UPLOAD |
No | false |
Allow full upload on sync conflict |
Example .env File
# Required: Path to your Anki collection
ANKI_COLLECTION_PATH=/path/to/collection.anki21
# Optional: Server configuration
ANKICONNECT_PORT=8765
ANKICONNECT_BIND=127.0.0.1
# Optional: AnkiWeb sync credentials
ANKICONNECT_ANKIWEB_USER=your@email.com
ANKICONNECT_ANKIWEB_PASS=your_password
# Optional: Custom sync server
# ANKIWEB_URL=https://your-sync-server.com
⚠️ Security Warning: Store credentials securely. Never commit
.envfiles to version control.
🚀 Usage
Quick Start with uvx (No Installation)
# Run the API server directly
ANKI_COLLECTION_PATH=/path/to/collection.anki21 uvx anki-connect-server
# Or with sync enabled
ANKI_COLLECTION_PATH=/path/to/collection.anki21 \
ANKICONNECT_ANKIWEB_USER=user \
ANKICONNECT_ANKIWEB_PASS=pass \
uvx anki-connect-server
Development Server
uv run uvicorn anki_connect_server.api:app --reload --port 8765
Production Server
uv run uvicorn anki_connect_server.api:app --host 0.0.0.0 --port 8765
Using the CLI
# Start the API server
uv run server
# Start the MCP server
uv run mcp-server
MCP Server with uvx
# Run MCP server without installation
ANKI_COLLECTION_PATH=/path/to/collection.anki21 uvx --from anki-connect-server mcp-server
📚 API Reference
The server exposes a single POST endpoint at /api that accepts AnkiConnect-style JSON requests.
Request Format
{
"action": "actionName",
"version": 6,
"params": {
"param1": "value1",
"param2": "value2"
}
}
Response Format
{
"result": <action_result>,
"error": null
}
On error:
{
"result": null,
"error": "Error message"
}
Examples
Get Deck Names
curl -X POST http://localhost:8765/api \
-H "Content-Type: application/json" \
-d '{"action": "deckNames", "version": 6}'
Create a Deck
curl -X POST http://localhost:8765/api \
-H "Content-Type: application/json" \
-d '{"action": "createDeck", "version": 6, "params": {"deck": "My New Deck"}}'
Add a Note
curl -X POST http://localhost:8765/api \
-H "Content-Type: application/json" \
-d '{
"action": "addNote",
"version": 6,
"params": {
"note": {
"deckName": "Default",
"modelName": "Basic",
"fields": {
"Front": "Hello",
"Back": "World"
},
"tags": ["api"]
}
}
}'
Sync with AnkiWeb
curl -X POST http://localhost:8765/api \
-H "Content-Type: application/json" \
-d '{"action": "sync", "version": 6}'
Batch Multiple Actions
curl -X POST http://localhost:8765/api \
-H "Content-Type: application/json" \
-d '{
"action": "multi",
"version": 6,
"params": {
"actions": [
{"action": "deckNames", "params": {}},
{"action": "modelNames", "params": {}}
]
}
}'
Supported Actions
Misc
version- Get API versionsync- Sync with AnkiWebsyncStatus- Get sync statussyncMedia- Sync media onlymulti- Execute multiple actionsimportPackage- Import.apkgfileexportPackage- Export deck to.apkg
Decks
deckNames- Get all deck namesdeckNamesAndIds- Get deck names with IDscreateDeck- Create a new deckdeleteDecks- Delete deckschangeDeck- Move cards to different deckgetDecks- Get decks for cardsgetDeckConfig- Get deck configurationsaveDeckConfig- Save deck configurationsetDeckConfigId- Assign config to deckscloneDeckConfigId- Clone deck configremoveDeckConfigId- Remove deck config
Models
modelNames- Get all model namesmodelNamesAndIds- Get model names with IDsmodelFieldNames- Get field names for modelmodelFieldsOnTemplates- Get fields used in templatescreateModel- Create a new note modelmodelTemplates- Get card templatesmodelStyling- Get CSS stylingupdateModelTemplates- Update templatesupdateModelStyling- Update CSS
Notes
addNote- Add a single noteaddNotes- Add multiple notescanAddNotes- Check if notes can be addedupdateNoteFields- Update note fieldsfindNotes- Search for notesnotesInfo- Get note detailsdeleteNotes- Delete notesaddTags- Add tags to notesremoveTags- Remove tags from notesgetTags- Get all tags
Cards
findCards- Search for cardscardsToNotes- Get note IDs from card IDscardsInfo- Get card detailssuspend- Suspend cardsunsuspend- Unsuspend cardsareSuspended- Check if cards are suspendedareDue- Check if cards are duegetIntervals- Get card intervals
Media
getMediaDirPath- Get media directory pathstoreMediaFile- Store a media file (base64)retrieveMediaFile- Retrieve a media filedeleteMediaFile- Delete a media file
🤖 MCP Server
The server includes a Model Context Protocol (MCP) integration for AI assistants.
Starting the MCP Server
uv run mcp-server
Available MCP Tools
get_deck_names- Get all deck namesget_deck_names_and_ids- Get decks with IDscreate_deck- Create a new deckdelete_decks- Delete decksget_model_names- Get all model namesget_model_field_names- Get fields for a modeladd_note- Add a new notefind_notes- Search for notesget_notes_info- Get note detailsdelete_notes- Delete notesfind_cards- Search for cardsget_cards_info- Get card detailssuspend_cards/unsuspend_cards- Manage card suspensionare_suspended/are_due- Check card statusget_card_intervals- Get card intervalsget_all_tags- Get all tagsadd_tags/remove_tags- Manage tagsget_media_dir_path- Get media directorystore_media_file/retrieve_media_file/delete_media_file- Media operationschange_deck- Move cards between deckscards_to_notes- Convert card IDs to note IDsget_deck_config- Get deck configurationget_model_templates/get_model_styling- Model customizationget_api_version- Get API versionimport_package/export_package- Import/export deckssync/sync_media/get_sync_status- Sync operations
Adding to Claude Desktop
Add to your claude_desktop_config.json:
{
"mcpServers": {
"anki-connect-server": {
"command": "uvx",
"args": ["--from", "anki-connect-server", "mcp-server"],
"env": {
"ANKI_COLLECTION_PATH": "/path/to/collection.anki21"
}
}
}
}
🐳 Docker
Building the Image
docker build -t anki-connect-server .
Running the Container
docker run -d \
-p 8765:8765 \
-v /path/to/collection.anki21:/data/collection.anki21 \
-e ANKI_COLLECTION_PATH=/data/collection.anki21 \
-e ANKICONNECT_ANKIWEB_USER=your@email.com \
-e ANKICONNECT_ANKIWEB_PASS=your_password \
--name anki-connect-server \
anki-connect-server
Docker Compose
version: '3.8'
services:
anki-connect-server:
build: .
ports:
- "8765:8765"
volumes:
- ./collection.anki21:/data/collection.anki21
environment:
- ANKI_COLLECTION_PATH=/data/collection.anki21
- ANKICONNECT_ANKIWEB_USER=${ANKIWEB_USER}
- ANKICONNECT_ANKIWEB_PASS=${ANKIWEB_PASS}
restart: unless-stopped
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file anki_connect_server-0.2.0.tar.gz.
File metadata
- Download URL: anki_connect_server-0.2.0.tar.gz
- Upload date:
- Size: 22.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
307c9d249ced7264a1fc544a04562f24c59decf93db676206264faef15c7ddc4
|
|
| MD5 |
f8770ecba52e29667e60e5cc424a8968
|
|
| BLAKE2b-256 |
1c1ccda27b946376884b4b9ea2f48578d734b1c606696e08ff3074938cb24e20
|
File details
Details for the file anki_connect_server-0.2.0-py3-none-any.whl.
File metadata
- Download URL: anki_connect_server-0.2.0-py3-none-any.whl
- Upload date:
- Size: 14.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.7.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1225acf7f51c0ebeca83084fed4bd6597efec14c23f82f530a9ef225ba8be8b9
|
|
| MD5 |
e0bbd8fb9e75f8b321aae2e0afb79a4e
|
|
| BLAKE2b-256 |
f3c35820e84c21b620e75ecc242960e28e78b23213b490d2d7527a6f9a1f02fa
|