Skip to content

Commit d73e18d

Browse files
committed
Merge fix/issue-8-python-version-check: Python version check with AbortAddonImport (#8)
2 parents 3783191 + 0d03cc5 commit d73e18d

File tree

3 files changed

+45
-4
lines changed

3 files changed

+45
-4
lines changed

CLAUDE.md

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,32 @@ All `print()` statements and `logging` output appears in the terminal.
229229
- [MCP Protocol](https://modelcontextprotocol.io/) - Model Context Protocol specification
230230
- [FastMCP](https://github.com/jlowin/fastmcp) - MCP SDK used by this addon
231231

232-
## Common Issues
232+
## Known Gotchas
233+
234+
### Imports Must Be Relative
235+
236+
All imports in this addon use **relative imports** (e.g., `from ....tool_decorator import Tool`). This is the Anki addon ecosystem standard — AnkiConnect does this too. Absolute imports (`from anki_mcp_server.config import ...`) break AnkiWeb installs because AnkiWeb uses the addon ID (`124672614/`) as the directory name, not the package name.
237+
238+
### Anki Scheduler API Pitfalls
239+
240+
- `col.sched.deck_due_tree()` — correct way to get deck stats (AnkiConnect pattern). Tree nodes have: `deck_id`, `name`, `new_count`, `learn_count`, `review_count`, `total_in_deck` (Anki 2.1.46+)
241+
- `col.sched.counts()` — returns (new, learning, review) for the **currently selected** deck
242+
- `col.sched.counts_for_deck_today()` — does **NOT** work in modern Anki, silently returns wrong values
243+
- Raw SQL (`col.db`) is acceptable for analytics/stats (revlog, card stats) — AnkiConnect does this too. For deck stats, always prefer `deck_due_tree()` over SQL.
244+
245+
### Python Version Compatibility
246+
247+
- MCP Python SDK requires Python >= 3.10 (uses `match`/`case`, `X | Y` syntax) — hard blocker, no workaround
248+
- Anki 25.02 and earlier: Python 3.9 (**not supported**)
249+
- Anki 25.07+: Python 3.13 (supported)
250+
- No Anki version ships Python 3.10/3.11/3.12 — went directly from 3.9 → 3.13
251+
- `__init__.py` has an early version check that raises `ImportError` with a clear message on Python < 3.10
252+
253+
### Install Methods
254+
255+
Always test both install methods when making changes:
256+
- `.ankiaddon` file (double-click or *Tools → Add-ons → Install from file...*)
257+
- AnkiWeb code (`124672614`) — directory name is the addon ID, not the package name
233258

234259
### UI Freezes During Operations
235260

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,8 @@ These tools interact with Anki's user interface:
138138

139139
## Requirements
140140

141-
- Anki 25.x or later (Python 3.13)
141+
- **Anki 25.07 or later** (ships Python 3.13)
142+
- Anki 25.02 and earlier ship Python 3.9, which is **not supported** — the MCP SDK requires Python 3.10+ ([#8](https://github.com/ankimcp/anki-mcp-server-addon/issues/8))
142143

143144
## Architecture
144145

anki_mcp_server/__init__.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,23 @@
1-
# Vendor imports - must be first, before any other imports
1+
# Python version check - must be first, before any vendor imports that use 3.10+ syntax
22
import sys
3+
4+
if sys.version_info < (3, 10):
5+
from aqt.addons import AbortAddonImport
6+
from aqt.utils import showWarning
7+
8+
showWarning(
9+
f"<b>AnkiMCP Server</b> requires <b>Anki 25.07 or later</b>.<br><br>"
10+
f"Your Anki is running Python {sys.version_info.major}.{sys.version_info.minor}, "
11+
f"but the MCP protocol SDK requires Python 3.10+.<br><br>"
12+
f"Please upgrade Anki to continue using this addon.<br>"
13+
f'<a href="https://github.com/ankimcp/anki-mcp-server-addon/issues/8">More info</a>',
14+
title="AnkiMCP Server",
15+
)
16+
raise AbortAddonImport()
17+
318
from pathlib import Path
419

5-
__version__ = "0.1.1"
20+
__version__ = "0.3.4"
621

722
# Packages we vendor that might conflict with other addons
823
_VENDOR_PACKAGES = ['mcp', 'pydantic', 'pydantic_core', 'starlette', 'uvicorn', 'anyio', 'httpx', 'websockets']

0 commit comments

Comments
 (0)