#!/bin/bash
# Setup script for Anybox MCP Server with Claude Desktop
set -e
echo "π§ Anybox MCP Server - Claude Desktop Setup"
echo "============================================"
echo ""
# Get the directory where this script is located
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
VENV_PYTHON="$SCRIPT_DIR/venv/bin/python"
SERVER_SCRIPT="$SCRIPT_DIR/anybox_mcp_server.py"
CLAUDE_CONFIG="$HOME/Library/Application Support/Claude/claude_desktop_config.json"
# Check if Anybox is running
if ! pgrep -x "Anybox" > /dev/null; then
echo "β οΈ Warning: Anybox doesn't appear to be running."
echo " Please start Anybox before continuing."
read -p " Press Enter to continue anyway, or Ctrl+C to exit..."
fi
# Check if virtual environment exists
if [ ! -f "$VENV_PYTHON" ]; then
echo "β Error: Virtual environment not found at $VENV_PYTHON"
echo " Please run: python3 -m venv venv && source venv/bin/activate && pip install -r requirements.txt"
exit 1
fi
# Prompt for API key
echo ""
echo "π Please enter your Anybox API key:"
echo " (Found in Anybox β Preferences β General)"
read -p " API Key: " ANYBOX_API_KEY
if [ -z "$ANYBOX_API_KEY" ]; then
echo "β Error: API key cannot be empty"
exit 1
fi
# Test the API key
echo ""
echo "π Testing API connection..."
if curl -s -H "x-api-key: $ANYBOX_API_KEY" http://127.0.0.1:6391/tags > /dev/null 2>&1; then
echo "β
API connection successful!"
else
echo "β Error: Could not connect to Anybox API"
echo " Please check:"
echo " - Anybox is running"
echo " - API key is correct"
echo " - Anybox is accessible at http://127.0.0.1:6391"
exit 1
fi
# Create Claude Desktop config directory if it doesn't exist
mkdir -p "$(dirname "$CLAUDE_CONFIG")"
# Read existing config or create new one
if [ -f "$CLAUDE_CONFIG" ]; then
EXISTING_CONFIG=$(cat "$CLAUDE_CONFIG")
else
EXISTING_CONFIG="{}"
fi
# Create the MCP server configuration
echo ""
echo "π Updating Claude Desktop configuration..."
# Use Python to merge the JSON configs
python3 << EOF
import json
import os
existing = json.loads('''$EXISTING_CONFIG''')
# Ensure mcpServers key exists
if 'mcpServers' not in existing:
existing['mcpServers'] = {}
# Add or update the anybox server configuration
existing['mcpServers']['anybox'] = {
"command": "$VENV_PYTHON",
"args": ["$SERVER_SCRIPT"],
"env": {
"ANYBOX_API_KEY": "$ANYBOX_API_KEY"
}
}
# Write the updated config
with open("$CLAUDE_CONFIG", 'w') as f:
json.dump(existing, f, indent=2)
print("β
Configuration updated successfully!")
EOF
echo ""
echo "π Setup Complete!"
echo ""
echo "Next steps:"
echo " 1. Restart Claude Desktop completely (Quit and reopen)"
echo " 2. You should now see the Anybox tools available"
echo " 3. Try asking Claude: 'List my Anybox tags'"
echo ""
echo "Configuration file: $CLAUDE_CONFIG"
echo ""