arcticaurora commited on
Commit
7a3cc47
·
verified ·
1 Parent(s): 97dbb26

Update start.sh

Browse files
Files changed (1) hide show
  1. start.sh +49 -19
start.sh CHANGED
@@ -19,7 +19,7 @@ export SUPABASE_ANON_KEY="${SUPABASE_ANON_KEY}"
19
  export CONFIG_ID="mcp_settings"
20
 
21
  echo "Debug: SUPABASE_URL = ${SUPABASE_URL}"
22
- echo "Debug: SUPABASE_ANON_KEY = ${SUPABASE_ANON_KEY:0:20}..." # Show first 20 chars only
23
  # ================================================================
24
 
25
  # --- Define paths ---
@@ -50,37 +50,70 @@ if ! command -v curl &> /dev/null; then
50
  exit 1
51
  fi
52
 
53
- # Make the request with error checking
54
- RESPONSE=$(curl -s -f -X GET \
 
55
  "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}&select=content" \
56
  -H "apikey: ${SUPABASE_ANON_KEY}" \
57
- -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" 2>&1) || {
58
- echo "ERROR: curl failed with exit code $?"
59
- echo "Response/Error: $RESPONSE"
60
- exit 1
61
- }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
63
  echo "Debug: Raw response from Supabase: $RESPONSE"
64
 
65
  # Extract JSON content from response
66
- if [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ]; then
67
  echo "Debug: Processing response..."
68
  echo "$RESPONSE" | python3 -c "
69
  import sys, json
70
  try:
71
  data = json.load(sys.stdin)
72
- print(json.dumps(data[0]['content'] if data else {}))
 
 
 
73
  except Exception as e:
74
  print(f'ERROR: Failed to parse JSON: {e}', file=sys.stderr)
75
- sys.exit(1)
76
  " > "$CONFIG_FILE_PATH" || {
77
  echo "ERROR: Failed to parse JSON response"
78
  echo "Creating empty config instead..."
79
  echo "{}" > "$CONFIG_FILE_PATH"
80
  }
81
- echo "✅ Config downloaded successfully."
 
 
 
 
 
 
82
  else
83
- echo "⚠️ No config found in Supabase (empty response), creating empty file..."
84
  echo "{}" > "$CONFIG_FILE_PATH"
85
  fi
86
 
@@ -88,19 +121,19 @@ echo "Debug: Config file created at $CONFIG_FILE_PATH"
88
  echo "Debug: Config file contents:"
89
  cat "$CONFIG_FILE_PATH"
90
 
91
- # 3. Function to sync file to Supabase
92
  sync_to_supabase() {
93
  if [ -f "$CONFIG_FILE_PATH" ]; then
94
  FILE_CONTENT=$(cat "$CONFIG_FILE_PATH" | python3 -c "import sys, json; print(json.dumps(json.load(sys.stdin)))")
95
 
96
- curl -s -X PATCH \
97
  "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}" \
98
  -H "apikey: ${SUPABASE_ANON_KEY}" \
99
  -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
100
  -H "Content-Type: application/json" \
101
  -H "Prefer: return=minimal" \
102
  -d "{\"content\":${FILE_CONTENT},\"updated_at\":\"$(date -u +%Y-%m-%dT%H:%M:%S)\"}" \
103
- > /dev/null
104
 
105
  echo "✅ [Sync] Config uploaded to Supabase at $(date)"
106
  fi
@@ -135,9 +168,6 @@ echo "🚀 Starting MCPHub server on port ${PORT}..."
135
  cd "$RUN_DIR"
136
 
137
  echo "Debug: Current directory: $(pwd)"
138
- echo "Debug: Files in directory:"
139
- ls -la
140
-
141
  echo "Debug: Running npm start..."
142
  npm start || {
143
  echo "ERROR: npm start failed with exit code $?"
 
19
  export CONFIG_ID="mcp_settings"
20
 
21
  echo "Debug: SUPABASE_URL = ${SUPABASE_URL}"
22
+ echo "Debug: SUPABASE_ANON_KEY = ${SUPABASE_ANON_KEY:0:20}..."
23
  # ================================================================
24
 
25
  # --- Define paths ---
 
50
  exit 1
51
  fi
52
 
53
+ # Make the request with HTTP/1.1 and better error handling
54
+ echo "Debug: Attempting connection with HTTP/1.1..."
55
+ RESPONSE=$(curl --http1.1 -s -S -X GET \
56
  "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}&select=content" \
57
  -H "apikey: ${SUPABASE_ANON_KEY}" \
58
+ -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
59
+ -H "Accept: application/json" \
60
+ 2>&1)
61
+
62
+ CURL_EXIT_CODE=$?
63
+ if [ $CURL_EXIT_CODE -ne 0 ]; then
64
+ echo "ERROR: curl failed with exit code $CURL_EXIT_CODE"
65
+ echo "Trying alternative approach with wget..."
66
+
67
+ # Fallback to wget if available
68
+ if command -v wget &> /dev/null; then
69
+ RESPONSE=$(wget -qO- \
70
+ --header="apikey: ${SUPABASE_ANON_KEY}" \
71
+ --header="Authorization: Bearer ${SUPABASE_ANON_KEY}" \
72
+ "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}&select=content" 2>&1)
73
+
74
+ if [ $? -ne 0 ]; then
75
+ echo "ERROR: Both curl and wget failed"
76
+ echo "Creating empty config as fallback..."
77
+ echo "{}" > "$CONFIG_FILE_PATH"
78
+ fi
79
+ else
80
+ echo "wget not available, creating empty config..."
81
+ echo "{}" > "$CONFIG_FILE_PATH"
82
+ fi
83
+ else
84
+ echo "Debug: Request successful"
85
+ fi
86
 
87
  echo "Debug: Raw response from Supabase: $RESPONSE"
88
 
89
  # Extract JSON content from response
90
+ if [ -n "$RESPONSE" ] && [ "$RESPONSE" != "[]" ] && [[ ! "$RESPONSE" =~ "ERROR" ]]; then
91
  echo "Debug: Processing response..."
92
  echo "$RESPONSE" | python3 -c "
93
  import sys, json
94
  try:
95
  data = json.load(sys.stdin)
96
+ if data and len(data) > 0:
97
+ print(json.dumps(data[0]['content']))
98
+ else:
99
+ print('{}')
100
  except Exception as e:
101
  print(f'ERROR: Failed to parse JSON: {e}', file=sys.stderr)
102
+ print('{}')
103
  " > "$CONFIG_FILE_PATH" || {
104
  echo "ERROR: Failed to parse JSON response"
105
  echo "Creating empty config instead..."
106
  echo "{}" > "$CONFIG_FILE_PATH"
107
  }
108
+
109
+ if [ -s "$CONFIG_FILE_PATH" ]; then
110
+ echo "✅ Config downloaded successfully."
111
+ else
112
+ echo "⚠️ Config file is empty, using default..."
113
+ echo "{}" > "$CONFIG_FILE_PATH"
114
+ fi
115
  else
116
+ echo "⚠️ No config found in Supabase (empty/error response), creating empty file..."
117
  echo "{}" > "$CONFIG_FILE_PATH"
118
  fi
119
 
 
121
  echo "Debug: Config file contents:"
122
  cat "$CONFIG_FILE_PATH"
123
 
124
+ # 3. Function to sync file to Supabase (also using HTTP/1.1)
125
  sync_to_supabase() {
126
  if [ -f "$CONFIG_FILE_PATH" ]; then
127
  FILE_CONTENT=$(cat "$CONFIG_FILE_PATH" | python3 -c "import sys, json; print(json.dumps(json.load(sys.stdin)))")
128
 
129
+ curl --http1.1 -s -X PATCH \
130
  "${SUPABASE_URL}/rest/v1/configs?id=eq.${CONFIG_ID}" \
131
  -H "apikey: ${SUPABASE_ANON_KEY}" \
132
  -H "Authorization: Bearer ${SUPABASE_ANON_KEY}" \
133
  -H "Content-Type: application/json" \
134
  -H "Prefer: return=minimal" \
135
  -d "{\"content\":${FILE_CONTENT},\"updated_at\":\"$(date -u +%Y-%m-%dT%H:%M:%S)\"}" \
136
+ > /dev/null 2>&1 || echo "Warning: Sync failed, will retry..."
137
 
138
  echo "✅ [Sync] Config uploaded to Supabase at $(date)"
139
  fi
 
168
  cd "$RUN_DIR"
169
 
170
  echo "Debug: Current directory: $(pwd)"
 
 
 
171
  echo "Debug: Running npm start..."
172
  npm start || {
173
  echo "ERROR: npm start failed with exit code $?"