UNPKG

@ankimcp/anki-mcp-server

Version:

Model Context Protocol server for Anki - enables AI assistants to interact with your Anki flashcards

69 lines • 2.47 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.listDecks = listDecks; const deck_hierarchy_utils_1 = require("../../../../../utils/deck-hierarchy.utils.js"); async function listDecks(params, client) { const { includeStats = false } = params; const deckNames = await client.invoke("deckNames"); if (!deckNames || deckNames.length === 0) { return { success: true, message: "No decks found in Anki", decks: [], total: 0, }; } let decks; let summary; if (includeStats) { const deckNamesAndIds = await client.invoke("deckNamesAndIds", {}); const deckStatsResponse = await client.invoke("getDeckStats", { decks: deckNames, }); decks = deckNames.map((name) => { const deckId = deckNamesAndIds?.[name]; const stats = deckId != null ? deckStatsResponse?.[String(deckId)] : undefined; if (stats) { return { name, stats: { deck_id: stats.deck_id || 0, name, new_count: stats.new_count || 0, learn_count: stats.learn_count || 0, review_count: stats.review_count || 0, total_new: stats.new_count || 0, total_cards: stats.total_in_deck || 0, }, }; } return { name }; }); const rootDeckNames = new Set((0, deck_hierarchy_utils_1.getRootDeckNames)(deckNames)); summary = decks.reduce((acc, deck) => { if (!deck.stats) { return acc; } acc.total_cards += deck.stats.total_cards; if (rootDeckNames.has(deck.name)) { acc.new_cards += deck.stats.new_count; acc.learning_cards += deck.stats.learn_count; acc.review_cards += deck.stats.review_count; } return acc; }, { total_cards: 0, new_cards: 0, learning_cards: 0, review_cards: 0 }); } else { decks = deckNames.map((name) => ({ name })); } const result = { success: true, decks, total: decks.length, }; if (summary) { result.summary = summary; } return result; } //# sourceMappingURL=listDecks.action.js.map