UNPKG

@ankimcp/anki-mcp-server

Version:

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

105 lines • 5.16 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 GuiCurrentCardTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.GuiCurrentCardTool = 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"); let GuiCurrentCardTool = GuiCurrentCardTool_1 = class GuiCurrentCardTool { ankiClient; logger = new common_1.Logger(GuiCurrentCardTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async guiCurrentCard(_args) { try { this.logger.log("Getting current card information from GUI"); const cardInfo = await this.ankiClient.invoke("guiCurrentCard"); if (!cardInfo) { this.logger.log("Not currently in review mode"); return { success: true, cardInfo: null, inReview: false, message: "Not currently in review mode", hint: "Current card information exists only while a deck is being reviewed in Anki.", }; } this.logger.log(`Retrieved current card: ${cardInfo.cardId} from deck "${cardInfo.deckName}"`); return { success: true, cardInfo, inReview: true, message: `Current card: ${cardInfo.cardId} from deck "${cardInfo.deckName}"`, hint: "This is the card currently shown in Anki's review window.", }; } catch (error) { this.logger.error("Failed to get current card information", error); return (0, anki_utils_1.createErrorResponse)(error, { hint: "This can happen when Anki is not running or its GUI is not visible", }); } } }; exports.GuiCurrentCardTool = GuiCurrentCardTool; __decorate([ (0, mcp_nest_1.Tool)({ name: "guiCurrentCard", description: "Reads the card currently shown in the Anki desktop app's review screen: question, answer, fields, deck, note type and answer buttons. Changes nothing on screen. " + "The result always includes the answer, so calling it while the user is reviewing in Anki reveals the answer before they respond; present_card can show a card without its answer. " + "When Anki is not in review mode, AnkiConnect reports an error ('Gui review is not currently active.').", parameters: zod_1.z.object({}), outputSchema: zod_1.z.object({ success: zod_1.z.boolean(), cardInfo: zod_1.z .object({ answer: zod_1.z.string(), question: zod_1.z.string(), deckName: zod_1.z.string(), modelName: zod_1.z.string(), cardId: zod_1.z.number(), buttons: zod_1.z.array(zod_1.z.number()), nextReviews: zod_1.z.array(zod_1.z.string()), fields: zod_1.z .record(zod_1.z.string(), zod_1.z.object({ value: zod_1.z.string(), order: zod_1.z.number() })) .optional(), }) .nullable(), inReview: zod_1.z.boolean(), message: zod_1.z.string(), hint: zod_1.z.string(), }), annotations: { title: "Get Current Review Card", 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) ], GuiCurrentCardTool.prototype, "guiCurrentCard", null); exports.GuiCurrentCardTool = GuiCurrentCardTool = GuiCurrentCardTool_1 = __decorate([ (0, mcp_nest_1.McpController)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], GuiCurrentCardTool); //# sourceMappingURL=gui-current-card.tool.js.map