SuperMarioGPT / test_mcp_server.py
DarkDriftz's picture
Upload 18 files
49b8c43 verified
#!/usr/bin/env python3
"""
Test script for MarioGPT MCP Server
"""
import asyncio
import json
from mcp_server import mcp_server, GenerateLevelParams
async def test_mcp_server():
"""Test MCP server functionality"""
print("=" * 60)
print("MarioGPT MCP Server Test Suite")
print("=" * 60)
# Test 1: List tools
print("\n[Test 1] Listing available tools...")
try:
tools = await mcp_server.list_tools()
print(f"βœ“ Found {len(tools)} tools:")
for tool in tools:
print(f" - {tool.name}: {tool.description[:80]}...")
except Exception as e:
print(f"βœ— Failed to list tools: {e}")
return
# Test 2: Get level suggestions
print("\n[Test 2] Getting level suggestions...")
try:
result = await mcp_server.call_tool(
name="get_level_suggestions",
arguments={}
)
print(f"βœ“ Retrieved suggestions:")
print(result[0].text[:200] + "...")
except Exception as e:
print(f"βœ— Failed to get suggestions: {e}")
# Test 3: Validate parameters schema
print("\n[Test 3] Validating parameter schema...")
try:
schema = GenerateLevelParams.model_json_schema()
print(f"βœ“ Schema validation passed")
print(f" Properties: {', '.join(schema['properties'].keys())}")
except Exception as e:
print(f"βœ— Schema validation failed: {e}")
# Test 4: Parameter validation
print("\n[Test 4] Testing parameter validation...")
# Valid parameters
try:
params = GenerateLevelParams(
prompt="many pipes, some enemies, high elevation",
temperature=1.5,
level_size=1000
)
print(f"βœ“ Valid parameters accepted")
except Exception as e:
print(f"βœ— Valid parameters rejected: {e}")
# Invalid temperature (too high)
try:
params = GenerateLevelParams(
prompt="test",
temperature=5.0
)
print(f"βœ— Invalid temperature accepted (should fail)")
except Exception as e:
print(f"βœ“ Invalid temperature correctly rejected")
# Invalid level size (too small)
try:
params = GenerateLevelParams(
prompt="test",
level_size=50
)
print(f"βœ— Invalid level_size accepted (should fail)")
except Exception as e:
print(f"βœ“ Invalid level_size correctly rejected")
# Test 5: Generate level (mock test - requires model)
print("\n[Test 5] Testing level generation (requires model)...")
print("⚠ Skipping actual generation test (requires full model setup)")
print(" To test generation, run:")
print(" python mcp_server.py")
print(" Then use MCP client to call generate_mario_level")
print("\n" + "=" * 60)
print("Test suite completed!")
print("=" * 60)
async def test_mcp_protocol():
"""Test MCP protocol compatibility"""
print("\n[Protocol Test] MCP Protocol Compatibility")
print("-" * 60)
# Check server initialization
print("βœ“ Server initialized:", mcp_server.name)
# Check tool registration
tools = await mcp_server.list_tools()
print(f"βœ“ Tools registered: {len(tools)}")
# Check tool schemas
for tool in tools:
schema = tool.inputSchema
if schema:
print(f"βœ“ {tool.name} has valid input schema")
else:
print(f"⚠ {tool.name} has no input schema")
print("-" * 60)
if __name__ == "__main__":
print("\nStarting MCP Server Tests...\n")
try:
# Run async tests
asyncio.run(test_mcp_server())
asyncio.run(test_mcp_protocol())
print("\nβœ“ All tests completed successfully!")
except KeyboardInterrupt:
print("\n\n⚠ Tests interrupted by user")
except Exception as e:
print(f"\nβœ— Test suite failed: {e}")
import traceback
traceback.print_exc()