|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +set -e # Exit on error |
| 4 | + |
| 5 | +echo "🚀 Installing Trigger.dev MCP Server..." |
| 6 | + |
| 7 | +# Get the absolute path to the node binary |
| 8 | +NODE_PATH=$(which node) |
| 9 | +if [ -z "$NODE_PATH" ]; then |
| 10 | + echo "❌ Error: Node.js not found in PATH" |
| 11 | + echo "Please ensure Node.js is installed and available in your PATH" |
| 12 | + exit 1 |
| 13 | +fi |
| 14 | + |
| 15 | +# Get the directory where this script is located |
| 16 | +SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)" |
| 17 | + |
| 18 | +# Construct the path to the CLI index.js file |
| 19 | +CLI_PATH="$SCRIPT_DIR/dist/esm/index.js" |
| 20 | + |
| 21 | +# Construct the path to the MCP log file |
| 22 | +MCP_LOG_FILE="$SCRIPT_DIR/.mcp.log" |
| 23 | + |
| 24 | +# Make sure the MCP log file exists |
| 25 | +touch "$MCP_LOG_FILE" |
| 26 | + |
| 27 | +# Check if the CLI file exists |
| 28 | +if [ ! -f "$CLI_PATH" ]; then |
| 29 | + echo "❌ Error: CLI file not found at $CLI_PATH" |
| 30 | + echo "Make sure to build the CLI first with: pnpm run build" |
| 31 | + exit 1 |
| 32 | +fi |
| 33 | + |
| 34 | +# Ensure the CLI is executable |
| 35 | +chmod +x "$CLI_PATH" |
| 36 | + |
| 37 | +echo "✅ Found Node.js at: $NODE_PATH" |
| 38 | +echo "✅ Found CLI at: $CLI_PATH" |
| 39 | + |
| 40 | +# Claude Code configuration |
| 41 | +CLAUDE_CONFIG="$HOME/.claude.json" |
| 42 | + |
| 43 | +echo "📁 Claude configuration file: $CLAUDE_CONFIG" |
| 44 | + |
| 45 | +# Check if Claude config exists, create if it doesn't |
| 46 | +if [ ! -f "$CLAUDE_CONFIG" ]; then |
| 47 | + echo "📝 Creating new Claude configuration file..." |
| 48 | + echo '{"mcpServers": {}}' > "$CLAUDE_CONFIG" |
| 49 | +fi |
| 50 | + |
| 51 | +# Use Node.js to manipulate the JSON |
| 52 | +echo "🔧 Updating Claude configuration..." |
| 53 | + |
| 54 | +node -e " |
| 55 | +const fs = require('fs'); |
| 56 | +const path = require('path'); |
| 57 | +
|
| 58 | +const configPath = '$CLAUDE_CONFIG'; |
| 59 | +const nodePath = '$NODE_PATH'; |
| 60 | +const cliPath = '$CLI_PATH'; |
| 61 | +const logFile = '$MCP_LOG_FILE'; |
| 62 | +
|
| 63 | +try { |
| 64 | + // Read existing config |
| 65 | + let config; |
| 66 | + try { |
| 67 | + const configContent = fs.readFileSync(configPath, 'utf8'); |
| 68 | + config = JSON.parse(configContent); |
| 69 | + } catch (error) { |
| 70 | + console.log('📝 Creating new configuration structure...'); |
| 71 | + config = {}; |
| 72 | + } |
| 73 | +
|
| 74 | + // Ensure mcpServers object exists |
| 75 | + if (!config.mcpServers) { |
| 76 | + config.mcpServers = {}; |
| 77 | + } |
| 78 | +
|
| 79 | + // Add/update trigger.dev entry |
| 80 | + config.mcpServers['trigger'] = { |
| 81 | + command: nodePath, |
| 82 | + args: [cliPath, 'mcp', '--log-file', logFile] |
| 83 | + }; |
| 84 | +
|
| 85 | + // Write back to file with proper formatting |
| 86 | + fs.writeFileSync(configPath, JSON.stringify(config, null, 2)); |
| 87 | + |
| 88 | + console.log('✅ Successfully installed Trigger.dev MCP server to Claude Code'); |
| 89 | + console.log(''); |
| 90 | + console.log('📋 Configuration Details:'); |
| 91 | + console.log(' • Config file:', configPath); |
| 92 | + console.log(' • Node.js path:', nodePath); |
| 93 | + console.log(' • CLI path:', cliPath); |
| 94 | + console.log(''); |
| 95 | + console.log('🎉 Installation complete! You can now use Trigger.dev MCP commands in Claude Code.'); |
| 96 | + console.log('💡 Try typing @ in Claude Code and select \"triggerdev\" to get started.'); |
| 97 | + |
| 98 | +} catch (error) { |
| 99 | + console.error('❌ Error updating Claude configuration:', error.message); |
| 100 | + process.exit(1); |
| 101 | +} |
| 102 | +" |
| 103 | + |
| 104 | +echo "" |
| 105 | +echo "🔍 You can test the MCP server with:" |
| 106 | +echo " pnpm run inspector" |
0 commit comments