#!/usr/bin/env python3
"""
MCP Server Setup Diagnostic Tool
================================
This script tests if your MCP server setup is working correctly.
"""
import sys
import subprocess
import json
from pathlib import Path
def test_python_environment():
"""Test Python environment"""
print("π Testing Python Environment:")
print(f" Python version: {sys.version}")
print(f" Python executable: {sys.executable}")
print(f" Virtual environment: {'β
' if hasattr(sys, 'real_prefix') or (hasattr(sys, 'base_prefix') and sys.base_prefix != sys.prefix) else 'β'}")
def test_imports():
"""Test required imports"""
print("\nπ¦ Testing Required Imports:")
required_packages = [
'mcp',
'librosa',
'soundfile',
'numpy',
'torch',
'demucs',
'stem_mcp'
]
for package in required_packages:
try:
__import__(package)
print(f" β
{package}")
except ImportError as e:
print(f" β {package} - {e}")
def test_mcp_server():
"""Test MCP server startup"""
print("\nπ₯οΈ Testing MCP Server Startup:")
try:
# Test the server can start
result = subprocess.run([
sys.executable, '-m', 'stem_mcp.server', '--help'
], capture_output=True, text=True, timeout=5)
if result.returncode == 0:
print(" β
Server starts successfully")
print(" β
Help command works")
else:
print(f" β Server failed to start: {result.stderr}")
except Exception as e:
print(f" β Server test failed: {e}")
def test_audio_files():
"""Test audio file access"""
print("\nπ΅ Testing Audio Files:")
test_file = Path("examples/test_sample.wav")
if test_file.exists():
print(f" β
Test audio file exists: {test_file}")
size_mb = test_file.stat().st_size / (1024 * 1024)
print(f" β
File size: {size_mb:.2f} MB")
else:
print(f" β Test audio file not found: {test_file}")
def test_claude_config():
"""Test Claude Desktop configuration"""
print("\nβοΈ Testing Claude Desktop Configuration:")
config_path = Path.home() / "Library/Application Support/Claude/claude_desktop_config.json"
if config_path.exists():
print(f" β
Config file exists: {config_path}")
try:
with open(config_path) as f:
config = json.load(f)
if 'mcpServers' in config and 'stem-processing' in config['mcpServers']:
print(" β
stem-processing server configured")
server_config = config['mcpServers']['stem-processing']
command = server_config.get('command', '')
if Path(command).exists():
print(f" β
Command file exists: {command}")
else:
print(f" β Command file not found: {command}")
else:
print(" β stem-processing server not configured")
except Exception as e:
print(f" β Error reading config: {e}")
else:
print(f" β Config file not found: {config_path}")
def test_wrapper_script():
"""Test the wrapper script"""
print("\nπ Testing Wrapper Script:")
wrapper_path = Path("start_mcp_server.sh")
if wrapper_path.exists():
print(f" β
Wrapper script exists: {wrapper_path}")
# Check if executable
if wrapper_path.stat().st_mode & 0o111:
print(" β
Wrapper script is executable")
else:
print(" β Wrapper script is not executable")
# Test wrapper script
try:
result = subprocess.run([
str(wrapper_path), '--help'
], capture_output=True, text=True, timeout=5)
if result.returncode == 0:
print(" β
Wrapper script works")
else:
print(f" β Wrapper script failed: {result.stderr}")
except Exception as e:
print(f" β Wrapper script test failed: {e}")
else:
print(f" β Wrapper script not found: {wrapper_path}")
def main():
"""Run all diagnostic tests"""
print("π§ MCP Server Setup Diagnostic")
print("=" * 50)
# Change to script directory
script_dir = Path(__file__).parent
import os
os.chdir(script_dir)
# Add src to Python path
sys.path.insert(0, str(script_dir / "src"))
test_python_environment()
test_imports()
test_mcp_server()
test_audio_files()
test_claude_config()
test_wrapper_script()
print("\n" + "=" * 50)
print("π― Diagnostic Complete!")
print("\nIf you see β errors above, those need to be fixed for Claude Desktop to work.")
print("If all tests show β
, restart Claude Desktop and try again!")
if __name__ == "__main__":
main()