#!/usr/bin/env python3
"""Setup script for Claude Desktop integration."""
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():
"""Set up Claude Desktop configuration for the ElevenLabs MCP server."""
print("ElevenLabs MCP Server - Claude Desktop Setup")
print("=" * 50)
# Get the current directory
current_dir = os.path.dirname(os.path.abspath(__file__))
# Get API key from user
api_key = input("\nEnter your ElevenLabs API key (or press Enter to use placeholder): ").strip()
if not api_key:
api_key = "your-api-key-here"
print("⚠️ Using placeholder API key. You'll need to update it manually.")
# 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")
}
}
}
}
# Get Claude Desktop config path
claude_config_path = get_claude_desktop_config_path()
print(f"\nClaude Desktop config path: {claude_config_path}")
# Check if Claude Desktop config directory exists
config_dir = claude_config_path.parent
if not config_dir.exists():
print(f"✗ Claude Desktop config directory does not exist: {config_dir}")
print(" Make sure Claude Desktop is installed and has been run at least once.")
return False
# 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}")
return False
# 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
# Display success message
print("\n" + "=" * 50)
print("🎉 Claude Desktop Setup Complete!")
print("\nNext steps:")
print("1. Restart Claude Desktop completely")
print("2. Look for the MCP server connection indicator")
print("3. Try these test commands:")
print(" - 'What MCP tools are available?'")
print(" - 'List my ElevenLabs agents'")
print(" - 'Show my knowledge base documents'")
if api_key == "your-api-key-here":
print(f"\n⚠️ Remember to update your API key in:")
print(f" {claude_config_path}")
print(" Replace 'your-api-key-here' with your actual ElevenLabs API key")
print("\n📚 Documentation:")
print(" - README.md: Complete usage guide")
print(" - CLAUDE_DESKTOP_TEST.md: Testing instructions")
print(" - TESTING_SUMMARY.md: Full test results")
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 server_config['env']['ELEVENLABS_API_KEY'] == "your-api-key-here":
print("⚠️ API key is still placeholder - update it with your real key")
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
if __name__ == "__main__":
success = setup_claude_desktop()
if success:
verify_setup()
else:
print("\n❌ Setup failed. Please check the errors above.")
sys.exit(1)