UNPKG

@ankimcp/anki-mcp-server

Version:

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

54 lines • 1.95 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvalidCardIdsError = void 0; exports.changeDeck = changeDeck; class InvalidCardIdsError extends Error { invalidIds; totalRequested; constructor(invalidIds, totalRequested) { super(InvalidCardIdsError.buildMessage(invalidIds, totalRequested)); this.invalidIds = invalidIds; this.totalRequested = totalRequested; this.name = "InvalidCardIdsError"; } static buildMessage(ids, total) { const MAX_SHOWN = 10; const shown = ids.slice(0, MAX_SHOWN).join(", "); const suffix = ids.length > MAX_SHOWN ? ` (and ${ids.length - MAX_SHOWN} more)` : ""; return (`${ids.length} of ${total} card ID(s) do not exist in the Anki ` + `collection: [${shown}]${suffix}. No cards were moved.`); } } exports.InvalidCardIdsError = InvalidCardIdsError; async function changeDeck(params, client) { const { cards, deck } = params; if (!cards || cards.length === 0) { throw new Error("cards array cannot be empty"); } if (!deck || deck.trim() === "") { throw new Error("deck name cannot be empty"); } const trimmedDeck = deck.trim(); const cardsInfo = await client.invoke("cardsInfo", { cards }); const invalidIds = []; cards.forEach((id, index) => { const info = cardsInfo?.[index]; if (!info || typeof info.cardId !== "number") { invalidIds.push(id); } }); if (invalidIds.length > 0) { throw new InvalidCardIdsError(invalidIds, cards.length); } await client.invoke("changeDeck", { cards, deck: trimmedDeck, }); return { success: true, message: `Successfully moved ${cards.length} card(s) to deck "${trimmedDeck}"`, cardsAffected: cards.length, targetDeck: trimmedDeck, }; } //# sourceMappingURL=changeDeck.action.js.map