Collection Manager¶
Manages Anki collection lifecycle and provides thread-safe access.
Collection Manager for Anki MCP Server.
Handles opening, closing, and managing Anki collection instances. Supports multiple collections and thread-safe access.
- class mousetail.server.collection_manager.CollectionManager[source]¶
Bases:
objectManages Anki collection lifecycle and access.
- check_collection_accessible(path=None)[source]¶
Check if a collection is accessible (not locked by Anki app).
- Parameters:
path (
Optional[str]) – Path to collection file. If None, uses default.- Return type:
- Returns:
Resolved collection path
- Raises:
ValueError – If path is invalid or collection doesn’t exist
AnkiError – If collection is locked or cannot be accessed
- open_collection(path=None)[source]¶
Open a collection and return its path identifier.
- Parameters:
path (
Optional[str]) – Path to collection file. If None, uses default.- Return type:
- Returns:
Collection path (identifier)
- Raises:
ValueError – If path is invalid or collection doesn’t exist
AnkiError – If collection cannot be opened
- close_collection(path)[source]¶
Close a collection.
- Parameters:
path (
str) – Path to collection file
- get_collection(path=None)[source]¶
Get a collection with thread-safe access.
- Parameters:
path (
Optional[str]) – Path to collection. If None, uses default or first open collection.- Yields:
Collection instance
Example
>>> manager = CollectionManager() >>> with manager.get_collection() as col: ... note = col.new_note(notetype)
- mousetail.server.collection_manager.get_manager()[source]¶
Get the global collection manager instance.
- Return type:
CollectionManager Class¶
- class mousetail.server.collection_manager.CollectionManager[source]
Bases:
objectManages Anki collection lifecycle and access.
- __init__()[source]
- list_available_collections()[source]
List all available Anki collections on the system.
- check_collection_accessible(path=None)[source]
Check if a collection is accessible (not locked by Anki app).
- Parameters:
path (
Optional[str]) – Path to collection file. If None, uses default.- Return type:
- Returns:
Resolved collection path
- Raises:
ValueError – If path is invalid or collection doesn’t exist
AnkiError – If collection is locked or cannot be accessed
- open_collection(path=None)[source]
Open a collection and return its path identifier.
- Parameters:
path (
Optional[str]) – Path to collection file. If None, uses default.- Return type:
- Returns:
Collection path (identifier)
- Raises:
ValueError – If path is invalid or collection doesn’t exist
AnkiError – If collection cannot be opened
- close_all()[source]
Close all open collections.
- get_collection(path=None)[source]
Get a collection with thread-safe access.
- Parameters:
path (
Optional[str]) – Path to collection. If None, uses default or first open collection.- Yields:
Collection instance
Example
>>> manager = CollectionManager() >>> with manager.get_collection() as col: ... note = col.new_note(notetype)
Global Manager Function¶
- mousetail.server.collection_manager.get_manager()[source]
Get the global collection manager instance.
- Return type: