#!/bin/bash # Monta Partner API MCP Server Launcher for Claude Desktop # This script can be copied anywhere and runs standalone without requiring the source code set -e # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check for Node.js if ! command -v node &> /dev/null; then echo -e "${RED}❌ Error: Node.js is not installed.${NC}" >&2 echo -e "${YELLOW}👉 Please install Node.js 18+ from https://nodejs.org/${NC}" >&2 exit 1 fi # Check Node version NODE_VERSION=$(node -v | cut -d'v' -f2 | cut -d'.' -f1) if [ "$NODE_VERSION" -lt 18 ]; then echo -e "${RED}❌ Error: Node.js 18+ required (you have $(node -v))${NC}" >&2 exit 1 fi # Check authentication if [ -z "$MONTA_CLIENT_ID" ] && [ -z "$MONTA_BEARER_TOKEN" ]; then echo -e "${RED}❌ Error: No authentication configured.${NC}" >&2 echo -e "${YELLOW}Please set in Claude Desktop config:${NC}" >&2 echo " - MONTA_CLIENT_ID and MONTA_CLIENT_SECRET, or" >&2 echo " - MONTA_BEARER_TOKEN" >&2 exit 1 fi echo -e "${GREEN}🚀 Starting Monta Partner API MCP server...${NC}" >&2 # Get the directory where this script is located SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" cd "$SCRIPT_DIR" # Download the MCP adapter bundle if not present or outdated ADAPTER_FILE="monta-mcp-adapter.js" ADAPTER_URL="https://partner-api-mcp.monta.app/mcp/bundle.js" # Check if we need to update (older than 24 hours or doesn't exist) if [ -f "$ADAPTER_FILE" ]; then # Check if file is older than 24 hours if [ "$(uname)" = "Darwin" ]; then # macOS FILE_AGE=$(stat -f %m "$ADAPTER_FILE") else # Linux FILE_AGE=$(stat -c %Y "$ADAPTER_FILE") fi CURRENT_TIME=$(date +%s) AGE_HOURS=$(( (CURRENT_TIME - FILE_AGE) / 3600 )) if [ $AGE_HOURS -gt 24 ]; then echo -e "${YELLOW}📥 Updating MCP adapter (bundle is ${AGE_HOURS}h old)...${NC}" >&2 curl -s -o "${ADAPTER_FILE}.tmp" "$ADAPTER_URL" || { echo -e "${RED}Failed to update adapter, using cached version${NC}" >&2 } if [ -f "${ADAPTER_FILE}.tmp" ]; then mv "${ADAPTER_FILE}.tmp" "$ADAPTER_FILE" fi fi else echo -e "${YELLOW}📥 Downloading MCP adapter...${NC}" >&2 curl -s -o "$ADAPTER_FILE" "$ADAPTER_URL" || { echo -e "${RED}❌ Failed to download MCP adapter${NC}" >&2 exit 1 } fi # Run the adapter exec node "$ADAPTER_FILE"