name: Publish to MCP Registry

on:
  release:
    types: [published]
  workflow_dispatch:

jobs:
  publish:
    name: Publish server.json to MCP Registry
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4

      - name: Publish to MCP Registry
        run: |
          response=$(curl -s -w "\n%{http_code}" -X POST \
            https://registry.modelcontextprotocol.io/v0/publish \
            -H "Authorization: Bearer ${{ secrets.MCP_REGISTRY_TOKEN }}" \
            -H "Content-Type: application/json" \
            --data-binary @server.json)

          body=$(echo "$response" | head -n -1)
          status=$(echo "$response" | tail -n 1)

          echo "$body"
          if [ "$status" -lt 200 ] || [ "$status" -ge 300 ]; then
            echo "::error::MCP Registry publish failed with HTTP $status"
            exit 1
          fi
