UNPKG

@thelord/mcp-server-docker-npx

Version:

🐋 Docker MCP Server with NPX support - Manage Docker containers, images, networks, and volumes with natural language. Includes Docker socket access and remote Docker support via SSH/TCP.

93 lines (77 loc) 2.68 kB
#!/usr/bin/env node const { spawn } = require('child_process'); const path = require('path'); // Configuration from environment variables const DOCKER_HOST = process.env.DOCKER_HOST || 'unix:///var/run/docker.sock'; const MCP_SERVER_DOCKER_HOST = process.env.MCP_SERVER_DOCKER_HOST || DOCKER_HOST; // Set environment for the Python process const env = { ...process.env, DOCKER_HOST: MCP_SERVER_DOCKER_HOST }; // Try to run the Python MCP server function runPythonServer() { // Try different methods to run the MCP server const commands = [ ['mcp-server-docker'], // If installed globally ['python', ['-c', 'from mcp_server_docker import main; main()']], ['python3', ['-c', 'from mcp_server_docker import main; main()']], ['python', ['-m', 'mcp_server_docker']], ['python3', ['-m', 'mcp_server_docker']] ]; function tryCommand(index) { if (index >= commands.length) { console.error('Failed to start MCP server. Please ensure mcp-server-docker is installed.'); console.error('Install with: pip install mcp-server-docker'); process.exit(1); } const [cmd, args = []] = commands[index]; const child = spawn(cmd, args, { stdio: 'inherit', env: env }); child.on('error', (err) => { if (err.code === 'ENOENT') { // Command not found, try next one tryCommand(index + 1); } else { console.error(`Error running ${cmd}:`, err.message); process.exit(1); } }); child.on('exit', (code) => { if (code !== 0 && index < commands.length - 1) { // Command failed, try next one tryCommand(index + 1); } else { process.exit(code || 0); } }); } tryCommand(0); } // Handle CLI arguments for Docker host configuration if (process.argv.includes('--help') || process.argv.includes('-h')) { console.log(` MCP Server Docker - NPX Wrapper Usage: npx mcp-server-docker [options] Options: --docker-host <host> Docker host URL (default: unix:///var/run/docker.sock) --help, -h Show this help message Environment Variables: DOCKER_HOST Docker host URL MCP_SERVER_DOCKER_HOST Override Docker host for MCP server Examples: npx mcp-server-docker npx mcp-server-docker --docker-host tcp://192.168.1.100:2376 DOCKER_HOST=ssh://user@host npx mcp-server-docker `); process.exit(0); } // Parse --docker-host argument const hostIndex = process.argv.indexOf('--docker-host'); if (hostIndex !== -1 && hostIndex + 1 < process.argv.length) { env.DOCKER_HOST = process.argv[hostIndex + 1]; env.MCP_SERVER_DOCKER_HOST = process.argv[hostIndex + 1]; } runPythonServer();