num_cards_due_today
Check how many Anki flashcards are due for review today, optionally filtered by deck, to help manage daily study sessions.
Instructions
Get the number of cards due exactly today, with an optional deck filter.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| deck | No |
Implementation Reference
- mcp_ankiconnect/server.py:242-252 (handler)The core handler function implementing the num_cards_due_today tool logic. It uses a context manager for Anki client and the _find_due_card_ids helper to count due cards today, optionally filtered by deck. Decorated with @mcp.tool() for registration and error handling.@mcp.tool() @handle_anki_connection_error # Apply decorator async def num_cards_due_today(deck: Optional[str] = None) -> str: """Get the number of cards due exactly today, with an optional deck filter.""" async with get_anki_client() as anki: # Use the helper, specifying day=0 for today card_ids = await _find_due_card_ids(anki, deck, day=0) count = len(card_ids) deck_msg = f" in deck '{deck}'" if deck else " across all decks" return f"There are {count} cards due today{deck_msg}."
- mcp_ankiconnect/server.py:77-103 (helper)Supporting helper function that constructs Anki search queries to find card IDs due on a specific day (used with day=0 for today) and retrieves them via the Anki client, optionally filtered by deck.async def _find_due_card_ids( client: AnkiConnectClient, deck: Optional[str] = None, day: Optional[int] = 0 ) -> List[int]: """Finds card IDs due on a specific day relative to today (0=today).""" if day < 0: raise ValueError("Day must be non-negative.") # Construct the search query # prop:due=0 means due today # prop:due=1 means due tomorrow (relative to review time) # prop:due<=N finds cards due today up to N days in the future. if day == 0: prop = "prop:due=0" # Due exactly today else: prop = f"prop:due<={day}" query = f"is:due -is:suspended {prop}" if deck: # Add deck to query, ensuring proper quoting for spaces query += f' "deck:{deck}"' logger.debug(f"Executing Anki card search query: {query}") card_ids = await client.find_cards(query=query) logger.info(f"Found {len(card_ids)} cards for query: {query}") return card_ids
- mcp_ankiconnect/server.py:242-242 (registration)The @mcp.tool() decorator registers the num_cards_due_today function as an MCP tool.@mcp.tool()