Files

28 lines
792 B
Go

package mcphttp
import (
"os"
"strings"
)
// EndpointURL is the absolute URL the in-process REST bridge uses to reach
// the streamable-HTTP MCP endpoint. Override with MCP_INTERNAL_URL.
func EndpointURL() string {
if u := strings.TrimSpace(os.Getenv("MCP_INTERNAL_URL")); u != "" {
return u
}
addr := strings.TrimSpace(os.Getenv("MCP_LISTEN_ADDR"))
if addr == "" {
addr = "127.0.0.1:8085"
}
// Bind addresses like 0.0.0.0:8085 are not dialable; use loopback.
if strings.HasPrefix(addr, "0.0.0.0:") {
addr = "127.0.0.1:" + strings.TrimPrefix(addr, "0.0.0.0:")
} else if strings.HasPrefix(addr, "[::]:") {
addr = "127.0.0.1:" + strings.TrimPrefix(addr, "[::]:")
} else if strings.HasPrefix(addr, ":") {
addr = "127.0.0.1" + addr
}
return "http://" + addr + Endpoint
}