demo.py•10.6 kB
#!/usr/bin/env python3
"""
🎵 Stem MCP Server - Interactive Demo
=====================================
This demo shows you exactly how your MCP server works and what it can do.
Run this to see all the tools in action!
"""
import asyncio
import sys
from pathlib import Path
import json
# Add the src directory to Python path
sys.path.insert(0, str(Path(__file__).parent / "src"))
from stem_mcp.audio_processor import AudioProcessor
from stem_mcp.tools_schema import TOOLS_SCHEMA
def print_header(title, emoji="🎵"):
"""Print a fancy header"""
print("\n" + "="*60)
print(f"{emoji} {title}")
print("="*60)
def print_tool_info(tool_name, description):
"""Print tool information"""
print(f"\n🔧 Tool: {tool_name}")
print(f"📄 Description: {description}")
print("-" * 50)
async def demo_mcp_server():
"""Demo the MCP server functionality"""
print_header("STEM MCP SERVER DEMO", "🎵")
print("Welcome to your professional audio processing MCP server!")
print("This demo shows you what each tool does and how to use them.")
# Initialize the audio processor
print_header("1. SERVER INITIALIZATION", "⚡")
processor = AudioProcessor()
print(f"✅ Audio Processor initialized")
print(f"🖥️ Processing device: {processor.device}")
print(f"🎚️ Sample rate: {processor.sample_rate} Hz")
print(f"📁 Temp directory: {processor.temp_dir}")
# Show all available tools
print_header("2. AVAILABLE MCP TOOLS", "🛠️")
print(f"Total tools available: {len(TOOLS_SCHEMA)}")
print()
for i, tool in enumerate(TOOLS_SCHEMA, 1):
print(f"{i}. 🎯 {tool['name']}")
print(f" 📝 {tool['description']}")
# Show required parameters
required = tool['inputSchema']['properties']
required_params = tool['inputSchema'].get('required', [])
print(" 📋 Parameters:")
for param_name, param_info in required.items():
required_mark = "🔴" if param_name in required_params else "🟡"
param_type = param_info.get('type', 'any')
description = param_info.get('description', 'No description')
print(f" {required_mark} {param_name} ({param_type}): {description}")
print()
# Demo each tool with example calls
print_header("3. TOOL DEMONSTRATIONS", "🎬")
# Demo 1: Generate Stems
print_tool_info("generate_stems", "AI-powered source separation using Demucs")
example_call = {
"tool": "generate_stems",
"arguments": {
"audio_path": "/path/to/song.wav",
"output_dir": "./stems_output",
"model_type": "htdemucs",
"num_stems": 4
}
}
print("📞 Example MCP Call:")
print(json.dumps(example_call, indent=2))
print("📤 Expected Output:")
print(" 📁 song/vocals.wav - Isolated vocal track")
print(" 📁 song/drums.wav - Isolated drum track")
print(" 📁 song/bass.wav - Isolated bass track")
print(" 📁 song/other.wav - All other instruments")
# Demo 2: Audio Analysis
print_tool_info("analyze_audio", "Extract musical features and characteristics")
example_call = {
"tool": "analyze_audio",
"arguments": {
"audio_path": "/path/to/song.wav"
}
}
print("📞 Example MCP Call:")
print(json.dumps(example_call, indent=2))
print("📤 Expected Output:")
print(" 🎵 Tempo: 128.5 BPM")
print(" 🎹 Key: G major")
print(" ⏱️ Duration: 3:45")
print(" 🔊 Spectral analysis data")
print(" 📊 Musical feature extraction")
# Demo 3: Create Loop
print_tool_info("create_loop", "Generate seamless loops with crossfading")
example_call = {
"tool": "create_loop",
"arguments": {
"audio_path": "/path/to/drums.wav",
"loop_duration": 8.0,
"bpm": 120,
"crossfade_duration": 0.2
}
}
print("📞 Example MCP Call:")
print(json.dumps(example_call, indent=2))
print("📤 Expected Output:")
print(" 🔄 drums_loop.wav - 8-second seamless loop")
print(" 🎵 Tempo matched to 120 BPM")
print(" 🎚️ 0.2s crossfade for smooth transitions")
# Demo 4: Split Stems
print_tool_info("split_stems", "Split audio into smaller segments")
example_call = {
"tool": "split_stems",
"arguments": {
"stem_path": "/path/to/vocals.wav",
"segment_length": 15.0,
"overlap": 2.0,
"output_dir": "./segments"
}
}
print("📞 Example MCP Call:")
print(json.dumps(example_call, indent=2))
print("📤 Expected Output:")
print(" 📁 vocals_segment_001.wav (15s)")
print(" 📁 vocals_segment_002.wav (15s, 2s overlap)")
print(" 📁 vocals_segment_003.wav (15s, 2s overlap)")
# Demo 5: Extract Vocal
print_tool_info("extract_vocal", "Isolate vocal track specifically")
example_call = {
"tool": "extract_vocal",
"arguments": {
"audio_path": "/path/to/song.wav",
"method": "demucs"
}
}
print("📞 Example MCP Call:")
print(json.dumps(example_call, indent=2))
print("📤 Expected Output:")
print(" 🎤 song_vocals.wav - Clean vocal track")
print(" 🎵 High-quality AI separation")
# Demo 6: Isolate Instrument
print_tool_info("isolate_instrument", "Extract specific instruments")
example_call = {
"tool": "isolate_instrument",
"arguments": {
"audio_path": "/path/to/song.wav",
"instrument": "drums",
"method": "demucs"
}
}
print("📞 Example MCP Call:")
print(json.dumps(example_call, indent=2))
print("📤 Expected Output:")
print(" 🥁 song_drums.wav - Isolated drum track")
print(" 🎵 Clean instrument separation")
# Real-world usage examples
print_header("4. REAL-WORLD USAGE SCENARIOS", "🎯")
scenarios = [
{
"title": "🎧 Remix Production",
"description": "Extract stems from a track to create a remix",
"workflow": [
"1. Use 'generate_stems' to separate vocals, drums, bass, other",
"2. Use 'create_loop' to make drum loops for your remix",
"3. Use 'analyze_audio' to match the original tempo",
"4. Import stems into Logic Pro for remixing"
]
},
{
"title": "🎵 Sample Creation",
"description": "Create samples for beat making",
"workflow": [
"1. Use 'isolate_instrument' to extract drum sounds",
"2. Use 'split_stems' to chop drums into individual hits",
"3. Use 'create_loop' to make seamless drum patterns",
"4. Import samples into Logic Pro's sampler"
]
},
{
"title": "🎤 Vocal Processing",
"description": "Process vocals for mixing",
"workflow": [
"1. Use 'extract_vocal' to isolate vocal track",
"2. Use 'analyze_audio' to understand vocal characteristics",
"3. Use 'split_stems' to separate verse/chorus sections",
"4. Process each section differently in Logic Pro"
]
},
{
"title": "📊 Music Analysis",
"description": "Analyze tracks for music theory work",
"workflow": [
"1. Use 'analyze_audio' to get tempo, key, and features",
"2. Use 'generate_stems' to study individual parts",
"3. Use analysis data to understand song structure",
"4. Apply insights to your own compositions"
]
}
]
for scenario in scenarios:
print(f"\n{scenario['title']}")
print(f"📄 {scenario['description']}")
print("🔄 Workflow:")
for step in scenario['workflow']:
print(f" {step}")
print()
# Integration guide
print_header("5. INTEGRATION WITH LOGIC PRO", "🎚️")
print("Your MCP server integrates seamlessly with Logic Pro:")
print()
print("📥 Export from Logic Pro:")
print(" • Bounce audio tracks to WAV/AIFF files")
print(" • Export full mixes or individual stems")
print(" • Use 'Share' > 'Export Song to Audio File'")
print()
print("🔄 Process with MCP:")
print(" • Use MCP client (Claude Desktop, VS Code, etc.)")
print(" • Call stem processing tools with your audio files")
print(" • Get processed stems, loops, and analysis data")
print()
print("📤 Import back to Logic Pro:")
print(" • Drag processed files into Logic Pro projects")
print(" • Use stems for advanced mixing techniques")
print(" • Use loops in Logic Pro's loop library")
print(" • Apply analysis insights to your production")
# Performance tips
print_header("6. PERFORMANCE & TIPS", "⚡")
print("🚀 Getting the best performance:")
print()
print("🖥️ Hardware:")
print(" • CPU: Currently using CPU processing")
print(" • GPU: Install CUDA PyTorch for 10x speedup")
print(" • RAM: 16GB+ recommended for large files")
print(" • Storage: SSD recommended for faster I/O")
print()
print("📁 File Formats:")
print(" • Best: WAV, FLAC (lossless)")
print(" • Good: High-quality MP3 (320kbps)")
print(" • Avoid: Low-quality compressed files")
print()
print("⚙️ Settings:")
print(" • Use 'htdemucs' model for best quality")
print(" • Use 'htdemucs_6s' for 6-stem separation")
print(" • Adjust segment_length based on available RAM")
print(" • Use appropriate crossfade_duration for smooth loops")
print_header("🎉 DEMO COMPLETE!", "✅")
print("Your Stem MCP Server is ready for professional audio processing!")
print()
print("Next steps:")
print("1. 📱 Open your MCP client (Claude Desktop, VS Code Claude, etc.)")
print("2. 🎵 Load some audio files you want to process")
print("3. 🛠️ Use the tools we just demonstrated")
print("4. 🎚️ Import results back into Logic Pro")
print()
print("Have fun creating amazing music! 🎵✨")
if __name__ == "__main__":
asyncio.run(demo_mcp_server())