card_cardsToNotes
Convert Anki card IDs to their corresponding note IDs to manage flashcards and review content efficiently.
Instructions
Returns an unordered array of note IDs for the given card IDs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cards | Yes | A list of card IDs. |
Implementation Reference
- src/anki_mcp/card_service.py:33-40 (handler)Handler function that executes the tool logic: converts a list of card IDs to their corresponding note IDs by calling the AnkiConnect `cardsToNotes` API.@card_mcp.tool( name="cardsToNotes", description="Returns an unordered array of note IDs for the given card IDs.", ) async def convert_cards_to_notes_tool( cards: Annotated[List[int], Field(description="A list of card IDs.")], ) -> List[int]: return await anki_call("cardsToNotes", cards=cards)
- src/anki_mcp/__init__.py:25-25 (registration)Top-level registration of the card service into the main MCP server with 'card' prefix, resulting in the tool name 'card_cardsToNotes'.await anki_mcp.import_server("card", card_mcp)
- src/anki_mcp/card_service.py:33-40 (schema)Pydantic-based input schema (Annotated[List[int]]) and output type (List[int]) defined in the tool decorator.@card_mcp.tool( name="cardsToNotes", description="Returns an unordered array of note IDs for the given card IDs.", ) async def convert_cards_to_notes_tool( cards: Annotated[List[int], Field(description="A list of card IDs.")], ) -> List[int]: return await anki_call("cardsToNotes", cards=cards)
- src/anki_mcp/common.py:8-23 (helper)Utility function `anki_call` that performs HTTP POST to AnkiConnect API, used by the handler to invoke 'cardsToNotes'.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