Skip to content
Open
6 changes: 3 additions & 3 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -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,
)
Expand Down
14 changes: 11 additions & 3 deletions mcp_servers/condor/condor_client.py
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -24,11 +24,19 @@ 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}"

try:
ip = ipaddress.ip_address(BIND_HOST)
if ip.version == 6:
BIND_HOST = f"[{BIND_HOST}]"
except ValueError:
pass

url = f"http://{BIND_HOST}:{BIND_PORT}/api/v1{path}"
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
Comment thread
greptile-apps[bot] marked this conversation as resolved.
Outdated
token = create_jwt(settings.user_id, role="user")
headers = {"Authorization": f"Bearer {token}"}

Expand Down
14 changes: 13 additions & 1 deletion utils/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -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