feat(mcp): add --host support for HTTP mode and harden daemon startup#232
Open
feat(mcp): add --host support for HTTP mode and harden daemon startup#232
Conversation
--host flag to MCP HTTP server8738690 to
330452d
Compare
Author
|
Added follow-up hardening in |
Add explicit bind-host control for `qmd mcp --http` and fix the daemon false-success startup bug. - New `--host <ADDR>` flag for foreground and daemon HTTP modes - Host validation: rejects URLs, flags, host:port, bracketed non-IPv6, whitespace, and empty values via src/mcp-host.ts - Host normalization: handles [::1] → bind ::1 / display [::1], defaults to localhost - Daemon IPC readiness: parent waits for child bind confirmation before writing mcp.pid and reporting success; port collisions now exit 1 with no stale PID file - Settled guard prevents double-resolution from message+exit races - EADDRINUSE errors now include the bind host Ported from the v1.1.x PR tobi#232 branch to the v2.0.x source layout (src/cli/qmd.ts, src/mcp/server.ts). Fixes tobi#227. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
6ba8786 to
2fa5726
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
PR #232 Draft — Updated 2026-03-11
Title
feat(mcp): add --host support for HTTP mode and harden daemon startup
Body
Summary
Refreshes PR #232 on top of current upstream
main(post-v2.0.1).The original PR targeted the pre-v2 layout (
src/qmd.ts,src/mcp.ts).Since v2.0.0 moved the relevant code into
src/cli/qmd.tsandsrc/mcp/ server.ts, this update ports the same feature to the current code shapeand includes additional hardening around validation and daemon startup.
Fixes #227.
Problem
Current
mainstill starts MCP HTTP with a hardcodedlocalhostbind andno explicit host override. That is unreliable for VM/container host-access paths where the client reaches the host over IPv4 but the server binds to IPv6 loopback.
I re-verified the original Colima reachability issue against current
upstream on March 11, 2026 in an isolated Colima environment:
::1localhostand[::1]worked on the host127.0.0.1did nothost.docker.internalA control test in the same environment confirmed the network behavior
behind the issue:
127.0.0.1was reachable from the Colima container::1was notCurrent
mainalso still has a separate daemon startup bug:qmd mcp --http --daemonreports success before the child has actually bound therequested port. With a deterministic port-collision repro, the parent
exited successfully, printed
Started on ..., and wrotemcp.pideventhough the child had already failed with
EADDRINUSE.What This Change Adds
qmd mcp --http --host <ADDR>qmd mcp --http --daemon --host <ADDR>EADDRINUSEreportingmcp.pidafter successful bindStarted on ...after successful bindHardening Included
This version also rejects malformed
--hostinput early, including:host:portpassed to--host[localhost]Validation
Validated against current upstream
main(post-v2.0.1):upstream
upstream with a deterministic port collision
Local verification on the refreshed v2 port:
pnpm -s tsc -p tsconfig.build.jsonpnpm vitest run test/mcp-host.test.ts→30/30pnpm vitest run test/mcp.test.ts→74/74pnpm vitest run test/cli.test.ts→112/112pnpm vitest run test/→773/773Examples