#!/bin/bash
# Start the teams-channel server in HTTP-only mode (Streamable HTTP MCP on
# MCP_PORTS["teams-mcp"]=18811, no Bot Framework webhook, no stdio MCP).
#
# Useful for:
#   - Local dev when you only want to exercise the MCP tool surface over HTTP
#   - Running on a host that already has another teams-channel instance
#     owning the Bot Framework webhook on 3978 (e.g. the Hetzner VM where the
#     primary teams-channel is driven by `claude --agent` and this sibling
#     just exposes /mcp to remote clients like claude.ai / Poke).
#
# Requires: MSTEAMS_APP_ID, MSTEAMS_APP_PASSWORD, MSTEAMS_TENANT_ID,
#           MCP_BEARER_TOKEN (loaded from .env or process env).
set -euo pipefail

DIR="$(cd "$(dirname "$0")" && pwd)"
cd "$DIR"

# Load env from .env if present
if [ -f "$DIR/.env" ]; then
  set -a
  # shellcheck disable=SC1090
  source "$DIR/.env"
  set +a
fi

if [ -z "${MCP_BEARER_TOKEN:-}" ]; then
  echo "ERROR: MCP_BEARER_TOKEN not set (required for HTTP MCP listener)" >&2
  exit 1
fi

export MSTEAMS_APP_ID MSTEAMS_APP_PASSWORD MSTEAMS_TENANT_ID MCP_BEARER_TOKEN
export TEAMS_HTTP_ONLY=1

exec "${BUN:-bun}" run "$DIR/server.ts"
