|
4 | 4 | # SIDEMANTIC_MODE: "serve" (default), "mcp", or "both" |
5 | 5 | MODE="${SIDEMANTIC_MODE:-serve}" |
6 | 6 |
|
7 | | -# Build shared args from environment variables |
8 | | -ARGS="" |
| 7 | +# Build arg arrays for each command. |
| 8 | +# serve accepts: --connection, --db, --host, --port, --username, --password |
| 9 | +# mcp-serve accepts: --db only |
| 10 | + |
| 11 | +# Serve args |
| 12 | +SERVE_ARGS="--host 0.0.0.0" |
9 | 13 | if [ -n "$SIDEMANTIC_CONNECTION" ]; then |
10 | | - ARGS="$ARGS --connection $SIDEMANTIC_CONNECTION" |
| 14 | + SERVE_ARGS="$SERVE_ARGS --connection \"$SIDEMANTIC_CONNECTION\"" |
11 | 15 | fi |
12 | 16 | if [ -n "$SIDEMANTIC_DB" ]; then |
13 | | - ARGS="$ARGS --db $SIDEMANTIC_DB" |
| 17 | + SERVE_ARGS="$SERVE_ARGS --db \"$SIDEMANTIC_DB\"" |
14 | 18 | fi |
15 | | - |
16 | | -# Serve-specific args |
17 | | -SERVE_ARGS="" |
18 | 19 | if [ -n "$SIDEMANTIC_USERNAME" ]; then |
19 | | - SERVE_ARGS="$SERVE_ARGS --username $SIDEMANTIC_USERNAME" |
| 20 | + SERVE_ARGS="$SERVE_ARGS --username \"$SIDEMANTIC_USERNAME\"" |
20 | 21 | fi |
21 | 22 | if [ -n "$SIDEMANTIC_PASSWORD" ]; then |
22 | | - SERVE_ARGS="$SERVE_ARGS --password $SIDEMANTIC_PASSWORD" |
| 23 | + SERVE_ARGS="$SERVE_ARGS --password \"$SIDEMANTIC_PASSWORD\"" |
23 | 24 | fi |
24 | 25 | if [ -n "$SIDEMANTIC_PORT" ]; then |
25 | | - SERVE_ARGS="$SERVE_ARGS --port $SIDEMANTIC_PORT" |
| 26 | + SERVE_ARGS="$SERVE_ARGS --port \"$SIDEMANTIC_PORT\"" |
| 27 | +fi |
| 28 | + |
| 29 | +# MCP args (only --db is supported) |
| 30 | +MCP_ARGS="" |
| 31 | +if [ -n "$SIDEMANTIC_DB" ]; then |
| 32 | + MCP_ARGS="$MCP_ARGS --db \"$SIDEMANTIC_DB\"" |
26 | 33 | fi |
27 | 34 |
|
28 | 35 | case "$MODE" in |
29 | 36 | serve) |
30 | | - exec sidemantic serve --host 0.0.0.0 $ARGS $SERVE_ARGS "$@" |
| 37 | + eval exec sidemantic serve $SERVE_ARGS "$@" |
31 | 38 | ;; |
32 | 39 | mcp) |
33 | | - exec sidemantic mcp-serve $ARGS "$@" |
| 40 | + eval exec sidemantic mcp-serve $MCP_ARGS "$@" |
34 | 41 | ;; |
35 | 42 | both) |
36 | | - # Start PG server in background, MCP on stdio in foreground |
37 | | - sidemantic serve --host 0.0.0.0 $ARGS $SERVE_ARGS & |
| 43 | + eval sidemantic serve $SERVE_ARGS & |
38 | 44 | SERVE_PID=$! |
39 | 45 | trap "kill $SERVE_PID 2>/dev/null" EXIT |
40 | | - exec sidemantic mcp-serve $ARGS "$@" |
| 46 | + eval exec sidemantic mcp-serve $MCP_ARGS "$@" |
41 | 47 | ;; |
42 | 48 | *) |
43 | 49 | echo "Unknown SIDEMANTIC_MODE: $MODE (use serve, mcp, or both)" >&2 |
|
0 commit comments