#!/usr/bin/env python3
"""
Test script to verify Azure Security MCP setup
"""
import os
import sys
from dotenv import load_dotenv
def check_python_version():
"""Check Python version"""
version = sys.version_info
if version.major < 3 or (version.major == 3 and version.minor < 8):
print("❌ Python 3.8+ required")
return False
print(f"✓ Python {version.major}.{version.minor}.{version.micro}")
return True
def check_dependencies():
"""Check if required packages are installed"""
required_packages = [
'mcp',
'azure.identity',
'azure.mgmt.resource',
'azure.mgmt.network',
'azure.mgmt.storage',
'azure.mgmt.compute',
'groq',
'dotenv'
]
missing = []
for package in required_packages:
try:
__import__(package.replace('-', '_'))
print(f"✓ {package}")
except ImportError:
print(f"❌ {package} not installed")
missing.append(package)
if missing:
print(f"\nInstall missing packages:")
print(f"pip install {' '.join(missing)}")
return False
return True
def check_environment():
"""Check environment variables"""
load_dotenv()
groq_key = os.getenv("GROQ_API_KEY")
azure_sub = os.getenv("AZURE_SUBSCRIPTION_ID")
if not groq_key:
print("❌ GROQ_API_KEY not set in .env")
print(" Get your free API key from: https://console.groq.com")
return False
else:
print(f"✓ GROQ_API_KEY set ({groq_key[:10]}...)")
if not azure_sub:
print("⚠️ AZURE_SUBSCRIPTION_ID not set (can enter at runtime)")
else:
print(f"✓ AZURE_SUBSCRIPTION_ID set ({azure_sub[:8]}...)")
return True
def check_azure_auth():
"""Check Azure authentication"""
try:
from azure.identity import DefaultAzureCredential
from azure.core.exceptions import ClientAuthenticationError
credential = DefaultAzureCredential()
# Try to get a token
try:
token = credential.get_token("https://management.azure.com/.default")
print("✓ Azure authentication successful")
return True
except ClientAuthenticationError:
print("❌ Azure authentication failed")
print(" Run: az login")
return False
except Exception as e:
print(f"❌ Error checking Azure auth: {str(e)}")
return False
def main():
"""Run all checks"""
print("="*60)
print("AZURE SECURITY MCP - SETUP VERIFICATION")
print("="*60)
print("\n1. Checking Python version...")
python_ok = check_python_version()
print("\n2. Checking dependencies...")
deps_ok = check_dependencies()
print("\n3. Checking environment variables...")
env_ok = check_environment()
print("\n4. Checking Azure authentication...")
azure_ok = check_azure_auth()
print("\n" + "="*60)
if python_ok and deps_ok and env_ok and azure_ok:
print("✓ ALL CHECKS PASSED!")
print("\nYou're ready to run the agent:")
print(" python agent.py")
else:
print("❌ SOME CHECKS FAILED")
print("\nPlease fix the issues above before running the agent.")
if not deps_ok:
print("\nInstall dependencies:")
print(" pip install -r requirements.txt")
if not env_ok:
print("\nConfigure environment:")
print(" 1. Copy .env.example to .env")
print(" 2. Add your GROQ_API_KEY")
print(" 3. Add your AZURE_SUBSCRIPTION_ID")
if not azure_ok:
print("\nConfigure Azure authentication:")
print(" az login")
print("="*60)
if __name__ == "__main__":
main()