Files
webfetch-mcpo-docker/entrypoint.sh
T

69 lines
2.0 KiB
Bash
Raw Normal View History

#!/bin/sh
set -eu
2026-10-06 17:27:28 +01:00
# Runs up to two servers in one container, each spawning its own stdio
# `node server.mjs` child:
#
# - mcpo (OpenAPI, for Open WebUI) on $MCPO_PORT.
#
# - supergateway (native streamable-HTTP MCP, for coding clients) on
# $MCP_PORT, path /mcp.
#
# mcpo's --api-key is a CLI flag, not something it reads from its own
2026-10-06 17:27:28 +01:00
# environment, so the command line is built here at container start.
#
# webfetch-mcp reads SEARXNG_BASE / DEBUG / DETAILED_LOG from its own
2026-10-06 17:27:28 +01:00
# process environment. No passthrough is needed here: both mcpo and
# supergateway start the child with this container's environment inherited.
2026-10-06 17:27:28 +01:00
MCPO_PORT="${MCPO_PORT:-8000}"
MCP_PORT="${MCP_PORT:-8080}"
ENABLE_MCPO="${ENABLE_MCPO:-true}"
ENABLE_MCP="${ENABLE_MCP:-true}"
2026-10-06 17:27:28 +01:00
pids=""
shutdown() {
# shellcheck disable=SC2086
[ -n "$pids" ] && kill -TERM $pids 2>/dev/null || true
}
trap 'shutdown; wait; exit 143' TERM INT
if [ "$ENABLE_MCP" = "true" ]; then
supergateway --stdio "node /app/webfetch-mcp/server.mjs" \
--outputTransport streamableHttp --port "$MCP_PORT" \
--healthEndpoint /healthz &
pids="$pids $!"
fi
2026-10-06 17:27:28 +01:00
if [ "$ENABLE_MCPO" = "true" ]; then
if [ -n "${MCPO_API_KEY:-}" ]; then
mcpo --host 0.0.0.0 --port "$MCPO_PORT" --api-key "$MCPO_API_KEY" -- node /app/webfetch-mcp/server.mjs &
else
mcpo --host 0.0.0.0 --port "$MCPO_PORT" -- node /app/webfetch-mcp/server.mjs &
fi
pids="$pids $!"
fi
if [ -z "$pids" ]; then
echo "Both ENABLE_MCPO and ENABLE_MCP are false; nothing to run." >&2
exit 1
fi
# Exit as soon as either server dies, taking the other down with it, so the
# orchestrator restarts the whole container rather than leaving it half-up.
# POSIX sh has no `wait -n`, so poll instead.
while :; do
for pid in $pids; do
if ! kill -0 "$pid" 2>/dev/null; then
status=0
wait "$pid" || status=$?
echo "Process $pid exited (status $status); stopping container." >&2
shutdown
wait || true
exit "$(( status == 0 ? 1 : status ))"
fi
done
sleep 1
done