File size: 3,746 Bytes
4c75d73
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#!/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.")