UNPKG

mcp-activity-tracker

Version:

MCP server for automatic worklog creation based on computer activity monitoring

116 lines (93 loc) • 3.05 kB
#!/usr/bin/env node const { spawn } = require('child_process'); const path = require('path'); const fs = require('fs'); function findBestPython() { return new Promise((resolve) => { const pythonVersions = ['python3.11', 'python3.10', 'python3.9', 'python3']; function tryNext(index) { if (index >= pythonVersions.length) { resolve(null); return; } const python = spawn(pythonVersions[index], ['--version']); python.on('close', (code) => { if (code === 0) { resolve(pythonVersions[index]); } else { tryNext(index + 1); } }); python.on('error', () => { tryNext(index + 1); }); } tryNext(0); }); } function installPythonDeps(pythonCmd) { return new Promise((resolve, reject) => { const requirementsPath = path.join(__dirname, '..', 'requirements.txt'); console.log('šŸ“¦ Installing Python dependencies...'); const pip = spawn(pythonCmd, ['-m', 'pip', 'install', '-r', requirementsPath], { stdio: 'inherit' }); pip.on('close', (code) => { if (code === 0) { console.log('āœ… Python dependencies installed successfully'); resolve(); } else { reject(new Error(`pip install failed with code ${code}`)); } }); }); } async function main() { console.log('šŸš€ Starting MCP Activity Tracker...'); // Find best Python version const pythonCmd = await findBestPython(); if (!pythonCmd) { console.error('āŒ Python 3.9+ is required but not found'); console.error('Please install Python 3.9 or higher and try again'); process.exit(1); } console.log(`āœ… Found Python: ${pythonCmd}`); // Install Python dependencies try { await installPythonDeps(pythonCmd); } catch (error) { console.error('āŒ Failed to install Python dependencies:', error.message); console.error('Please run: pip install fastmcp psutil pynput plyer browser-history watchdog'); process.exit(1); } // Path to the Python script const scriptPath = path.join(__dirname, '..', 'src', 'mcp_activity_tracker.py'); if (!fs.existsSync(scriptPath)) { console.error('āŒ MCP server script not found:', scriptPath); process.exit(1); } console.log('šŸ“” Starting MCP Activity Tracker server...'); // Start the Python MCP server const mcpServer = spawn(pythonCmd, [scriptPath], { stdio: 'inherit' }); mcpServer.on('close', (code) => { if (code !== 0) { console.error(`āŒ MCP server exited with code ${code}`); process.exit(code); } }); mcpServer.on('error', (err) => { console.error('āŒ Failed to start MCP server:', err.message); process.exit(1); }); // Handle process termination process.on('SIGINT', () => { console.log('\nšŸ›‘ Shutting down MCP Activity Tracker...'); mcpServer.kill('SIGINT'); }); process.on('SIGTERM', () => { mcpServer.kill('SIGTERM'); }); } main().catch(console.error);