fix: bind loopback by address and pin the sandbox port so containers work

Two defaults that each break the Inspector inside a container.

#1951 — the web UI never loads in a VS Code dev container. `HOST` defaulted
to the NAME `localhost`, and `server.listen(port, host)` resolves a name
through `dns.lookup` and binds the SINGLE address it gets back. Since Node 17
the default result order is `verbatim`, so on a glibc Linux host — whose
/etc/hosts maps localhost to both 127.0.0.1 and ::1 — that is `::1`. The
server bound IPv6 loopback only and refused every IPv4 client, including the
dev container port forwarder. It presents as an endless spinner rather than a
connection error because the forwarder accepts on the host side before failing
to connect inward. Default to the ADDRESS 127.0.0.1 instead; an explicit
HOST=localhost is still honored as typed.

#2008 — the Apps tab is unreachable in any container. The MCP Apps sandbox
listened on an OS-assigned port, so it changed every run and could never be
named in a devcontainer `forwardPorts`, a `docker run -p`, or a tunnel. Default
it to a fixed 6275, mirroring CLIENT_PORT's fixed 6274, and retry once on an
OS-assigned port (loudly) if it is taken — the collision a dynamic default
never had.

Verified in the reporter's exact image
(mcr.microsoft.com/devcontainers/typescript-node:4-24-trixie): both listeners
come up on 127.0.0.1 and answer 200 on 6274 and 6275/sandbox.

Also EXPOSE 6275 and set MCP_SANDBOX_PORT in the image, and document both
defaults in the web README, the migration guide, and the root README's Docker
section.

Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
cliffhall 2026-08-15 12:13:06 -04:00
commit adde9ccf94

View file

@ -1,12 +1,24 @@
import { describe, it, expect } from "vitest";
import {
BIND_ALL_INTERFACES_ENV,
DEFAULT_BIND_HOST,
resolveBindHostname,
} from "../../../../server/resolve-bind-host.js";
describe("resolveBindHostname", () => {
it("defaults to localhost when HOST is unset", () => {
expect(resolveBindHostname({})).toBe("localhost");
// Regression guard for #1951. The default must be an *address*, never the
// name `localhost`: `listen()` resolves a name and binds the single address
// the resolver returns first, which on glibc Linux is `::1` — leaving every
// IPv4 client (a dev container's port forwarder, an `ssh -L` to 127.0.0.1, a
// container healthcheck) refused. See DEFAULT_BIND_HOST.
it("defaults to the IPv4 loopback address, not the name localhost", () => {
expect(resolveBindHostname({})).toBe("127.0.0.1");
expect(resolveBindHostname({})).toBe(DEFAULT_BIND_HOST);
expect(resolveBindHostname({})).not.toBe("localhost");
});
it("still honors an explicit HOST=localhost as typed", () => {
expect(resolveBindHostname({ HOST: "localhost" })).toBe("localhost");
});
it("returns a loopback HOST unchanged", () => {