setup.pyโข7.46 kB
#!/usr/bin/env python3
"""
Setup script for Awesome Linux MCP Server
Helps users configure the server for their environment.
"""
import os
import sys
import json
import subprocess
from pathlib import Path
def check_python_version():
"""Check if Python version is compatible."""
if sys.version_info < (3, 8):
print("โ Python 3.8+ is required")
sys.exit(1)
print(f"โ
Python {sys.version.split()[0]} detected")
def check_dependencies():
"""Check if required Python packages are installed."""
required_packages = [
'mcp',
'paramiko',
'pyppeteer',
'psutil'
]
missing_packages = []
for package in required_packages:
try:
__import__(package.replace('-', '_'))
print(f"โ
{package} is installed")
except ImportError:
missing_packages.append(package)
print(f"โ {package} is missing")
if missing_packages:
print(f"\n๐ฆ Installing missing packages: {', '.join(missing_packages)}")
try:
subprocess.check_call([
sys.executable, '-m', 'pip', 'install', *missing_packages
])
print("โ
Dependencies installed successfully")
except subprocess.CalledProcessError:
print("โ Failed to install dependencies. Please install manually:")
print(f"pip install {' '.join(missing_packages)}")
return False
return True
def check_chrome():
"""Check if Chrome/Chromium is available for browser automation."""
try:
result = subprocess.run(
['which', 'google-chrome'],
capture_output=True,
text=True
)
if result.returncode == 0:
print("โ
Google Chrome found")
return True
except:
pass
try:
result = subprocess.run(
['which', 'chromium-browser'],
capture_output=True,
text=True
)
if result.returncode == 0:
print("โ
Chromium found")
return True
except:
pass
print("โ ๏ธ Chrome/Chromium not found. Browser automation may not work.")
print(" Install Chrome/Chromium or set BROWSER_HEADLESS=false to see browser window.")
return False
def create_env_file():
"""Create .env file from template."""
env_file = Path('.env')
template_file = Path('config.example.env')
if env_file.exists():
response = input("โ ๏ธ .env file already exists. Overwrite? (y/N): ")
if response.lower() != 'y':
print("โญ๏ธ Skipping .env creation")
return
if not template_file.exists():
print("โ config.example.env template not found")
return
try:
env_file.write_text(template_file.read_text())
print("โ
.env file created from template")
print("๐ Please edit .env with your SSH configuration")
except Exception as e:
print(f"โ Failed to create .env file: {e}")
def setup_claude_config():
"""Help set up Claude Desktop configuration."""
print("\n๐ค Claude Desktop Configuration")
print("-" * 40)
# Detect OS and config path
home = Path.home()
if sys.platform == "darwin": # macOS
config_path = home / "Library" / "Application Support" / "Claude" / "claude_desktop_config.json"
elif sys.platform == "win32": # Windows
config_path = home / "AppData" / "Roaming" / "Claude" / "claude_desktop_config.json"
else: # Linux
config_path = home / ".config" / "Claude" / "claude_desktop_config.json"
print(f"๐ Config file location: {config_path}")
if not config_path.exists():
print("โน๏ธ Claude Desktop config file doesn't exist yet")
print(" It will be created when you first run Claude Desktop")
return
# Read existing config
try:
config = json.loads(config_path.read_text())
except:
config = {"mcpServers": {}}
# Check if our server is already configured
if "linux-server" in config.get("mcpServers", {}):
print("โ
Linux MCP server already configured in Claude Desktop")
return
# Ask user if they want to add the configuration
response = input("โ Add Linux MCP server to Claude Desktop config? (y/N): ")
if response.lower() != 'y':
print("โญ๏ธ Skipping Claude Desktop configuration")
return
# Get the absolute path to the server
server_path = Path(__file__).parent / "linux_mcp_server.py"
server_path_str = str(server_path.absolute())
# Create server configuration
server_config = {
"command": sys.executable,
"args": [server_path_str],
"env": {
"SSH_HOST": os.environ.get("SSH_HOST", "your-server.com"),
"SSH_USER": os.environ.get("SSH_USER", "your-username"),
"SSH_KEY_PATH": os.environ.get("SSH_KEY_PATH", "/path/to/key"),
"BROWSER_HEADLESS": "true"
}
}
config.setdefault("mcpServers", {})["linux-server"] = server_config
try:
config_path.write_text(json.dumps(config, indent=2))
print("โ
Linux MCP server added to Claude Desktop configuration")
print("๐ Restart Claude Desktop to load the new server")
except Exception as e:
print(f"โ Failed to update Claude Desktop config: {e}")
print(f" Manual config:\n{json.dumps(server_config, indent=2)}")
def test_server():
"""Run basic tests."""
print("\n๐งช Running basic tests...")
try:
result = subprocess.run([
sys.executable, "test_server.py"
], capture_output=True, text=True, cwd=Path(__file__).parent)
if result.returncode == 0:
print("โ
Basic tests passed")
return True
else:
print("โ Basic tests failed")
print("STDOUT:", result.stdout)
print("STDERR:", result.stderr)
return False
except Exception as e:
print(f"โ Test execution failed: {e}")
return False
def main():
"""Main setup function."""
print("๐ Awesome Linux MCP Server Setup")
print("=" * 40)
steps = [
("Checking Python version", check_python_version),
("Checking dependencies", check_dependencies),
("Checking Chrome/Chromium", check_chrome),
("Creating .env file", create_env_file),
("Setting up Claude Desktop", setup_claude_config),
("Running basic tests", test_server),
]
completed = 0
total = len(steps)
for step_name, step_func in steps:
print(f"\n{step_name}...")
try:
if step_func():
completed += 1
except Exception as e:
print(f"โ {step_name} failed: {e}")
print(f"\n๐ Setup Results: {completed}/{total} steps completed")
if completed == total:
print("๐ Setup completed successfully!")
print("\n๐ Next steps:")
print("1. Edit .env with your SSH server details")
print("2. Test SSH connection manually: ssh user@host")
print("3. Run the server: python linux_mcp_server.py")
print("4. Restart Claude Desktop to use the server")
else:
print("โ ๏ธ Setup completed with some issues.")
print(" Please address the failed steps before using the server.")
if __name__ == "__main__":
main()