-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathclient_example_json_run.sh
More file actions
executable file
·94 lines (77 loc) · 2.37 KB
/
Copy pathclient_example_json_run.sh
File metadata and controls
executable file
·94 lines (77 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/bin/bash
# Run the Python client example with local MCP servers
set -e
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Get the script directory
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_DIR="$(dirname "$SCRIPT_DIR")"
# Kill any existing processes on ports 3001 and 3002
kill_port() {
local port=$1
local pids=$(lsof -ti :$port 2>/dev/null || true)
if [ -n "$pids" ]; then
echo -e "${YELLOW}Killing existing process on port $port${NC}"
echo "$pids" | xargs kill -9 2>/dev/null || true
fi
}
# Cleanup function
cleanup() {
echo -e "\n${YELLOW}Cleaning up...${NC}"
kill_port 3001
kill_port 3002
echo -e "${GREEN}Done${NC}"
}
trap cleanup EXIT
echo -e "${GREEN}======================================${NC}"
echo -e "${GREEN}Running Python Client Example${NC}"
echo -e "${GREEN}======================================${NC}"
echo ""
# Check if native library exists
if [ ! -d "$PROJECT_DIR/native/lib" ]; then
echo -e "${RED}Error: Native library not found at $PROJECT_DIR/native/lib${NC}"
echo -e "${YELLOW}Please run ./build.sh first${NC}"
exit 1
fi
# Kill any existing processes on ports
kill_port 3001
kill_port 3002
# Start server3001
echo -e "${YELLOW}Starting server3001...${NC}"
cd "$SCRIPT_DIR/server3001"
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}Installing dependencies for server3001...${NC}"
npm install
fi
npm run dev > /dev/null 2>&1 &
SERVER3001_PID=$!
echo -e "${GREEN}server3001 started (PID: $SERVER3001_PID)${NC}"
# Start server3002
echo -e "${YELLOW}Starting server3002...${NC}"
cd "$SCRIPT_DIR/server3002"
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}Installing dependencies for server3002...${NC}"
npm install
fi
npm run dev > /dev/null 2>&1 &
SERVER3002_PID=$!
echo -e "${GREEN}server3002 started (PID: $SERVER3002_PID)${NC}"
# Wait for servers to start
echo -e "${YELLOW}Waiting for servers to start...${NC}"
sleep 3
# Run the Python client
echo ""
echo -e "${YELLOW}Running Python client...${NC}"
echo ""
cd "$PROJECT_DIR"
# Run with library path for native library and PYTHONPATH for module discovery
PYTHONPATH="$PROJECT_DIR" \
DYLD_LIBRARY_PATH="$PROJECT_DIR/native/lib" \
LD_LIBRARY_PATH="$PROJECT_DIR/native/lib" \
python3 examples/client_example_json.py "$@"
echo ""
echo -e "${GREEN}Example completed${NC}"
exit 0