#!/bin/bash
echo "π Setting up MCP Next.js development environment..."
# Install dependencies first
echo "π¦ Installing dependencies..."
if command -v pnpm &> /dev/null; then
pnpm install
elif command -v npm &> /dev/null; then
npm install
else
echo "β Neither pnpm nor npm found. Please install Node.js and a package manager."
exit 1
fi
echo "β
Dependencies installed successfully"
echo ""
# Check for Upstash Redis configuration
if [ -f .env.local ] && grep -q "UPSTASH_REDIS_REST_URL" .env.local && grep -q "UPSTASH_REDIS_REST_TOKEN" .env.local; then
echo "β
Upstash Redis already configured!"
echo " Using cloud Redis database for SSE transport"
echo ""
echo "π Starting development server..."
pnpm dev
exit 0
fi
echo "π Redis Setup Options:"
echo " 1. Upstash KV (Cloud Redis) - Recommended for production"
echo " 2. Local Docker Redis - Good for development"
echo ""
# Check if .env.development.local exists (from vercel env pull)
if [ -f .env.development.local ]; then
echo "π Found .env.development.local from Vercel"
echo " This likely contains Upstash Redis configuration"
echo " Copying to .env.local for local development..."
cp .env.development.local .env.local
echo "β
Environment variables copied"
echo ""
echo "π Starting development server..."
pnpm dev
exit 0
fi
echo "π³ Setting up local Redis with Docker..."
if ! command -v docker &> /dev/null; then
echo "β Docker is not installed. Please install Docker first:"
echo " Visit: https://docs.docker.com/get-docker/"
echo ""
echo "π‘ Alternative: Set up Upstash Redis instead:"
echo " 1. Run: vercel link (if not already linked)"
echo " 2. Run: vercel env pull .env.development.local"
echo " 3. Run this script again"
exit 1
fi
if ! docker info &> /dev/null; then
echo "β Docker daemon is not running. Please start Docker first."
echo " β’ Open Docker Desktop application"
echo " β’ Or start Docker daemon if using Docker CLI"
echo ""
echo "β οΈ You can still use the HTTP transport without Redis:"
echo " β’ Run 'pnpm dev'"
echo " β’ Test with: 'node scripts/test-streamable-http-client.mjs http://localhost:3000'"
echo ""
else
if docker ps | grep -q "redis-mcp"; then
echo "β
Redis container 'redis-mcp' is already running"
else
if docker ps -a | grep -q "redis-mcp"; then
echo "π Starting existing Redis container..."
docker start redis-mcp
else
echo "π¦ Creating new Redis container..."
docker run -d --name redis-mcp -p 6379:6379 redis:latest
fi
echo "β
Redis is now running on localhost:6379"
fi
fi
ENV_CREATED=false
if [ ! -f .env.local ]; then
echo "π Creating .env.local file..."
echo "REDIS_URL=redis://localhost:6379" > .env.local
echo "β
Created .env.local with Redis configuration"
ENV_CREATED=true
else
if ! grep -q "REDIS_URL" .env.local; then
echo "π Adding Redis URL to existing .env.local..."
echo "REDIS_URL=redis://localhost:6379" >> .env.local
echo "β
Added Redis configuration to .env.local"
ENV_CREATED=true
else
echo "β
Redis URL already configured in .env.local"
fi
fi
if [ "$ENV_CREATED" = true ]; then
echo "π Stopping any running Next.js server to pick up new environment variables..."
pkill -f "next dev" 2>/dev/null || true
sleep 2
fi
echo ""
echo "π Local Redis setup complete! You can now:"
echo " β’ Test SSE client: 'pnpm test:sse'"
echo " β’ Test HTTP client: 'pnpm test:http'"
echo ""
echo "π³ Redis Management:"
echo " β’ Stop Redis: 'docker stop redis-mcp'"
echo " β’ Remove Redis: 'docker rm redis-mcp'"
echo ""
echo "π€ To connect to Claude Desktop, add this to your config:"
echo " {\"mcpServers\":{\"agent-bootcamp\":{\"command\":\"npx\",\"args\":[\"-y\",\"mcp-remote\",\"http://localhost:3000/mcp\"]}}}"
echo ""
echo "βοΈ To switch to Upstash Redis later:"
echo " 1. Run: vercel link"
echo " 2. Run: vercel env pull .env.development.local"
echo " 3. Restart the development server"
echo ""
echo "π Starting development server..."
pnpm dev