Skip to content

Commit 2b204f8

Browse files
fix: remap compose agent URLs for native backend runs
The Agent tab 503'd because native spring-boot:run sourced Compose DNS (deepsql-agent:8788) which does not resolve on the host. Remap those hosts to loopback in start-backend.sh, and let the agent container reach a host-side Java backend via host.docker.internal. Co-authored-by: Venkat SF <venkatesh.sakamuri@stayflexi.com>
1 parent 2eaa625 commit 2b204f8

5 files changed

Lines changed: 47 additions & 6 deletions

File tree

.env.example

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,9 @@ EMBEDDING_FAIL_OPEN=false
141141
# AGENT_WEBUI_URL Agent HTTP API. Compose default: http://deepsql-agent:8787
142142
# AGENT_PROVISIONER_URL Per-user profile provisioner. Compose default:
143143
# http://deepsql-agent:8788/provision
144+
# DEEPSQL_API_BASE_URL Where the agent container's MCP tools call the backend.
145+
# Compose default: http://backend:8080/api/
146+
# Native Java + Compose agent: http://host.docker.internal:8080/api/
144147
# AGENT_PROVISION_SECRET Shared secret between backend and agent (required).
145148
# DEEPSQL_AGENT_PORT / DEEPSQL_AGENT_PROVISIONER_PORT — host port mappings
146149
# (compose binds these to 127.0.0.1 only; public path is nginx /agent-api).

AGENTS.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -264,9 +264,16 @@ only covers cloud-specific, non-obvious caveats.
264264
non-`public` schemas (`crm`, `sales`, `finance`, `hr`, `inventory`) for Brain /
265265
MCP cross-schema checks. Prefer schema-qualified SQL (`sales.orders`); bare
266266
names follow the role’s `search_path` (usually `public`).
267-
- **`AGENT_WEBUI_URL` for native runs.** Default is `http://deepsql-agent:8787`
268-
(Compose DNS). Native local must set `AGENT_WEBUI_URL=http://127.0.0.1:8787` in
269-
`.env` or CLI/Slack `AgentChatClient` cannot reach the agent API.
267+
- **`AGENT_WEBUI_URL` / `AGENT_PROVISIONER_URL` for native runs.** Compose
268+
defaults (`http://deepsql-agent:8787` and `…:8788/provision`) do not resolve
269+
on the host. Native local must point both at loopback
270+
(`http://127.0.0.1:8787` and `http://127.0.0.1:8788/provision`) or the Agent
271+
tab returns 503 `Could not provision the DeepSQL Agent for this user`.
272+
`scripts/start-backend.sh` remaps those hostnames automatically when they
273+
don't resolve. If the agent container is used with a host-side Java backend,
274+
set `DEEPSQL_API_BASE_URL=http://host.docker.internal:8080/api/` so MCP
275+
tools can reach the native process (compose publishes `host.docker.internal`
276+
via `extra_hosts`).
270277
- **DeepSQL CLI (`deepsql`) for agent testing.** Install from the repo package:
271278
`cd mcp && DEEPSQL_SKIP_AGENT_SETUP=1 npm install -g .` (prefix
272279
`~/.npm-global`, keep that on `PATH`). Auth against local backend with an MCP

docker-compose.yml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,10 @@ services:
140140
DEEPSQL_CHAT_API_KEY: ${DEEPSQL_CHAT_API_KEY:-}
141141
DEEPSQL_CHAT_ENDPOINT: ${DEEPSQL_CHAT_ENDPOINT:-}
142142
DEEPSQL_CHAT_MODEL: ${DEEPSQL_CHAT_MODEL:-gpt-5.4}
143-
# Reach the backend over the compose network (MCP tools + provisioner)
144-
DEEPSQL_API_BASE_URL: http://backend:8080/api/
143+
# Reach the backend over the compose network (MCP tools + provisioner).
144+
# Override to http://host.docker.internal:8080/api/ when the Java backend
145+
# runs on the host (native `mvn spring-boot:run`) instead of Compose.
146+
DEEPSQL_API_BASE_URL: ${DEEPSQL_API_BASE_URL:-http://backend:8080/api/}
145147
# Shared secret with backend AgentBridgeService
146148
AGENT_PROVISION_SECRET: ${AGENT_PROVISION_SECRET:-}
147149
# Origins allowed by the agent API CSRF check
@@ -153,6 +155,8 @@ services:
153155
DEEPSQL_AGENT_TRUSTED_PROXY_CIDRS: ${DEEPSQL_AGENT_TRUSTED_PROXY_CIDRS:-10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
154156
HERMES_WEBUI_TRUSTED_PROXY_CIDRS: ${DEEPSQL_AGENT_TRUSTED_PROXY_CIDRS:-10.0.0.0/8,172.16.0.0/12,192.168.0.0/16}
155157
HERMES_WEBUI_TRUSTED_AUTH_HEADER: X-Remote-User
158+
extra_hosts:
159+
- "host.docker.internal:host-gateway"
156160
ports:
157161
- "127.0.0.1:${DEEPSQL_AGENT_PORT:-8787}:8787"
158162
- "127.0.0.1:${DEEPSQL_AGENT_PROVISIONER_PORT:-8788}:8788"
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Sourced by scripts/start-backend.sh (outer shell and the inner bash -lc).
2+
# Compose service hostnames only resolve on the compose network. Native
3+
# `mvn spring-boot:run` still sources a Compose-oriented .env, so rewrite
4+
# those hosts to loopback when they don't resolve.
5+
if ! getent hosts postgres >/dev/null 2>&1; then
6+
if [ -n "${DB_URL:-}" ]; then
7+
export DB_URL="${DB_URL//:\/\/postgres:/:\/\/127.0.0.1:}"
8+
fi
9+
fi
10+
if ! getent hosts valkey >/dev/null 2>&1; then
11+
case "${SPRING_DATA_REDIS_HOST:-}" in
12+
valkey|"") export SPRING_DATA_REDIS_HOST=127.0.0.1 ;;
13+
esac
14+
fi
15+
if ! getent hosts deepsql-agent >/dev/null 2>&1; then
16+
if [ -n "${AGENT_WEBUI_URL:-}" ]; then
17+
export AGENT_WEBUI_URL="${AGENT_WEBUI_URL//deepsql-agent/127.0.0.1}"
18+
fi
19+
if [ -n "${AGENT_PROVISIONER_URL:-}" ]; then
20+
export AGENT_PROVISIONER_URL="${AGENT_PROVISIONER_URL//deepsql-agent/127.0.0.1}"
21+
fi
22+
fi

scripts/start-backend.sh

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ ENV_FILE="$PROJECT_ROOT/.env"
99
echo "Starting DBA Agent Backend..."
1010
echo "================================"
1111

12+
REMAP_SCRIPT="$SCRIPT_DIR/remap-compose-hosts-for-native.sh"
13+
1214
if [ -f "$ENV_FILE" ]; then
1315
echo "Loading environment from .env..."
1416
set -a
@@ -18,13 +20,16 @@ if [ -f "$ENV_FILE" ]; then
1820
echo "Local source-run startup ignores SPRING_PROFILES_ACTIVE=prod from .env"
1921
unset SPRING_PROFILES_ACTIVE
2022
fi
23+
# shellcheck source=remap-compose-hosts-for-native.sh
24+
source "$REMAP_SCRIPT"
25+
echo "Agent provisioner: ${AGENT_PROVISIONER_URL:-unset}"
2126
fi
2227

2328
build_backend_launch_command() {
2429
local mvn_command="$1"
2530
local env_snippet=""
2631
if [ -f "$ENV_FILE" ]; then
27-
env_snippet="set -a && source \"$ENV_FILE\" && set +a && if [ \"\${SPRING_PROFILES_ACTIVE:-}\" = \"prod\" ]; then unset SPRING_PROFILES_ACTIVE; fi && "
32+
env_snippet="set -a && source \"$ENV_FILE\" && set +a && if [ \"\${SPRING_PROFILES_ACTIVE:-}\" = \"prod\" ]; then unset SPRING_PROFILES_ACTIVE; fi && source \"$REMAP_SCRIPT\" && "
2833
fi
2934
printf '%s' "${env_snippet}cd \"$PROJECT_ROOT/backend\" && exec ${mvn_command} spring-boot:run"
3035
}

0 commit comments

Comments
 (0)