UNPKG

@ankimcp/anki-mcp-server

Version:

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

88 lines • 4.17 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 GuiUndoTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.GuiUndoTool = 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 GuiUndoTool = GuiUndoTool_1 = class GuiUndoTool { ankiClient; logger = new common_1.Logger(GuiUndoTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async guiUndo(_args) { try { this.logger.log("Undoing last action in Anki"); const success = await this.ankiClient.invoke("guiUndo"); if (!success) { this.logger.warn("Nothing to undo"); return { success: true, undone: false, message: "Nothing to undo", hint: "There are no recent actions to undo in Anki.", }; } this.logger.log("Last action undone successfully"); return { success: true, undone: true, message: "Last action undone successfully", hint: "The previous action has been reversed; the Anki GUI shows the result.", }; } catch (error) { this.logger.error("Failed to undo action", error); return (0, anki_utils_1.createErrorResponse)(error, { hint: "This can happen when Anki is not running or its GUI is not visible", }); } } }; exports.GuiUndoTool = GuiUndoTool; __decorate([ (0, mcp_nest_1.Tool)({ name: "guiUndo", description: "Triggers Anki's Edit > Undo in the desktop app, reverting whatever Anki's undo history holds as the most recent action — which may be something the user did in Anki rather than a change made through this server, and some AnkiConnect changes (e.g. updateNoteFields) are not recorded in that history at all. " + "AnkiConnect reports success once the command is issued, even when there was nothing to undo. For when the user asks to undo something in Anki.", parameters: zod_1.z.object({}), outputSchema: zod_1.z.object({ success: zod_1.z.boolean(), undone: zod_1.z.boolean(), message: zod_1.z.string(), hint: zod_1.z.string(), }), annotations: { title: "Undo Last Action", readOnlyHint: false, destructiveHint: true, idempotentHint: false, openWorldHint: false, }, }), __param(0, (0, microservices_1.Payload)()), __metadata("design:type", Function), __metadata("design:paramtypes", [Object]), __metadata("design:returntype", Promise) ], GuiUndoTool.prototype, "guiUndo", null); exports.GuiUndoTool = GuiUndoTool = GuiUndoTool_1 = __decorate([ (0, mcp_nest_1.McpController)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], GuiUndoTool); //# sourceMappingURL=gui-undo.tool.js.map