card_findCards
Search Anki flashcards to retrieve card IDs using Anki search queries, enabling targeted card management and review.
Instructions
Returns an array of card IDs for a given Anki search query.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Anki search query (e.g., 'deck:current is:new'). |
Implementation Reference
- src/anki_mcp/card_service.py:11-20 (handler)The handler function `find_cards_tool` that executes the core logic of the `card_findCards` tool by invoking AnkiConnect's `findCards` API with the search query.@card_mcp.tool( name="findCards", description="Returns an array of card IDs for a given Anki search query.", ) async def find_cards_tool( query: Annotated[ str, Field(description="Anki search query (e.g., 'deck:current is:new').") ], ) -> List[int]: return await anki_call("findCards", query=query)
- src/anki_mcp/__init__.py:25-25 (registration)Registers the `card_mcp` FastMCP instance with the prefix 'card', transforming local tool name 'findCards' into the global tool name 'card_findCards'.await anki_mcp.import_server("card", card_mcp)
- src/anki_mcp/card_service.py:15-20 (schema)Pydantic-based input schema (query: str) and output type (List[int]) for the card_findCards tool.async def find_cards_tool( query: Annotated[ str, Field(description="Anki search query (e.g., 'deck:current is:new').") ], ) -> List[int]: return await anki_call("findCards", query=query)
- src/anki_mcp/common.py:8-23 (helper)Shared helper function `anki_call` used by the handler to communicate with AnkiConnect API.async def anki_call(action: str, **params: Any) -> Any: async with httpx.AsyncClient() as client: payload = {"action": action, "version": 6, "params": params} result = await client.post(ANKICONNECT_URL, json=payload) result.raise_for_status() result_json = result.json() error = result_json.get("error") if error: raise Exception(f"AnkiConnect error for action '{action}': {error}") response = result_json.get("result") if "result" in result_json: return response return result_json