rts-commander / examples /mcp_connection_test.py
Luigi's picture
Initial commit: Complete RTS project with MCP evaluation
551ad28
#!/usr/bin/env python3
"""
Simple test script to demonstrate connecting to the MCP server
"""
import asyncio
import sys
import os
# Add the web directory to the path
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..'))
async def test_mcp_connection():
"""Test connecting to the MCP server."""
print("Testing MCP server connection...")
print("This is a demonstration of how an MCP client would connect.")
print()
# Import the MCP server to verify it can be imported
try:
from mcp_server import RTSGameMCP
print("โœ… MCP server module can be imported")
except Exception as e:
print(f"โŒ Failed to import MCP server module: {e}")
return False
# Show what the server configuration looks like
try:
server = RTSGameMCP()
print(f"โœ… MCP server created successfully")
print(f" Server name: {server.mcp.name}")
print(f" Server port: {server.mcp.settings.port}")
print(f" Server host: {server.mcp.settings.host}")
print()
# Show available tools
print("Available tools:")
print(" - get_game_state()")
print(" - get_ai_analysis(language)")
print(" - move_units(unit_ids, target_x, target_y)")
print(" - attack_unit(attacker_ids, target_id)")
print(" - build_building(building_type, position_x, position_y, player_id)")
print(" - send_game_command(command_type, **kwargs)")
print()
# Show available resources
print("Available resources:")
print(" - game_documentation")
print(" - game_rules")
print()
return True
except Exception as e:
print(f"โŒ Failed to create MCP server: {e}")
return False
def main():
"""Main function."""
print("MCP Connection Test")
print("=" * 50)
print()
success = asyncio.run(test_mcp_connection())
if success:
print("๐ŸŽ‰ MCP connection test completed successfully!")
print()
print("To actually use the MCP server:")
print("1. Start the game server: python start.py")
print("2. Start the MCP server: python mcp_server.py")
print("3. Connect with an MCP-compatible client to localhost:8001")
return 0
else:
print("โŒ MCP connection test failed!")
return 1
if __name__ == "__main__":
sys.exit(main())