Run supergateway on port 8080 (streamable HTTP at /mcp) next to mcpo on 8000, each spawning its own webfetch-mcp child. Supervise both under tini. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit was merged in pull request #2.
This commit is contained in:
+59
-11
@@ -1,20 +1,68 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
# 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
|
||||
# environment, but the actual value must come from the container's
|
||||
# environment rather than being baked into the image. This script builds
|
||||
# the mcpo command line at container start so that can happen.
|
||||
# environment, so the command line is built here at container start.
|
||||
#
|
||||
# webfetch-mcp reads SEARXNG_BASE / DEBUG / DETAILED_LOG from its own
|
||||
# process environment. No passthrough is needed here: mcpo builds the
|
||||
# spawned child's environment as {**os.environ, **extra}, so anything set
|
||||
# on this container's environment reaches webfetch-mcp automatically.
|
||||
# process environment. No passthrough is needed here: both mcpo and
|
||||
# supergateway start the child with this container's environment inherited.
|
||||
|
||||
PORT="${MCPO_PORT:-8000}"
|
||||
MCPO_PORT="${MCPO_PORT:-8000}"
|
||||
MCP_PORT="${MCP_PORT:-8080}"
|
||||
ENABLE_MCPO="${ENABLE_MCPO:-true}"
|
||||
ENABLE_MCP="${ENABLE_MCP:-true}"
|
||||
|
||||
if [ -n "${MCPO_API_KEY:-}" ]; then
|
||||
exec mcpo --host 0.0.0.0 --port "$PORT" --api-key "$MCPO_API_KEY" -- node /app/webfetch-mcp/server.mjs
|
||||
else
|
||||
exec mcpo --host 0.0.0.0 --port "$PORT" -- node /app/webfetch-mcp/server.mjs
|
||||
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
|
||||
|
||||
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
|
||||
|
||||
Reference in New Issue
Block a user