#!/usr/bin/env python3 """ Test script for A1D MCP Server """ import os import sys def test_imports(): """Test if all modules can be imported""" try: import gradio as gr print("✅ Gradio imported successfully") import config print("✅ Config module imported successfully") import utils print("✅ Utils module imported successfully") import app print("✅ App module imported successfully") return True except ImportError as e: print(f"❌ Import error: {e}") return False def test_config(): """Test configuration""" try: from config import TOOLS_CONFIG, GRADIO_CONFIG print(f"✅ Found {len(TOOLS_CONFIG)} tools configured:") for tool_name in TOOLS_CONFIG.keys(): print(f" - {tool_name}") print(f"✅ Gradio config: {GRADIO_CONFIG['title']}") return True except Exception as e: print(f"❌ Config error: {e}") return False def test_gradio_app(): """Test Gradio app creation""" try: # Set a dummy API key for testing os.environ['A1D_API_KEY'] = 'test_key_for_demo' from app import create_gradio_app demo = create_gradio_app() print("✅ Gradio app created successfully") print(f"✅ App title: {demo.title}") return True except Exception as e: print(f"❌ Gradio app error: {e}") return False def test_tool_functions(): """Test individual tool functions""" try: # Set a dummy API key for testing os.environ['A1D_API_KEY'] = 'test_key_for_demo' from app import remove_bg, image_upscaler, image_generator # Test with invalid inputs to check validation result = remove_bg("invalid_url") if "Invalid image URL format" in result: print("✅ URL validation working") result = image_upscaler("invalid_url", 3) if "Invalid image URL format" in result: print("✅ Image upscaler validation working") result = image_generator("") if "Prompt is required" in result: print("✅ Prompt validation working") return True except Exception as e: print(f"❌ Tool function error: {e}") return False def main(): """Run all tests""" print("🧪 Testing A1D MCP Server...") print("=" * 50) tests = [ ("Imports", test_imports), ("Configuration", test_config), ("Gradio App", test_gradio_app), ("Tool Functions", test_tool_functions), ] passed = 0 total = len(tests) for test_name, test_func in tests: print(f"\n📋 Testing {test_name}...") if test_func(): passed += 1 print(f"✅ {test_name} test passed") else: print(f"❌ {test_name} test failed") print("\n" + "=" * 50) print(f"🎯 Test Results: {passed}/{total} tests passed") if passed == total: print("🎉 All tests passed! The MCP server is ready to use.") return 0 else: print("⚠️ Some tests failed. Please check the errors above.") return 1 if __name__ == "__main__": sys.exit(main())