Spaces:
Runtime error
Runtime error
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify MCP integration functionality | |
| """ | |
| import sys | |
| import os | |
| sys.path.append(os.path.dirname(os.path.abspath(__file__))) | |
| def test_mcp_import(): | |
| """Test if MCP tools can be imported correctly""" | |
| try: | |
| from src.mcp.mcp_tools import GradioMCPTools | |
| print("✅ Successfully imported GradioMCPTools") | |
| return True | |
| except ImportError as e: | |
| print(f"❌ Failed to import GradioMCPTools: {e}") | |
| return False | |
| def test_game_facade_methods(): | |
| """Test if GameFacade has all required methods for MCP""" | |
| try: | |
| from src.facades.game_facade import GameFacade | |
| from src.core.game_engine import GameEngine | |
| # Initialize game engine | |
| engine = GameEngine() | |
| facade = GameFacade(engine) | |
| # Test required methods | |
| required_methods = [ | |
| 'get_recent_chat_messages', | |
| 'get_recent_world_events', | |
| 'get_available_npcs', | |
| 'get_raw_world_data' | |
| ] | |
| for method_name in required_methods: | |
| if hasattr(facade, method_name): | |
| print(f"✅ Method {method_name} exists") | |
| else: | |
| print(f"❌ Method {method_name} missing") | |
| return False | |
| # Test game_engine property | |
| if hasattr(facade, 'game_engine'): | |
| print("✅ game_engine property exists") | |
| else: | |
| print("❌ game_engine property missing") | |
| return False | |
| return True | |
| except Exception as e: | |
| print(f"❌ Error testing GameFacade: {e}") | |
| return False | |
| def test_raw_world_data(): | |
| """Test raw world data functionality""" | |
| try: | |
| from src.facades.game_facade import GameFacade | |
| from src.core.game_engine import GameEngine | |
| # Initialize game engine | |
| engine = GameEngine() | |
| facade = GameFacade(engine) | |
| # Test raw world data | |
| raw_data = facade.get_raw_world_data() | |
| if isinstance(raw_data, dict): | |
| print("✅ get_raw_world_data returns dict") | |
| # Check for required keys | |
| required_keys = ['world_state', 'players', 'npcs', 'locations'] | |
| for key in required_keys: | |
| if key in raw_data: | |
| print(f"✅ Raw data contains {key}") | |
| else: | |
| print(f"❌ Raw data missing {key}") | |
| else: | |
| print(f"❌ get_raw_world_data returns {type(raw_data)}, expected dict") | |
| return False | |
| return True | |
| except Exception as e: | |
| print(f"❌ Error testing raw world data: {e}") | |
| return False | |
| if __name__ == "__main__": | |
| print("🧪 Testing MCP Integration...") | |
| print("=" * 50) | |
| tests = [ | |
| ("MCP Import", test_mcp_import), | |
| ("GameFacade Methods", test_game_facade_methods), | |
| ("Raw World Data", test_raw_world_data) | |
| ] | |
| 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} PASSED") | |
| else: | |
| print(f"❌ {test_name} FAILED") | |
| print("\n" + "=" * 50) | |
| print(f"📊 Results: {passed}/{total} tests passed") | |
| if passed == total: | |
| print("🎉 All tests passed! MCP integration is working correctly.") | |
| else: | |
| print("⚠️ Some tests failed. Please check the issues above.") | |