# Cubic Echo — MCP servers
# mcp-skills-manager, mcp-ragdown and mcp-actual, and a Postgres for the first.
# https://cubicecho.com/guides/mcp/
#
# Don't use Actual Budget? Delete the mcp-actual service and its volume.
#
# Set in the stack's environment (generate secrets and tokens with
# `openssl rand -hex 32`, and keep them):
#   PUBLIC_HOST             this machine's LAN address or hostname, e.g. 192.168.1.10
#   POSTGRES_PASSWORD
#   SKILLS_AUTH_SECRET      signs mcp-skills-manager's sessions
#   RAGDOWN_TOKEN, ACTUAL_MCP_TOKEN
#   NOTES_DIR               the Markdown folder mcp-ragdown indexes (default ./notes)
#   ACTUAL_SERVER_URL, ACTUAL_PASSWORD, ACTUAL_SYNC_ID   for mcp-actual
#
# mcp-ragdown and mcp-actual generate an empty token and print it to their logs.
# mcp-skills-manager has no token: people sign in (pair it with heautou, or set
# SKILLS_OIDC_*), and each MCP client gets an API key from its Settings.
#
# Upgrading a stack made before mcp-skills-manager 5? Read this first:
# https://cubicecho.com/guides/mcp/#upgrading-to-5
name: cubicecho-mcp

services:
  mcp-skills-manager:
    image: ghcr.io/cubicecho/mcp-skills-manager:latest
    restart: unless-stopped
    depends_on:
      postgres: { condition: service_healthy }
    environment:
      DATABASE_URL: ${SKILLS_DATABASE_URL:-postgres://cubicecho:${POSTGRES_PASSWORD:?set POSTGRES_PASSWORD}@postgres:5432/mcp_skills}
      BETTER_AUTH_SECRET: ${SKILLS_AUTH_SECRET:?set SKILLS_AUTH_SECRET}
      APP_URL: ${SKILLS_URL:-http://${PUBLIC_HOST:-localhost}:${SKILLS_PORT:-3100}}
      OIDC_ISSUER: ${SKILLS_OIDC_ISSUER:-}   # or pair with heautou from the sign-in page
      OIDC_CLIENT_ID: ${SKILLS_OIDC_CLIENT_ID:-}
      OIDC_CLIENT_SECRET: ${SKILLS_OIDC_CLIENT_SECRET:-}
      OIDC_CLIENT_AUTH: ${SKILLS_OIDC_CLIENT_AUTH:-}
      OIDC_NAME: ${SKILLS_OIDC_NAME:-}
      SECURE_LOCAL_NET: ${SKILLS_SECURE_LOCAL_NET:-${SECURE_LOCAL_NET:-}}
      TRUST_PROXY: ${SKILLS_TRUST_PROXY:-false}
    ports:
      - "${SKILLS_PORT:-3100}:3000"
    volumes:
      - skills-data:/data

  mcp-ragdown:
    image: vantreeseba/mcp-ragdown:latest
    restart: unless-stopped
    environment:
      RAGDOWN_TOKEN: ${RAGDOWN_TOKEN:-}
      RAGDOWN_READ_ONLY: ${RAGDOWN_READ_ONLY:-false}
      RAGDOWN_PUBLIC_URL: ${RAGDOWN_PUBLIC_URL:-}
      SECURE_LOCAL_NET: ${SECURE_LOCAL_NET:-false}
    ports:
      - "${RAGDOWN_PORT:-3102}:3000"
    volumes:
      - ${NOTES_DIR:-./notes}:/docs
      - ragdown-data:/data

  mcp-actual:
    image: ghcr.io/cubicecho/mcp-actual:latest
    restart: unless-stopped
    environment:
      ACTUAL_SERVER_URL: ${ACTUAL_SERVER_URL:-}
      ACTUAL_PASSWORD: ${ACTUAL_PASSWORD:-}
      ACTUAL_SYNC_ID: ${ACTUAL_SYNC_ID:-}
      ACTUAL_ENCRYPTION_PASSWORD: ${ACTUAL_ENCRYPTION_PASSWORD:-}
      ACTUAL_ENABLE_WRITES: ${ACTUAL_ENABLE_WRITES:-}
      MCP_ACTUAL_TOKEN: ${ACTUAL_MCP_TOKEN:-}
      SECURE_LOCAL_NET: ${SECURE_LOCAL_NET:-}
      DATA_DIR: /data
    ports:
      - "${ACTUAL_MCP_PORT:-3101}:3000"
    volumes:
      - actual-data:/data

  # mcp-skills-manager needs Postgres 18 or later; the other two need none.
  postgres:
    image: postgres:18-alpine
    restart: unless-stopped
    environment:
      POSTGRES_USER: cubicecho
      POSTGRES_PASSWORD: ${POSTGRES_PASSWORD}
      POSTGRES_DB: cubicecho
    configs:
      - source: create-databases
        target: /docker-entrypoint-initdb.d/create-databases.sql
    volumes:
      - postgres-data:/var/lib/postgresql
    healthcheck:
      test: ["CMD-SHELL", "pg_isready -U cubicecho -d cubicecho"]
      interval: 5s
      timeout: 5s
      retries: 10

# Runs once, when the Postgres volume is first created.
configs:
  create-databases:
    content: |
      CREATE DATABASE mcp_skills;

volumes:
  skills-data:
  ragdown-data:
  actual-data:
  postgres-data:
