# Fly.io config for the remote MCP endpoint (per ADR 0001, container/Node).
# One-command deploy:
#   fly launch --no-deploy      # creates the app from this file (first time)
#   fly secrets set TIDB_CLOUD_PUBLIC_KEY=... TIDB_CLOUD_PRIVATE_KEY=...
#   fly deploy
# See docs/DEPLOY.md for the full walkthrough (auth modes, OAuth, origins).
app = "tidbcloud-mcp"
primary_region = "sjc"
# Give the app time to drain in-flight requests and release ephemeral SQL users on
# SIGINT/SIGTERM before Fly sends SIGKILL (must exceed TIDB_MCP_SHUTDOWN_TIMEOUT_MS=10s).
kill_timeout = "15s"

[build]
  dockerfile = "Dockerfile"

[env]
  PORT = "3000"
  # Multi-tenant: each request brings its own TiDB Cloud API key; the server holds none.
  TIDB_MCP_REQUIRE_AUTH = "true"
  # Read-only by default and NOT overridable per request (scopes only narrow, never expand).
  # A shared endpoint that people may point a production key at must not expose mutating tools,
  # especially since an agent can auto-confirm a destructive action. To exercise writes and the
  # preflight flow, run locally (stdio) or self-host with your own blast radius.
  TIDB_MCP_READ_ONLY = "true"
  # Where the client address comes from, which is what the pre-auth rate limit is keyed by.
  #
  # Fly sets Fly-Client-IP itself and does not append to it, so a caller cannot put a value there.
  # Without this the server refuses to trust any header and falls back to the connection address,
  # which behind Fly's proxy is the proxy: every unproven caller would share one 1 r/s bucket, so
  # after each deploy tenants would reprove at roughly one per second and get 429s until they did.
  # Safe in the sense that nothing is forgeable, not safe in the sense that it works.
  #
  # On AWS behind an ALB this becomes TIDB_MCP_TRUSTED_PROXY_DEPTH = "1" instead, because an ALB
  # APPENDS to X-Forwarded-For, so the trustworthy entry is the last one rather than a header.
  TIDB_MCP_CLIENT_IP_HEADER = "fly-client-ip"
  TIDB_MCP_BANNER = "Internal evaluation endpoint, READ-ONLY. Bring your own TiDB Cloud API key (the server holds none). To try writes and the preflight flow, run locally or self-host."

[http_service]
  internal_port = 3000
  force_https = true
  # Keep the machine genuinely warm so the shared eval endpoint has no cold-start delay.
  # min_machines_running alone did NOT hold a machine up (both were observed stopped, giving a
  # ~6.4s cold start), so autostop is off entirely. One always-on shared-cpu-1x/512MB is ~$2/mo.
  auto_stop_machines = false
  auto_start_machines = true
  min_machines_running = 1

  [[http_service.checks]]
    method = "GET"
    path = "/health"
    interval = "30s"
    timeout = "5s"

[[vm]]
  size = "shared-cpu-1x"
  memory = "512mb"
