diff --git a/main.py b/main.py index 0c31d131..bdd3b261 100644 --- a/main.py +++ b/main.py @@ -20,7 +20,7 @@ from condor.persistence import SafePicklePersistence from handlers import cancel_command, clear_all_input_states from utils.auth import restricted -from utils.config import TELEGRAM_TOKEN, WEB_PORT, WEB_URL +from utils.config import TELEGRAM_TOKEN, BIND_HOST, BIND_PORT, WEB_URL, WEB_PORT # Enable logging logging.basicConfig( @@ -777,8 +777,8 @@ async def _run_dual(application: Application) -> None: web_app = create_app() config = uvicorn.Config( web_app, - host="0.0.0.0", - port=WEB_PORT, + host=BIND_HOST, + port=BIND_PORT, log_level="info", access_log=False, ) diff --git a/mcp_servers/condor/condor_client.py b/mcp_servers/condor/condor_client.py index e851a0f5..1c3e74b1 100644 --- a/mcp_servers/condor/condor_client.py +++ b/mcp_servers/condor/condor_client.py @@ -1,8 +1,8 @@ """HTTP client for calling the Condor main-process web API.""" import re - import aiohttp +import ipaddress from mcp_servers.condor.exceptions import APIError from mcp_servers.condor.settings import settings @@ -24,11 +24,25 @@ async def call_main_api( """ from condor.runtime.timeouts import TIMEOUTS from condor.web.auth import create_jwt - from utils.config import WEB_PORT + from utils.config import BIND_HOST, BIND_PORT if timeout is None: timeout = TIMEOUTS.mcp_call - url = f"http://127.0.0.1:{WEB_PORT}/api/v1{path}" + + host = BIND_HOST + + try: + ip = ipaddress.ip_address(host) + + if ip.is_unspecified: + host = "::1" if ip.version == 6 else "127.0.0.1" + + if ip.version == 6: + host = f"[{host}]" + except ValueError: + pass + + url = f"http://{host}:{BIND_PORT}/api/v1{path}" token = create_jwt(settings.user_id, role="user") headers = {"Authorization": f"Bearer {token}"} diff --git a/utils/config.py b/utils/config.py index 14d7631a..f3dbd301 100644 --- a/utils/config.py +++ b/utils/config.py @@ -27,7 +27,19 @@ if _web_url_raw: WEB_URL = _web_url_raw.rstrip("/") _parsed = urlparse(WEB_URL) - WEB_PORT = _parsed.port or (443 if _parsed.scheme == "https" else 80) + + if _parsed.port: + WEB_PORT = _parsed.port + elif _web_port_raw: + WEB_PORT = int(_web_port_raw) + else: + WEB_PORT = 443 if _parsed.scheme == "https" else 80 else: WEB_PORT = int(_web_port_raw) if _web_port_raw else 8088 WEB_URL = f"http://localhost:{WEB_PORT}" + +_bind_host_raw = os.environ.get("BIND_HOST", "").strip() +_bind_port_raw = os.environ.get("BIND_PORT", "").strip() + +BIND_HOST = str(_bind_host_raw) if _bind_host_raw else "0.0.0.0" +BIND_PORT = int(_bind_port_raw) if _bind_port_raw else WEB_PORT