UNPKG

@ankimcp/anki-mcp-server

Version:

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

101 lines • 4.85 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 ModelTemplatesTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelTemplatesTool = 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 ModelTemplatesTool = ModelTemplatesTool_1 = class ModelTemplatesTool { ankiClient; logger = new common_1.Logger(ModelTemplatesTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async modelTemplates({ modelName }) { try { this.logger.log(`Retrieving templates for model: ${modelName}`); const templates = await this.ankiClient.invoke("modelTemplates", { modelName: modelName, }); if (!templates || Object.keys(templates).length === 0) { this.logger.warn(`No templates found for model: ${modelName}`); return (0, anki_utils_1.createErrorResponse)(new Error(`Model "${modelName}" not found or has no card templates`), { modelName: modelName, hint: "modelNames lists the available models", }); } const cardCount = Object.keys(templates).length; this.logger.log(`Retrieved ${cardCount} templates for model ${modelName}`); return { success: true, modelName: modelName, templates: templates, message: `Retrieved ${cardCount} card template(s) for model "${modelName}"`, hint: "updateModelTemplates replaces the Front/Back HTML of these card templates", }; } catch (error) { this.logger.error(`Failed to retrieve templates for model ${modelName}`, error); return (0, anki_utils_1.createErrorResponse)(error, { modelName: modelName, hint: "This can happen when Anki is not running or the model name is wrong", }); } } }; exports.ModelTemplatesTool = ModelTemplatesTool; __decorate([ (0, mcp_nest_1.Tool)({ name: "modelTemplates", description: "Get the card templates (Front and Back HTML) for a specific note type (model). " + "Returns each card template's Front and Back HTML content. " + "Use this before updateModelTemplates to see current templates and plan changes.", parameters: zod_1.z.object({ modelName: zod_1.z .string() .min(1) .describe("The name of the model/note type to get templates for"), }), outputSchema: zod_1.z.object({ success: zod_1.z.boolean(), modelName: zod_1.z.string(), templates: zod_1.z.record(zod_1.z.string(), zod_1.z.object({ Front: zod_1.z.string(), Back: zod_1.z.string(), })), message: zod_1.z.string(), hint: zod_1.z.string(), }), annotations: { title: "Get Note Type Templates", 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) ], ModelTemplatesTool.prototype, "modelTemplates", null); exports.ModelTemplatesTool = ModelTemplatesTool = ModelTemplatesTool_1 = __decorate([ (0, mcp_nest_1.McpController)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], ModelTemplatesTool); //# sourceMappingURL=model-templates.tool.js.map