From 50ee642b3e109839b52c787a8a999a2e56d36483 Mon Sep 17 00:00:00 2001 From: sigoden Date: Tue, 11 Feb 2025 08:28:46 +0800 Subject: feat(mcp): auto install deps before starting mcp bridge server (#161) --- scripts/mcp.sh | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) (limited to 'scripts') diff --git a/scripts/mcp.sh b/scripts/mcp.sh index eb0bfaa..87b5183 100755 --- a/scripts/mcp.sh +++ b/scripts/mcp.sh @@ -4,6 +4,7 @@ set -e ROOT_DIR="$(cd -- "$( dirname -- "${BASH_SOURCE[0]}" )/.." &> /dev/null && pwd)" BIN_DIR="$ROOT_DIR/bin" MCP_DIR="$ROOT_DIR/cache/__mcp__" +MCP_LOG_FILE="$MCP_DIR/mcp-bridge.log" MCP_JSON_PATH="$ROOT_DIR/mcp.json" FUNCTIONS_JSON_PATH="$ROOT_DIR/functions.json" MCP_BRIDGE_PORT="${MCP_BRIDGE_PORT:-8808}" @@ -23,7 +24,9 @@ start() { llm_functions_dir="$(cygpath -w "$llm_functions_dir")" fi echo "Start MCP Bridge server..." - nohup node "$index_js" "$llm_functions_dir" > "$MCP_DIR/mcp-bridge.log" 2>&1 & + echo "Install node dependencies..." > "$MCP_LOG_FILE" + npm install --prefix "$ROOT_DIR/mcp/bridge" 1>/dev/null 2>> "$MCP_LOG_FILE" + nohup node "$index_js" "$llm_functions_dir" >> "$MCP_LOG_FILE" 2>&1 & wait-for-server echo "Merge MCP tools into functions.json" "$0" merge-functions -S @@ -62,12 +65,13 @@ run@tool() { # @cmd Show the logs # @flag -f --follow Follow mode logs() { - args="" - if [[ -n "$argc_follow" ]]; then - args="$args -f" + if [[ ! -f "$MCP_LOG_FILE" ]]; then + _die "error: not found log file at '$MCP_LOG_FILE'" fi - if [[ -f "$MCP_DIR/mcp-bridge.log" ]]; then - tail $args "$MCP_DIR/mcp-bridge.log" + if [[ -n "$argc_follow" ]]; then + tail -f "$MCP_LOG_FILE" + else + cat "$MCP_LOG_FILE" fi } -- cgit v1.2.3