@ankimcp/anki-mcp-server
Version:
Model Context Protocol server for Anki - enables AI assistants to interact with your Anki flashcards
76 lines • 3.63 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 SyncTool_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SyncTool = 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 SyncTool = SyncTool_1 = class SyncTool {
ankiClient;
logger = new common_1.Logger(SyncTool_1.name);
constructor(ankiClient) {
this.ankiClient = ankiClient;
}
async sync(_args) {
try {
this.logger.log("Synchronizing Anki collection with AnkiWeb");
await this.ankiClient.invoke("sync");
this.logger.log("Anki sync completed successfully");
return {
success: true,
message: "Successfully synchronized with AnkiWeb",
timestamp: new Date().toISOString(),
};
}
catch (error) {
this.logger.error("Failed to sync with AnkiWeb", error);
return (0, anki_utils_1.createErrorResponse)(error, {
hint: "This can happen when Anki is not running or the Anki desktop app is not logged into AnkiWeb",
});
}
}
};
exports.SyncTool = SyncTool;
__decorate([
(0, mcp_nest_1.Tool)({
name: "sync",
description: "Synchronizes the local Anki collection with AnkiWeb (network call; needs the Anki desktop app to be logged in to AnkiWeb). The other tools work on the local collection (apart from media downloads from URLs passed to storeMediaFile or updateNoteFields), so reviews made on other devices show up only after a sync, and changes made here reach other devices only after a sync.",
parameters: zod_1.z.object({}),
outputSchema: zod_1.z.object({
success: zod_1.z.boolean(),
message: zod_1.z.string(),
timestamp: zod_1.z.string(),
}),
annotations: {
title: "Sync with AnkiWeb",
readOnlyHint: false,
destructiveHint: false,
idempotentHint: true,
openWorldHint: true,
},
}),
__param(0, (0, microservices_1.Payload)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], SyncTool.prototype, "sync", null);
exports.SyncTool = SyncTool = SyncTool_1 = __decorate([
(0, mcp_nest_1.McpController)(),
__metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient])
], SyncTool);
//# sourceMappingURL=sync.tool.js.map