#!/usr/bin/env python3
"""
Example script to test the Stem MCP Server tools locally.
This demonstrates how the MCP tools work before integrating with an MCP client.
"""
import asyncio
import logging
import sys
from pathlib import Path
# Add the src directory to Python path
sys.path.insert(0, str(Path(__file__).parent.parent / "src"))
from stem_mcp.audio_processor import AudioProcessor
from stem_mcp.tools_schema import TOOLS_SCHEMA
# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
async def test_audio_processor():
"""Test the audio processor functionality."""
print("🎵 Testing Stem MCP Server Components...")
print("=" * 50)
# Initialize processor
processor = AudioProcessor()
print(f"✅ Audio processor initialized with device: {processor.device}")
print()
# Show available tools
print("📋 Available MCP Tools:")
for i, tool in enumerate(TOOLS_SCHEMA, 1):
print(f" {i}. {tool['name']} - {tool['description']}")
print()
# Test with a sample audio file (you can replace this with your own)
sample_audio = "examples/sample.wav"
if not Path(sample_audio).exists():
print("⚠️ No sample audio file found.")
print("To test with real audio:")
print(f" 1. Place an audio file at: {sample_audio}")
print(" 2. Run this script again")
print()
print("For now, showing what the tools would do...")
# Show example tool calls
print("🔧 Example Tool Calls:")
print()
print("1. Generate Stems:")
print(" Arguments: {'audio_path': '/path/to/song.wav', 'model_type': 'htdemucs'}")
print(" Output: Separates into vocals.wav, drums.wav, bass.wav, other.wav")
print()
print("2. Create Loop:")
print(" Arguments: {'audio_path': '/path/to/drums.wav', 'loop_duration': 4.0}")
print(" Output: Creates seamless 4-second loop with crossfading")
print()
print("3. Analyze Audio:")
print(" Arguments: {'audio_path': '/path/to/song.wav'}")
print(" Output: BPM, key, spectral analysis, and musical features")
print()
return
try:
# Test audio analysis
print("🔍 Testing Audio Analysis...")
result = await processor.analyze_audio(sample_audio)
print(result)
print()
# Test loop creation
print("🔄 Testing Loop Creation...")
result = await processor.create_loop(
audio_path=sample_audio,
loop_duration=2.0,
crossfade_duration=0.1
)
print(result)
print()
except Exception as e:
print(f"❌ Error during testing: {e}")
print("This is expected if you don't have a sample audio file.")
print("✅ Component testing complete!")
print()
print("🚀 Next Steps:")
print("1. Configure your MCP client with mcp-config-example.json")
print("2. Start the MCP server: python -m stem_mcp.server")
print("3. Use the tools through your MCP client (e.g., Claude Desktop)")
if __name__ == "__main__":
asyncio.run(test_audio_processor())