122 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
			
		
		
	
	
			122 lines
		
	
	
		
			3.9 KiB
		
	
	
	
		
			Python
		
	
	
	
	
	
| #!/usr/bin/env python3
 | |
| """
 | |
| MCP Server Startup Script
 | |
| Handles environment setup and server initialization
 | |
| """
 | |
| 
 | |
| import os
 | |
| import sys
 | |
| import subprocess
 | |
| import shutil
 | |
| from pathlib import Path
 | |
| 
 | |
| def check_python_version():
 | |
|     """Check if Python version is compatible"""
 | |
|     if sys.version_info < (3, 8):
 | |
|         print("❌ Error: Python 3.8 or higher is required")
 | |
|         print(f"Current version: {sys.version}")
 | |
|         sys.exit(1)
 | |
|     print(f"✅ Python version: {sys.version.split()[0]}")
 | |
| 
 | |
| def check_git():
 | |
|     """Check if Git is installed"""
 | |
|     try:
 | |
|         subprocess.run(["git", "--version"], check=True, capture_output=True)
 | |
|         print("✅ Git is installed")
 | |
|     except (subprocess.CalledProcessError, FileNotFoundError):
 | |
|         print("❌ Error: Git is not installed or not in PATH")
 | |
|         print("Please install Git: https://git-scm.com/")
 | |
|         sys.exit(1)
 | |
| 
 | |
| def check_node():
 | |
|     """Check if Node.js is installed (optional)"""
 | |
|     try:
 | |
|         subprocess.run(["node", "--version"], check=True, capture_output=True)
 | |
|         print("✅ Node.js is installed")
 | |
|     except (subprocess.CalledProcessError, FileNotFoundError):
 | |
|         print("⚠️  Warning: Node.js is not installed")
 | |
|         print("This is optional but recommended for projects with package.json")
 | |
| 
 | |
| def install_dependencies():
 | |
|     """Install Python dependencies"""
 | |
|     print("\n📦 Installing Python dependencies...")
 | |
|     try:
 | |
|         subprocess.run([sys.executable, "-m", "pip", "install", "-r", "requirements.txt"], check=True)
 | |
|         print("✅ Dependencies installed successfully")
 | |
|     except subprocess.CalledProcessError as e:
 | |
|         print(f"❌ Error installing dependencies: {e}")
 | |
|         sys.exit(1)
 | |
| 
 | |
| def setup_environment():
 | |
|     """Set up environment file"""
 | |
|     env_file = Path(".env")
 | |
|     env_example = Path("env.example")
 | |
|     
 | |
|     if not env_file.exists():
 | |
|         if env_example.exists():
 | |
|             shutil.copy(env_example, env_file)
 | |
|             print("✅ Created .env file from template")
 | |
|             print("⚠️  Please edit .env file and add your API keys")
 | |
|         else:
 | |
|             print("⚠️  No .env file found and no template available")
 | |
|     else:
 | |
|         print("✅ .env file already exists")
 | |
| 
 | |
| def check_api_keys():
 | |
|     """Check if API keys are configured"""
 | |
|     from dotenv import load_dotenv
 | |
|     load_dotenv()
 | |
|     
 | |
|     gemini_key = os.getenv("GEMINI_API_KEY")
 | |
|     openai_key = os.getenv("OPENAI_API_KEY")
 | |
|     
 | |
|     if not gemini_key and not openai_key:
 | |
|         print("⚠️  Warning: No API keys configured")
 | |
|         print("Please add GEMINI_API_KEY or OPENAI_API_KEY to .env file")
 | |
|         print("You can still start the server, but AI features won't work")
 | |
|     else:
 | |
|         if gemini_key:
 | |
|             print("✅ Gemini API key configured")
 | |
|         if openai_key:
 | |
|             print("✅ OpenAI API key configured")
 | |
| 
 | |
| def create_directories():
 | |
|     """Create necessary directories"""
 | |
|     directories = ["templates", "static"]
 | |
|     for directory in directories:
 | |
|         Path(directory).mkdir(exist_ok=True)
 | |
|     print("✅ Directories created")
 | |
| 
 | |
| def start_server():
 | |
|     """Start the FastAPI server"""
 | |
|     print("\n🚀 Starting MCP Server...")
 | |
|     print("📱 Web interface will be available at: http://localhost:8000")
 | |
|     print("🔧 API documentation at: http://localhost:8000/docs")
 | |
|     print("\nPress Ctrl+C to stop the server")
 | |
|     
 | |
|     try:
 | |
|         subprocess.run([sys.executable, "main.py"])
 | |
|     except KeyboardInterrupt:
 | |
|         print("\n👋 Server stopped")
 | |
| 
 | |
| def main():
 | |
|     """Main startup function"""
 | |
|     print("🤖 MCP Server - AI-Powered Code Editor")
 | |
|     print("=" * 50)
 | |
|     
 | |
|     # Pre-flight checks
 | |
|     check_python_version()
 | |
|     check_git()
 | |
|     check_node()
 | |
|     
 | |
|     # Setup
 | |
|     create_directories()
 | |
|     setup_environment()
 | |
|     install_dependencies()
 | |
|     check_api_keys()
 | |
|     
 | |
|     # Start server
 | |
|     start_server()
 | |
| 
 | |
| if __name__ == "__main__":
 | |
|     main()  | 
