UNPKG

@ankimcp/anki-mcp-server

Version:

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

115 lines • 5.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 ModelStylingTool_1; Object.defineProperty(exports, "__esModule", { value: true }); exports.ModelStylingTool = 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 ModelStylingTool = ModelStylingTool_1 = class ModelStylingTool { ankiClient; logger = new common_1.Logger(ModelStylingTool_1.name); constructor(ankiClient) { this.ankiClient = ankiClient; } async modelStyling({ modelName }) { try { this.logger.log(`Retrieving CSS styling for model: ${modelName}`); const styling = await this.ankiClient.invoke("modelStyling", { modelName: modelName, }); if (!styling || !styling.css) { this.logger.warn(`No styling found for model: ${modelName}`); return (0, anki_utils_1.createErrorResponse)(new Error(`Model "${modelName}" not found or has no styling`), { modelName: modelName, hint: "modelNames lists the available models", }); } const css = styling.css; const cssLength = css.length; const hasCardClass = css.includes(".card"); const hasFrontClass = css.includes(".front"); const hasBackClass = css.includes(".back"); const hasClozeClass = css.includes(".cloze"); this.logger.log(`Retrieved CSS styling for model ${modelName} (${cssLength} chars)`); return { success: true, modelName: modelName, css: css, cssInfo: { length: cssLength, hasCardStyling: hasCardClass, hasFrontStyling: hasFrontClass, hasBackStyling: hasBackClass, hasClozeStyling: hasClozeClass, }, message: `Retrieved CSS styling for model "${modelName}"`, hint: "This CSS is automatically applied when cards of this type are rendered in Anki", }; } catch (error) { this.logger.error(`Failed to retrieve styling 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.ModelStylingTool = ModelStylingTool; __decorate([ (0, mcp_nest_1.Tool)({ name: "modelStyling", description: "Get the CSS styling for a specific note type (model). This CSS is used when rendering cards of this type.", parameters: zod_1.z.object({ modelName: zod_1.z .string() .min(1) .describe("The name of the model/note type to get styling for"), }), outputSchema: zod_1.z.object({ success: zod_1.z.boolean(), modelName: zod_1.z.string(), css: zod_1.z.string(), cssInfo: zod_1.z.object({ length: zod_1.z.number(), hasCardStyling: zod_1.z.boolean(), hasFrontStyling: zod_1.z.boolean(), hasBackStyling: zod_1.z.boolean(), hasClozeStyling: zod_1.z.boolean(), }), message: zod_1.z.string(), hint: zod_1.z.string(), }), annotations: { title: "Get Note Type CSS", 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) ], ModelStylingTool.prototype, "modelStyling", null); exports.ModelStylingTool = ModelStylingTool = ModelStylingTool_1 = __decorate([ (0, mcp_nest_1.McpController)(), __metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient]) ], ModelStylingTool); //# sourceMappingURL=model-styling.tool.js.map