""" Test script for TransitApp MCP Server Verifies all MCP tools are working correctly """ import json from app import ( get_nearby_transit, plan_trip, get_realtime_vehicle_location, get_service_alerts, compare_trip_modes, search_stops_and_stations ) def test_tool(tool_name, func, *args): """Test a single MCP tool""" print(f"\n{'='*60}") print(f"Testing: {tool_name}") print('='*60) try: result = func(*args) data = json.loads(result) print(json.dumps(data, indent=2)) print(f"āœ… {tool_name} - PASSED") return True except Exception as e: print(f"āŒ {tool_name} - FAILED: {e}") return False def main(): """Run all tests""" print("šŸš‡ TransitApp MCP Server - Testing Suite") print("=========================================\n") tests_passed = 0 tests_total = 0 # Test 1: Nearby Transit tests_total += 1 if test_tool( "get_nearby_transit", get_nearby_transit, 40.7420, -73.9871, 500, "all" ): tests_passed += 1 # Test 2: Trip Planning tests_total += 1 if test_tool( "plan_trip", plan_trip, 40.7420, -73.9871, 40.7060, -74.0110, "now", "all", "balanced" ): tests_passed += 1 # Test 3: Real-time Vehicle Location tests_total += 1 if test_tool( "get_realtime_vehicle_location", get_realtime_vehicle_location, "M15", "both" ): tests_passed += 1 # Test 4: Service Alerts tests_total += 1 if test_tool( "get_service_alerts", get_service_alerts, 40.7420, -73.9871, 5000, "all" ): tests_passed += 1 # Test 5: Mode Comparison tests_total += 1 if test_tool( "compare_trip_modes", compare_trip_modes, 40.7420, -73.9871, 40.7060, -74.0110 ): tests_passed += 1 # Test 6: Search Stops tests_total += 1 if test_tool( "search_stops_and_stations", search_stops_and_stations, "23rd St", 40.7420, -73.9871, 10 ): tests_passed += 1 # Summary print(f"\n{'='*60}") print("TEST SUMMARY") print('='*60) print(f"Tests Passed: {tests_passed}/{tests_total}") print(f"Success Rate: {tests_passed/tests_total*100:.1f}%") if tests_passed == tests_total: print("\nāœ… All tests passed! Server is ready for deployment.") return 0 else: print(f"\nāš ļø {tests_total - tests_passed} test(s) failed. Review errors above.") return 1 if __name__ == "__main__": exit(main())