UNPKG

@ankimcp/anki-mcp-server

Version:

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

88 lines • 4.31 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 GuiShowQuestionTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.GuiShowQuestionTool = 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 GuiShowQuestionTool = GuiShowQuestionTool_1 = class GuiShowQuestionTool { ankiClient; logger = new common_1.Logger(GuiShowQuestionTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async guiShowQuestion(_args) { try { this.logger.log("Showing question side of current card"); const inReview = await this.ankiClient.invoke("guiShowQuestion"); if (!inReview) { this.logger.warn("Not in review mode"); return { success: true, inReview: false, message: "Not in review mode - question cannot be shown", hint: "This tool works only while a deck is being reviewed in Anki.", }; } this.logger.log("Question side shown"); return { success: true, inReview: true, message: "Question side is now displayed", hint: "The question is shown in Anki's review window.", }; } catch (error) { this.logger.error("Failed to show question", error); return (0, anki_utils_1.createErrorResponse)(error, { hint: "This can happen when Anki is not running, its GUI is not visible, or it is not in review mode", }); } } }; exports.GuiShowQuestionTool = GuiShowQuestionTool; __decorate([ (0, mcp_nest_1.Tool)({ name: "guiShowQuestion", description: "Flips the card on the Anki desktop app's review screen back to its question side, on the user's screen. Does not return the card's content and does not record a review. " + "inReview is false (and nothing changes) when Anki is not in review mode. For when the user asks to show the question in Anki; the review tools here (present_card, rate_card) run a review without the Anki window.", parameters: zod_1.z.object({}), outputSchema: zod_1.z.object({ success: zod_1.z.boolean(), inReview: zod_1.z.boolean(), message: zod_1.z.string(), hint: zod_1.z.string(), }), annotations: { title: "Show Card Question", readOnlyHint: false, destructiveHint: false, idempotentHint: true, openWorldHint: false, }, }), __param(0, (0, microservices_1.Payload)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], GuiShowQuestionTool.prototype, "guiShowQuestion", null); exports.GuiShowQuestionTool = GuiShowQuestionTool = GuiShowQuestionTool_1 = __decorate([ (0, mcp_nest_1.McpController)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], GuiShowQuestionTool); //# sourceMappingURL=gui-show-question.tool.js.map