|
| 1 | +name: Validate and publish FunASR MCP server |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request: |
| 5 | + paths: |
| 6 | + - "examples/mcp_server/**" |
| 7 | + - ".github/workflows/publish-mcp-server.yml" |
| 8 | + push: |
| 9 | + branches: ["main"] |
| 10 | + tags: ["mcp-v*"] |
| 11 | + paths: |
| 12 | + - "examples/mcp_server/**" |
| 13 | + - ".github/workflows/publish-mcp-server.yml" |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +env: |
| 17 | + IMAGE_NAME: ghcr.io/modelscope/funasr-mcp |
| 18 | + MCP_PUBLISHER_VERSION: v1.8.0 |
| 19 | + MCP_PUBLISHER_SHA256: 1370446bbe74d562608e8005a6ccce02d146a661fbd78674e11cc70b9618d6cf |
| 20 | + |
| 21 | +jobs: |
| 22 | + validate: |
| 23 | + runs-on: ubuntu-latest |
| 24 | + permissions: |
| 25 | + contents: read |
| 26 | + |
| 27 | + steps: |
| 28 | + - uses: actions/checkout@v7 |
| 29 | + |
| 30 | + - uses: actions/setup-python@v6 |
| 31 | + with: |
| 32 | + python-version: "3.10" |
| 33 | + |
| 34 | + - name: Run MCP unit and metadata tests |
| 35 | + run: python -m unittest discover -s examples/mcp_server -p "test_*.py" -v |
| 36 | + |
| 37 | + - name: Validate server.json against the official schema |
| 38 | + run: | |
| 39 | + python -m pip install --disable-pip-version-check "jsonschema==4.25.1" |
| 40 | + schema_url="$(jq -r '."$schema"' examples/mcp_server/server.json)" |
| 41 | + curl --fail --show-error --silent --location --retry 3 \ |
| 42 | + "$schema_url" -o "$RUNNER_TEMP/server.schema.json" |
| 43 | + python - <<'PY' |
| 44 | + import json |
| 45 | + import os |
| 46 | + from pathlib import Path |
| 47 | +
|
| 48 | + from jsonschema import Draft7Validator |
| 49 | +
|
| 50 | + metadata = json.loads(Path("examples/mcp_server/server.json").read_text()) |
| 51 | + schema = json.loads( |
| 52 | + (Path(os.environ["RUNNER_TEMP"]) / "server.schema.json").read_text() |
| 53 | + ) |
| 54 | + Draft7Validator(schema).validate(metadata) |
| 55 | + PY |
| 56 | +
|
| 57 | + - name: Install verified MCP publisher |
| 58 | + run: | |
| 59 | + archive="$RUNNER_TEMP/mcp-publisher.tar.gz" |
| 60 | + curl --fail --show-error --silent --location --retry 3 \ |
| 61 | + "https://github.com/modelcontextprotocol/registry/releases/download/${MCP_PUBLISHER_VERSION}/mcp-publisher_linux_amd64.tar.gz" \ |
| 62 | + -o "$archive" |
| 63 | + echo "${MCP_PUBLISHER_SHA256} $archive" | sha256sum --check |
| 64 | + tar -xzf "$archive" -C "$RUNNER_TEMP" mcp-publisher |
| 65 | +
|
| 66 | + - name: Validate metadata with the official Registry |
| 67 | + run: | |
| 68 | + "$RUNNER_TEMP/mcp-publisher" validate examples/mcp_server/server.json |
| 69 | +
|
| 70 | + - name: Check release tag matches server version |
| 71 | + id: metadata |
| 72 | + shell: bash |
| 73 | + run: | |
| 74 | + version="$(jq -r '.version' examples/mcp_server/server.json)" |
| 75 | + echo "version=$version" >> "$GITHUB_OUTPUT" |
| 76 | + if [[ "$GITHUB_REF" == refs/tags/mcp-v* ]]; then |
| 77 | + tag_version="${GITHUB_REF_NAME#mcp-v}" |
| 78 | + test "$tag_version" = "$version" || { |
| 79 | + echo "Tag version $tag_version does not match server.json $version" >&2 |
| 80 | + exit 1 |
| 81 | + } |
| 82 | + fi |
| 83 | +
|
| 84 | + - uses: docker/setup-buildx-action@v4 |
| 85 | + |
| 86 | + - name: Build local MCP image |
| 87 | + uses: docker/build-push-action@v7 |
| 88 | + with: |
| 89 | + context: examples/mcp_server |
| 90 | + load: true |
| 91 | + push: false |
| 92 | + tags: funasr-mcp:test |
| 93 | + build-args: | |
| 94 | + VERSION=${{ steps.metadata.outputs.version }} |
| 95 | + VCS_REF=${{ github.sha }} |
| 96 | + cache-from: type=gha,scope=funasr-mcp |
| 97 | + cache-to: type=gha,mode=max,scope=funasr-mcp |
| 98 | + |
| 99 | + - name: Smoke-test MCP protocol inside the image |
| 100 | + run: python examples/mcp_server/smoke_test.py funasr-mcp:test |
| 101 | + |
| 102 | + publish: |
| 103 | + if: startsWith(github.ref, 'refs/tags/mcp-v') |
| 104 | + needs: validate |
| 105 | + runs-on: ubuntu-latest |
| 106 | + environment: mcp-registry-publish |
| 107 | + permissions: |
| 108 | + contents: read |
| 109 | + id-token: write |
| 110 | + packages: write |
| 111 | + |
| 112 | + steps: |
| 113 | + - uses: actions/checkout@v7 |
| 114 | + |
| 115 | + - name: Read server version |
| 116 | + id: metadata |
| 117 | + run: echo "version=$(jq -r '.version' examples/mcp_server/server.json)" >> "$GITHUB_OUTPUT" |
| 118 | + |
| 119 | + - uses: docker/login-action@v4 |
| 120 | + with: |
| 121 | + registry: ghcr.io |
| 122 | + username: ${{ github.actor }} |
| 123 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 124 | + |
| 125 | + - uses: docker/setup-buildx-action@v4 |
| 126 | + |
| 127 | + - name: Publish versioned MCP image |
| 128 | + uses: docker/build-push-action@v7 |
| 129 | + with: |
| 130 | + context: examples/mcp_server |
| 131 | + push: true |
| 132 | + tags: | |
| 133 | + ${{ env.IMAGE_NAME }}:${{ steps.metadata.outputs.version }} |
| 134 | + ${{ env.IMAGE_NAME }}:latest |
| 135 | + build-args: | |
| 136 | + VERSION=${{ steps.metadata.outputs.version }} |
| 137 | + VCS_REF=${{ github.sha }} |
| 138 | + cache-from: type=gha,scope=funasr-mcp |
| 139 | + cache-to: type=gha,mode=max,scope=funasr-mcp |
| 140 | + |
| 141 | + - name: Make the GHCR package public |
| 142 | + env: |
| 143 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 144 | + run: | |
| 145 | + gh api --method PATCH \ |
| 146 | + "/orgs/${GITHUB_REPOSITORY_OWNER}/packages/container/funasr-mcp" \ |
| 147 | + -f visibility=public |
| 148 | +
|
| 149 | + - name: Install verified MCP publisher |
| 150 | + run: | |
| 151 | + archive="$RUNNER_TEMP/mcp-publisher.tar.gz" |
| 152 | + curl --fail --show-error --silent --location --retry 3 \ |
| 153 | + "https://github.com/modelcontextprotocol/registry/releases/download/${MCP_PUBLISHER_VERSION}/mcp-publisher_linux_amd64.tar.gz" \ |
| 154 | + -o "$archive" |
| 155 | + echo "${MCP_PUBLISHER_SHA256} $archive" | sha256sum --check |
| 156 | + tar -xzf "$archive" -C "$RUNNER_TEMP" mcp-publisher |
| 157 | +
|
| 158 | + - name: Publish metadata to the official MCP Registry |
| 159 | + working-directory: examples/mcp_server |
| 160 | + run: | |
| 161 | + "$RUNNER_TEMP/mcp-publisher" login github-oidc |
| 162 | + "$RUNNER_TEMP/mcp-publisher" publish |
| 163 | +
|
| 164 | + - name: Verify the Registry listing |
| 165 | + run: | |
| 166 | + for attempt in {1..6}; do |
| 167 | + if curl --fail --show-error --silent --get \ |
| 168 | + --data-urlencode "search=io.github.modelscope/funasr-mcp" \ |
| 169 | + https://registry.modelcontextprotocol.io/v0.1/servers \ |
| 170 | + | jq -e '.servers[] | select(.server.name == "io.github.modelscope/funasr-mcp")' \ |
| 171 | + >/dev/null; then |
| 172 | + exit 0 |
| 173 | + fi |
| 174 | + sleep 10 |
| 175 | + done |
| 176 | + echo "Published server did not appear in the Registry within 60 seconds" >&2 |
| 177 | + exit 1 |
0 commit comments