UNPKG

@ever_cheng/memory-task-mcp

Version:

Memory and task management MCP Server

125 lines 4.75 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || (function () { var ownKeys = function(o) { ownKeys = Object.getOwnPropertyNames || function (o) { var ar = []; for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k; return ar; }; return ownKeys(o); }; return function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]); __setModuleDefault(result, mod); return result; }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.defaultConfig = void 0; exports.getConfig = getConfig; /** * Configuration Management */ const path = __importStar(require("path")); /** * Parse command line arguments for data directory */ function parseDataDirFromArgs() { const args = process.argv.slice(2); for (let i = 0; i < args.length; i++) { const arg = args[i]; // Handle --data-dir=<path> format if (arg.startsWith('--data-dir=')) { const value = arg.split('=')[1]; return value && value.trim() ? value.trim() : null; } // Handle --data-dir <path> format if (arg === '--data-dir' && i + 1 < args.length) { const value = args[i + 1]; return value && value.trim() ? value.trim() : null; } } return null; } /** * Default Configuration */ exports.defaultConfig = { dataDir: parseDataDirFromArgs() || process.env.DATA_DIR || path.join(process.cwd(), 'mem_task_data'), memoriesPath: '', // Will be set in getConfig tasksPath: '', // Will be set in getConfig goalsPath: '', // Will be set in getConfig cache: { memory: { maxSize: 1000, // Cache up to 1000 memory items ttlMs: 3600000, // Cache expiration time: 1 hour }, task: { maxSize: 500, // Cache up to 500 task items ttlMs: 3600000, // Cache expiration time: 1 hour }, goal: { maxSize: 500, // Cache up to 500 goals ttlMs: 3600000, // Cache expiration time: 1 hour }, }, logging: { level: 'debug', format: 'simple', }, }; /** * Get System Configuration */ function getConfig(userId) { const config = { ...exports.defaultConfig }; // 從環境變數或參數獲取 user_id,預設為 'default' const currentUserId = userId || process.env.USER_ID || 'default'; // 構建多租戶路徑 const userDataDir = path.join(config.dataDir, currentUserId); // Set paths with multi-tenant support config.memoriesPath = path.join(userDataDir, 'memories'); config.tasksPath = path.join(userDataDir, 'tasks'); config.goalsPath = path.join(userDataDir, 'goals'); // 設置多租戶 ChromaDB collection name config.chromaCollectionName = `memtask_memories_${currentUserId}`; // Override configuration from environment variables if (process.env.MCP_CACHE_MEMORY_MAX_SIZE) { config.cache.memory.maxSize = parseInt(process.env.MCP_CACHE_MEMORY_MAX_SIZE, 10); } if (process.env.MCP_CACHE_MEMORY_TTL) { config.cache.memory.ttlMs = parseInt(process.env.MCP_CACHE_MEMORY_TTL, 10); } if (process.env.MCP_CACHE_TASK_MAX_SIZE) { config.cache.task.maxSize = parseInt(process.env.MCP_CACHE_TASK_MAX_SIZE, 10); } if (process.env.MCP_CACHE_TASK_TTL) { config.cache.task.ttlMs = parseInt(process.env.MCP_CACHE_TASK_TTL, 10); } if (process.env.MCP_LOG_LEVEL && ['debug', 'info', 'warn', 'error'].includes(process.env.MCP_LOG_LEVEL)) { config.logging.level = process.env.MCP_LOG_LEVEL; } if (process.env.MCP_LOG_FORMAT && ['simple', 'json'].includes(process.env.MCP_LOG_FORMAT)) { config.logging.format = process.env.MCP_LOG_FORMAT; } return config; } //# sourceMappingURL=config.js.map