221 lines
6.2 KiB
Python
221 lines
6.2 KiB
Python
#!/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) |