From d9bf0f4b5379f97ce4d1fcfab160319a78b5d6a8 Mon Sep 17 00:00:00 2001 From: Vishal Jain Date: Tue, 17 Jun 2025 21:48:00 +0100 Subject: [PATCH] Switch to simplified Twilio MCP integration using @yiyang.1i/sms-mcp-server - Replace API Key/Secret auth with Account SID/Auth Token - Configure MCP during Docker build instead of runtime - Remove mcp-config.json and config directory - Simplify startup script by removing MCP configuration logic - Update documentation and test scripts for new auth method The MCP server is now configured directly in the Dockerfile using 'claude mcp add-json' command, making the setup more reliable and eliminating runtime configuration complexity. --- .env.example | 3 +-- Dockerfile | 18 +++++++++++------- README.md | 7 ++----- config/mcp-config.json | 24 ------------------------ scratchpad.md | 35 +++++++++++++++++++++++++++++++++++ scripts/setup-env.sh | 6 ++---- scripts/startup.sh | 23 +++++++++-------------- test-twilio.js | 7 +++---- 8 files changed, 63 insertions(+), 60 deletions(-) delete mode 100644 config/mcp-config.json diff --git a/.env.example b/.env.example index 86784df..f58c456 100644 --- a/.env.example +++ b/.env.example @@ -6,7 +6,6 @@ ANTHROPIC_API_KEY=your_anthropic_api_key_here # Optional: Twilio credentials for SMS notifications TWILIO_ACCOUNT_SID=your_twilio_account_sid -TWILIO_API_KEY=your_twilio_api_key -TWILIO_API_SECRET=your_twilio_api_secret +TWILIO_AUTH_TOKEN=your_twilio_auth_token TWILIO_FROM_NUMBER=+1234567890 TWILIO_TO_NUMBER=+0987654321 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 75f5242..fe17600 100644 --- a/Dockerfile +++ b/Dockerfile @@ -28,14 +28,8 @@ RUN npm install -g @anthropic-ai/claude-code # Ensure npm global bin is in PATH ENV PATH="/usr/local/bin:${PATH}" -# Install Twilio MCP server -RUN npm install -g @twilio-alpha/mcp - # Create directories for configuration -RUN mkdir -p /app/config /app/.claude /home/claude-user/.claude - -# Copy MCP configuration -COPY config/mcp-config.json /app/config/ +RUN mkdir -p /app/.claude /home/claude-user/.claude # Copy startup script COPY scripts/startup.sh /app/ @@ -51,6 +45,16 @@ RUN chown -R claude-user:claude-user /app /home/claude-user # Switch to non-root user USER claude-user +# Configure MCP server during build if Twilio credentials are provided +RUN bash -c 'source /app/.env && \ + if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_AUTH_TOKEN" ]; then \ + echo "Configuring Twilio MCP server..." && \ + /usr/local/bin/claude mcp add-json twilio \ + "{\"command\":\"npx\",\"args\":[\"-y\",\"@yiyang.1i/sms-mcp-server\"],\"env\":{\"ACCOUNT_SID\":\"$TWILIO_ACCOUNT_SID\",\"AUTH_TOKEN\":\"$TWILIO_AUTH_TOKEN\",\"FROM_NUMBER\":\"$TWILIO_FROM_NUMBER\"}}"; \ + else \ + echo "No Twilio credentials found, skipping MCP configuration"; \ + fi' + # Set working directory to mounted volume WORKDIR /workspace diff --git a/README.md b/README.md index a4b8d5f..3822318 100644 --- a/README.md +++ b/README.md @@ -33,8 +33,7 @@ A Docker container setup for running Claude Code with full autonomous permission # For Twilio MCP integration (optional): TWILIO_ACCOUNT_SID=your_twilio_sid - TWILIO_API_KEY=your_twilio_api_key - TWILIO_API_SECRET=your_twilio_api_secret + TWILIO_AUTH_TOKEN=your_twilio_auth_token TWILIO_FROM_NUMBER=your_twilio_number TWILIO_TO_NUMBER=your_phone_number ``` @@ -44,7 +43,7 @@ A Docker container setup for running Claude Code with full autonomous permission > - You can use the image from any directory without needing the .env file > - Keep your image secure since it contains your credentials - > **Note**: Twilio MCP requires API Key/Secret instead of Auth Token. Create API keys in your Twilio Console under Account → API keys & tokens. + > **Note**: Twilio MCP uses Account SID and Auth Token. You can find these in your Twilio Console. 3. **Build and install:** ```bash @@ -138,8 +137,6 @@ claude-docker/ │ ├── claude-docker.sh # Wrapper script for container │ ├── install.sh # Installation script │ └── startup.sh # Container startup script -├── config/ -│ └── mcp-config.json # MCP server configuration └── templates/ └── scratchpad.md # Template for project context ``` diff --git a/config/mcp-config.json b/config/mcp-config.json deleted file mode 100644 index 568e180..0000000 --- a/config/mcp-config.json +++ /dev/null @@ -1,24 +0,0 @@ -{ - "mcpServers": { - "twilio": { - "type": "stdio", - "command": "npx", - "args": [ - "-y", - "@twilio-alpha/mcp", - "${TWILIO_ACCOUNT_SID}/${TWILIO_API_KEY}:${TWILIO_API_SECRET}", - "--services", - "twilio_api_v2010", - "--tags", - "Api20100401Message" - ], - "env": { - "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}" - } - } - } -} \ No newline at end of file diff --git a/scratchpad.md b/scratchpad.md index 349f5f0..16b1c23 100644 --- a/scratchpad.md +++ b/scratchpad.md @@ -128,6 +128,41 @@ Building a Docker container that runs Claude Code with full autonomous permissio - Tokens stored in temp locations that get cleared - Need to find exact token storage location and persist it +## MCP Integration Update (2024-12-17) + +### ✅ COMPLETED: Simplified Twilio MCP Integration + +**What Changed:** +1. **Switched MCP Server:** From `@twilio-alpha/mcp` (API Key/Secret) to `@yiyang.1i/sms-mcp-server` (Auth Token) +2. **Simplified Configuration:** MCP setup now happens during Docker build instead of runtime +3. **Removed Complexity:** No more mcp-config.json or environment variable substitution + +**Implementation Details:** +1. **Updated .env.example:** + - Removed: `TWILIO_API_KEY` and `TWILIO_API_SECRET` + - Added: `TWILIO_AUTH_TOKEN` + - Kept: `TWILIO_ACCOUNT_SID`, `TWILIO_FROM_NUMBER`, `TWILIO_TO_NUMBER` + +2. **Updated Dockerfile:** + - Removed global installation of `@twilio-alpha/mcp` + - Added MCP configuration during build using `claude mcp add-json` command + - MCP server is configured if Twilio credentials are present in .env + +3. **Simplified startup.sh:** + - Removed all MCP configuration logic + - Just loads environment variables and starts Claude + - Shows Twilio status on startup + +4. **Removed Files:** + - `config/mcp-config.json` (no longer needed) + - `config/` directory (now empty) + +**Result:** +- MCP configuration is baked into the Docker image at build time +- No runtime configuration needed +- Simpler, more reliable setup +- SMS capability available via `twilio__send_text` command + ## Quick References - Install: `./scripts/install.sh` - Usage: `claude-docker` (from any project directory) diff --git a/scripts/setup-env.sh b/scripts/setup-env.sh index b935466..7a2f603 100644 --- a/scripts/setup-env.sh +++ b/scripts/setup-env.sh @@ -24,8 +24,7 @@ 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 +read -sp "Enter your Twilio Auth Token: " TWILIO_AUTH_TOKEN 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 @@ -34,8 +33,7 @@ read -p "Enter the phone number to receive SMS (with country code): " TWILIO_TO_ 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_AUTH_TOKEN=$TWILIO_AUTH_TOKEN TWILIO_FROM_NUMBER=$TWILIO_FROM_NUMBER TWILIO_TO_NUMBER=$TWILIO_TO_NUMBER EOF diff --git a/scripts/startup.sh b/scripts/startup.sh index 5d4edf1..39a399c 100755 --- a/scripts/startup.sh +++ b/scripts/startup.sh @@ -1,29 +1,24 @@ #!/bin/bash # ABOUTME: Startup script for Claude Code container with MCP server -# ABOUTME: Configures environment and starts Claude Code with Twilio MCP integration +# ABOUTME: Loads environment and starts Claude Code with pre-configured Twilio MCP # 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" + echo "Loading environment from baked-in .env file" set -a source /app/.env 2>/dev/null || true set +a - # Export Twilio variables for MCP server + # Export Twilio variables for runtime use export TWILIO_ACCOUNT_SID - export TWILIO_API_KEY - export TWILIO_API_SECRET + export TWILIO_AUTH_TOKEN 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." + echo "WARNING: No .env file found in image." fi -# Configure Claude Code to use the MCP server -export CLAUDE_MCP_CONFIG=/app/config/mcp-config.json - # Check for existing authentication if [ -f "$HOME/.claude/.credentials.json" ]; then echo "Found existing Claude authentication" @@ -33,14 +28,14 @@ else fi # Verify Twilio MCP configuration -if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_API_KEY" ] && [ -n "$TWILIO_API_SECRET" ]; then - echo "Twilio MCP pre-configured with:" +if [ -n "$TWILIO_ACCOUNT_SID" ] && [ -n "$TWILIO_AUTH_TOKEN" ]; then + echo "Twilio MCP server 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" + echo " - SMS capability ready via: twilio__send_text" else - echo "No Twilio credentials found, MCP features will be unavailable" + echo "No Twilio credentials found" fi # Start Claude Code with permissions bypass diff --git a/test-twilio.js b/test-twilio.js index 73266bd..a84b4e7 100755 --- a/test-twilio.js +++ b/test-twilio.js @@ -2,21 +2,20 @@ // Test script to verify Twilio SMS functionality const accountSid = process.env.TWILIO_ACCOUNT_SID; -const authToken = process.env.TWILIO_API_SECRET; -const apiKey = process.env.TWILIO_API_KEY; +const authToken = process.env.TWILIO_AUTH_TOKEN; const fromNumber = process.env.TWILIO_FROM_NUMBER; const toNumber = process.env.TWILIO_TO_NUMBER; console.log('Twilio Test Configuration:'); console.log(`Account SID: ${accountSid?.substring(0, 10)}...`); -console.log(`API Key: ${apiKey?.substring(0, 10)}...`); +console.log(`Auth Token: ${authToken ? '***' + authToken.substring(authToken.length - 4) : 'Not set'}`); console.log(`From: ${fromNumber}`); console.log(`To: ${toNumber}`); // Using Twilio REST API directly const https = require('https'); -const auth = Buffer.from(`${apiKey}:${authToken}`).toString('base64'); +const auth = Buffer.from(`${accountSid}:${authToken}`).toString('base64'); const data = new URLSearchParams({ To: toNumber, From: fromNumber,