#!/usr/bin/env python3 """ MCP Server Setup Test Tests all components to ensure they're working correctly """ import os import sys import subprocess import importlib from pathlib import Path def test_python_version(): """Test Python version""" print("๐Ÿ Testing Python version...") if sys.version_info >= (3, 8): print(f"โœ… Python {sys.version.split()[0]} - Compatible") return True else: print(f"โŒ Python {sys.version.split()[0]} - Incompatible (need 3.8+)") return False def test_dependencies(): """Test if all required dependencies are installed""" print("\n๐Ÿ“ฆ Testing dependencies...") required_packages = [ 'fastapi', 'uvicorn', 'gitpython', 'requests', 'python-dotenv', 'pydantic' ] optional_packages = [ 'google.generativeai', 'openai' ] all_good = True for package in required_packages: try: importlib.import_module(package) print(f"โœ… {package}") except ImportError: print(f"โŒ {package} - Missing") all_good = False print("\n๐Ÿ”ง Optional packages:") for package in optional_packages: try: importlib.import_module(package) print(f"โœ… {package}") except ImportError: print(f"โš ๏ธ {package} - Not installed (AI features won't work)") return all_good def test_git(): """Test Git installation""" print("\n๐Ÿ”ง Testing Git...") try: result = subprocess.run(["git", "--version"], capture_output=True, text=True) if result.returncode == 0: print(f"โœ… Git: {result.stdout.strip()}") return True else: print("โŒ Git not working properly") return False except FileNotFoundError: print("โŒ Git not found in PATH") return False def test_node(): """Test Node.js installation (optional)""" print("\n๐Ÿ”ง Testing Node.js...") try: result = subprocess.run(["node", "--version"], capture_output=True, text=True) if result.returncode == 0: print(f"โœ… Node.js: {result.stdout.strip()}") return True else: print("โš ๏ธ Node.js not working properly") return False except FileNotFoundError: print("โš ๏ธ Node.js not found (optional)") return False def test_files(): """Test if all required files exist""" print("\n๐Ÿ“ Testing files...") required_files = [ 'main.py', 'requirements.txt', 'env.example', 'README.md' ] required_dirs = [ 'templates', 'static' ] all_good = True for file in required_files: if Path(file).exists(): print(f"โœ… {file}") else: print(f"โŒ {file} - Missing") all_good = False for directory in required_dirs: if Path(directory).exists(): print(f"โœ… {directory}/") else: print(f"โŒ {directory}/ - Missing") all_good = False return all_good def test_environment(): """Test environment configuration""" print("\n๐Ÿ” Testing environment...") from dotenv import load_dotenv load_dotenv() gemini_key = os.getenv("GEMINI_API_KEY") openai_key = os.getenv("OPENAI_API_KEY") if gemini_key and gemini_key != "your_gemini_api_key_here": print("โœ… Gemini API key configured") else: print("โš ๏ธ Gemini API key not configured") if openai_key and openai_key != "your_openai_api_key_here": print("โœ… OpenAI API key configured") else: print("โš ๏ธ OpenAI API key not configured") if not gemini_key and not openai_key: print("โš ๏ธ No AI API keys configured - AI features won't work") return False return True def test_server_import(): """Test if the server can be imported""" print("\n๐Ÿš€ Testing server import...") try: # Test basic import import main print("โœ… Server module imports successfully") return True except Exception as e: print(f"โŒ Server import failed: {e}") return False def run_tests(): """Run all tests""" print("๐Ÿงช MCP Server Setup Test") print("=" * 50) tests = [ ("Python Version", test_python_version), ("Dependencies", test_dependencies), ("Git", test_git), ("Node.js", test_node), ("Files", test_files), ("Environment", test_environment), ("Server Import", test_server_import) ] results = [] for test_name, test_func in tests: try: result = test_func() results.append((test_name, result)) except Exception as e: print(f"โŒ {test_name} test failed with error: {e}") results.append((test_name, False)) # Summary print("\n" + "=" * 50) print("๐Ÿ“Š Test Summary:") print("=" * 50) passed = 0 total = len(results) for test_name, result in results: status = "โœ… PASS" if result else "โŒ FAIL" print(f"{test_name:<20} {status}") if result: passed += 1 print(f"\nResults: {passed}/{total} tests passed") if passed == total: print("๐ŸŽ‰ All tests passed! Your MCP Server is ready to use.") print("\nTo start the server, run:") print(" python main.py") print(" or") print(" python start.py") else: print("โš ๏ธ Some tests failed. Please fix the issues before running the server.") print("\nCommon fixes:") print("1. Install missing dependencies: pip install -r requirements.txt") print("2. Configure API keys in .env file") print("3. Install Git if not present") return passed == total if __name__ == "__main__": success = run_tests() sys.exit(0 if success else 1)