anki-mcp-http
Version:
Model Context Protocol server for Anki - enables AI assistants to interact with your Anki flashcards
82 lines (77 loc) • 3.31 kB
JavaScript
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.checkForUpdates = checkForUpdates;
exports.parseCliArgs = parseCliArgs;
exports.displayStartupBanner = displayStartupBanner;
const commander_1 = require("commander");
const fs_1 = require("fs");
const path_1 = require("path");
const update_notifier_1 = __importDefault(require("update-notifier"));
function getPackageJson() {
try {
return JSON.parse((0, fs_1.readFileSync)((0, path_1.join)(__dirname, '../package.json'), 'utf-8'));
}
catch {
return { version: '0.0.0', name: 'anki-mcp-http' };
}
}
function getVersion() {
return getPackageJson().version;
}
function checkForUpdates() {
(0, update_notifier_1.default)({ pkg: getPackageJson() }).notify();
}
function parseCliArgs() {
const program = new commander_1.Command();
program
.name('ankimcp')
.description('AnkiMCP HTTP Server - Model Context Protocol server for Anki')
.version(getVersion())
.option('-p, --port <number>', 'Port to listen on', '3000')
.option('-h, --host <address>', 'Host to bind to', '127.0.0.1')
.option('-a, --anki-connect <url>', 'AnkiConnect URL', 'http://localhost:8765')
.addHelpText('after', `
Examples:
$ ankimcp # Use defaults
$ ankimcp --port 8080 # Custom port
$ ankimcp --host 0.0.0.0 --port 3000 # Listen on all interfaces
$ ankimcp --anki-connect http://localhost:8765
Usage with ngrok:
1. Start ankimcp in one terminal
2. In another terminal: ngrok http 3000
3. Share the ngrok URL with your AI assistant
`);
program.parse();
const options = program.opts();
return {
port: parseInt(options.port.toString(), 10),
host: options.host,
ankiConnect: options.ankiConnect,
};
}
function displayStartupBanner(options) {
const version = getVersion();
const title = `AnkiMCP HTTP Server v${version}`;
const padding = Math.floor((64 - title.length) / 2);
const paddedTitle = ' '.repeat(padding) + title + ' '.repeat(64 - padding - title.length);
console.log(`
╔════════════════════════════════════════════════════════════════╗
║${paddedTitle}║
╚════════════════════════════════════════════════════════════════╝
🚀 Server running on: http://${options.host}:${options.port}
🔌 AnkiConnect URL: ${options.ankiConnect}
Configuration:
• Port: ${options.port} (override: --port 8080)
• Host: ${options.host} (override: --host 0.0.0.0)
• AnkiConnect: ${options.ankiConnect}
(override: --anki-connect http://localhost:8765)
Usage with ngrok:
1. In another terminal: ngrok http ${options.port}
2. Share the ngrok URL with your AI assistant
Run 'ankimcp --help' for more options.
`);
}
//# sourceMappingURL=cli.js.map
;