@ankimcp/anki-mcp-server
Version:
Model Context Protocol server for Anki - enables AI assistants to interact with your Anki flashcards
88 lines • 4.25 kB
JavaScript
;
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 GuiShowAnswerTool_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.GuiShowAnswerTool = 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 GuiShowAnswerTool = GuiShowAnswerTool_1 = class GuiShowAnswerTool {
ankiClient;
logger = new common_1.Logger(GuiShowAnswerTool_1.name);
constructor(ankiClient) {
this.ankiClient = ankiClient;
}
async guiShowAnswer(_args) {
try {
this.logger.log("Showing answer side of current card");
const inReview = await this.ankiClient.invoke("guiShowAnswer");
if (!inReview) {
this.logger.warn("Not in review mode");
return {
success: true,
inReview: false,
message: "Not in review mode - answer cannot be shown",
hint: "This tool works only while a deck is being reviewed in Anki.",
};
}
this.logger.log("Answer side shown");
return {
success: true,
inReview: true,
message: "Answer side is now displayed",
hint: "The answer is shown in Anki's review window.",
};
}
catch (error) {
this.logger.error("Failed to show answer", error);
return (0, anki_utils_1.createErrorResponse)(error, {
hint: "This can happen when Anki is not running, its GUI is not visible, or it is not in review mode",
});
}
}
};
exports.GuiShowAnswerTool = GuiShowAnswerTool;
__decorate([
(0, mcp_nest_1.Tool)({
name: "guiShowAnswer",
description: "Flips the card on the Anki desktop app's review screen to its answer side, on the user's screen. Does not return the card's content and does not record a review. " +
"inReview is false (and nothing changes) when Anki is not in review mode. For when the user asks to reveal the answer in Anki; the review tools here (present_card, rate_card) run a review without the Anki window.",
parameters: zod_1.z.object({}),
outputSchema: zod_1.z.object({
success: zod_1.z.boolean(),
inReview: zod_1.z.boolean(),
message: zod_1.z.string(),
hint: zod_1.z.string(),
}),
annotations: {
title: "Show Card Answer",
readOnlyHint: false,
destructiveHint: false,
idempotentHint: true,
openWorldHint: false,
},
}),
__param(0, (0, microservices_1.Payload)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], GuiShowAnswerTool.prototype, "guiShowAnswer", null);
exports.GuiShowAnswerTool = GuiShowAnswerTool = GuiShowAnswerTool_1 = __decorate([
(0, mcp_nest_1.McpController)(),
__metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient])
], GuiShowAnswerTool);
//# sourceMappingURL=gui-show-answer.tool.js.map