UNPKG

@openmemory/install

Version:

OpenMemory MCP server installation tool

140 lines (135 loc) 4.41 kB
#!/usr/bin/env node import { clientNames, logger, readConfig, writeAugmentVSCodeSettingsFromObject, writeConfig } from "./chunk-24QWB3NU.js"; // src/index.ts import yargs from "yargs"; import { hideBin } from "yargs/helpers"; // src/commands/install.ts import pc from "picocolors"; var { green, red } = pc; function builder(yargs2) { return yargs2.option("name", { type: "string", description: 'Name of the server (defaults to "openmemory")', default: "openmemory" }).option("client", { type: "string", description: "Client to use for installation", demandOption: true, choices: clientNames }).option("env", { type: "string", description: "Environment variables as key=value pairs (can be used multiple times). OPENMEMORY_API_KEY is required.", array: true }); } async function handler(argv) { if (!argv.client || !clientNames.includes(argv.client)) { logger.error(`Invalid client: ${argv.client}. Available clients: ${clientNames.join(", ")}`); return; } const envVars = {}; if (argv.env && argv.env.length > 0) { for (const envVar of argv.env) { const [key, ...valueParts] = envVar.split("="); if (key && valueParts.length > 0) { envVars[key] = valueParts.join("="); } else { logger.warn(`Invalid environment variable format: ${envVar}. Expected KEY=VALUE format.`); } } } if (!envVars.OPENMEMORY_API_KEY) { logger.error("OPENMEMORY_API_KEY environment variable is required. Use --env OPENMEMORY_API_KEY=your_key"); return; } envVars.CLIENT_NAME = argv.client; const name = argv.name || "openmemory"; const ready = await logger.prompt( green(`Are you ready to install OpenMemory MCP server in ${argv.client}?`), { type: "confirm" } ); if (ready) { try { if (argv.client === "augment") { writeAugmentVSCodeSettingsFromObject({ name, command: "npx", args: ["-y", "openmemory"], env: envVars }); } const config = readConfig(argv.client); if (argv.client !== "augment") { const config2 = readConfig(argv.client); config2.mcpServers[name] = { command: "npx", args: ["-y", "openmemory"], env: envVars }; writeConfig(config2, argv.client); } logger.box(green(`Successfully installed OpenMemory MCP server in ${argv.client}.`)); } catch (e) { logger.error(red(e.message)); } } } // src/commands/local.ts import pc2 from "picocolors"; var { green: green2, red: red2 } = pc2; function builder2(yargs2) { return yargs2.positional("url", { type: "string", description: "URL for local MCP server", demandOption: true }).option("client", { type: "string", description: "Client to use for installation", demandOption: true, choices: clientNames }); } async function handler2(argv) { if (!argv.client || !clientNames.includes(argv.client)) { logger.error(`Invalid client: ${argv.client}. Available clients: ${clientNames.join(", ")}`); return; } const name = "openmemory-local"; try { if (argv.client === "augment") { import("./client-config-KQCUURPG.js").then(({ writeAugmentVSCodeSettingsFromObject: writeAugmentVSCodeSettingsFromObject2 }) => { writeAugmentVSCodeSettingsFromObject2({ name, command: "npx", args: ["-y", "supergateway", "--sse", argv.url] }); logger.box(green2(`Successfully installed local MCP server in augment client.`)); }); return; } const config = readConfig(argv.client); config.mcpServers[name] = { command: "npx", args: ["-y", "supergateway", "--sse", argv.url] }; writeConfig(config, argv.client); logger.box(green2(`Successfully installed local MCP server in ${argv.client}.`)); } catch (e) { logger.error(red2(e.message)); } } // src/index.ts var parser = yargs(hideBin(process.argv)).scriptName("@openmemory/install").command("install", "Install OpenMemory MCP server", builder, handler).command("local <url>", "Install a local dev MCP server", builder2, handler2).help().alias("h", "help").version().alias("v", "version"); if (!process.argv.slice(2).length || process.argv[2].startsWith("--")) { parser.parse(["install", ...process.argv.slice(2)]); } else { parser.parse(); }