UNPKG

anki-mcp-http

Version:

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

74 lines 3.87 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 GuiShowAnswerTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.GuiShowAnswerTool = void 0; const common_1 = require("@nestjs/common"); const mcp_nest_1 = require("@rekog/mcp-nest"); const zod_1 = require("zod"); const anki_connect_client_1 = require("../../../clients/anki-connect.client"); const anki_utils_1 = require("../../../utils/anki.utils"); let GuiShowAnswerTool = GuiShowAnswerTool_1 = class GuiShowAnswerTool { ankiClient; logger = new common_1.Logger(GuiShowAnswerTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async guiShowAnswer(_args, context) { try { this.logger.log('Showing answer side of current card'); await context.reportProgress({ progress: 50, total: 100 }); const inReview = await this.ankiClient.invoke('guiShowAnswer'); await context.reportProgress({ progress: 100, total: 100 }); if (!inReview) { this.logger.warn('Not in review mode'); return (0, anki_utils_1.createSuccessResponse)({ success: true, inReview: false, message: 'Not in review mode - answer cannot be shown', hint: 'Start reviewing a deck in Anki to use this tool.', }); } this.logger.log('Answer side shown'); return (0, anki_utils_1.createSuccessResponse)({ success: true, inReview: true, message: 'Answer side is now displayed', hint: 'Use guiCurrentCard to get full card details including the answer content.', }); } catch (error) { this.logger.error('Failed to show answer', error); return (0, anki_utils_1.createErrorResponse)(error, { hint: 'Make sure Anki is running, GUI is visible, and you are in review mode', }); } } }; exports.GuiShowAnswerTool = GuiShowAnswerTool; __decorate([ (0, mcp_nest_1.Tool)({ name: 'guiShowAnswer', description: 'Show the answer side of the current card in review mode. Returns true if in review mode, false otherwise. ' + 'CRITICAL: This tool is ONLY for note editing/creation workflows when user needs to view the answer side to verify content. ' + 'NEVER use this for conducting review sessions. Use the dedicated review tools (present_card) instead. ' + 'IMPORTANT: Only use when user explicitly requests showing the answer.', parameters: zod_1.z.object({}), }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], GuiShowAnswerTool.prototype, "guiShowAnswer", null); exports.GuiShowAnswerTool = GuiShowAnswerTool = GuiShowAnswerTool_1 = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], GuiShowAnswerTool); //# sourceMappingURL=gui-show-answer.tool.js.map