UNPKG

anki-mcp-http

Version:

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

79 lines 4.03 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 GuiEditNoteTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.GuiEditNoteTool = 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 GuiEditNoteTool = GuiEditNoteTool_1 = class GuiEditNoteTool { ankiClient; logger = new common_1.Logger(GuiEditNoteTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async guiEditNote({ note }, context) { try { this.logger.log(`Opening note editor for note ${note}`); await context.reportProgress({ progress: 50, total: 100 }); await this.ankiClient.invoke('guiEditNote', { note }); await context.reportProgress({ progress: 100, total: 100 }); this.logger.log(`Note editor opened for note ${note}`); return (0, anki_utils_1.createSuccessResponse)({ success: true, noteId: note, message: `Note editor opened for note ${note}`, hint: 'The user can now edit the note fields, tags, and cards in the Anki GUI. Changes will be saved when they close the editor.', }); } catch (error) { this.logger.error('Failed to open note editor', error); if (error instanceof Error) { if (error.message.includes('not found') || error.message.includes('invalid')) { return (0, anki_utils_1.createErrorResponse)(error, { noteId: note, hint: 'Note not found. Use findNotes to search for notes and get valid note IDs.', }); } } return (0, anki_utils_1.createErrorResponse)(error, { noteId: note, hint: 'Make sure Anki is running and the note ID is valid', }); } } }; exports.GuiEditNoteTool = GuiEditNoteTool; __decorate([ (0, mcp_nest_1.Tool)({ name: 'guiEditNote', description: 'Open Anki note editor dialog for a specific note ID. Allows manual editing of note fields, tags, and cards in the GUI. ' + 'IMPORTANT: Only use when user explicitly requests editing a note via GUI. ' + 'This tool is for note editing workflows when user wants to manually edit in Anki interface. ' + 'For programmatic editing, use updateNoteFields instead.', parameters: zod_1.z.object({ note: zod_1.z .number() .positive() .describe('Note ID to edit (get from findNotes or notesInfo)'), }), }), __metadata("design:type", Function), __metadata("design:paramtypes", [Object, Object]), __metadata("design:returntype", Promise) ], GuiEditNoteTool.prototype, "guiEditNote", null); exports.GuiEditNoteTool = GuiEditNoteTool = GuiEditNoteTool_1 = __decorate([ (0, common_1.Injectable)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], GuiEditNoteTool); //# sourceMappingURL=gui-edit-note.tool.js.map