UNPKG

@ankimcp/anki-mcp-server

Version:

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

120 lines • 6.2 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 DeckStatsTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.DeckStatsTool = 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_states_utils_1 = require("../../../utils/card-states.utils.js"); const deckStats_action_1 = require("./deckActions/actions/deckStats.action"); let DeckStatsTool = DeckStatsTool_1 = class DeckStatsTool { ankiClient; logger = new common_1.Logger(DeckStatsTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async execute(params) { try { this.logger.log(`Executing deckStats for deck: ${params.deck}`); const result = await (0, deckStats_action_1.deckStats)({ deck: params.deck, easeBuckets: params.easeBuckets, intervalBuckets: params.intervalBuckets, }, this.ankiClient); return result; } catch (error) { this.logger.error("Failed to execute deckStats", error); return (0, anki_utils_1.createErrorResponse)(error, { action: "deckStats", hint: "This can happen when Anki is not running or the deck name is wrong", }); } } }; exports.DeckStatsTool = DeckStatsTool; __decorate([ (0, mcp_nest_1.Tool)({ name: "deckStats", description: 'Get comprehensive statistics for a single deck including card counts, ease and interval distributions. Pass a deck name (e.g., "Japanese::JLPT N5") and optional bucket boundaries. ' + "Returns TWO different views that answer different questions: " + "`counts` is today's study queue as shown in Anki's deck browser (cards DUE TODAY, capped by the deck's daily new/review limits, suspended/buried excluded); " + "`states` is the true number of cards in each state (new / learning / review / suspended / buried), ignoring due dates and daily limits. " + 'To answer "how many cards do I have" use `states`; to answer "what will I study today" use `counts`. ' + "Both are rolled up over descendant decks (parent decks include their children). " + "`states` costs 5 additional Anki searches per call. " + `For counts: ${card_states_utils_1.DUE_TREE_INVARIANT_NOTE}`, parameters: zod_1.z.object({ deck: zod_1.z.string().describe('Deck name (e.g., "Japanese::JLPT N5")'), easeBuckets: zod_1.z .array(zod_1.z.number().positive()) .max(20) .optional() .describe("Bucket boundaries for ease factor distribution. Default: [2.0, 2.5, 3.0]"), intervalBuckets: zod_1.z .array(zod_1.z.number().positive()) .max(20) .optional() .describe("Bucket boundaries for interval distribution in days. Default: [7, 21, 90]"), }), outputSchema: zod_1.z.object({ success: zod_1.z.boolean(), deck: zod_1.z.string(), counts: (0, card_states_utils_1.dueTreeCountsSchema)({ scope: "this deck and all of its descendants", total: "Total cards in this deck AND all of its descendants, including " + 'suspended and buried. Example: stats for "German" include cards in ' + '"German::Verbs" and "German::Verbs::Irregular".', note: "All four bucket counts are rolled up over descendant decks.", }), states: (0, card_states_utils_1.cardStatesSchema)("this deck and all of its subdecks"), ease: zod_1.z.object({ mean: zod_1.z.number(), median: zod_1.z.number(), min: zod_1.z.number(), max: zod_1.z.number(), count: zod_1.z.number(), buckets: zod_1.z.record(zod_1.z.string(), zod_1.z.number()), }), intervals: zod_1.z.object({ mean: zod_1.z.number(), median: zod_1.z.number(), min: zod_1.z.number(), max: zod_1.z.number(), count: zod_1.z.number(), buckets: zod_1.z.record(zod_1.z.string(), zod_1.z.number()), }), }), annotations: { title: "Deck Statistics", readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }), __param(0, (0, microservices_1.Payload)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], DeckStatsTool.prototype, "execute", null); exports.DeckStatsTool = DeckStatsTool = DeckStatsTool_1 = __decorate([ (0, mcp_nest_1.McpController)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], DeckStatsTool); //# sourceMappingURL=deck-stats.tool.js.map