File size: 2,936 Bytes
551ad28
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""
Integration test for the MCP server
"""

import asyncio
import sys
import os
import time
import subprocess
import signal

# Add the web directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))

def test_mcp_server_startup():
    """Test that we can start and stop the MCP server."""
    try:
        # Import the MCP server
        from mcp_server import RTSGameMCP
        
        # Create an instance
        server = RTSGameMCP()
        
        # Verify that the server was created with the correct parameters
        assert hasattr(server, 'mcp'), "Server should have an mcp attribute"
        assert server.mcp.name == "RTS Commander MCP Server", "Server should have the correct name"
        assert server.mcp.settings.port == 8001, "Server should be configured to run on port 8001"
        
        print("โœ“ MCP server creation and configuration successful")
        return True
    except Exception as e:
        print(f"โœ— Failed to create or configure MCP server: {e}")
        return False

def test_mcp_tools_registration():
    """Test that tools are properly registered."""
    try:
        # Import the MCP server
        from mcp_server import RTSGameMCP
        
        # Create an instance
        server = RTSGameMCP()
        
        # Verify that tools are registered
        # Note: This is a simplified test - in practice, you'd need to check the FastMCP internals
        print("โœ“ MCP tools registration test completed")
        return True
    except Exception as e:
        print(f"โœ— Failed to test tools registration: {e}")
        return False

def test_mcp_resources_registration():
    """Test that resources are properly registered."""
    try:
        # Import the MCP server
        from mcp_server import RTSGameMCP
        
        # Create an instance
        server = RTSGameMCP()
        
        # Verify that resources are registered
        # Note: This is a simplified test - in practice, you'd need to check the FastMCP internals
        print("โœ“ MCP resources registration test completed")
        return True
    except Exception as e:
        print(f"โœ— Failed to test resources registration: {e}")
        return False

def main():
    """Run all integration tests."""
    print("Running MCP integration tests...")
    
    tests = [
        test_mcp_server_startup,
        test_mcp_tools_registration,
        test_mcp_resources_registration,
    ]
    
    results = []
    for test in tests:
        try:
            results.append(test())
        except Exception as e:
            print(f"โœ— Test {test.__name__} failed with exception: {e}")
            results.append(False)
    
    if all(results):
        print("\nโœ“ All MCP integration tests passed!")
        return 0
    else:
        print("\nโœ— Some MCP integration tests failed!")
        return 1

if __name__ == "__main__":
    sys.exit(main())