check_linkedin_status.sh11.1 kB
#!/bin/bash
# LinkedIn MCP Client Status Check Script
# Checks the status of LinkedIn MCP infrastructure
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROCESSES_DIR="$SCRIPT_DIR/.processes"
NETLIFY_PORT=8888
FASTAPI_PORT=8002
echo -e "${BLUE}📊 LinkedIn MCP Infrastructure Status${NC}"
echo "====================================="
# Function to check if port is in use
check_port() {
local port=$1
if lsof -Pi :$port -sTCP:LISTEN -t >/dev/null 2>&1; then
return 0
else
return 1
fi
}
# Function to check service status by PID file
check_pid_status() {
local service_name=$1
local pid_file="$PROCESSES_DIR/$2.pid"
if [ -f "$pid_file" ]; then
local pid=$(cat "$pid_file")
if ps -p $pid > /dev/null 2>&1; then
echo -e "${GREEN}✅ $service_name running (PID: $pid)${NC}"
return 0
else
echo -e "${RED}❌ $service_name not running (stale PID: $pid)${NC}"
rm -f "$pid_file"
return 1
fi
else
echo -e "${YELLOW}⚠️ $service_name PID file not found${NC}"
return 1
fi
}
# Function to test HTTP endpoint
test_endpoint() {
local name=$1
local url=$2
local expected_content=$3
local response=$(curl -s --max-time 5 "$url" 2>/dev/null || echo "ERROR")
if [ "$response" = "ERROR" ]; then
echo -e "${RED}❌ $name - Connection failed${NC}"
return 1
elif echo "$response" | grep -q "$expected_content"; then
echo -e "${GREEN}✅ $name - Responding correctly${NC}"
return 0
else
echo -e "${YELLOW}⚠️ $name - Responding but unexpected content${NC}"
return 1
fi
}
# Function to test MCP functionality
test_mcp_functionality() {
echo -e "\n${BLUE}🧪 Testing MCP Functionality${NC}"
echo "----------------------------"
# Test MCP init
echo -e "${BLUE}Testing MCP initialization...${NC}"
local mcp_response=$(curl -s --max-time 10 -X POST http://localhost:$NETLIFY_PORT/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"mcp/init","params":{},"id":"1"}' 2>/dev/null || echo "ERROR")
if echo "$mcp_response" | grep -q "linkedin-mcp-server"; then
echo -e "${GREEN}✅ MCP initialization working${NC}"
else
echo -e "${RED}❌ MCP initialization failed${NC}"
echo "Response: $mcp_response"
fi
# Test tool listing
echo -e "${BLUE}Testing MCP tool listing...${NC}"
local tools_response=$(curl -s --max-time 10 -X POST http://localhost:$NETLIFY_PORT/mcp \
-H "Content-Type: application/json" \
-d '{"jsonrpc":"2.0","method":"mcp/listTools","params":{},"id":"2"}' 2>/dev/null || echo "ERROR")
if echo "$tools_response" | grep -q "get-profile"; then
local tool_count=$(echo "$tools_response" | grep -o '"name"' | wc -l)
echo -e "${GREEN}✅ MCP tools listing working ($tool_count tools available)${NC}"
else
echo -e "${RED}❌ MCP tools listing failed${NC}"
fi
}
# Function to test FastAPI functionality
test_fastapi_functionality() {
echo -e "\n${BLUE}🐍 Testing FastAPI Functionality${NC}"
echo "-------------------------------"
# Test health endpoint
echo -e "${BLUE}Testing health endpoint...${NC}"
local health_response=$(curl -s --max-time 5 http://localhost:$FASTAPI_PORT/health 2>/dev/null || echo "ERROR")
if echo "$health_response" | grep -q "healthy"; then
echo -e "${GREEN}✅ Health endpoint working${NC}"
else
echo -e "${YELLOW}⚠️ Health endpoint responding but service may have issues${NC}"
fi
# Test tools endpoint
echo -e "${BLUE}Testing tools endpoint...${NC}"
local tools_response=$(curl -s --max-time 5 http://localhost:$FASTAPI_PORT/tools 2>/dev/null || echo "ERROR")
if echo "$tools_response" | grep -q "tools"; then
echo -e "${GREEN}✅ Tools endpoint working${NC}"
else
echo -e "${RED}❌ Tools endpoint failed${NC}"
fi
# Test profile endpoint (should fail without auth)
echo -e "${BLUE}Testing profile endpoint (no auth)...${NC}"
local profile_response=$(curl -s --max-time 5 http://localhost:$FASTAPI_PORT/profile 2>/dev/null || echo "ERROR")
if echo "$profile_response" | grep -q -i "token"; then
echo -e "${GREEN}✅ Profile endpoint correctly requires authentication${NC}"
else
echo -e "${YELLOW}⚠️ Profile endpoint response unexpected${NC}"
fi
}
# Function to show log tails
show_log_tails() {
echo -e "\n${BLUE}📜 Recent Log Entries${NC}"
echo "-------------------"
if [ -f "$PROCESSES_DIR/netlify-dev.log" ]; then
echo -e "${BLUE}Netlify Server (last 5 lines):${NC}"
tail -5 "$PROCESSES_DIR/netlify-dev.log" | sed 's/^/ /'
echo ""
fi
if [ -f "$PROCESSES_DIR/fastapi.log" ]; then
echo -e "${BLUE}FastAPI Client (last 5 lines):${NC}"
tail -5 "$PROCESSES_DIR/fastapi.log" | sed 's/^/ /'
echo ""
fi
}
# Function to show system resources
show_resources() {
echo -e "\n${BLUE}💻 System Resources${NC}"
echo "-------------------"
# Memory usage for our processes
if [ -f "$PROCESSES_DIR/netlify.pid" ]; then
local netlify_pid=$(cat "$PROCESSES_DIR/netlify.pid" 2>/dev/null || echo "")
if [ -n "$netlify_pid" ] && ps -p $netlify_pid > /dev/null 2>&1; then
local mem_usage=$(ps -o rss= -p $netlify_pid 2>/dev/null | awk '{print $1/1024 " MB"}')
echo -e "${BLUE}Netlify Memory: ${mem_usage}${NC}"
fi
fi
if [ -f "$PROCESSES_DIR/fastapi.pid" ]; then
local fastapi_pid=$(cat "$PROCESSES_DIR/fastapi.pid" 2>/dev/null || echo "")
if [ -n "$fastapi_pid" ] && ps -p $fastapi_pid > /dev/null 2>&1; then
local mem_usage=$(ps -o rss= -p $fastapi_pid 2>/dev/null | awk '{print $1/1024 " MB"}')
echo -e "${BLUE}FastAPI Memory: ${mem_usage}${NC}"
fi
fi
# Port usage
echo -e "${BLUE}Port Usage:${NC}"
if check_port $NETLIFY_PORT; then
echo -e " Port $NETLIFY_PORT: ${GREEN}In Use${NC}"
else
echo -e " Port $NETLIFY_PORT: ${RED}Free${NC}"
fi
if check_port $FASTAPI_PORT; then
echo -e " Port $FASTAPI_PORT: ${GREEN}In Use${NC}"
else
echo -e " Port $FASTAPI_PORT: ${RED}Free${NC}"
fi
}
# Main status check function
main() {
# Check PID status
echo -e "${BLUE}🔍 Process Status${NC}"
echo "-----------------"
local netlify_running=false
local fastapi_running=false
if check_pid_status "Netlify Server" "netlify"; then
netlify_running=true
fi
if check_pid_status "FastAPI Client" "fastapi"; then
fastapi_running=true
fi
# Check port status
echo -e "\n${BLUE}🌐 Port Status${NC}"
echo "-------------"
if check_port $NETLIFY_PORT; then
echo -e "${GREEN}✅ Port $NETLIFY_PORT (Netlify) - In Use${NC}"
else
echo -e "${RED}❌ Port $NETLIFY_PORT (Netlify) - Free${NC}"
netlify_running=false
fi
if check_port $FASTAPI_PORT; then
echo -e "${GREEN}✅ Port $FASTAPI_PORT (FastAPI) - In Use${NC}"
else
echo -e "${RED}❌ Port $FASTAPI_PORT (FastAPI) - Free${NC}"
fastapi_running=false
fi
# Test HTTP endpoints
echo -e "\n${BLUE}🌍 HTTP Endpoint Status${NC}"
echo "----------------------"
test_endpoint "Netlify Landing Page" "http://localhost:$NETLIFY_PORT" "Netlify"
test_endpoint "MCP Endpoint" "http://localhost:$NETLIFY_PORT/mcp" "Method Not Allowed"
test_endpoint "FastAPI Root" "http://localhost:$FASTAPI_PORT/" "LinkedIn MCP Client"
test_endpoint "FastAPI Docs" "http://localhost:$FASTAPI_PORT/docs" "swagger"
# Test functionality if services are running
if $netlify_running && $fastapi_running; then
test_mcp_functionality
test_fastapi_functionality
fi
# Show additional information
show_resources
if [ "${1:-}" = "logs" ]; then
show_log_tails
fi
# Summary
echo -e "\n${BLUE}📋 Summary${NC}"
echo "----------"
if $netlify_running && $fastapi_running; then
echo -e "${GREEN}🟢 LinkedIn MCP Infrastructure is fully operational${NC}"
echo ""
echo -e "${BLUE}📡 Available Services:${NC}"
echo " • MCP Server: http://localhost:$NETLIFY_PORT/mcp"
echo " • LinkedIn API: http://localhost:$FASTAPI_PORT"
echo " • API Documentation: http://localhost:$FASTAPI_PORT/docs"
echo ""
echo -e "${BLUE}🔧 Management Commands:${NC}"
echo " • View Logs: $0 logs"
echo " • Run Tests: python test_linkedin.py"
echo " • Stop Services: ./stop_linkedin.sh"
elif $netlify_running || $fastapi_running; then
echo -e "${YELLOW}🟡 LinkedIn MCP Infrastructure is partially operational${NC}"
echo ""
if ! $netlify_running; then
echo -e "${RED}❌ Netlify MCP Server is not running${NC}"
fi
if ! $fastapi_running; then
echo -e "${RED}❌ FastAPI Client is not running${NC}"
fi
echo ""
echo -e "${BLUE}💡 Try restarting: ./start_linkedin.sh${NC}"
else
echo -e "${RED}🔴 LinkedIn MCP Infrastructure is not running${NC}"
echo ""
echo -e "${BLUE}💡 Start services: ./start_linkedin.sh${NC}"
fi
}
# Handle script arguments
case "${1:-status}" in
"status")
main
;;
"logs")
main "logs"
;;
"quick")
echo -e "${BLUE}🔍 Quick Status Check${NC}"
echo "===================="
if check_port $NETLIFY_PORT && check_port $FASTAPI_PORT; then
echo -e "${GREEN}✅ Both services appear to be running${NC}"
elif check_port $NETLIFY_PORT; then
echo -e "${YELLOW}⚠️ Only Netlify service running${NC}"
elif check_port $FASTAPI_PORT; then
echo -e "${YELLOW}⚠️ Only FastAPI service running${NC}"
else
echo -e "${RED}❌ No services running${NC}"
fi
;;
"help")
echo "LinkedIn MCP Infrastructure Status Check"
echo ""
echo "Usage: $0 [command]"
echo ""
echo "Commands:"
echo " status (default) - Full status check with functionality tests"
echo " logs - Full status check including recent log entries"
echo " quick - Quick port-based status check"
echo " help - Show this help"
;;
*)
echo -e "${RED}❌ Unknown command: $1${NC}"
echo "Use '$0 help' for usage information"
exit 1
;;
esac