#!/usr/bin/env python3
"""
Maya MCP Server - Setup Script
Automated installation and configuration
"""
import os
import sys
import json
import shutil
from pathlib import Path
class Colors:
HEADER = '\033[95m'
BLUE = '\033[94m'
GREEN = '\033[92m'
YELLOW = '\033[93m'
RED = '\033[91m'
END = '\033[0m'
BOLD = '\033[1m'
def print_header(text):
print(f"\n{Colors.HEADER}{Colors.BOLD}{'='*60}{Colors.END}")
print(f"{Colors.HEADER}{Colors.BOLD}{text:^60}{Colors.END}")
print(f"{Colors.HEADER}{Colors.BOLD}{'='*60}{Colors.END}\n")
def print_success(text):
print(f"{Colors.GREEN}✓ {text}{Colors.END}")
def print_error(text):
print(f"{Colors.RED}✗ {text}{Colors.END}")
def print_info(text):
print(f"{Colors.BLUE}ℹ {text}{Colors.END}")
def install_dependencies():
"""Install Python dependencies."""
print_info("Installing dependencies...")
try:
import subprocess
subprocess.check_call([
sys.executable, "-m", "pip", "install",
"-r", "requirements.txt",
"--break-system-packages"
])
print_success("Dependencies installed")
return True
except Exception as e:
print_error(f"Failed to install dependencies: {e}")
return False
def find_claude_config():
"""Find Claude Desktop configuration file."""
home = Path.home()
if sys.platform == "darwin": # macOS
config_path = home / "Library/Application Support/Claude/claude_desktop_config.json"
elif sys.platform == "win32": # Windows
config_path = home / "AppData/Roaming/Claude/claude_desktop_config.json"
else: # Linux
config_path = home / ".config/Claude/claude_desktop_config.json"
return config_path if config_path.exists() else None
def configure_claude():
"""Configure Claude Desktop."""
print_info("Configuring Claude Desktop...")
config_path = find_claude_config()
if not config_path:
print_info("Claude config not found - you'll need to configure manually")
print_manual_config()
return False
server_path = Path.cwd() / "src" / "expanded_mcp_server.py"
try:
with open(config_path, 'r') as f:
config = json.load(f)
except:
config = {}
if "mcpServers" not in config:
config["mcpServers"] = {}
config["mcpServers"]["maya"] = {
"command": sys.executable,
"args": [str(server_path)],
"env": {
"MAYA_HOST": "localhost",
"MAYA_PORT": "4434"
}
}
# Backup
backup_path = config_path.with_suffix('.json.backup')
try:
shutil.copy2(config_path, backup_path)
print_info(f"Backed up config to {backup_path}")
except:
pass
# Write
try:
with open(config_path, 'w') as f:
json.dump(config, f, indent=2)
print_success("Claude Desktop configured")
return True
except Exception as e:
print_error(f"Failed to configure Claude: {e}")
return False
def print_manual_config():
"""Print manual configuration instructions."""
server_path = Path.cwd() / "src" / "expanded_mcp_server.py"
print("\n" + "="*60)
print("Manual Configuration Required")
print("="*60)
print("\nAdd this to your Claude Desktop config file:")
print()
print(json.dumps({
"mcpServers": {
"maya": {
"command": sys.executable,
"args": [str(server_path)],
"env": {
"MAYA_HOST": "localhost",
"MAYA_PORT": "4434"
}
}
}
}, indent=2))
print("\nConfig file locations:")
print(" macOS: ~/Library/Application Support/Claude/claude_desktop_config.json")
print(" Windows: %APPDATA%/Claude/claude_desktop_config.json")
print(" Linux: ~/.config/Claude/claude_desktop_config.json")
print()
def print_next_steps():
"""Print next steps."""
print_header("Installation Complete!")
print(f"{Colors.BOLD}Next Steps:{Colors.END}\n")
print("1. Start Maya")
print()
print("2. In Maya Script Editor (Python), run:")
print(f"{Colors.BLUE} import maya.cmds as cmds{Colors.END}")
print(f"{Colors.BLUE} cmds.commandPort(name='localhost:4434', sourceType='python'){Colors.END}")
print()
print("3. Restart Claude Desktop")
print()
print("4. Try it out:")
print(f"{Colors.BLUE} \"Create a torus\"{Colors.END}")
print()
print(f"{Colors.BOLD}Documentation:{Colors.END}")
print(" docs/QUICK_START.md - Quick start guide")
print(" docs/TOOLS_REFERENCE.md - All tools")
print(" docs/EXAMPLES.md - Tutorials")
print()
print(f"{Colors.BOLD}Testing:{Colors.END}")
print(" python tests/test_connection.py")
print()
def main():
"""Main setup function."""
print_header("Maya MCP Server Setup")
success = True
# Install dependencies
success &= install_dependencies()
# Configure Claude
configure_claude()
# Next steps
print_next_steps()
if __name__ == "__main__":
main()