tts-gpu-service / test_mcp_integration.py
Peter Michael Gits
feat: Complete MCP integration with HTTP fallback v0.3.31
89c74a6
#!/usr/bin/env python3
"""
Test script to validate MCP integration in TTS service.
This script tests the MCP functionality without requiring GPU or full model loading.
"""
import asyncio
import json
import sys
import os
# Add the current directory to the path so we can import from app.py
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
async def test_mcp_integration():
"""Test the MCP integration functionality"""
print("πŸ§ͺ Testing TTS MCP Integration...")
try:
# Try to import the MCP components from our app
from app import MCP_AVAILABLE, mcp_server
print(f"βœ… MCP Availability: {'Available' if MCP_AVAILABLE else 'Not Available'}")
if not MCP_AVAILABLE:
print("⚠️ MCP not available - this is expected if mcp package is not installed")
print("πŸ” To install MCP: pip install mcp>=1.0.0")
return True
if mcp_server is None:
print("❌ MCP server not initialized properly")
return False
print("βœ… MCP server instance created successfully")
# Test tool listing (this should work without GPU)
try:
# Import the handler function
from app import handle_list_tools
# Get the list of tools
tools = await handle_list_tools()
print(f"βœ… Available MCP tools ({len(tools)}):")
for tool in tools:
print(f" - {tool.name}: {tool.description}")
# Verify we have the expected tools
expected_tools = {"tts_synthesize", "tts_batch_synthesize", "tts_get_info"}
actual_tools = {tool.name for tool in tools}
if expected_tools == actual_tools:
print("βœ… All expected tools are available")
else:
missing = expected_tools - actual_tools
extra = actual_tools - expected_tools
if missing:
print(f"❌ Missing tools: {missing}")
if extra:
print(f"⚠️ Extra tools: {extra}")
return False
except Exception as e:
print(f"❌ Error testing tool listing: {e}")
return False
# Test the get_info tool (this should work without GPU)
try:
from app import handle_call_tool
print("\nπŸ” Testing tts_get_info tool...")
info_result = await handle_call_tool("tts_get_info", {})
if info_result and len(info_result) > 0:
info_data = json.loads(info_result[0].text)
print("βœ… System info retrieved successfully")
print(f" - MCP Status: {info_data.get('mcp_status', 'Unknown')}")
print(f" - Available Tools: {len(info_data.get('available_tools', []))}")
print(f" - Voice Presets: {len(info_data.get('voice_presets', []))}")
else:
print("❌ Failed to get system info")
return False
except Exception as e:
print(f"❌ Error testing get_info tool: {e}")
return False
# Test error handling for invalid tool
try:
print("\nπŸ” Testing error handling...")
error_result = await handle_call_tool("invalid_tool", {})
if error_result and len(error_result) > 0:
error_data = json.loads(error_result[0].text)
if "error" in error_data and "Unknown tool" in error_data["error"]:
print("βœ… Error handling works correctly")
else:
print("❌ Unexpected error response format")
return False
else:
print("❌ No error response received")
return False
except Exception as e:
print(f"❌ Error testing error handling: {e}")
return False
print("\nπŸŽ‰ All MCP integration tests passed!")
return True
except ImportError as e:
print(f"❌ Import error: {e}")
return False
except Exception as e:
print(f"❌ Unexpected error: {e}")
return False
def test_voice_presets():
"""Test that voice presets are properly defined"""
try:
from app import VOICE_PRESETS
print(f"\n🎭 Testing Voice Presets ({len(VOICE_PRESETS)} available):")
if len(VOICE_PRESETS) == 0:
print("❌ No voice presets defined")
return False
for code, description in VOICE_PRESETS[:3]: # Show first 3
print(f" - {code}: {description}")
if len(VOICE_PRESETS) > 3:
print(f" ... and {len(VOICE_PRESETS) - 3} more")
print("βœ… Voice presets loaded successfully")
return True
except Exception as e:
print(f"❌ Error testing voice presets: {e}")
return False
def main():
"""Main test function"""
print("=" * 60)
print("πŸš€ TTS Service MCP Integration Test")
print("=" * 60)
# Test voice presets first (synchronous)
presets_ok = test_voice_presets()
# Test MCP integration (asynchronous)
mcp_ok = asyncio.run(test_mcp_integration())
print("\n" + "=" * 60)
if presets_ok and mcp_ok:
print("βœ… ALL TESTS PASSED - TTS MCP integration is ready!")
print("\nπŸ“‹ Summary:")
print(" βœ… Voice presets configured")
print(" βœ… MCP server setup complete")
print(" βœ… MCP tools available")
print(" βœ… Error handling working")
print("\nπŸš€ Ready to deploy TTS service with dual protocol support!")
return 0
else:
print("❌ SOME TESTS FAILED - Check the issues above")
return 1
if __name__ == "__main__":
sys.exit(main())