UNPKG

ez-mcp

Version:

A simple Model Context Protocol (MCP) server for executing command-line tools across different shell environments (WSL, PowerShell, CMD, Bash). Easy setup for Claude Desktop, GitHub Copilot, LM Studio, and Cursor.

187 lines (183 loc) 6.72 kB
#!/usr/bin/env node import * as fs from 'fs'; import * as path from 'path'; import * as os from 'os'; // Configuration templates for different AI tools const configurations = { claude: { name: "Claude Desktop", configPath: { windows: path.join(os.homedir(), 'AppData', 'Roaming', 'Claude', 'claude_desktop_config.json'), mac: path.join(os.homedir(), 'Library', 'Application Support', 'Claude', 'claude_desktop_config.json'), linux: path.join(os.homedir(), '.config', 'Claude', 'claude_desktop_config.json') }, template: { "mcpServers": { "commandline-tools": { "command": "npx", "args": ["ez-mcp"] } } } }, copilot: { name: "GitHub Copilot (VS Code)", configPath: { windows: path.join(os.homedir(), 'AppData', 'Roaming', 'Code', 'User', 'settings.json'), mac: path.join(os.homedir(), 'Library', 'Application Support', 'Code', 'User', 'settings.json'), linux: path.join(os.homedir(), '.config', 'Code', 'User', 'settings.json') }, template: { "github.copilot.chat.experimental.mcpServers": { "commandline-tools": { "command": "npx", "args": ["ez-mcp"] } } } }, lmstudio: { name: "LM Studio", configPath: { windows: path.join(os.homedir(), 'AppData', 'Roaming', 'LMStudio', 'config.json'), mac: path.join(os.homedir(), 'Library', 'Application Support', 'LMStudio', 'config.json'), linux: path.join(os.homedir(), '.config', 'LMStudio', 'config.json') }, template: { "mcpServers": { "commandline-tools": { "command": "npx", "args": ["ez-mcp"] } } } }, cursor: { name: "Cursor IDE", configPath: { windows: path.join(os.homedir(), 'AppData', 'Roaming', 'Cursor', 'User', 'settings.json'), mac: path.join(os.homedir(), 'Library', 'Application Support', 'Cursor', 'User', 'settings.json'), linux: path.join(os.homedir(), '.config', 'Cursor', 'User', 'settings.json') }, template: { "cursor.mcpServers": { "commandline-tools": { "command": "npx", "args": ["ez-mcp"] } } } } }; function getPlatform() { const platform = os.platform(); if (platform === 'win32') return 'windows'; if (platform === 'darwin') return 'mac'; return 'linux'; } function setupTool(toolName) { const config = configurations[toolName]; if (!config) { console.log(`[ERROR] Unknown tool: ${toolName}`); console.log(`Available tools: ${Object.keys(configurations).join(', ')}`); return; } const platform = getPlatform(); const configPath = config.configPath[platform]; const configDir = path.dirname(configPath); console.log(`[SETUP] Setting up ${config.name}...`); // Create config directory if it doesn't exist if (!fs.existsSync(configDir)) { console.log(`[DIR] Creating config directory: ${configDir}`); fs.mkdirSync(configDir, { recursive: true }); } let existingConfig = {}; // Read existing config if it exists if (fs.existsSync(configPath)) { try { const content = fs.readFileSync(configPath, 'utf8'); existingConfig = JSON.parse(content); console.log(`[READ] Found existing config file`); } catch (error) { console.log(`[WARN] Existing config file is invalid JSON, creating backup...`); fs.copyFileSync(configPath, `${configPath}.backup`); existingConfig = {}; } } // Smart merge configurations - preserve existing MCP servers const mergedConfig = { ...existingConfig }; // Handle different config structures for different tools if (toolName === 'claude' || toolName === 'lmstudio') { // For Claude and LM Studio, merge into mcpServers if (!mergedConfig.mcpServers) { mergedConfig.mcpServers = {}; } mergedConfig.mcpServers = { ...mergedConfig.mcpServers, ...config.template.mcpServers }; } else if (toolName === 'copilot') { // For GitHub Copilot, merge into experimental settings if (!mergedConfig['github.copilot.chat.experimental.mcpServers']) { mergedConfig['github.copilot.chat.experimental.mcpServers'] = {}; } mergedConfig['github.copilot.chat.experimental.mcpServers'] = { ...mergedConfig['github.copilot.chat.experimental.mcpServers'], ...config.template['github.copilot.chat.experimental.mcpServers'] }; } else if (toolName === 'cursor') { // For Cursor, merge into cursor.mcpServers if (!mergedConfig['cursor.mcpServers']) { mergedConfig['cursor.mcpServers'] = {}; } mergedConfig['cursor.mcpServers'] = { ...mergedConfig['cursor.mcpServers'], ...config.template['cursor.mcpServers'] }; } // Write the updated config try { fs.writeFileSync(configPath, JSON.stringify(mergedConfig, null, 2)); console.log(`[SUCCESS] Successfully configured ${config.name}!`); console.log(`[PATH] Config file: ${configPath}`); if (toolName === 'claude' || toolName === 'cursor') { console.log(`[RESTART] Please restart ${config.name} to apply changes`); } else if (toolName === 'copilot') { console.log(`[RESTART] Please restart VS Code to apply changes`); } } catch (error) { console.log(`[ERROR] Failed to write config file: ${error}`); } } function showHelp() { console.log(` [LAUNCHER] Command-Line Tools MCP Setup Usage: npx ez-mcp setup <tool> Available tools: claude - Claude Desktop copilot - GitHub Copilot (VS Code) lmstudio - LM Studio cursor - Cursor IDE Examples: npx ez-mcp setup claude npx ez-mcp setup copilot npx ez-mcp setup lmstudio npx ez-mcp setup cursor `); } // Main execution const args = process.argv.slice(2); if (args.length === 0 || args[0] === 'help' || args[0] === '--help' || args[0] === '-h') { showHelp(); } else if (args[0] === 'setup' && args[1]) { setupTool(args[1]); } else { console.log(`[ERROR] Invalid command. Use 'setup <tool>' or 'help'`); showHelp(); }