Anki MCP
Provides tools for previewing and adding Anki notes through AnkiConnect, including listing deck names, validating note content, deck/model and duplicate eligibility, and adding a previously previewed note after native macOS human approval. Notes use fixed Front/Back fields, are tagged, and duplicates are rejected using Anki's first-field/note-type rules.
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
Anki MCP
A small local Python MCP server for previewing and adding Anki notes through Codex or a ChatGPT custom plugin. Additions require a native macOS confirmation dialog, use a single configured deck, and check for duplicates.
This is an MIT-licensed prototype with local and live integration tests on macOS. The generic configuration has been tested with Anki, Codex Desktop (read-only tools), and a ChatGPT custom plugin through a Secure MCP Tunnel, including a human-approved addition and duplicate rejection.
See TESTING.md for the verified scope and remaining limitations.
Architecture
flowchart LR
C["Codex Desktop"] -->|"local MCP over stdio"| S["Python server"]
H["ChatGPT custom plugin"] --> T["OpenAI tunnel service"]
L["Local tunnel client"] -->|"outbound HTTPS polling and results"| T
T -.->|"work returned over that connection"| L
L -->|"MCP over stdio"| S
S -->|"127.0.0.1:8765"| A["AnkiConnect add-on"]
A --> N["Anki collection"]
S --> D["Human approval on the Mac"]AnkiConnect is an add-on inside Anki. The ChatGPT custom plugin is a separate account registration that exposes our MCP tools. Codex can launch the Python server directly and needs neither the tunnel nor that ChatGPT plugin.
The Python server does not call an AI model. The AI client supplies text; the server validates it and communicates with local AnkiConnect API v6. AnkiConnect remains bound to localhost. Each client may start a separate server process, so previews are not transferable between clients or across server restarts.
Related MCP server: Anki AI MCP Server
Local setup
Use macOS for the confirmation dialog. The development environment used Python
3.14 and MCP 1.30; other runtime versions are not verified with this lock file.
Install Anki and the AnkiConnect add-on,
and keep Anki open. Leave AnkiConnect on 127.0.0.1:8765.
From this project's directory:
python3 -m venv .venv
.venv/bin/python -m pip install -r requirements.lock.txt
cp config.example.json config.local.jsonEdit config.local.json with an existing deck and note type. Only deck
and model are accepted. The note type must have exactly Front, Back in
that order. The configuration is ignored by Git. No automatic deck creation
or fallback destination is provided. The tool caller cannot change the deck.
.venv/bin/python -m unittest -v
.venv/bin/python smoke_test.pyUse a custom sentence without editing the script:
.venv/bin/python smoke_test.py \
--front '朝ご飯を食べた後で、台所を片付けます。' \
--back '<b>読み</b><br>あさごはんをたべたあとで、だいどころをかたづけます。<br><b>意味</b><br>朝食の後、台所をきれいにします。'Supply both fields together. First run without --add and check can_add.
Then repeat with --add, click Cancel, and run read-only again: the note should
still be eligible. Repeat with --add and approve, then run read-only again:
it should be rejected as a duplicate. Use a sentence not already in Anki.
Each invocation creates a fresh preview; no preview IDs need to be copied.
The smoke test connects to real Anki but is read-only by default.
smoke_test.py --add requests approval for a real test note. If AnkiConnect
requires an API key, supply ANKICONNECT_API_KEY in the launch environment.
Do not put keys in JSON configuration, logs, source control or chats.
Tools and safeguards
Tool | Behavior |
| Lists all deck names without modifying Anki |
| Validates content, deck, model and duplicate eligibility; returns exact content and a temporary ID |
| Available with |
sequenceDiagram
actor User
participant AI
participant Server
participant Anki
User->>AI: Request a preview
AI->>Server: preview_card(front, back)
Server->>Anki: Check target and duplicates
Server-->>AI: Preview and temporary ID
AI-->>User: Show exact content
User->>AI: Request addition
AI->>Server: add_card(preview_id)
Server->>Anki: Recheck eligibility
Server-->>User: Mac approval dialog
alt Human approves
User->>Server: Click Add card
Server->>Anki: Recheck and add note
Server-->>AI: Added with note ID
else Cancel or timeout
Server-->>AI: Cancelled, nothing added
endPreviews expire after ten minutes and are consumed on an add attempt. A new preview is needed after failure, cancellation or a restart. The dialog defaults to Cancel and expires after 45 seconds. Never automate its approval.
Duplicates use Anki's first-field/note-type rules across the collection, not semantic similarity. Anki's own add call also disallows duplicates. If a write times out, inspect Anki before retrying because the response may have been lost.
Simple formatting and ruby HTML are allowed, without attributes, scripts,
images or sound directives. Each field is limited to 1500 characters. The Mac
dialog displays HTML source; keep content short enough to review completely.
Added notes receive the codex-anki tag for compatibility with the prototype.
Anki's templates and scheduling determine generated cards and review timing.
Codex configuration
Register the server with absolute paths substituted for these placeholders:
codex mcp add anki-local -- /absolute/path/to/project/.venv/bin/python /absolute/path/to/project/anki_mcp.pyFor additions, append --enable-writes to the server arguments. Quote paths
if they contain spaces. Set tool_timeout_sec = 120 in this server's entry in
~/.codex/config.toml to accommodate human approval. Use a fresh chat/reload
if tools are missing. See official MCP configuration.
ChatGPT: Platform tunnel first, custom plugin second
In Platform tunnel settings, create a private tunnel associated with the appropriate Platform organization and ChatGPT workspace. Record its tunnel ID locally.
Create a dedicated regular runtime API key with Restricted permissions, Tunnels Read + Use. Creating/managing the registration requires Manage separately. Do not use an Admin key as the runtime key.
Download the appropriate official tunnel-client release, verify its checksum, and install the executable at
.tools/tunnel-client/tunnel-client. The earlier prototype used v0.0.21 on Apple Silicon. The executable needs execute permission.Copy
tunnel.example.jsontotunnel.local.jsonand replace its placeholder ID. The launcher generates an ignored YAML profile with paths derived from this folder and an environment reference for the key.Run
.venv/bin/python start_tunnel.pyin your own Terminal. Enter the runtime key only at its hidden prompt. The launcher runs preflight before starting; check readiness, not merely a process-start message. Leave it running.In ChatGPT, open Plugins → Add → Add custom MCP server. Choose a name, Connection: Tunnel, and the matching tunnel. Select No authentication for this server's MCP layer; OpenAI tunnel access controls still apply. Review and approve the connection.
Test
list_decks, thenpreview_card. To enable additions, stop the client with Ctrl+C, restart withstart_tunnel.py --enable-writes, and refresh tools in ChatGPT's plugin settings. Verifyadd_cardappears and create a fresh preview before an approved addition.
Do not run two clients for the same tunnel at once. Platform/ChatGPT access and labels can vary by account. See OpenAI's tunnel guide.
The tunnel is outbound-only; no public AnkiConnect listener is needed. Its local
health listener binds to loopback, with the URL written to .tunnel-health.url.
The runtime key is kept in process memory/environment, not saved by the launcher.
There is no Keychain integration or automatic startup yet. Keep the Mac awake,
Anki open and Terminal running; someone must be at the Mac for additions.
Files and version control
File | Purpose |
| MCP server, Anki client, validation, previews and approval |
| Portable profile generation, hidden key prompt and foreground launch |
| Live MCP client test, read-only unless |
| Mocked safety/configuration/path tests |
| Generic templates for ignored local settings |
| Direct dependency and frozen environment versions |
| Future migration and rollback checklist |
| Planned work and delivered changes |
| Tested environments, observed results and remaining limits |
Git excludes local settings/profiles, keys, logs, installed dependencies, downloaded executables and generated media. Review staged content before each publication; ignore rules do not remove secrets already committed elsewhere. Anki data, Codex settings and OpenAI account registrations live outside this repository and require separate backups. Card text/tool results are visible to the AI service; local execution is not a promise that content stays on the Mac. The approval guard does not protect against other programs on the Mac using AnkiConnect directly.
Collaboration and release status
See CONTRIBUTING.md for safe development and test practices.
Keep installation-specific notes in ignored local-notes/ or *.local.md files.
The tracked ideas log and migration guide are generic and useful to contributors.
Before publishing future changes, review staged files and Git history for credentials or personal configuration and rerun the relevant tests. This repository backs up source code, not Anki collections or account settings.
License
Copyright (c) 2026 Gleb Tanaka. Distributed under the MIT License. Third-party software, including Anki, AnkiConnect, Python dependencies and the downloaded tunnel client, remains subject to its respective licenses.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Connect AI assistants to your approved computer for files, commands, browser and desktop tasks.
- DNS-DATA RemoteDeprecatedcom.dns-data
Connect AI assistants to authorized Windows and macOS devices for files, commands, and management.
Reach your own computers from any AI app: files, commands, screen and mouse, approvals and alerts.
Read, write and run Odoo actions from any AI app, as each user, with approval rules per colleague.
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 gradedqualityDmaintenanceBridge between AI assistants and Anki Desktop, enabling automated flashcard management and study document processing.ISC
- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to create and manage Anki cards through AnkiConnect, including decks, card creation, search, updates, deletion, and mobile sync.MIT
- FlicenseBqualityCmaintenanceEnables AI assistants to directly manage Anki flashcards, decks, notetypes, tags, and media, with support for batch operations, searches, and deck exports via file-based input/output.23-