Fix Twilio MCP integration with baked-in credentials
- Add proper type and env sections to mcp-config.json - Remove dynamic MCP add command, use pre-configured MCP - Bake .env credentials into Docker image at build time - Remove runtime .env volume mount - true one-time setup - Auto-rebuild image when .env file changes - Export Twilio env vars for MCP server subprocess - Remove conflicting .mcp.json file
This commit is contained in:
@@ -24,18 +24,42 @@ if [ ! -d "$CURRENT_DIR/.claude" ]; then
|
||||
echo "✓ Claude configuration created"
|
||||
fi
|
||||
|
||||
# Check if .env file exists in user's home claude-docker directory
|
||||
ENV_FILE="$HOME/.claude-docker/.env"
|
||||
if [ ! -f "$ENV_FILE" ]; then
|
||||
# Check if .env exists in claude-docker directory for building
|
||||
ENV_FILE="$PROJECT_ROOT/.env"
|
||||
if [ -f "$ENV_FILE" ]; then
|
||||
echo "✓ Found .env file with credentials"
|
||||
else
|
||||
echo "⚠️ No .env file found at $ENV_FILE"
|
||||
echo "Please create it with your API keys. See .env.example for reference."
|
||||
exit 1
|
||||
echo " Twilio MCP features will be unavailable."
|
||||
echo " To enable: create .env in claude-docker directory with your credentials"
|
||||
fi
|
||||
|
||||
# Build the Docker image if it doesn't exist
|
||||
# Check if we need to rebuild the image
|
||||
NEED_REBUILD=false
|
||||
|
||||
if ! docker images | grep -q "claude-docker"; then
|
||||
echo "Building Claude Docker image..."
|
||||
docker build -t claude-docker:latest "$PROJECT_ROOT"
|
||||
echo "Building Claude Docker image with your user permissions..."
|
||||
NEED_REBUILD=true
|
||||
elif ! docker image inspect claude-docker:latest | grep -q "USER_UID.*$(id -u)" 2>/dev/null; then
|
||||
echo "Rebuilding Claude Docker image to match your user permissions..."
|
||||
NEED_REBUILD=true
|
||||
elif [ -f "$ENV_FILE" ]; then
|
||||
# Check if .env is newer than the Docker image
|
||||
IMAGE_CREATED=$(docker inspect -f '{{.Created}}' claude-docker:latest 2>/dev/null)
|
||||
if [ -n "$IMAGE_CREATED" ]; then
|
||||
IMAGE_TIMESTAMP=$(date -d "$IMAGE_CREATED" +%s 2>/dev/null || date -j -f "%Y-%m-%dT%H:%M:%S" "${IMAGE_CREATED%%.*}" +%s 2>/dev/null)
|
||||
ENV_TIMESTAMP=$(stat -c %Y "$ENV_FILE" 2>/dev/null || stat -f %m "$ENV_FILE" 2>/dev/null)
|
||||
|
||||
if [ -n "$IMAGE_TIMESTAMP" ] && [ -n "$ENV_TIMESTAMP" ] && [ "$ENV_TIMESTAMP" -gt "$IMAGE_TIMESTAMP" ]; then
|
||||
echo "⚠️ .env file has been updated since last build"
|
||||
echo " Rebuilding to include new credentials..."
|
||||
NEED_REBUILD=true
|
||||
fi
|
||||
fi
|
||||
fi
|
||||
|
||||
if [ "$NEED_REBUILD" = true ]; then
|
||||
docker build --build-arg USER_UID=$(id -u) --build-arg USER_GID=$(id -g) -t claude-docker:latest "$PROJECT_ROOT"
|
||||
fi
|
||||
|
||||
# Ensure the claude-home directory exists
|
||||
@@ -45,8 +69,6 @@ mkdir -p "$HOME/.claude-docker/claude-home"
|
||||
echo "Starting Claude Code in Docker..."
|
||||
docker run -it --rm \
|
||||
-v "$CURRENT_DIR:/workspace" \
|
||||
-v "$ENV_FILE:/app/.env:ro" \
|
||||
-v "$HOME/.claude-docker/config:/app/.claude:rw" \
|
||||
-v "$HOME/.claude-docker/claude-home:/home/claude-user/.claude:rw" \
|
||||
--workdir /workspace \
|
||||
--name claude-docker-session \
|
||||
|
51
scripts/setup-env.sh
Normal file
51
scripts/setup-env.sh
Normal file
@@ -0,0 +1,51 @@
|
||||
#!/bin/bash
|
||||
# ABOUTME: Setup script to create ~/.claude-docker/.env with Twilio credentials
|
||||
# ABOUTME: Run this once on your host machine to configure Twilio for all projects
|
||||
|
||||
CLAUDE_DOCKER_DIR="$HOME/.claude-docker"
|
||||
ENV_FILE="$CLAUDE_DOCKER_DIR/.env"
|
||||
|
||||
# Create directory if it doesn't exist
|
||||
mkdir -p "$CLAUDE_DOCKER_DIR"
|
||||
|
||||
# Check if .env already exists
|
||||
if [ -f "$ENV_FILE" ]; then
|
||||
echo "⚠️ $ENV_FILE already exists!"
|
||||
read -p "Do you want to update it? (y/N) " -n 1 -r
|
||||
echo
|
||||
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
|
||||
exit 0
|
||||
fi
|
||||
fi
|
||||
|
||||
echo "Setting up Twilio credentials for Claude Docker..."
|
||||
echo "You'll need your Twilio account information."
|
||||
echo
|
||||
|
||||
# Collect Twilio credentials
|
||||
read -p "Enter your Twilio Account SID: " TWILIO_ACCOUNT_SID
|
||||
read -p "Enter your Twilio API Key: " TWILIO_API_KEY
|
||||
read -sp "Enter your Twilio API Secret: " TWILIO_API_SECRET
|
||||
echo
|
||||
read -p "Enter your Twilio phone number (with country code, e.g., +1234567890): " TWILIO_FROM_NUMBER
|
||||
read -p "Enter the phone number to receive SMS (with country code): " TWILIO_TO_NUMBER
|
||||
|
||||
# Create .env file
|
||||
cat > "$ENV_FILE" << EOF
|
||||
# Twilio credentials for Claude Docker
|
||||
TWILIO_ACCOUNT_SID=$TWILIO_ACCOUNT_SID
|
||||
TWILIO_API_KEY=$TWILIO_API_KEY
|
||||
TWILIO_API_SECRET=$TWILIO_API_SECRET
|
||||
TWILIO_FROM_NUMBER=$TWILIO_FROM_NUMBER
|
||||
TWILIO_TO_NUMBER=$TWILIO_TO_NUMBER
|
||||
EOF
|
||||
|
||||
# Set restrictive permissions
|
||||
chmod 600 "$ENV_FILE"
|
||||
|
||||
echo
|
||||
echo "✅ Twilio credentials saved to $ENV_FILE"
|
||||
echo "These credentials will be available to all Claude Docker sessions."
|
||||
echo
|
||||
echo "To test, run claude-docker from any project directory and use:"
|
||||
echo " node /workspace/test-twilio.js"
|
@@ -3,10 +3,22 @@
|
||||
# ABOUTME: Configures environment and starts Claude Code with Twilio MCP integration
|
||||
|
||||
# Load environment variables from .env if it exists
|
||||
# Use the .env file baked into the image at build time
|
||||
if [ -f /app/.env ]; then
|
||||
echo "Loading credentials from baked-in .env file"
|
||||
set -a
|
||||
source /app/.env 2>/dev/null || true
|
||||
set +a
|
||||
|
||||
# Export Twilio variables for MCP server
|
||||
export TWILIO_ACCOUNT_SID
|
||||
export TWILIO_API_KEY
|
||||
export TWILIO_API_SECRET
|
||||
export TWILIO_FROM_NUMBER
|
||||
export TWILIO_TO_NUMBER
|
||||
else
|
||||
echo "WARNING: No .env file found in image. Twilio features will be unavailable."
|
||||
echo "To enable Twilio: create .env in claude-docker directory before building the image."
|
||||
fi
|
||||
|
||||
# Configure Claude Code to use the MCP server
|
||||
@@ -20,11 +32,17 @@ else
|
||||
echo "Your login will be saved for future sessions"
|
||||
fi
|
||||
|
||||
# Start Claude Code with permissions bypass
|
||||
echo "Starting Claude Code..."
|
||||
if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_API_KEY" ]; then
|
||||
echo "Twilio MCP integration enabled"
|
||||
# Verify Twilio MCP configuration
|
||||
if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_API_KEY" ] && [ -n "$TWILIO_API_SECRET" ]; then
|
||||
echo "Twilio MCP pre-configured with:"
|
||||
echo " - Account SID: ${TWILIO_ACCOUNT_SID:0:10}..."
|
||||
echo " - From Number: $TWILIO_FROM_NUMBER"
|
||||
echo " - To Number: $TWILIO_TO_NUMBER"
|
||||
echo " - MCP Config: $CLAUDE_MCP_CONFIG"
|
||||
else
|
||||
echo "No Twilio credentials found, MCP features will be unavailable"
|
||||
fi
|
||||
|
||||
# Start Claude Code with permissions bypass
|
||||
echo "Starting Claude Code..."
|
||||
exec claude --dangerously-skip-permissions "$@"
|
Reference in New Issue
Block a user