Support $PORT env var for MCP agent port allocation

MCP agent sets $PORT for containers with route declarations.
$PORT takes precedence over HTTP_PORT from config, matching the mcdsl
convention used by all other platform services.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-03-28 18:07:49 -07:00
parent 0ecea29413
commit d3c174d9b0

12
main.go
View File

@@ -6,6 +6,7 @@ import (
"log"
"net"
"net/http"
"os"
"git.wntrmute.dev/kyle/goutils/config"
"git.wntrmute.dev/kyle/goutils/die"
@@ -29,10 +30,13 @@ func main() {
srv := &server{db: db}
http.Handle("/", srv)
addr := net.JoinHostPort(
config.Get("HTTP_ADDR"),
config.GetDefault("HTTP_PORT", "8000"),
)
// $PORT is set by the MCP agent for containers with route declarations.
// It takes precedence over config, matching the mcdsl convention.
port := os.Getenv("PORT")
if port == "" {
port = config.GetDefault("HTTP_PORT", "8000")
}
addr := net.JoinHostPort(config.Get("HTTP_ADDR"), port)
log.Print("listening on ", addr)
log.Fatal(http.ListenAndServe(addr, nil))
}