Initial commit

This commit is contained in:
Zhongwei Li
2025-11-30 09:00:29 +08:00
commit 3d376a9cd7
18 changed files with 4926 additions and 0 deletions

View File

@@ -0,0 +1,89 @@
#!/bin/bash
# Quick health check for MCPProxy
set -euo pipefail
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "=== MCPProxy Health Check ==="
echo
# Check if mcpproxy is running
echo -n "Process Status: "
if pgrep -x "mcpproxy" > /dev/null; then
echo -e "${GREEN}Running${NC}"
ps aux | grep mcpproxy | grep -v grep | head -1
else
echo -e "${RED}Not Running${NC}"
exit 1
fi
echo
# Get API key from config
API_KEY=$(grep '"api_key"' ~/.mcpproxy/mcp_config.json 2> /dev/null | cut -d'"' -f4 || echo "")
if [ -z "$API_KEY" ]; then
echo -e "${YELLOW}Warning: No API key found in config${NC}"
echo "Checking logs for auto-generated key..."
API_KEY=$(grep "api_key_prefix" ~/Library/Logs/mcpproxy/main.log 2> /dev/null | tail -1 | grep -o '"api_key":"[^"]*"' | cut -d'"' -f4 || echo "")
fi
if [ -z "$API_KEY" ]; then
echo -e "${RED}Error: Could not find API key${NC}"
exit 1
fi
# Check server status via API
echo "Server Status:"
RESPONSE=$(curl -s -H "X-API-Key: $API_KEY" "http://127.0.0.1:8080/api/v1/servers" 2> /dev/null)
if [ -z "$RESPONSE" ]; then
echo -e "${RED}Error: API returned empty response${NC}"
exit 1
fi
if echo "$RESPONSE" | python3 -c "import sys, json; data=json.load(sys.stdin); exit(0 if data.get('success', False) else 1)" 2> /dev/null; then
# Parse and display server info
echo "$RESPONSE" | python3 << 'PYTHON'
import sys, json
data = json.load(sys.stdin)
stats = data.get('data', {}).get('stats', {})
servers = data.get('data', {}).get('servers', [])
print(f" Total Servers: {stats.get('total_servers', 0)}")
print(f" Connected: {stats.get('connected_servers', 0)}")
print(f" Quarantined: {stats.get('quarantined_servers', 0)}")
print(f" Total Tools: {stats.get('total_tools', 0)}")
print(f" Docker Containers: {stats.get('docker_containers', 0)}")
print()
if servers:
print("Servers:")
for server in servers:
status_icon = "✓" if server.get('connected') else "✗"
name = server.get('name', 'unknown')
status = server.get('status', 'unknown')
tools = server.get('tool_count', 0)
error = server.get('last_error', '')
print(f" {status_icon} {name}: {status} ({tools} tools)")
if error:
print(f" Error: {error}")
PYTHON
else
echo -e "${RED}API Error:${NC}"
echo "$RESPONSE" | python3 -m json.tool 2> /dev/null || echo "$RESPONSE"
exit 1
fi
echo
echo "=== Docker Containers ==="
docker ps --filter "name=mcpproxy" --format "table {{.Names}}\t{{.Status}}\t{{.Image}}" || echo "None running"
echo
echo -e "${GREEN}Health check complete!${NC}"

View File

@@ -0,0 +1,74 @@
#!/bin/bash
# Compare two servers (one working, one broken) to find differences
# Usage: ./compare_servers.sh <working-server> <broken-server>
set -euo pipefail
if [ $# -lt 2 ]; then
echo "Usage: $0 <working-server-name> <broken-server-name>"
echo "Example: $0 glean buildkite"
exit 1
fi
WORKING="$1"
BROKEN="$2"
echo "=== Comparing Servers: $WORKING (working) vs $BROKEN (broken) ==="
echo
# Compare configurations
echo "Configuration Comparison"
echo "------------------------"
echo "Working server ($WORKING):"
grep -A 15 "\"name\": \"$WORKING\"" ~/.mcpproxy/mcp_config.json | head -20
echo
echo "Broken server ($BROKEN):"
grep -A 15 "\"name\": \"$BROKEN\"" ~/.mcpproxy/mcp_config.json | head -20
echo
# Compare connection status
echo "Connection Status Comparison"
echo "----------------------------"
echo "$WORKING status:"
grep "$WORKING" ~/Library/Logs/mcpproxy/main.log 2> /dev/null | grep -i "connected\|initialized" | tail -3 \
|| grep "$WORKING" ~/.mcpproxy/logs/main.log 2> /dev/null | grep -i "connected\|initialized" | tail -3 \
|| echo "No connection info found"
echo
echo "$BROKEN status:"
grep "$BROKEN" ~/Library/Logs/mcpproxy/main.log 2> /dev/null | grep -i "error\|failed" | tail -3 \
|| grep "$BROKEN" ~/.mcpproxy/logs/main.log 2> /dev/null | grep -i "error\|failed" | tail -3 \
|| echo "No error info found"
echo
# Compare stderr output
echo "Stderr Comparison"
echo "-----------------"
echo "$WORKING recent stderr:"
grep "stderr" ~/Library/Logs/mcpproxy/server-${WORKING}.log 2> /dev/null | tail -5 \
|| grep "stderr" ~/.mcpproxy/logs/server-${WORKING}.log 2> /dev/null | tail -5 \
|| echo "No stderr output"
echo
echo "$BROKEN recent stderr:"
grep "stderr" ~/Library/Logs/mcpproxy/server-${BROKEN}.log 2> /dev/null | tail -5 \
|| grep "stderr" ~/.mcpproxy/logs/server-${BROKEN}.log 2> /dev/null | tail -5 \
|| echo "No stderr output"
echo
# Docker container comparison
echo "Docker Container Comparison"
echo "---------------------------"
echo "$WORKING container:"
docker ps --filter "name=mcpproxy-${WORKING}" --format "{{.Names}}\t{{.Status}}\t{{.Image}}" 2> /dev/null || echo "No container"
echo
echo "$BROKEN container:"
docker ps --filter "name=mcpproxy-${BROKEN}" --format "{{.Names}}\t{{.Status}}\t{{.Image}}" 2> /dev/null || echo "No container"
echo
echo "=== Key Differences to Investigate ==="
echo "1. Check 'command' and 'args' differences in config"
echo "2. Check if error patterns match known issues (uvx package, Docker -it)"
echo "3. Check stderr for specific error messages"
echo "4. Check if Docker container is running for working but not broken"

View File

@@ -0,0 +1,93 @@
#!/bin/bash
# Diagnose a specific MCP server following mcpproxy-debug skill workflow
# Usage: ./diagnose_server.sh <server-name>
set -euo pipefail
if [ $# -lt 1 ]; then
echo "Usage: $0 <server-name>"
echo "Example: $0 buildkite"
exit 1
fi
SERVER_NAME="$1"
LOG_FILE="$HOME/Library/Logs/mcpproxy/server-${SERVER_NAME}.log"
# Check if log file exists (Linux fallback)
if [ ! -f "$LOG_FILE" ]; then
LOG_FILE="$HOME/.mcpproxy/logs/server-${SERVER_NAME}.log"
fi
if [ ! -f "$LOG_FILE" ]; then
echo "Error: Log file not found for server '$SERVER_NAME'"
echo "Checked locations:"
echo " - ~/Library/Logs/mcpproxy/server-${SERVER_NAME}.log (macOS)"
echo " - ~/.mcpproxy/logs/server-${SERVER_NAME}.log (Linux)"
exit 1
fi
echo "=== MCPProxy Server Diagnosis: $SERVER_NAME ==="
echo
# Step 1: Check connection status
echo "Step 1: Connection Status"
echo "-------------------------"
grep -i "connected\|error\|failed" ~/Library/Logs/mcpproxy/main.log 2> /dev/null | grep "$SERVER_NAME" | tail -5 \
|| grep -i "connected\|error\|failed" ~/.mcpproxy/logs/main.log 2> /dev/null | grep "$SERVER_NAME" | tail -5 \
|| echo "No recent connection status found in main log"
echo
# Step 2: Check for stderr messages (most revealing)
echo "Step 2: Recent stderr output (shows actual errors)"
echo "---------------------------------------------------"
grep "stderr" "$LOG_FILE" | tail -10
echo
# Step 3: Check for error patterns
echo "Step 3: Error Pattern Detection"
echo "--------------------------------"
if grep -q "unexpected argument" "$LOG_FILE"; then
echo "❌ Found: 'unexpected argument' error"
echo " → Likely cause: Missing package name for uvx/npx"
echo " → Fix: Add package name as first argument"
echo
fi
if grep -q "not a TTY" "$LOG_FILE"; then
echo "❌ Found: 'input device is not a TTY' error"
echo " → Likely cause: Using -it flag with Docker"
echo " → Fix: Use -i only (not -it) for stdin pipe"
echo
fi
if grep -q "context deadline exceeded" "$LOG_FILE"; then
echo "❌ Found: 'context deadline exceeded' error"
echo " → Likely cause: Server failed to initialize within timeout"
echo " → Check stderr above for specific reason"
echo
fi
if grep -q "Successfully connected" "$LOG_FILE"; then
echo "✅ Server successfully connected at some point"
grep "Successfully connected" "$LOG_FILE" | tail -1
echo
fi
# Step 4: Check Docker container status
echo "Step 4: Docker Container Status"
echo "--------------------------------"
if docker ps --filter "name=mcpproxy-${SERVER_NAME}" --format "{{.Names}}\t{{.Status}}\t{{.Image}}" 2> /dev/null | grep -q .; then
docker ps --filter "name=mcpproxy-${SERVER_NAME}" --format "{{.Names}}\t{{.Status}}\t{{.Image}}"
else
echo "No running Docker container found for $SERVER_NAME"
fi
echo
# Step 5: Recent log activity
echo "Step 5: Last 10 log entries"
echo "----------------------------"
tail -10 "$LOG_FILE"
echo
echo "=== End of Diagnosis ==="

View File

@@ -0,0 +1,24 @@
#!/bin/bash
# Extract current API key from config or logs
set -euo pipefail
# Try config file first
API_KEY=$(grep '"api_key"' ~/.mcpproxy/mcp_config.json 2> /dev/null | cut -d'"' -f4 || echo "")
if [ -n "$API_KEY" ]; then
echo "$API_KEY"
exit 0
fi
# Try logs for auto-generated key
echo "No API key in config, checking logs..." >&2
API_KEY=$(grep -i "api key" ~/Library/Logs/mcpproxy/main.log 2> /dev/null | grep -o '"api_key":"[^"]*"' | tail -1 | cut -d'"' -f4 || echo "")
if [ -n "$API_KEY" ]; then
echo "$API_KEY"
exit 0
fi
echo "Error: Could not find API key" >&2
exit 1