#!/usr/bin/env python3
"""
Comprehensive test report for MCP Audio Server
"""
import json
import sys
import os
import time
from datetime import datetime
# Suppress pygame messages
os.environ['PYGAME_HIDE_SUPPORT_PROMPT'] = '1'
# Add current directory to path
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
from audio_server import MCPAudioServer, handle_json_rpc_request
def generate_test_report():
"""Generate a comprehensive test report"""
print("๐ MCP Audio Server - Comprehensive Test Report")
print("=" * 60)
print(f"Test Date: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
print()
test_results = {
"server_initialization": False,
"tools_available": 0,
"tts_functionality": False,
"audio_control": False,
"status_query": False,
"json_rpc_interface": False,
"error_handling": False,
"parameter_validation": False
}
try:
# Test 1: Server Initialization
print("๐ง 1. Server Initialization")
print("-" * 30)
server = MCPAudioServer()
test_results["server_initialization"] = True
print(" โ
Server initialized successfully")
# Test 2: Tools Availability
print("\n๐ 2. Tools Availability")
print("-" * 30)
tools = server.list_tools()
test_results["tools_available"] = len(tools["tools"])
print(f" โ
Found {test_results['tools_available']} tools:")
for tool in tools["tools"]:
print(f" โข {tool['name']}: {tool['description'][:50]}...")
# Test 3: Text-to-Speech Functionality
print("\n๐ฃ๏ธ 3. Text-to-Speech Functionality")
print("-" * 30)
tts_result = server.call_tool("speak_text", {
"text": "MCP Audio Server test successful",
"rate": 150,
"volume": 0.7
})
test_results["tts_functionality"] = tts_result.get("success", False)
if test_results["tts_functionality"]:
print(" โ
TTS functionality working")
else:
print(f" โ TTS failed: {tts_result.get('error', 'Unknown error')}")
# Test 4: Audio Control
print("\n๐ฎ 4. Audio Control")
print("-" * 30)
stop_result = server.call_tool("stop_audio", {})
test_results["audio_control"] = stop_result.get("success", False)
if test_results["audio_control"]:
print(" โ
Audio control working")
else:
print(f" โ Audio control failed: {stop_result.get('error', 'Unknown error')}")
# Test 5: Status Query
print("\n๐ 5. Status Query")
print("-" * 30)
status_result = server.call_tool("get_audio_status", {})
test_results["status_query"] = status_result.get("success", False)
if test_results["status_query"]:
status = status_result.get("status", {})
print(f" โ
Status query working")
print(f" โข TTS Available: {status.get('tts_available', 'Unknown')}")
print(f" โข Audio System: {status.get('pygame_available', 'Unknown')}")
print(f" โข Currently Playing: {status.get('music_playing', 'Unknown')}")
else:
print(f" โ Status query failed: {status_result.get('error', 'Unknown error')}")
# Test 6: JSON-RPC Interface
print("\n๐ 6. JSON-RPC Interface")
print("-" * 30)
json_request = {
"jsonrpc": "2.0",
"method": "tools/call",
"params": {
"name": "speak_text",
"arguments": {"text": "JSON-RPC test"}
},
"id": 1
}
json_response = handle_json_rpc_request(json.dumps(json_request))
try:
response_obj = json.loads(json_response)
test_results["json_rpc_interface"] = response_obj.get("result", {}).get("success", False)
if test_results["json_rpc_interface"]:
print(" โ
JSON-RPC interface working")
else:
print(" โ JSON-RPC interface failed")
except:
print(" โ JSON-RPC response parsing failed")
# Test 7: Error Handling
print("\n๐จ 7. Error Handling")
print("-" * 30)
error_tests = [
("Empty text", server.call_tool("speak_text", {"text": ""})),
("Invalid file", server.call_tool("play_audio_file", {"file_path": "/invalid/path.mp3"})),
("Unknown tool", server.call_tool("unknown_tool", {})),
("Missing params", server.call_tool("speak_text", {}))
]
error_count = 0
for test_name, result in error_tests:
if not result.get("success", True): # Should fail
error_count += 1
print(f" โ
{test_name}: Properly handled")
else:
print(f" โ {test_name}: Not properly handled")
test_results["error_handling"] = error_count == len(error_tests)
# Test 8: Parameter Validation
print("\n๐ง 8. Parameter Validation")
print("-" * 30)
param_tests = [
("Extreme rate", server.call_tool("speak_text", {"text": "test", "rate": 1000})),
("Negative volume", server.call_tool("speak_text", {"text": "test", "volume": -1.0})),
("High volume", server.call_tool("speak_text", {"text": "test", "volume": 2.0}))
]
param_success = 0
for test_name, result in param_tests:
if result.get("success", False): # Should handle gracefully
param_success += 1
print(f" โ
{test_name}: Handled gracefully")
else:
print(f" โ {test_name}: Failed to handle")
test_results["parameter_validation"] = param_success == len(param_tests)
except Exception as e:
print(f"\nโ Critical error during testing: {e}")
import traceback
traceback.print_exc()
# Generate Summary
print("\n๐ Test Summary")
print("=" * 60)
passed_tests = sum(1 for key, value in test_results.items()
if key != "tools_available" and value)
total_tests = len(test_results) - 1 # Exclude tools_available count
print(f"Tests Passed: {passed_tests}/{total_tests}")
print(f"Success Rate: {(passed_tests/total_tests)*100:.1f}%")
print()
print("Detailed Results:")
print(f" โข Server Initialization: {'โ
' if test_results['server_initialization'] else 'โ'}")
print(f" โข Tools Available: {test_results['tools_available']}")
print(f" โข TTS Functionality: {'โ
' if test_results['tts_functionality'] else 'โ'}")
print(f" โข Audio Control: {'โ
' if test_results['audio_control'] else 'โ'}")
print(f" โข Status Query: {'โ
' if test_results['status_query'] else 'โ'}")
print(f" โข JSON-RPC Interface: {'โ
' if test_results['json_rpc_interface'] else 'โ'}")
print(f" โข Error Handling: {'โ
' if test_results['error_handling'] else 'โ'}")
print(f" โข Parameter Validation: {'โ
' if test_results['parameter_validation'] else 'โ'}")
print("\n๐ฏ Recommendations:")
if passed_tests == total_tests:
print(" โข All tests passed! The MCP Audio Server is ready for production use.")
print(" โข Consider adding more audio format support if needed.")
print(" โข Monitor performance with longer audio files.")
else:
print(" โข Review failed tests and address any issues.")
print(" โข Ensure all dependencies are properly installed.")
print(" โข Check system audio configuration.")
print("\n๐ Ready for AI Model Integration!")
print("The MCP Audio Server can now be used with AI models to provide audio capabilities.")
return test_results
if __name__ == "__main__":
generate_test_report()