#!/usr/bin/env python3
"""Automated setup script for Claude Desktop integration (non-interactive)."""
import json
import os
import sys
import shutil
from pathlib import Path
def get_claude_desktop_config_path():
"""Get the Claude Desktop configuration file path for the current OS."""
if sys.platform == "darwin": # macOS
return Path.home() / "Library/Application Support/Claude/claude_desktop_config.json"
elif sys.platform == "win32": # Windows
return Path.home() / "AppData/Roaming/Claude/claude_desktop_config.json"
else: # Linux
return Path.home() / ".config/Claude/claude_desktop_config.json"
def setup_claude_desktop_auto():
"""Set up Claude Desktop configuration automatically."""
print("ElevenLabs MCP Server - Automated Claude Desktop Setup")
print("=" * 60)
# Get the current directory
current_dir = os.path.dirname(os.path.abspath(__file__))
# Use placeholder API key for now
api_key = "your-elevenlabs-api-key-here"
print(f"Using placeholder API key: {api_key}")
# Create configuration
config = {
"mcpServers": {
"elevenlabs": {
"command": "python",
"args": ["-m", "elevenlabs_mcp.server"],
"cwd": current_dir,
"env": {
"ELEVENLABS_API_KEY": api_key,
"PYTHONPATH": os.path.join(current_dir, "src"),
"LOG_LEVEL": "INFO"
}
}
}
}
# Get Claude Desktop config path
claude_config_path = get_claude_desktop_config_path()
print(f"\nClaude Desktop config path: {claude_config_path}")
print(f"Working directory: {current_dir}")
print(f"Python path: {os.path.join(current_dir, 'src')}")
# Create config directory if it doesn't exist
config_dir = claude_config_path.parent
if not config_dir.exists():
print(f"Creating config directory: {config_dir}")
config_dir.mkdir(parents=True, exist_ok=True)
# Check if config file already exists
if claude_config_path.exists():
print(f"✓ Existing config file found")
# Load existing configuration
try:
with open(claude_config_path, 'r') as f:
existing_config = json.load(f)
# Merge configurations
if "mcpServers" not in existing_config:
existing_config["mcpServers"] = {}
existing_config["mcpServers"]["elevenlabs"] = config["mcpServers"]["elevenlabs"]
config = existing_config
print("✓ Merged with existing configuration")
except json.JSONDecodeError:
print("⚠️ Existing config file is invalid JSON. Creating backup...")
backup_path = claude_config_path.with_suffix('.json.backup')
shutil.copy2(claude_config_path, backup_path)
print(f"✓ Backup created: {backup_path}")
except Exception as e:
print(f"⚠️ Error reading existing config: {e}")
print("Creating new configuration...")
else:
print("Creating new configuration file...")
# Write the configuration
try:
with open(claude_config_path, 'w') as f:
json.dump(config, f, indent=2)
print(f"✓ Configuration written successfully")
# Also save a copy in the current directory for reference
reference_path = os.path.join(current_dir, "claude_desktop_config_installed.json")
with open(reference_path, 'w') as f:
json.dump(config, f, indent=2)
print(f"✓ Reference copy saved: {reference_path}")
except Exception as e:
print(f"✗ Error writing configuration: {e}")
return False
return True
def verify_setup():
"""Verify that the setup was successful."""
print("\nVerifying setup...")
# Check if config file exists and is valid
claude_config_path = get_claude_desktop_config_path()
if not claude_config_path.exists():
print("✗ Configuration file not found")
return False
try:
with open(claude_config_path, 'r') as f:
config = json.load(f)
if "mcpServers" in config and "elevenlabs" in config["mcpServers"]:
print("✓ ElevenLabs MCP server found in configuration")
server_config = config["mcpServers"]["elevenlabs"]
print(f"✓ Command: {server_config['command']} {' '.join(server_config['args'])}")
print(f"✓ Working directory: {server_config['cwd']}")
print(f"✓ Python path: {server_config['env']['PYTHONPATH']}")
if "your-elevenlabs-api-key-here" in server_config['env']['ELEVENLABS_API_KEY']:
print("⚠️ API key is placeholder - you need to update it!")
else:
print("✓ API key is set")
return True
else:
print("✗ ElevenLabs MCP server not found in configuration")
return False
except Exception as e:
print(f"✗ Error reading configuration: {e}")
return False
def print_next_steps():
"""Print the next steps for the user."""
print("\n" + "=" * 60)
print("🎉 Claude Desktop Setup Complete!")
print("\nIMPORTANT: You must update the API key!")
claude_config_path = get_claude_desktop_config_path()
print(f"\n📝 Edit this file:")
print(f" {claude_config_path}")
print(f"\n🔑 Replace 'your-elevenlabs-api-key-here' with your actual API key")
print(f" Get your API key from: https://elevenlabs.io/app/settings/api-keys")
print(f"\n🔄 After updating the API key:")
print(" 1. Restart Claude Desktop completely (Quit and reopen)")
print(" 2. Wait 10-30 seconds for the MCP server to initialize")
print(" 3. Look for the MCP connection indicator")
print(f"\n🧪 Test commands to try in Claude Desktop:")
print(" - 'What MCP tools are available?'")
print(" - 'List my ElevenLabs agents'")
print(" - 'Show my ElevenLabs knowledge base documents'")
print(" - 'Create a simple customer service agent'")
print(f"\n📚 Documentation:")
print(" - CLAUDE_DESKTOP_INTEGRATION_GUIDE.md: Complete integration guide")
print(" - CLAUDE_DESKTOP_TEST.md: Detailed testing instructions")
print(" - README.md: Full documentation")
if __name__ == "__main__":
try:
success = setup_claude_desktop_auto()
if success:
verify_setup()
print_next_steps()
else:
print("\n❌ Setup failed. Please check the errors above.")
sys.exit(1)
except KeyboardInterrupt:
print("\n\n⚠️ Setup interrupted by user.")
sys.exit(1)
except Exception as e:
print(f"\n❌ Unexpected error: {e}")
sys.exit(1)