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:
12
main.go
12
main.go
@@ -6,6 +6,7 @@ import (
|
|||||||
"log"
|
"log"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
"os"
|
||||||
|
|
||||||
"git.wntrmute.dev/kyle/goutils/config"
|
"git.wntrmute.dev/kyle/goutils/config"
|
||||||
"git.wntrmute.dev/kyle/goutils/die"
|
"git.wntrmute.dev/kyle/goutils/die"
|
||||||
@@ -29,10 +30,13 @@ func main() {
|
|||||||
srv := &server{db: db}
|
srv := &server{db: db}
|
||||||
http.Handle("/", srv)
|
http.Handle("/", srv)
|
||||||
|
|
||||||
addr := net.JoinHostPort(
|
// $PORT is set by the MCP agent for containers with route declarations.
|
||||||
config.Get("HTTP_ADDR"),
|
// It takes precedence over config, matching the mcdsl convention.
|
||||||
config.GetDefault("HTTP_PORT", "8000"),
|
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.Print("listening on ", addr)
|
||||||
log.Fatal(http.ListenAndServe(addr, nil))
|
log.Fatal(http.ListenAndServe(addr, nil))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user