UNPKG

@ankimcp/anki-mcp-server

Version:

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

126 lines • 6.34 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; var __param = (this && this.__param) || function (paramIndex, decorator) { return function (target, key) { decorator(target, key, paramIndex); } }; var ForgetCardsTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.ForgetCardsTool = exports.forgetCardsInputSchema = void 0; const common_1 = require("@nestjs/common"); const microservices_1 = require("@nestjs/microservices"); const mcp_nest_1 = require("@rekog/mcp-nest"); const zod_1 = require("zod"); const anki_connect_client_1 = require("../../../clients/anki-connect.client.js"); const anki_utils_1 = require("../../../utils/anki.utils.js"); const card_validation_utils_1 = require("../../../utils/card-validation.utils.js"); exports.forgetCardsInputSchema = zod_1.z.object({ cards: zod_1.z .array(zod_1.z.number().int().positive()) .min(1) .max(100) .describe("Array of card IDs to reset to new (max 100). Card IDs (not note IDs) — use get_cards, " + "get_due_cards, or notesInfo to obtain them."), }); let ForgetCardsTool = ForgetCardsTool_1 = class ForgetCardsTool { ankiClient; logger = new common_1.Logger(ForgetCardsTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async execute(params) { const cards = Array.isArray(params?.cards) ? [...new Set(params.cards)] : []; try { this.logger.log(`Executing forgetCards: ${cards.length} card(s)`); if (cards.length === 0) { throw new Error("cards array is required for forgetCards action"); } const cardsInfo = await (0, card_validation_utils_1.fetchExistingCards)(cards, this.ankiClient, "No cards were reset."); const reset = cardsInfo.map((card) => ({ cardId: card.cardId, previousState: (0, anki_utils_1.getCardType)(card.type ?? -1), previousIntervalDays: card.interval ?? 0, reps: card.reps ?? 0, lapses: card.lapses ?? 0, })); await this.ankiClient.invoke("forgetCards", { cards }); this.logger.log(`Reset ${cards.length} card(s) to new`); return { success: true, message: `Successfully reset ${cards.length} card(s) to new`, cardsAffected: cards.length, reset, }; } catch (error) { this.logger.error("Failed to execute forgetCards", error); return (0, anki_utils_1.createErrorResponse)(error, { action: "forgetCards", cardIds: cards, hint: "This can happen when Anki is not running or the card IDs are invalid (note IDs are not card IDs)", }); } } }; exports.ForgetCardsTool = ForgetCardsTool; __decorate([ (0, mcp_nest_1.Tool)({ name: "forgetCards", description: "Reset cards to the new queue, discarding their current scheduling (interval, due date, and ease factor). " + "Use this when a card should be relearned from scratch — for example when the user keeps failing to recall " + "a word that Anki has scheduled months out. Prefer this over rating a card 'Again': a rating records a real " + "review and counts as a lapse, which distorts both future scheduling and the collection's statistics. " + "The review log is preserved, so past reviews still show in card info and statistics. " + "This changes scheduling only — note content, tags, and deck placement are untouched. " + "Cards that are already new are unaffected, so re-running is safe.", parameters: exports.forgetCardsInputSchema, outputSchema: zod_1.z.object({ success: zod_1.z.boolean(), message: zod_1.z.string(), cardsAffected: zod_1.z.number(), reset: zod_1.z .array(zod_1.z.object({ cardId: zod_1.z.number(), previousState: zod_1.z .string() .describe("Card state before the reset: new, learning, review, or relearning"), previousIntervalDays: zod_1.z .number() .describe("Scheduling interval in days before the reset (0 for new cards)"), reps: zod_1.z .number() .describe("Total reviews logged for the card (unchanged by the reset)"), lapses: zod_1.z .number() .describe("Total lapses logged for the card (unchanged by the reset)"), })) .describe("Per-card state captured immediately before the reset, so the caller can report " + "what was given up."), }), annotations: { title: "Reset Cards to New", readOnlyHint: false, destructiveHint: true, idempotentHint: true, openWorldHint: false, }, }), __param(0, (0, microservices_1.Payload)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], ForgetCardsTool.prototype, "execute", null); exports.ForgetCardsTool = ForgetCardsTool = ForgetCardsTool_1 = __decorate([ (0, mcp_nest_1.McpController)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], ForgetCardsTool); //# sourceMappingURL=forget-cards.tool.js.map