list_decks_and_notes
Retrieve all Anki decks and note types with their fields to organize and manage flashcard content through the MCP-AnkiConnect integration.
Instructions
Get all decks (excluding specified patterns) and note types with their fields.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
No arguments | |||
Implementation Reference
- mcp_ankiconnect/server.py:253-289 (handler)The handler function for the 'list_decks_and_notes' tool, decorated with @mcp.tool() for registration. It lists filtered decks and note types with their fields from Anki, returning a formatted string.@mcp.tool() @handle_anki_connection_error # Apply decorator async def list_decks_and_notes() -> str: """Get all decks (excluding specified patterns) and note types with their fields.""" async with get_anki_client() as anki: all_decks = await anki.deck_names() # Filter decks based on EXCLUDE_STRINGS decks = [d for d in all_decks if not any(ex.lower() in d.lower() for ex in EXCLUDE_STRINGS)] logger.info(f"Filtered decks: {decks}") all_model_names = await anki.model_names() note_types = [] for model in all_model_names: if any(ex.lower() in model.lower() for ex in EXCLUDE_STRINGS): continue try: fields = await anki.model_field_names(model) note_types.append({"name": model, "fields": fields}) except Exception as e: logger.warning(f"Could not get fields for model '{model}': {e}. Skipping this model.") # Format the output string deck_list_str = f"You have {len(decks)} filtered decks: {', '.join(decks)}" if decks else "No filtered decks found." note_type_list = [] if note_types: for note in note_types: # Format fields as "FieldName": "type" (assuming string for simplicity) field_str = ', '.join([f'"{field}": "string"' for field in note['fields']]) note_type_list.append(f"- {note['name']}: {{ {field_str} }}") note_types_str = f"Your filtered note types and their fields are:\n" + "\n".join(note_type_list) else: note_types_str = "No filtered note types found." return f"{deck_list_str}\n\n{note_types_str}"