setup.shโข4.23 kB
#!/bin/bash
# Component Library MCP Server (TypeScript) - Quick Setup Script
set -e
echo "๐ Component Library MCP Server Setup (TypeScript Version)"
echo "========================================================="
echo ""
# Check if Node.js is installed
if ! command -v node &> /dev/null; then
echo "โ Node.js is not installed. Please install Node.js first."
exit 1
fi
echo "โ
Node.js found: $(node --version)"
# Check if npm is installed
if ! command -v npm &> /dev/null; then
echo "โ npm is not installed. Please install npm."
exit 1
fi
echo "โ
npm found: $(npm --version)"
echo ""
# Install dependencies
echo "๐ฆ Installing dependencies..."
npm install
echo ""
# Build TypeScript
echo "๐จ Building TypeScript..."
npm run build
echo ""
# Get paths from user
echo "๐ Please provide the following paths:"
echo " (Press Enter to use default example paths for testing)"
echo ""
read -p "Path to component library source [./example-docs/components]: " COMP_PATH
COMP_PATH=${COMP_PATH:-./example-docs/components}
read -p "Path to documentation [./example-docs]: " DOCS_PATH
DOCS_PATH=${DOCS_PATH:-./example-docs}
read -p "Path to examples [./example-docs/examples]: " EXAMPLES_PATH
EXAMPLES_PATH=${EXAMPLES_PATH:-./example-docs/examples}
# Make paths absolute
COMP_PATH=$(cd "$(dirname "$COMP_PATH")" && pwd)/$(basename "$COMP_PATH")
DOCS_PATH=$(cd "$(dirname "$DOCS_PATH")" && pwd)/$(basename "$DOCS_PATH")
EXAMPLES_PATH=$(cd "$(dirname "$EXAMPLES_PATH")" && pwd)/$(basename "$EXAMPLES_PATH")
# Create .env file
echo ""
echo "๐ Creating .env file..."
cat > .env << EOF
COMPONENTS_PATH=$COMP_PATH
DOCS_PATH=$DOCS_PATH
EXAMPLES_PATH=$EXAMPLES_PATH
EOF
echo "โ
.env file created"
echo ""
# Get installation path
INSTALL_PATH=$(pwd)
# Detect OS for config path
if [[ "$OSTYPE" == "darwin"* ]]; then
CONFIG_PATH="$HOME/Library/Application Support/Claude/claude_desktop_config.json"
elif [[ "$OSTYPE" == "linux-gnu"* ]]; then
CONFIG_PATH="$HOME/.config/claude/claude_desktop_config.json"
elif [[ "$OSTYPE" == "msys" || "$OSTYPE" == "cygwin" || "$OSTYPE" == "win32" ]]; then
CONFIG_PATH="$APPDATA/Claude/claude_desktop_config.json"
else
CONFIG_PATH="~/.config/claude/claude_desktop_config.json"
fi
# Create Claude Desktop config
echo "๐ง Generating Claude Desktop configuration..."
echo ""
CONFIG_JSON=$(cat <<EOF
{
"mcpServers": {
"component-library": {
"command": "node",
"args": ["$INSTALL_PATH/dist/index.js"],
"env": {
"COMPONENTS_PATH": "$COMP_PATH",
"DOCS_PATH": "$DOCS_PATH",
"EXAMPLES_PATH": "$EXAMPLES_PATH"
}
}
}
}
EOF
)
echo "๐ Configuration for Claude Desktop:"
echo " Config file location: $CONFIG_PATH"
echo ""
echo "$CONFIG_JSON"
echo ""
# Ask if user wants to automatically update config
read -p "Would you like to add this to your Claude Desktop config? (y/n): " UPDATE_CONFIG
if [ "$UPDATE_CONFIG" = "y" ] || [ "$UPDATE_CONFIG" = "Y" ]; then
# Create config directory if it doesn't exist
mkdir -p "$(dirname "$CONFIG_PATH")"
# Backup existing config if it exists
if [ -f "$CONFIG_PATH" ]; then
cp "$CONFIG_PATH" "$CONFIG_PATH.backup"
echo "๐ฆ Backed up existing config to $CONFIG_PATH.backup"
fi
# Update or create config
echo "$CONFIG_JSON" > "$CONFIG_PATH"
echo "โ
Configuration updated!"
fi
echo ""
# Ask if user wants to run test
read -p "Would you like to run tests to verify the setup? (y/n): " RUN_TEST
if [ "$RUN_TEST" = "y" ] || [ "$RUN_TEST" = "Y" ]; then
echo ""
echo "๐งช Running tests..."
npm test
fi
echo ""
echo "โ
Setup complete!"
echo ""
echo "Next steps:"
echo "1. Restart Claude Desktop"
echo "2. Start using the component-library MCP in your conversations!"
echo ""
echo "Example usage:"
echo ' "Use component-library MCP to list all components"'
echo ' "Get details about the Panel component using component-library"'
echo ' "Show me examples of the Form component"'
echo ""
echo "For development mode with hot reload:"
echo " Change 'node' to 'npx' and"
echo " '$INSTALL_PATH/dist/index.js' to 'tsx', '$INSTALL_PATH/src/index.ts'"
echo " in your Claude Desktop config"