diff --git a/.github/workflows/pr-build.yml b/.github/workflows/pr-build.yml index 354d86333..f61889c15 100644 --- a/.github/workflows/pr-build.yml +++ b/.github/workflows/pr-build.yml @@ -443,3 +443,7 @@ jobs: set -eo pipefail docker run --rm --entrypoint mcpproxy mcpproxy-server:pr version | tee /tmp/version.txt grep -q '(server)' /tmp/version.txt + + # #1942: default 0.0.0.0:8080, MCPPROXY_LISTEN honoured, --listen wins. + - name: Smoke-test the listen address + run: bash scripts/test-docker-listen.sh mcpproxy-server:pr diff --git a/Dockerfile b/Dockerfile index 6b06c3ef3..e40633529 100644 --- a/Dockerfile +++ b/Dockerfile @@ -33,4 +33,12 @@ COPY --from=builder /mcpproxy /usr/local/bin/mcpproxy EXPOSE 8080 -ENTRYPOINT ["mcpproxy", "serve", "--listen", "0.0.0.0:8080"] +# The container default listen address comes from the environment, not from a +# hardcoded --listen flag: a flag outranks MCPPROXY_LISTEN, so baking one into +# the ENTRYPOINT made `-e MCPPROXY_LISTEN=...` a silent no-op (#1942). +# Precedence is unchanged otherwise: `--listen` passed as container args still +# wins over MCPPROXY_LISTEN, which wins over the config file's `listen`. Set +# MCPPROXY_LISTEN to an empty value to fall back to the config file. +ENV MCPPROXY_LISTEN=0.0.0.0:8080 + +ENTRYPOINT ["mcpproxy", "serve"] diff --git a/docs/configuration/environment-variables.md b/docs/configuration/environment-variables.md index ef9c40eea..f8a11b236 100644 --- a/docs/configuration/environment-variables.md +++ b/docs/configuration/environment-variables.md @@ -28,7 +28,7 @@ Environment variables are useful for CI/CD environments or temporary overrides d | Variable | Description | Example | |----------|-------------|---------| -| `MCPPROXY_LISTEN` | Override listen address | `127.0.0.1:8080` or `:8080` | +| `MCPPROXY_LISTEN` | Override listen address. `--listen` wins when both are set; an empty value leaves the config file's `listen`. The server Docker image sets it to `0.0.0.0:8080` | `127.0.0.1:8080` or `:8080` | | `MCPPROXY_API_KEY` | Set API key for authentication | `my-secret-key` | | `MCPPROXY_API_KEY_FILE` | Read the API key from a file (absolute path). Set it or `MCPPROXY_API_KEY`, not both; see [API key from a file](#api-key-from-a-file) | `/run/secrets/mcpproxy_api_key` | | `MCPPROXY_OAUTH_TOKEN_ENCRYPTION_KEY` | Key that encrypts the upstream OAuth tokens in `config.db` (base64, 32 bytes). Overrides `oauth_token_encryption_key`. Set it or the `_FILE` form, not both. See [OAuth Token Encryption](../features/oauth-token-encryption.md) | `bXkta2V5...` | diff --git a/docs/getting-started/installation.md b/docs/getting-started/installation.md index fe88cae50..98984a402 100644 --- a/docs/getting-started/installation.md +++ b/docs/getting-started/installation.md @@ -435,8 +435,13 @@ docker run -d --name mcpproxy \ directory: with it the config is still looked up in the working directory and `$HOME/.mcpproxy` (`/root/.mcpproxy` in this image). Releases before this change ignored `/mcp_config.json` under `serve`, so on those, mount the volume at the default `/root/.mcpproxy` path instead. -- **Port**: the entrypoint is `mcpproxy serve --listen 0.0.0.0:8080`, so the container listens on - `8080` inside the network namespace. The `-p 127.0.0.1:8080:8080` above keeps it reachable only +- **Port**: the entrypoint is `mcpproxy serve` and the image sets `MCPPROXY_LISTEN=0.0.0.0:8080`, + so the container listens on `8080` inside the network namespace. To move it, pass + `-e MCPPROXY_LISTEN=0.0.0.0:9090` (and publish that port), or append `--listen 0.0.0.0:9090` + after the image name — the flag wins over the variable. The config file's `listen` is used only + when `MCPPROXY_LISTEN` is set empty (`-e MCPPROXY_LISTEN=`); releases before v0.75 hardcoded + `--listen 0.0.0.0:8080` in the entrypoint and ignored `MCPPROXY_LISTEN`. + The `-p 127.0.0.1:8080:8080` above keeps it reachable only from the host; drop the `127.0.0.1:` prefix only if you deliberately want it on the network, and read [Network exposure: localhost by default](#network-exposure-localhost-by-default) first. - **State**: config, the BBolt DB, and the search index live in `/root/.mcpproxy`. Mount a volume diff --git a/docs/operations/deploying-for-a-team.md b/docs/operations/deploying-for-a-team.md index 26e1e9939..b972d6ba5 100644 --- a/docs/operations/deploying-for-a-team.md +++ b/docs/operations/deploying-for-a-team.md @@ -54,8 +54,9 @@ storage) or accepting the gap. ## Persistent volume: `--config` and `--data-dir` -The container's `ENTRYPOINT` is -`mcpproxy serve --listen 0.0.0.0:8080` (see the repository `Dockerfile`); a +The container's `ENTRYPOINT` is `mcpproxy serve` and the image sets +`MCPPROXY_LISTEN=0.0.0.0:8080` (see the repository `Dockerfile`), so `args` +holds only flags — a `--listen` there wins over the variable; a Kubernetes `args` override adds `--config` and `--data-dir` explicitly rather than relying on the image's defaults, because both must point inside the **same** mounted volume: @@ -285,7 +286,6 @@ spec: - name: mcpproxy image: ghcr.io/smart-mcp-proxy/mcpproxy-server:latest args: - - "serve" - "--listen=0.0.0.0:8080" - "--config=/data/mcp_config.json" - "--data-dir=/data" diff --git a/examples/compose-stdio-sidecars/docker-compose.yml b/examples/compose-stdio-sidecars/docker-compose.yml index dc375c4c1..3535d3569 100644 --- a/examples/compose-stdio-sidecars/docker-compose.yml +++ b/examples/compose-stdio-sidecars/docker-compose.yml @@ -35,7 +35,7 @@ services: # Pinned by digest (v0.73.0). ${file:} references and MCPPROXY_API_KEY_FILE # need v0.72.0 or newer. Bump tag and digest together. image: ghcr.io/smart-mcp-proxy/mcpproxy-server:v0.73.0@sha256:0f6cd65a3bc63f117d7f0fff7c539836c076f1834db620bf5fa9bbdd62578919 - command: ["serve", "--listen=0.0.0.0:8080", "--config=/config/mcp_config.json", "--data-dir=/data"] + command: ["--listen=0.0.0.0:8080", "--config=/config/mcp_config.json", "--data-dir=/data"] environment: MCPPROXY_API_KEY_FILE: /run/secrets/mcpproxy_api_key secrets: [mcpproxy_api_key, sidecar_api_key] diff --git a/scripts/test-docker-listen.sh b/scripts/test-docker-listen.sh new file mode 100644 index 000000000..0369971cd --- /dev/null +++ b/scripts/test-docker-listen.sh @@ -0,0 +1,82 @@ +#!/usr/bin/env bash +# Smoke-test the listen address of the server Docker image (#1942). +# +# Usage: scripts/test-docker-listen.sh [image] (default: mcpproxy-server:pr) +# +# Checks, against a real container each time: +# 1. default -> listens on 0.0.0.0:8080 +# 2. -e MCPPROXY_LISTEN -> listens on the env address, not on 8080 +# 3. --listen + env -> the CLI flag wins over MCPPROXY_LISTEN +# The image is distroless (no shell, no curl), so every probe goes through a +# published port from the host. +set -euo pipefail + +IMAGE="${1:-mcpproxy-server:pr}" +PREFIX="mcpproxy-listen-smoke-$$" +containers=() + +cleanup() { + for c in "${containers[@]:-}"; do + [ -n "$c" ] && docker rm -f "$c" >/dev/null 2>&1 || true + done +} +trap cleanup EXIT + +# start -- +start() { + local name="$PREFIX-$1"; shift + local run_args=() cmd_args=() + while [ $# -gt 0 ] && [ "$1" != "--" ]; do run_args+=("$1"); shift; done + [ $# -gt 0 ] && shift + cmd_args=("$@") + containers+=("$name") + docker run -d --name "$name" \ + -e MCPPROXY_API_KEY=listen-smoke-key \ + -e MCPPROXY_TELEMETRY=false \ + "${run_args[@]}" "$IMAGE" ${cmd_args[@]+"${cmd_args[@]}"} >/dev/null +} + +# expect_up : /healthz answers within 60s. +expect_up() { + local name="$PREFIX-$1" port="$2" + for _ in $(seq 1 60); do + if curl -fsS --max-time 2 "http://127.0.0.1:$port/healthz" >/dev/null 2>&1; then + echo "ok: $1 answers on host port $port" + return 0 + fi + if [ "$(docker inspect -f '{{.State.Running}}' "$name")" != "true" ]; then + echo "FAIL: $1 exited" >&2; docker logs "$name" >&2 || true; return 1 + fi + sleep 1 + done + echo "FAIL: $1 did not answer on host port $port" >&2 + docker logs "$name" >&2 || true + return 1 +} + +# expect_down : nothing in the container listens behind it. +expect_down() { + if curl -fsS --max-time 2 "http://127.0.0.1:$2/healthz" >/dev/null 2>&1; then + echo "FAIL: $1 unexpectedly answers on host port $2" >&2 + return 1 + fi + echo "ok: $1 does not answer on host port $2" +} + +# 1. Default: the image listens on 0.0.0.0:8080. +start default -p 127.0.0.1:18080:8080 +expect_up default 18080 + +# 2. MCPPROXY_LISTEN moves the listener; 8080 is no longer bound. +start env -e MCPPROXY_LISTEN=0.0.0.0:9090 \ + -p 127.0.0.1:18090:9090 -p 127.0.0.1:18091:8080 +expect_up env 18090 +expect_down env 18091 + +# 3. --listen (container args) outranks MCPPROXY_LISTEN. +start flag -e MCPPROXY_LISTEN=0.0.0.0:9090 \ + -p 127.0.0.1:18070:7070 -p 127.0.0.1:18071:9090 -- --listen 0.0.0.0:7070 +expect_up flag 18070 +expect_down flag 18071 + +echo "docker listen smoke test passed for $IMAGE"