@echo off
setlocal

rem Resolve the directory containing this bat file (works at any install path).
set "BAT_DIR=%~dp0"
rem Remove trailing backslash so paths join cleanly.
if "%BAT_DIR:~-1%"=="\" set "BAT_DIR=%BAT_DIR:~0,-1%"

rem Only set GX_CONFIG_PATH when the caller hasn't provided one.
if not defined GX_CONFIG_PATH (
  set "GX_CONFIG_PATH=%BAT_DIR%\config.json"
)

set "GX_MCP_STDIO=true"

rem Launch the gateway exe that lives alongside this bat file.
set "GATEWAY_EXE=%BAT_DIR%\GxMcp.Gateway.exe"
if exist "%GATEWAY_EXE%" (
  "%GATEWAY_EXE%"
  exit /b %ERRORLEVEL%
)

rem Fallback: run the DLL via dotnet (dev layout where .exe is not present).
cd /d "%BAT_DIR%"
dotnet GxMcp.Gateway.dll
