Spaces:
Sleeping
Sleeping
File size: 2,456 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 |
#!/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()) |