@ankimcp/anki-mcp-server
Version:
Model Context Protocol server for Anki - enables AI assistants to interact with your Anki flashcards
95 lines • 4.5 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 StoreMediaFileTool_1;
Object.defineProperty(exports, "__esModule", { value: true });
exports.StoreMediaFileTool = 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");
const storeMediaFile_action_1 = require("./mediaActions/actions/storeMediaFile.action");
let StoreMediaFileTool = StoreMediaFileTool_1 = class StoreMediaFileTool {
ankiClient;
logger = new common_1.Logger(StoreMediaFileTool_1.name);
constructor(ankiClient) {
this.ankiClient = ankiClient;
}
async execute(params) {
try {
this.logger.log(`Executing storeMediaFile: ${params.filename}`);
const result = await (0, storeMediaFile_action_1.storeMediaFile)({
filename: params.filename,
data: params.data,
path: params.path,
url: params.url,
deleteExisting: params.deleteExisting,
}, this.ankiClient);
return result;
}
catch (error) {
this.logger.error("Failed to execute storeMediaFile", error);
return (0, anki_utils_1.createErrorResponse)(error, {
action: "storeMediaFile",
hint: "This can happen when Anki is not running or the media source (data/path/url) is invalid",
});
}
}
};
exports.StoreMediaFileTool = StoreMediaFileTool;
__decorate([
(0, mcp_nest_1.Tool)({
name: "storeMediaFile",
description: "Upload a media file to Anki's collection.media folder. Supports base64 data, absolute file paths, or URLs. By default a file with the same name is overwritten.",
parameters: zod_1.z.object({
filename: zod_1.z
.string()
.describe('Filename to store in Anki (e.g., "pronunciation.mp3", "image.jpg")'),
data: zod_1.z.string().optional().describe("Base64-encoded file content"),
path: zod_1.z
.string()
.optional()
.describe("Absolute path to a local media file (images, audio, video only)"),
url: zod_1.z.string().optional().describe("URL to download file from"),
deleteExisting: zod_1.z
.boolean()
.optional()
.default(true)
.describe("Overwrite existing file (default: true)"),
}),
outputSchema: zod_1.z.object({
success: zod_1.z.boolean(),
filename: zod_1.z.string(),
message: zod_1.z.string(),
prefixedWithUnderscore: zod_1.z.boolean(),
}),
annotations: {
title: "Store Media File",
readOnlyHint: false,
destructiveHint: true,
idempotentHint: false,
openWorldHint: true,
},
}),
__param(0, (0, microservices_1.Payload)()),
__metadata("design:type", Function),
__metadata("design:paramtypes", [Object]),
__metadata("design:returntype", Promise)
], StoreMediaFileTool.prototype, "execute", null);
exports.StoreMediaFileTool = StoreMediaFileTool = StoreMediaFileTool_1 = __decorate([
(0, mcp_nest_1.McpController)(),
__metadata("design:paramtypes", [anki_connect_client_1.AnkiConnectClient])
], StoreMediaFileTool);
//# sourceMappingURL=store-media-file.tool.js.map