diff --git a/.env.example b/.env.example index bfadfd4..6deabd0 100644 --- a/.env.example +++ b/.env.example @@ -11,6 +11,11 @@ MCP_REGISTRY_DATABASE_URL=postgres://username:password@localhost:5432/mcp-regist # For offline development, use: data/seed.json MCP_REGISTRY_SEED_FROM=https://registry.modelcontextprotocol.io/v0/servers +# Validate seed data against the registry rules on import (default: true) +# Set to false for offline development when seeding from a local file, since +# data/seed.json is not guaranteed to pass validation +MCP_REGISTRY_ENABLE_REGISTRY_VALIDATION=true + # GitHub OAuth configuration # These creds are for local development with the 'MCP Registry Login (Local)' GitHub App # They don't provide any real privileged access, hence why it's okay that they're here @@ -27,6 +32,14 @@ MCP_REGISTRY_JWT_PRIVATE_KEY=bb2c6b424005acd5df47a9e2c87f446def86dd740c888ea3efb # This should be disabled in prod MCP_REGISTRY_ENABLE_ANONYMOUS_AUTH=false +# GitHub OIDC token exchange (for `mcp-publisher login github-oidc`) +# Expected `aud` claim on incoming GitHub Actions OIDC tokens. Must equal the +# scheme + host that publishers pass via `--registry` (e.g. `https://registry.example.com`). +# The publisher CLI derives the audience from `--registry` automatically; the server +# rejects all OIDC exchanges if this is unset, so set it on every deployment that +# accepts GitHub Actions publishes. +MCP_REGISTRY_GITHUB_OIDC_AUDIENCE= + # Google Cloud Identity OIDC configuration for admin access # Enable OIDC authentication for @modelcontextprotocol.io admin accounts MCP_REGISTRY_OIDC_ENABLED=false diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index b37dd38..e373661 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -9,5 +9,5 @@ To publish an MCP server to the registry, use the `mcp-publisher` CLI tool. See ## Development - Use `make` targets where possible (run `make help` to see available targets) -- Run `make check` to run lint, unit tests, and integration tests +- Run `make check` to run lint, schema validation, and all tests (this also stops any running dev-compose environment) - Run `make dev-compose` to start the local development environment \ No newline at end of file diff --git a/.github/dependabot.yml b/.github/dependabot.yml index ea28507..ee01027 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -3,28 +3,28 @@ updates: - package-ecosystem: gomod directory: / groups: - opentelemetry: - patterns: - - "go.opentelemetry.io/*" - schedule: - interval: daily - - package-ecosystem: gomod - directory: /deploy - groups: - opentelemetry: - patterns: - - "go.opentelemetry.io/*" - schedule: - interval: daily - - package-ecosystem: github-actions - directory: / - groups: - actions: + go-dependencies: patterns: - "*" schedule: - interval: daily - - package-ecosystem: "docker" - directory: "/" + interval: weekly + - package-ecosystem: gomod + directory: /deploy + groups: + deploy-go-dependencies: + patterns: + - "*" schedule: - interval: "daily" + interval: weekly + - package-ecosystem: github-actions + directory: / + groups: + github-actions: + patterns: + - "*" + schedule: + interval: weekly + - package-ecosystem: docker + directory: / + schedule: + interval: weekly diff --git a/.github/workflows/cancel-pulumi-lock.yml b/.github/workflows/cancel-pulumi-lock.yml index 345c0be..a42911f 100644 --- a/.github/workflows/cancel-pulumi-lock.yml +++ b/.github/workflows/cancel-pulumi-lock.yml @@ -24,10 +24,10 @@ jobs: environment: ${{ inputs.environment }} steps: - name: Checkout code - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - name: Setup Pulumi - uses: pulumi/actions@8582a9e8cc630786854029b4e09281acd6794b58 + uses: pulumi/actions@8e5e406f4007fca908480587cb9893c07090f58d with: pulumi-version: ${{ env.PULUMI_VERSION }} diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e0dbb93..4e42207 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -16,18 +16,18 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - name: Set up Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e with: go-version: 'stable' cache: true - name: Run lint - uses: golangci/golangci-lint-action@1e7e51e771db61008b38414a730f564565cf7c20 + uses: golangci/golangci-lint-action@ba0d7d2ec06a0ea1cb5fa41b2e4a3ab91d21278a with: - version: v2.11.4 + version: v2.13.1 - name: Validate schemas and examples run: make validate @@ -48,16 +48,16 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout code - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - name: Set up Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e with: go-version: 'stable' cache: true - name: Set up ko - uses: ko-build/setup-ko@v0.9 + uses: ko-build/setup-ko@v0.10 - name: Run all tests run: make test-all diff --git a/.github/workflows/claude.yml b/.github/workflows/claude.yml index 36a9fc2..01e2b06 100644 --- a/.github/workflows/claude.yml +++ b/.github/workflows/claude.yml @@ -26,7 +26,7 @@ jobs: actions: read steps: - name: Checkout repository - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with: fetch-depth: 1 diff --git a/.github/workflows/close-invalid-publish-prs.yml b/.github/workflows/close-invalid-publish-prs.yml new file mode 100644 index 0000000..53ce498 --- /dev/null +++ b/.github/workflows/close-invalid-publish-prs.yml @@ -0,0 +1,151 @@ +name: Close invalid publish PRs + +# Stage 2 of 2 (see detect-invalid-publish-prs.yml for stage 1). +# +# Runs in the trusted base-repo context (triggered by workflow_run, not by the +# PR itself), so it has a write token. It picks up the PR number flagged by +# stage 1 and, after independently re-validating the PR from the API, posts a +# comment pointing at the publishing docs, labels it `invalid`, and closes it. +# +# Trust boundary: the ONLY thing crossing from the untrusted stage is the PR +# number (sanitized to digits below). We re-derive every decision (state, +# author, changed files) here, so a wrong/stale artifact can never cause us to +# close a PR that doesn't actually match. + +on: + workflow_run: + workflows: ["Detect invalid publish PRs"] + types: [completed] + +permissions: + contents: read + pull-requests: write + issues: write # labels on PRs go through the issues API + actions: read # needed to list/download the stage-1 artifact + +jobs: + close: + if: github.event.workflow_run.conclusion == 'success' + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + RUN_ID: ${{ github.event.workflow_run.id }} + COMMENT_BODY: | + Hi @__AUTHOR__ ๐Ÿ‘‹ โ€” thanks for your interest in the MCP Registry! + + It looks like this PR is trying to publish an MCP server by adding or editing server files in this repository (under `servers/`, `data/servers/`, or in `data/seed.json`). That isn't how servers get published, so I'm closing this PR automatically. + + **Servers are published with the [`mcp-publisher`](https://github.com/modelcontextprotocol/registry/blob/main/docs/modelcontextprotocol-io/quickstart.mdx) CLI**, not by opening a pull request against this repo. The CLI verifies that you own your namespace and submits your `server.json` directly to the live registry API. + + To publish your server, follow the **[Publishing Quickstart](https://github.com/modelcontextprotocol/registry/blob/main/docs/modelcontextprotocol-io/quickstart.mdx)**. In short: + + ```bash + # Build the publisher CLI + make publisher + + # Authenticate (e.g. via GitHub) and publish your server.json + ./bin/mcp-publisher login github + ./bin/mcp-publisher publish + ``` + + Note: `data/seed.json` is seed data for **local development only** โ€” adding entries there does not publish anything to the registry. + + If you believe this was closed in error, please leave a comment and a maintainer will take a look. ๐Ÿ™‡ + + _This is an automated message._ + + steps: + - name: Check for flagged-pr artifact + id: check + run: | + set -euo pipefail + names="$(gh api "repos/$GH_REPO/actions/runs/$RUN_ID/artifacts" --jq '.artifacts[].name' || true)" + if printf '%s\n' "$names" | grep -qx "flagged-pr"; then + echo "found=true" >> "$GITHUB_OUTPUT" + else + echo "No flagged-pr artifact on run $RUN_ID; nothing to do." + echo "found=false" >> "$GITHUB_OUTPUT" + fi + + - name: Download flagged PR number + if: steps.check.outputs.found == 'true' + uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 + with: + name: flagged-pr + run-id: ${{ github.event.workflow_run.id }} + github-token: ${{ github.token }} + + - name: Re-validate and close + if: steps.check.outputs.found == 'true' + run: | + set -euo pipefail + + # Sanitize: the only cross-boundary input. Keep digits only. + PR_NUMBER="$(tr -dc '0-9' < pr-number.txt)" + if [ -z "$PR_NUMBER" ]; then + echo "No valid PR number in artifact; skipping." + exit 0 + fi + echo "Re-validating PR #$PR_NUMBER" + + state="$(gh pr view "$PR_NUMBER" --json state --jq '.state')" + if [ "$state" != "OPEN" ]; then + echo "PR #$PR_NUMBER is $state, not OPEN; skipping." + exit 0 + fi + + # Use the REST endpoint: `gh pr view --json` does not expose an + # authorAssociation field, so calling it there exits non-zero and, + # under `set -euo pipefail`, aborts the job before we ever close. + assoc="$(gh api "repos/$GH_REPO/pulls/$PR_NUMBER" --jq '.author_association')" + case "$assoc" in + MEMBER|OWNER|COLLABORATOR) + echo "Author association '$assoc' is trusted; skipping." + exit 0 + ;; + esac + + # Idempotency: if a maintainer reopens after we labeled it, leave it be. + # Capture into a var first so a transient gh failure can't fail open + # (an errored fetch piped to grep would otherwise look "not labeled"). + labels="$(gh pr view "$PR_NUMBER" --json labels --jq '.labels[].name' || true)" + if printf '%s\n' "$labels" | grep -qx "invalid"; then + echo "PR #$PR_NUMBER already labeled 'invalid'; skipping." + exit 0 + fi + + # Paginated REST endpoint (gh pr view --json files caps at 100, no pagination). + mapfile -t FILES < <(gh api --paginate "repos/$GH_REPO/pulls/$PR_NUMBER/files" --jq '.[].filename') + if [ "${#FILES[@]}" -eq 0 ]; then + echo "No files for PR #$PR_NUMBER; skipping." + exit 0 + fi + # Keep this list in sync with the copy in stage 1. + publish_attempt=0 + other=0 + for f in "${FILES[@]}"; do + if [[ "$f" == servers/* \ + || "$f" == data/servers/* \ + || "$f" == data/data/servers/* \ + || "$f" =~ ^data/[^/]*server\.json$ \ + || "$f" == "data/seed.json" \ + || "$f" == "server.json" \ + || "$f" == "servers.json" ]]; then + publish_attempt=1 + else + other=1 + fi + done + if [ "$publish_attempt" -ne 1 ] || [ "$other" -ne 0 ]; then + echo "PR #$PR_NUMBER no longer matches the publish-attempt pattern; skipping." + exit 0 + fi + + author="$(gh pr view "$PR_NUMBER" --json author --jq '.author.login')" + body="${COMMENT_BODY//__AUTHOR__/$author}" + + echo "Commenting on, labeling, and closing PR #$PR_NUMBER" + gh pr comment "$PR_NUMBER" --body "$body" + gh pr edit "$PR_NUMBER" --add-label "invalid" || echo "Could not add label; continuing." + gh pr close "$PR_NUMBER" diff --git a/.github/workflows/deploy-production.yml b/.github/workflows/deploy-production.yml index cd03772..bd21054 100644 --- a/.github/workflows/deploy-production.yml +++ b/.github/workflows/deploy-production.yml @@ -23,16 +23,16 @@ jobs: cancel-in-progress: false steps: - name: Checkout code - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - name: Setup Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e with: go-version: 'stable' cache: true - name: Setup Pulumi - uses: pulumi/actions@8582a9e8cc630786854029b4e09281acd6794b58 + uses: pulumi/actions@8e5e406f4007fca908480587cb9893c07090f58d with: pulumi-version: ${{ env.PULUMI_VERSION }} diff --git a/.github/workflows/deploy-staging.yml b/.github/workflows/deploy-staging.yml index 946aaaf..eb68cfb 100644 --- a/.github/workflows/deploy-staging.yml +++ b/.github/workflows/deploy-staging.yml @@ -22,19 +22,19 @@ jobs: packages: write steps: - name: Checkout repository - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - name: Set up Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e with: go-version: 'stable' cache: true - name: Set up ko - uses: ko-build/setup-ko@v0.9 + uses: ko-build/setup-ko@v0.10 - name: Log in to Container Registry - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f with: registry: ghcr.io username: ${{ github.actor }} @@ -70,16 +70,16 @@ jobs: cancel-in-progress: false steps: - name: Checkout code - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - name: Setup Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e with: go-version: 'stable' cache: true - name: Setup Pulumi - uses: pulumi/actions@8582a9e8cc630786854029b4e09281acd6794b58 + uses: pulumi/actions@8e5e406f4007fca908480587cb9893c07090f58d with: pulumi-version: ${{ env.PULUMI_VERSION }} diff --git a/.github/workflows/detect-invalid-publish-prs.yml b/.github/workflows/detect-invalid-publish-prs.yml new file mode 100644 index 0000000..816e169 --- /dev/null +++ b/.github/workflows/detect-invalid-publish-prs.yml @@ -0,0 +1,96 @@ +name: Detect invalid publish PRs + +# Stage 1 of 2 (see close-invalid-publish-prs.yml for stage 2). +# +# Some contributors try to "publish" a server by opening a PR that adds files +# under servers/ or edits data/seed.json. That is not how publishing works - +# servers are published with the mcp-publisher CLI against the live registry +# API. This job only DETECTS such PRs. It runs from the (untrusted) PR context +# with a read-only token, so it cannot comment on or close anything. When it +# finds a match it records just the PR number as an artifact; the privileged +# stage-2 workflow picks that up via workflow_run and acts on it. +# +# We never check out or run the PR's code - we only read changed file paths. + +on: + pull_request: + types: [opened, reopened] + +permissions: + contents: read + pull-requests: read + +jobs: + detect: + runs-on: ubuntu-latest + env: + GH_TOKEN: ${{ github.token }} + GH_REPO: ${{ github.repository }} + PR_NUMBER: ${{ github.event.pull_request.number }} + AUTHOR_ASSOCIATION: ${{ github.event.pull_request.author_association }} + steps: + - name: Classify PR + id: classify + run: | + set -euo pipefail + match=false + + # Maintainers may legitimately touch these files (e.g. dev seed data), + # so never flag their PRs. + case "$AUTHOR_ASSOCIATION" in + MEMBER|OWNER|COLLABORATOR) + echo "Author association '$AUTHOR_ASSOCIATION' is trusted; not flagging." + ;; + *) + # Use the paginated REST endpoint: `gh pr view --json files` caps + # at 100 files with no pagination, which could truncate a large PR + # and cause a false match. + mapfile -t FILES < <(gh api --paginate "repos/$GH_REPO/pulls/$PR_NUMBER/files" --jq '.[].filename') + if [ "${#FILES[@]}" -gt 0 ]; then + # Flag only if the PR touches *exclusively* publish-attempt files + # and nothing else, so that legit PRs touching seed data + # alongside real code are left alone. + # + # Keep this list in sync with the copy in stage 2. It stays an + # explicit list rather than a broad `**/server.json` glob: + # because we require *every* file to match, an over-broad + # pattern would auto-close a legitimate single-file PR. + # data/servers/** is here because #1524 put its server.json + # there - a natural guess next to data/seed.json - and slipped + # through the original servers/**-only list. + publish_attempt=0 + other=0 + for f in "${FILES[@]}"; do + if [[ "$f" == servers/* \ + || "$f" == data/servers/* \ + || "$f" == data/data/servers/* \ + || "$f" =~ ^data/[^/]*server\.json$ \ + || "$f" == "data/seed.json" \ + || "$f" == "server.json" \ + || "$f" == "servers.json" ]]; then + publish_attempt=1 + else + echo "Non-publish file changed: $f" + other=1 + fi + done + if [ "$publish_attempt" -eq 1 ] && [ "$other" -eq 0 ]; then + match=true + fi + fi + ;; + esac + + echo "PR #$PR_NUMBER match=$match" + echo "match=$match" >> "$GITHUB_OUTPUT" + if [ "$match" = "true" ]; then + echo "$PR_NUMBER" > pr-number.txt + fi + + - name: Record flagged PR number + if: steps.classify.outputs.match == 'true' + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v4 + with: + name: flagged-pr + path: pr-number.txt + retention-days: 1 diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index b1f807f..8285c08 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -14,24 +14,24 @@ jobs: runs-on: ubuntu-latest steps: - name: Checkout - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 with: fetch-depth: 0 - name: Set up Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e with: go-version: 'stable' cache: true - name: Install cosign - uses: sigstore/cosign-installer@cad07c2e89fa2edd6e2d7bab4c1aa38e53f76003 # v4.1.1 + uses: sigstore/cosign-installer@6f9f17788090df1f26f669e9d70d6ae9567deba6 # v4.1.2 - name: Install Syft - uses: anchore/sbom-action/download-syft@v0.24.0 + uses: anchore/sbom-action/download-syft@v0.24.2 - name: Run GoReleaser - uses: goreleaser/goreleaser-action@ec59f474b9834571250b370d4735c50f8e2d1e29 + uses: goreleaser/goreleaser-action@f06c13b6b1a9625abc9e6e439d9c05a8f2190e94 with: distribution: goreleaser version: v2.12.0 @@ -45,19 +45,19 @@ jobs: needs: goreleaser steps: - name: Checkout - uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 + uses: actions/checkout@9c091bb21b7c1c1d1991bb908d89e4e9dddfe3e0 - name: Set up Go - uses: actions/setup-go@4a3601121dd01d1626a1e23e37211e3254c1c06c + uses: actions/setup-go@b7ad1dad31e06c5925ef5d2fc7ad053ef454303e with: go-version: 'stable' cache: true - name: Set up ko - uses: ko-build/setup-ko@v0.9 + uses: ko-build/setup-ko@v0.10 - name: Log in to Container Registry - uses: docker/login-action@4907a6ddec9925e35a0a9e82d7399ccc52663121 + uses: docker/login-action@dbcb813823bdd20940b903addbd779551569679f with: registry: ghcr.io username: ${{ github.actor }} diff --git a/.github/workflows/sync-schema.yml b/.github/workflows/sync-schema.yml index a59583b..7fbe6a7 100644 --- a/.github/workflows/sync-schema.yml +++ b/.github/workflows/sync-schema.yml @@ -15,10 +15,10 @@ jobs: steps: - name: Checkout repository - uses: actions/checkout@v6 + uses: actions/checkout@v7 - name: Checkout static repo - uses: actions/checkout@v6 + uses: actions/checkout@v7 with: repository: modelcontextprotocol/static path: static-repo diff --git a/.golangci.yml b/.golangci.yml index 5f3ad3c..571ead5 100644 --- a/.golangci.yml +++ b/.golangci.yml @@ -22,7 +22,7 @@ linters: - gocyclo - godox - gomoddirectives - - gomodguard + - gomodguard_v2 - goprintffuncname - gosec - grouper @@ -55,6 +55,10 @@ linters: max-complexity: 20 dupl: threshold: 300 + goconst: + # Repeated literals in tests are fixture data ("1.0.0", "Test server", ...); + # hoisting them into constants hurts readability more than it helps. + ignore-tests: true gocognit: min-complexity: 51 nestif: diff --git a/CHANGES.md b/CHANGES.md deleted file mode 100644 index e69de29..0000000 diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a5a42cb..7a1e1b5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -32,7 +32,8 @@ See the [README](README.md#quick-start) for prerequisites and instructions on ru ### Running checks ```bash -# Run lint, unit tests and integration tests +# Run lint, schema validation, and all tests +# Note: this also runs `make dev-down`, stopping any running dev-compose environment make check ``` diff --git a/README.md b/README.md index 3a456de..8178365 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ The MCP registry provides MCP clients with a list of MCP servers, like an app st **2025-09-08 update**: The registry has launched in preview ๐ŸŽ‰ ([announcement blog post](https://blog.modelcontextprotocol.io/posts/2025-09-08-mcp-registry-preview/)). While the system is now more stable, this is still a preview release and breaking changes or data resets may occur. A general availability (GA) release will follow later. We'd love your feedback in [GitHub discussions](https://github.com/modelcontextprotocol/registry/discussions/new?category=ideas) or in the [#registry-dev Discord](https://discord.com/channels/1358869848138059966/1369487942862504016) ([joining details here](https://modelcontextprotocol.io/community/communication)). -Current key maintainers: -- **Adam Jones** (Anthropic) [@domdomegg](https://github.com/domdomegg) +Registry Working Group: +- **Radoslav (Rado) Dimitrov** (Stacklok) [@rdimitrov](https://github.com/rdimitrov) - WG Lead - **Tadas Antanavicius** (PulseMCP) [@tadasant](https://github.com/tadasant) -- **Toby Padilla** (GitHub) [@toby](https://github.com/toby) -- **Radoslav (Rado) Dimitrov** (Stacklok) [@rdimitrov](https://github.com/rdimitrov) +- **Bob Dickinson** (TeamSpark) [@BobDickinson](https://github.com/BobDickinson) +- **Preeti (Pree) Dewani** (Ravenmail) [@pree-dew](https://github.com/pree-dew) ## Contributing @@ -32,9 +32,9 @@ Often (but not always) ideas flow through this pipeline: #### Pre-requisites - **Docker** -- **Go 1.24.x** +- **Go** - version per the `go` directive in [go.mod](./go.mod); the Go toolchain fetches it for you - **ko** - Container image builder for Go ([installation instructions](https://ko.build/install/)) -- **golangci-lint v2.4.0** +- **golangci-lint** - version per the `golangci-lint-action` pin in [ci.yml](./.github/workflows/ci.yml), so local lint matches CI #### Running the server @@ -54,7 +54,7 @@ The setup can be configured with environment variables in [docker-compose.yml](.
Alternative: Running a pre-built Docker image -Pre-built Docker images are automatically published to GitHub Container Registry: +Pre-built Docker images are automatically published to GitHub Container Registry. Note that the image does not bundle PostgreSQL, so you need to run your own and point the registry at it via `MCP_REGISTRY_DATABASE_URL` (see [docker-compose.yml](./docker-compose.yml) for a working example): ```bash # Run latest stable release @@ -94,7 +94,8 @@ See [the publisher guide](./docs/modelcontextprotocol-io/quickstart.mdx) for mor #### Other commands ```bash -# Run lint, unit tests and integration tests +# Run lint, schema validation, and all tests +# Note: this also runs `make dev-down`, stopping any running dev-compose environment make check ``` @@ -110,7 +111,8 @@ For Claude and other AI tools: Always prefer make targets over custom commands w ``` โ”œโ”€โ”€ cmd/ # Application entry points -โ”‚ โ””โ”€โ”€ publisher/ # Server publishing tool +โ”‚ โ”œโ”€โ”€ publisher/ # Server publishing tool +โ”‚ โ””โ”€โ”€ registry/ # Registry API server โ”œโ”€โ”€ data/ # Seed data โ”œโ”€โ”€ deploy/ # Deployment configuration (Pulumi) โ”œโ”€โ”€ docs/ # Documentation @@ -119,6 +121,7 @@ For Claude and other AI tools: Always prefer make targets over custom commands w โ”‚ โ”œโ”€โ”€ auth/ # Authentication (GitHub OAuth, JWT, namespace blocking) โ”‚ โ”œโ”€โ”€ config/ # Configuration management โ”‚ โ”œโ”€โ”€ database/ # Data persistence (PostgreSQL) +โ”‚ โ”œโ”€โ”€ importer/ # Seed data import โ”‚ โ”œโ”€โ”€ service/ # Business logic โ”‚ โ”œโ”€โ”€ telemetry/ # Metrics and monitoring โ”‚ โ””โ”€โ”€ validators/ # Input validation diff --git a/cmd/publisher/README.md b/cmd/publisher/README.md index cd9b91a..3a5a792 100644 --- a/cmd/publisher/README.md +++ b/cmd/publisher/README.md @@ -14,9 +14,12 @@ make publisher make dev-compose # Start local registry ./bin/mcp-publisher init ./bin/mcp-publisher login none --registry=http://localhost:8080 -./bin/mcp-publisher publish --registry=http://localhost:8080 +./bin/mcp-publisher publish ``` +`publish` takes the registry URL from the token saved by `login`, so it accepts no `--registry` +flag โ€” passing one would be read as the `server.json` path. + ## Architecture ### Commands @@ -24,6 +27,7 @@ make dev-compose # Start local registry - **`login`** - Handle authentication (github, dns, http, none) - **`publish`** - Validate and upload servers to registry - **`status`** - Update server lifecycle status (active, deprecated, deleted) +- **`validate`** - Validate server.json without publishing - **`logout`** - Clear stored credentials ### Authentication Providers @@ -44,4 +48,3 @@ Optional: enables `dns` and `http` methods to sign out-of-process without direct - **`main.go`** - CLI setup and command routing - **`commands/`** - Command implementations with auto-detection logic - **`auth/`** - Authentication provider implementations -- **`build.sh`** - Cross-platform build script diff --git a/cmd/publisher/auth/azurekeyvault/common.go b/cmd/publisher/auth/azurekeyvault/common.go index d1e9501..776ed14 100644 --- a/cmd/publisher/auth/azurekeyvault/common.go +++ b/cmd/publisher/auth/azurekeyvault/common.go @@ -64,8 +64,8 @@ func (d Signer) GetSignedTimestamp(ctx context.Context) (*string, []byte, error) fmt.Fprintln(os.Stdout, "Successfully read the public key from Key Vault.") auth.PrintEcdsaP384KeyInfo(ecdsa.PublicKey{ Curve: elliptic.P384(), - X: new(big.Int).SetBytes(keyResp.Key.X), - Y: new(big.Int).SetBytes(keyResp.Key.Y), + X: new(big.Int).SetBytes(keyResp.Key.X), //nolint:staticcheck // SA1019: needs crypto/ecdh refactor + Y: new(big.Int).SetBytes(keyResp.Key.Y), //nolint:staticcheck // SA1019: needs crypto/ecdh refactor }) timestamp := auth.GetTimestamp() diff --git a/cmd/publisher/auth/common.go b/cmd/publisher/auth/common.go index 053b543..c12386a 100644 --- a/cmd/publisher/auth/common.go +++ b/cmd/publisher/auth/common.go @@ -164,10 +164,10 @@ func parseRawPrivateKey(curve elliptic.Curve, privateKeyBytes []byte) (*ecdsa.Pr return &ecdsa.PrivateKey{ PublicKey: ecdsa.PublicKey{ Curve: curve, - X: x, - Y: y, + X: x, //nolint:staticcheck // SA1019: needs crypto/ecdh refactor + Y: y, //nolint:staticcheck // SA1019: needs crypto/ecdh refactor }, - D: d, + D: d, //nolint:staticcheck // SA1019: needs crypto/ecdh refactor }, nil } diff --git a/cmd/publisher/auth/github-at.go b/cmd/publisher/auth/github-at.go index 3e53529..fef3774 100644 --- a/cmd/publisher/auth/github-at.go +++ b/cmd/publisher/auth/github-at.go @@ -17,6 +17,31 @@ const ( GitHubAccessTokenURL = "https://github.com/login/oauth/access_token" // #nosec:G101 ) +const ( + // defaultPollInterval is the initial device-flow polling interval in + // seconds, per RFC 8628 ยง3.5. + defaultPollInterval = 5 + // maxPollInterval caps how large the polling interval may grow. RFC 8628 + // ยง3.5 mandates a 5-second increase on each slow_down but leaves the + // maximum to the implementation; this prevents a misbehaving auth server + // from growing the interval unboundedly. + maxPollInterval = 60 + // defaultExpiresIn is the device-code lifetime in seconds used when the + // device-code response omits expires_in. + defaultExpiresIn = 900 + // maxExpiresIn caps the device-code lifetime a response may claim. It sits + // well past GitHub's documented 15 minutes; the cap stops a misbehaving or + // hostile response from pushing the deadline (and the polling loop) far + // into the future. + maxExpiresIn = 3600 + // incorrectDeviceCodeGraceRetries is the total number of extra polls a + // single login may spend on incorrect_device_code before giving up โ€” a + // budget for the whole login, not per occurrence. cli/cli#9302 reports the + // same error for a code that had just been issued; a genuinely invalid code + // still fails, only a few seconds later. + incorrectDeviceCodeGraceRetries = 2 +) + // DeviceCodeResponse represents the response from GitHub's device code endpoint type DeviceCodeResponse struct { DeviceCode string `json:"device_code"` @@ -32,6 +57,38 @@ type AccessTokenResponse struct { TokenType string `json:"token_type"` Scope string `json:"scope"` Error string `json:"error,omitempty"` + // ErrorDescription and ErrorURI accompany Error in GitHub's responses; + // surfacing them turns opaque failures like "incorrect_device_code" into + // diagnosable reports. + ErrorDescription string `json:"error_description,omitempty"` + ErrorURI string `json:"error_uri,omitempty"` +} + +// errorDetail renders Error together with any error_description and error_uri +// GitHub returned, so failures reach the user diagnosable rather than opaque. +func (r AccessTokenResponse) errorDetail() string { + detail := r.Error + if r.ErrorDescription != "" { + detail += ": " + r.ErrorDescription + } + if r.ErrorURI != "" { + detail += " (" + r.ErrorURI + ")" + } + return detail +} + +func decodeAccessTokenResponse(statusCode int, body []byte) (AccessTokenResponse, error) { + var tokenResp AccessTokenResponse + // OAuth errors may use HTTP 400 (RFC 6749 ยง5.2), not just HTTP 200. + if statusCode != http.StatusOK && statusCode != http.StatusBadRequest { + return tokenResp, fmt.Errorf("token endpoint returned %d: %s", statusCode, body) + } + + err := json.Unmarshal(body, &tokenResp) + if statusCode == http.StatusBadRequest && (err != nil || tokenResp.Error == "") { + return tokenResp, fmt.Errorf("token endpoint returned %d: %s", statusCode, body) + } + return tokenResp, err } // RegistryTokenResponse represents the response from registry's token exchange endpoint @@ -46,6 +103,24 @@ type GitHubATProvider struct { registryURL string providedToken string // Token provided via --token flag or MCP_GITHUB_TOKEN env var githubToken string // In-memory GitHub token set by Login() + + // accessTokenURL is the GitHub access-token polling endpoint. It is a field + // (rather than the package constant) so tests can point it at a mock server. + accessTokenURL string + // deviceCodeURL is the GitHub device-code endpoint, a field for the same + // reason as accessTokenURL. + deviceCodeURL string + // pollInterval is the initial polling interval in seconds. Defaults to + // defaultPollInterval; overridable in tests to avoid real delays. Updated + // from the device-code response's interval when GitHub returns one. + pollInterval int + // expiresIn is the device-code lifetime in seconds. Defaults to + // defaultExpiresIn; updated from the device-code response's expires_in + // when GitHub returns one. + expiresIn int + // sleep abstracts time.Sleep so tests can run without real delays and + // assert the back-off sequence. Defaults to time.Sleep. + sleep func(time.Duration) } // ServerHealthResponse represents the response from the health endpoint @@ -62,8 +137,13 @@ func NewGitHubATProvider(registryURL, token string) Provider { } return &GitHubATProvider{ - registryURL: registryURL, - providedToken: token, + registryURL: registryURL, + providedToken: token, + accessTokenURL: GitHubAccessTokenURL, + deviceCodeURL: GitHubDeviceCodeURL, + pollInterval: defaultPollInterval, + expiresIn: defaultExpiresIn, + sleep: time.Sleep, } } @@ -149,7 +229,7 @@ func (g *GitHubATProvider) requestDeviceCode(ctx context.Context) (string, strin return "", "", "", err } - req, err := http.NewRequestWithContext(ctx, http.MethodPost, GitHubDeviceCodeURL, bytes.NewBuffer(jsonData)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, g.deviceCodeURL, bytes.NewBuffer(jsonData)) if err != nil { return "", "", "", err } @@ -178,6 +258,21 @@ func (g *GitHubATProvider) requestDeviceCode(ctx context.Context) (string, strin return "", "", "", err } + // Per RFC 8628 ยง3.2 interval and expires_in are bound to this device code, + // so reset any pacing left over from a previous code before adopting them. + // Clamp both: a hostile or buggy response must not grow the interval past + // maxPollInterval (the invariant maxPollInterval exists for) nor push the + // deadline unboundedly into the future, and clamping also keeps the + // derived time.Duration well clear of int64 overflow. + g.pollInterval = defaultPollInterval + g.expiresIn = defaultExpiresIn + if deviceCodeResp.Interval > 0 { + g.pollInterval = min(deviceCodeResp.Interval, maxPollInterval) + } + if deviceCodeResp.ExpiresIn > 0 { + g.expiresIn = min(deviceCodeResp.ExpiresIn, maxExpiresIn) + } + return deviceCodeResp.DeviceCode, deviceCodeResp.UserCode, deviceCodeResp.VerificationURI, nil } @@ -198,13 +293,28 @@ func (g *GitHubATProvider) pollForToken(ctx context.Context, deviceCode string) return "", err } - // Default polling interval and expiration time - interval := 5 // seconds - expiresIn := 900 // 15 minutes + // Pacing comes from the device-code response (via requestDeviceCode), + // falling back to GitHub's documented defaults. + interval := g.pollInterval + expiresIn := g.expiresIn + // Zero-value fallback: providers built directly rather than through + // requestDeviceCode (the test seam) carry no lifetime. Keep this guard. + if expiresIn <= 0 { + expiresIn = defaultExpiresIn + } deadline := time.Now().Add(time.Duration(expiresIn) * time.Second) + graceRetries := 0 + // serverErrorInterval grows the wait between consecutive 5xx retries and is + // reset by any other response. + serverErrorInterval := interval + // lastErr holds the most recent retryable failure so a deadline reached + // mid-retry reports that diagnostic instead of a bare "timed out". It is + // cleared whenever polling recovers, so a genuine user timeout after a + // recovered blip still reports plainly. + var lastErr error for time.Now().Before(deadline) { - req, err := http.NewRequestWithContext(ctx, http.MethodPost, GitHubAccessTokenURL, bytes.NewBuffer(jsonData)) + req, err := http.NewRequestWithContext(ctx, http.MethodPost, g.accessTokenURL, bytes.NewBuffer(jsonData)) if err != nil { return "", err } @@ -223,20 +333,54 @@ func (g *GitHubATProvider) pollForToken(ctx context.Context, deviceCode string) return "", err } - var tokenResp AccessTokenResponse - err = json.Unmarshal(body, &tokenResp) + // A transient 5xx must not abandon a login the user may already have + // approved in the browser. Each consecutive 5xx grows the wait by 5s up + // to maxPollInterval, so a sustained outage costs a couple of dozen + // requests rather than hundreds; the deadline bounds the number of + // these retries. + if resp.StatusCode >= http.StatusInternalServerError { + lastErr = fmt.Errorf("token endpoint returned %d", resp.StatusCode) + serverErrorInterval = min(serverErrorInterval+5, maxPollInterval) + g.sleep(time.Duration(serverErrorInterval) * time.Second) + continue + } + serverErrorInterval = interval + + tokenResp, err := decodeAccessTokenResponse(resp.StatusCode, body) if err != nil { return "", err } - if tokenResp.Error == "authorization_pending" { - // User hasn't authorized yet, wait and retry - time.Sleep(time.Duration(interval) * time.Second) + // Per RFC 8628 ยง3.5, both authorization_pending and slow_down indicate + // the client should keep polling. slow_down additionally requires that + // the polling interval be increased by 5 seconds. + if tokenResp.Error == "authorization_pending" || tokenResp.Error == "slow_down" { + if tokenResp.Error == "slow_down" { + interval += 5 + if interval > maxPollInterval { + interval = maxPollInterval + } + } + lastErr = nil + g.sleep(time.Duration(interval) * time.Second) continue } if tokenResp.Error != "" { - return "", fmt.Errorf("token request failed: %s", tokenResp.Error) + failure := fmt.Errorf("token request failed: %s", tokenResp.errorDetail()) + + // incorrect_device_code has been reported for codes that were in + // fact valid (cli/cli#9302; cause never confirmed), so spend a + // couple of grace polls before abandoning a login the user may + // have approved. + if tokenResp.Error == "incorrect_device_code" && graceRetries < incorrectDeviceCodeGraceRetries { + graceRetries++ + lastErr = failure + g.sleep(time.Duration(interval) * time.Second) + continue + } + + return "", failure } if tokenResp.AccessToken != "" { @@ -247,6 +391,9 @@ func (g *GitHubATProvider) pollForToken(ctx context.Context, deviceCode string) return "", fmt.Errorf("failed to obtain access token") } + if lastErr != nil { + return "", fmt.Errorf("device code authorization timed out; last response: %w", lastErr) + } return "", fmt.Errorf("device code authorization timed out") } diff --git a/cmd/publisher/auth/github-oidc.go b/cmd/publisher/auth/github-oidc.go index e4b51ed..9b32e44 100644 --- a/cmd/publisher/auth/github-oidc.go +++ b/cmd/publisher/auth/github-oidc.go @@ -7,7 +7,9 @@ import ( "fmt" "io" "net/http" + "net/url" "os" + "strings" ) type GitHubOIDCProvider struct { @@ -23,8 +25,13 @@ func NewGitHubOIDCProvider(registryURL string) Provider { // GetToken retrieves the registry JWT token using GitHub Actions OIDC token func (o *GitHubOIDCProvider) GetToken(ctx context.Context) (string, error) { + audience, err := audienceFromRegistryURL(o.registryURL) + if err != nil { + return "", fmt.Errorf("invalid --registry URL: %w", err) + } + // Get OIDC token from GitHub Actions endpoint - oidcToken, err := o.getOIDCTokenFromGitHub(ctx) + oidcToken, err := o.getOIDCTokenFromGitHub(ctx, audience) if err != nil { return "", fmt.Errorf("failed to get OIDC token from GitHub: %w", err) } @@ -99,8 +106,8 @@ func (o *GitHubOIDCProvider) exchangeOIDCTokenForRegistry(ctx context.Context, o return tokenResp.RegistryToken, nil } -// getOIDCTokenFromGitHub fetches the OIDC token from GitHub Actions endpoint -func (o *GitHubOIDCProvider) getOIDCTokenFromGitHub(ctx context.Context) (string, error) { +// getOIDCTokenFromGitHub fetches the OIDC token from GitHub Actions endpoint. +func (o *GitHubOIDCProvider) getOIDCTokenFromGitHub(ctx context.Context, audience string) (string, error) { // Check for required environment variables requestToken := os.Getenv("ACTIONS_ID_TOKEN_REQUEST_TOKEN") if requestToken == "" { @@ -113,7 +120,7 @@ func (o *GitHubOIDCProvider) getOIDCTokenFromGitHub(ctx context.Context) (string } // Build the full URL with audience parameter - fullURL := requestURL + "&audience=mcp-registry" + fullURL := requestURL + "&audience=" + url.QueryEscape(audience) // Create the request req, err := http.NewRequestWithContext(ctx, http.MethodGet, fullURL, nil) //nolint:gosec // G704: URL is from GitHub Actions ACTIONS_ID_TOKEN_REQUEST_URL env var @@ -158,3 +165,19 @@ func (o *GitHubOIDCProvider) getOIDCTokenFromGitHub(ctx context.Context) (string return tokenResp.Value, nil } + +// audienceFromRegistryURL returns scheme + lowercased host for the given URL. +func audienceFromRegistryURL(registryURL string) (string, error) { + registryURL = strings.TrimSpace(registryURL) + if registryURL == "" { + return "", fmt.Errorf("registry URL is empty") + } + u, err := url.Parse(registryURL) + if err != nil { + return "", fmt.Errorf("parse %q: %w", registryURL, err) + } + if u.Scheme == "" || u.Host == "" { + return "", fmt.Errorf("registry URL must include scheme and host: %q", registryURL) + } + return u.Scheme + "://" + strings.ToLower(u.Host), nil +} diff --git a/cmd/publisher/auth/github-oidc_internal_test.go b/cmd/publisher/auth/github-oidc_internal_test.go new file mode 100644 index 0000000..e8a5068 --- /dev/null +++ b/cmd/publisher/auth/github-oidc_internal_test.go @@ -0,0 +1,48 @@ +package auth + +import "testing" + +func TestAudienceFromRegistryURL(t *testing.T) { + tests := []struct { + input string + want string + wantErr bool + }{ + // Canonical forms + {"https://registry.modelcontextprotocol.io", "https://registry.modelcontextprotocol.io", false}, + {"https://staging.registry.modelcontextprotocol.io", "https://staging.registry.modelcontextprotocol.io", false}, + + // Trailing slash and path are stripped + {"https://registry.modelcontextprotocol.io/", "https://registry.modelcontextprotocol.io", false}, + {"https://registry.modelcontextprotocol.io/api/v0", "https://registry.modelcontextprotocol.io", false}, + + // Host is lowercased + {"https://Registry.Example.COM", "https://registry.example.com", false}, + + // Whitespace is tolerated + {" https://registry.example ", "https://registry.example", false}, + + // Invalid inputs + {"", "", true}, + {"registry.example", "", true}, // missing scheme + {"https://", "", true}, // missing host + {"://nothing", "", true}, // missing scheme + } + for _, tc := range tests { + t.Run(tc.input, func(t *testing.T) { + got, err := audienceFromRegistryURL(tc.input) + if tc.wantErr { + if err == nil { + t.Fatalf("expected error for %q, got %q", tc.input, got) + } + return + } + if err != nil { + t.Fatalf("unexpected error for %q: %v", tc.input, err) + } + if got != tc.want { + t.Errorf("audienceFromRegistryURL(%q) = %q, want %q", tc.input, got, tc.want) + } + }) + } +} diff --git a/cmd/publisher/auth/github_at_device_flow_internal_test.go b/cmd/publisher/auth/github_at_device_flow_internal_test.go new file mode 100644 index 0000000..b1e13ac --- /dev/null +++ b/cmd/publisher/auth/github_at_device_flow_internal_test.go @@ -0,0 +1,532 @@ +package auth + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "sync" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// seqTokenServer serves a fixed sequence of (status, body) responses, one per +// request, reusing the last one once the sequence is exhausted. Unlike +// newMockTokenServer it can serve non-200 statuses and non-JSON bodies, which +// the transient-5xx path needs. +type seqTokenServer struct { + srv *httptest.Server + mu sync.Mutex + seen int + items []seqResp +} + +type seqResp struct { + status int + body string +} + +func newSeqTokenServer(t *testing.T, items ...seqResp) *seqTokenServer { + t.Helper() + s := &seqTokenServer{items: items} + s.srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + s.mu.Lock() + item := s.items[len(s.items)-1] + if s.seen < len(s.items) { + item = s.items[s.seen] + } + s.seen++ + s.mu.Unlock() + w.Header().Set("Content-Type", "application/json") + w.WriteHeader(item.status) + _, _ = w.Write([]byte(item.body)) + })) + t.Cleanup(s.srv.Close) + return s +} + +func (s *seqTokenServer) requests() int { + s.mu.Lock() + defer s.mu.Unlock() + return s.seen +} + +func okResp(body string) seqResp { return seqResp{status: http.StatusOK, body: body} } + +// serverErrorResp is a 502 carrying an HTML body rather than JSON, the shape a +// transient edge failure takes. +func serverErrorResp() seqResp { + return seqResp{status: http.StatusBadGateway, body: `Server Error`} +} + +const ( + testClientID = "test-client-id" + + pendingBody = `{"error":"authorization_pending"}` + incorrectBody = `{"error":"incorrect_device_code"}` + // The full shape GitHub sends for this error, description and URI included. + incorrectVerboseBody = `{"error":"incorrect_device_code","error_description":"The device_code provided is not valid.","error_uri":"https://docs.github.com/developers/apps/authorizing-oauth-apps#error-codes-for-the-device-flow"}` + tokenBody = `{"access_token":"gho_test_token","token_type":"bearer","scope":"read:org,read:user"}` // #nosec G101 -- test fixture, not a real secret +) + +// TestPollForToken_IncorrectDeviceCodeIsTerminalAfterGrace confirms a code that +// stays invalid past the grace polls still fails, and fails with the error +// GitHub reported rather than a rewritten one. +func TestPollForToken_IncorrectDeviceCodeIsTerminalAfterGrace(t *testing.T) { + gh := newSeqTokenServer(t, okResp(pendingBody), okResp(pendingBody), okResp(incorrectBody)) + p, _ := newPollTestProvider(gh.srv.URL) + + _, err := p.pollForToken(context.Background(), "issued-device-code") + require.Error(t, err) + assert.Equal(t, "token request failed: incorrect_device_code", err.Error()) + // 2 pending + 1 incorrect + 2 grace polls that also answer incorrect. + assert.Equal(t, 5, gh.requests()) +} + +// TestPollForToken_TransientIncorrectDeviceCodeRecovered covers the case the +// grace retries exist for: one incorrect_device_code between a pending poll and +// a successful one must not discard a token the user already authorised. +func TestPollForToken_TransientIncorrectDeviceCodeRecovered(t *testing.T) { + gh := newSeqTokenServer(t, okResp(pendingBody), okResp(incorrectBody), okResp(tokenBody)) + p, _ := newPollTestProvider(gh.srv.URL) + + token, err := p.pollForToken(context.Background(), "issued-device-code") + require.NoError(t, err, "one transient incorrect_device_code must not be fatal") + assert.Equal(t, "gho_test_token", token) + assert.Equal(t, 3, gh.requests()) +} + +func TestPollForToken_OAuthErrorsRetryOnBadRequest(t *testing.T) { + for _, status := range []int{http.StatusOK, http.StatusBadRequest} { + for _, code := range []string{"authorization_pending", "slow_down", "incorrect_device_code"} { + t.Run(fmt.Sprintf("%d/%s", status, code), func(t *testing.T) { + gh := newSeqTokenServer(t, + seqResp{status: status, body: fmt.Sprintf(`{"error":%q}`, code)}, + okResp(tokenBody), + ) + p, slept := newPollTestProvider(gh.srv.URL) + p.pollInterval = defaultPollInterval + + token, err := p.pollForToken(context.Background(), "issued-device-code") + require.NoError(t, err) + assert.Equal(t, "gho_test_token", token) + assert.Equal(t, 2, gh.requests()) + wait := time.Duration(defaultPollInterval) * time.Second + if code == "slow_down" { + wait += 5 * time.Second + } + assert.Equal(t, []time.Duration{wait}, *slept) + }) + } + } +} + +func TestPollForToken_BadRequestOAuthErrorsRemainTerminal(t *testing.T) { + for _, code := range []string{"access_denied", "expired_token", "unknown_error", "incorrect_device_code"} { + t.Run(code, func(t *testing.T) { + gh := newSeqTokenServer(t, seqResp{ + status: http.StatusBadRequest, + body: fmt.Sprintf(`{"error":%q,"error_description":"Request rejected","error_uri":"https://github.com/error"}`, code), + }) + p, slept := newPollTestProvider(gh.srv.URL) + + token, err := p.pollForToken(context.Background(), "issued-device-code") + require.EqualError(t, err, "token request failed: "+code+": Request rejected (https://github.com/error)") + assert.Empty(t, token) + retries := 0 + if code == "incorrect_device_code" { + retries = incorrectDeviceCodeGraceRetries + } + assert.Equal(t, 1+retries, gh.requests()) + assert.Len(t, *slept, retries) + }) + } +} + +// TestPollForToken_ErrorDescriptionAndURISurfaced confirms the grace budget is +// spent in full against a persistently invalid code, and that GitHub's +// error_description and error_uri reach the user instead of being discarded. +func TestPollForToken_ErrorDescriptionAndURISurfaced(t *testing.T) { + gh := newSeqTokenServer(t, okResp(incorrectVerboseBody)) + p, _ := newPollTestProvider(gh.srv.URL) + + _, err := p.pollForToken(context.Background(), "issued-device-code") + require.Error(t, err) + assert.Contains(t, err.Error(), "incorrect_device_code") + assert.Contains(t, err.Error(), "The device_code provided is not valid.") + assert.Contains(t, err.Error(), "error-codes-for-the-device-flow") + assert.Equal(t, 1+incorrectDeviceCodeGraceRetries, gh.requests()) +} + +// TestPollForToken_TransientServerErrorRetried confirms a 5xx (which carries an +// HTML body, not JSON) is retried rather than ending the login. +func TestPollForToken_TransientServerErrorRetried(t *testing.T) { + gh := newSeqTokenServer(t, + serverErrorResp(), + okResp(tokenBody), + ) + p, slept := newPollTestProvider(gh.srv.URL) + + token, err := p.pollForToken(context.Background(), "issued-device-code") + require.NoError(t, err) + assert.Equal(t, "gho_test_token", token) + assert.Equal(t, 2, gh.requests()) + assert.Len(t, *slept, 1, "the 5xx must be followed by one back-off") +} + +// TestPollForToken_FirstPollIsImmediate pins the polling schedule: the first +// request goes out without a preceding sleep, so a user who authorises quickly +// is not made to wait an interval for nothing. +func TestPollForToken_FirstPollIsImmediate(t *testing.T) { + gh := newSeqTokenServer(t, okResp(tokenBody)) + p, slept := newPollTestProvider(gh.srv.URL) + + _, err := p.pollForToken(context.Background(), "issued-device-code") + require.NoError(t, err) + assert.Equal(t, 1, gh.requests()) + assert.Empty(t, *slept, "an immediately successful poll must not sleep") +} + +// TestRequestDeviceCode_HonoursServerIntervalAndExpiry confirms the interval and +// expires_in in the device-code response are adopted rather than dropped. +func TestRequestDeviceCode_HonoursServerIntervalAndExpiry(t *testing.T) { + device := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"device_code":"dc-1","user_code":"AAAA-BBBB","verification_uri":"https://github.com/login/device","expires_in":60,"interval":7}`)) + })) + t.Cleanup(device.Close) + + p := &GitHubATProvider{ + clientID: testClientID, + deviceCodeURL: device.URL, + pollInterval: defaultPollInterval, + expiresIn: defaultExpiresIn, + } + + deviceCode, userCode, uri, err := p.requestDeviceCode(context.Background()) + require.NoError(t, err) + assert.Equal(t, "dc-1", deviceCode) + assert.Equal(t, "AAAA-BBBB", userCode) + assert.Equal(t, "https://github.com/login/device", uri) + assert.Equal(t, 7, p.pollInterval, "interval from the response must be adopted") + assert.Equal(t, 60, p.expiresIn, "expires_in from the response must be adopted") +} + +// TestRequestDeviceCode_KeepsDefaultsWhenOmitted confirms a response without +// interval or expires_in leaves the documented defaults in place. +func TestRequestDeviceCode_KeepsDefaultsWhenOmitted(t *testing.T) { + device := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(`{"device_code":"dc-2","user_code":"EEEE-FFFF","verification_uri":"https://github.com/login/device"}`)) + })) + t.Cleanup(device.Close) + + p := &GitHubATProvider{ + clientID: testClientID, + deviceCodeURL: device.URL, + pollInterval: defaultPollInterval, + expiresIn: defaultExpiresIn, + } + + _, _, _, err := p.requestDeviceCode(context.Background()) + require.NoError(t, err) + assert.Equal(t, defaultPollInterval, p.pollInterval) + assert.Equal(t, defaultExpiresIn, p.expiresIn) +} + +// deviceCodeServerReturning serves a single device-code response with the given +// raw JSON body, for exercising interval/expires_in handling. +func deviceCodeServerReturning(t *testing.T, body string) string { + t.Helper() + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _, _ = w.Write([]byte(body)) + })) + t.Cleanup(srv.Close) + return srv.URL +} + +// TestRequestDeviceCode_ClampsExcessiveInterval confirms an interval far above +// maxPollInterval is clamped, protecting the same invariant maxPollInterval +// enforces on the slow_down path. +func TestRequestDeviceCode_ClampsExcessiveInterval(t *testing.T) { + url := deviceCodeServerReturning(t, + `{"device_code":"dc","user_code":"AAAA-BBBB","verification_uri":"https://github.com/login/device","expires_in":900,"interval":86400}`) + + p := &GitHubATProvider{clientID: testClientID, deviceCodeURL: url, pollInterval: defaultPollInterval, expiresIn: defaultExpiresIn} + _, _, _, err := p.requestDeviceCode(context.Background()) + require.NoError(t, err) + assert.Equal(t, maxPollInterval, p.pollInterval, "interval above the cap must be clamped") +} + +// TestRequestDeviceCode_ClampsOverflowValues covers the overflow pair: values +// large enough that time.Duration(n)*time.Second wraps negative would make +// sleep return instantly (spinning the loop) and put the deadline in the past +// (yielding zero polls). Clamping keeps both within safe bounds. +func TestRequestDeviceCode_ClampsOverflowValues(t *testing.T) { + url := deviceCodeServerReturning(t, + `{"device_code":"dc","user_code":"AAAA-BBBB","verification_uri":"https://github.com/login/device","expires_in":10000000000,"interval":10000000000}`) + + p := &GitHubATProvider{clientID: testClientID, deviceCodeURL: url, pollInterval: defaultPollInterval, expiresIn: defaultExpiresIn} + _, _, _, err := p.requestDeviceCode(context.Background()) + require.NoError(t, err) + + assert.Equal(t, maxPollInterval, p.pollInterval) + assert.Equal(t, maxExpiresIn, p.expiresIn) +} + +// TestRequestDeviceCode_IgnoresNegativeValues confirms negative interval and +// expires_in are rejected in favour of the defaults, so neither can produce a +// negative sleep or a deadline already in the past. +func TestRequestDeviceCode_IgnoresNegativeValues(t *testing.T) { + url := deviceCodeServerReturning(t, + `{"device_code":"dc","user_code":"AAAA-BBBB","verification_uri":"https://github.com/login/device","expires_in":-1,"interval":-1}`) + + p := &GitHubATProvider{clientID: testClientID, deviceCodeURL: url, pollInterval: defaultPollInterval, expiresIn: defaultExpiresIn} + _, _, _, err := p.requestDeviceCode(context.Background()) + require.NoError(t, err) + + assert.Equal(t, defaultPollInterval, p.pollInterval, "negative interval must fall back to the default") + assert.Equal(t, defaultExpiresIn, p.expiresIn, "negative expires_in must fall back to the default") +} + +// TestPollForToken_TimeoutSurfacesLastError covers F2: when the deadline lands +// mid-retry, the timeout must carry the last retryable diagnostic instead of a +// bare "timed out". The grace poll records the full-shape incorrect_device_code +// and its following sleep crosses the (1-second) deadline. +func TestPollForToken_TimeoutSurfacesLastError(t *testing.T) { + gh := newSeqTokenServer(t, okResp(incorrectVerboseBody)) + p := &GitHubATProvider{ + clientID: testClientID, + accessTokenURL: gh.srv.URL, + pollInterval: 1, + expiresIn: 1, // deadline ~1s out + sleep: func(time.Duration) { time.Sleep(1100 * time.Millisecond) }, + } + + _, err := p.pollForToken(context.Background(), "issued-device-code") + require.Error(t, err) + assert.Contains(t, err.Error(), "timed out") + assert.Contains(t, err.Error(), "The device_code provided is not valid.", + "the last retryable diagnostic must survive the timeout") +} + +// TestPollForToken_TimeoutAfterRecoveryIsBare confirms lastErr is cleared when +// polling recovers: one transient 502 followed by healthy pending polls and +// then a genuine user timeout must report plainly, not blame the stale 502. +func TestPollForToken_TimeoutAfterRecoveryIsBare(t *testing.T) { + gh := newSeqTokenServer(t, + serverErrorResp(), + okResp(pendingBody), + ) + p := &GitHubATProvider{ + clientID: testClientID, + accessTokenURL: gh.srv.URL, + pollInterval: 1, + expiresIn: 1, // deadline ~1s out + sleep: func(time.Duration) { time.Sleep(400 * time.Millisecond) }, + } + + _, err := p.pollForToken(context.Background(), "issued-device-code") + require.Error(t, err) + assert.Equal(t, "device code authorization timed out", err.Error(), + "a recovered 502 must not be reported as the cause of a user timeout") +} + +// Non-OAuth failures retain HTTP diagnostics rather than JSON parsing errors. +func TestPollForToken_NonOKStatusSurfacesStatusAndBody(t *testing.T) { + for _, tt := range []struct { + name string + resp seqResp + }{ + {"rate_limited", seqResp{status: http.StatusTooManyRequests, body: "rate limited"}}, + {"bad_request_html", seqResp{status: http.StatusBadRequest, body: "bad request"}}, + {"bad_request_invalid_json", seqResp{status: http.StatusBadRequest, body: `{"error":`}}, + {"bad_request_empty_error", seqResp{status: http.StatusBadRequest, body: `{"error":""}`}}, + {"bad_request_token", seqResp{status: http.StatusBadRequest, body: tokenBody}}, + {"pending_on_other_status", seqResp{status: http.StatusForbidden, body: pendingBody}}, + } { + t.Run(tt.name, func(t *testing.T) { + gh := newSeqTokenServer(t, tt.resp) + p, slept := newPollTestProvider(gh.srv.URL) + + token, err := p.pollForToken(context.Background(), "issued-device-code") + require.EqualError(t, err, fmt.Sprintf("token endpoint returned %d: %s", tt.resp.status, tt.resp.body)) + assert.Empty(t, token) + assert.Equal(t, 1, gh.requests(), "a non-retryable status must stop polling") + assert.Empty(t, *slept) + }) + } +} + +// TestPollForToken_ConsecutiveServerErrorsBackOff confirms the 5xx wait grows by +// 5s per consecutive failure and is capped, so a sustained outage costs a +// bounded number of requests rather than hammering the endpoint. +func TestPollForToken_ConsecutiveServerErrorsBackOff(t *testing.T) { + responses := make([]seqResp, 0, 4) + for range [3]struct{}{} { + responses = append(responses, serverErrorResp()) + } + responses = append(responses, okResp(tokenBody)) + + gh := newSeqTokenServer(t, responses...) + p, slept := newPollTestProvider(gh.srv.URL) + + token, err := p.pollForToken(context.Background(), "issued-device-code") + require.NoError(t, err) + assert.Equal(t, "gho_test_token", token) + + // Base interval is 0 in the test provider, so the waits are 5, 10, 15. + require.Len(t, *slept, 3) + assert.Equal(t, 5*time.Second, (*slept)[0]) + assert.Equal(t, 10*time.Second, (*slept)[1]) + assert.Equal(t, 15*time.Second, (*slept)[2]) +} + +// TestPollForToken_ServerErrorBackOffResetsOnRecovery confirms the 5xx growth is +// reset by any non-5xx response, so an intermittent endpoint does not +// accumulate an ever-longer wait across separate blips. +func TestPollForToken_ServerErrorBackOffResetsOnRecovery(t *testing.T) { + serverError := serverErrorResp() + gh := newSeqTokenServer(t, + serverError, + okResp(pendingBody), + serverError, + okResp(tokenBody), + ) + p, slept := newPollTestProvider(gh.srv.URL) + + token, err := p.pollForToken(context.Background(), "issued-device-code") + require.NoError(t, err) + assert.Equal(t, "gho_test_token", token) + + // 5s for the first 5xx, 0s for the pending poll (base interval), then 5s + // again โ€” not 10s โ€” because the pending response reset the growth. + require.Len(t, *slept, 3) + assert.Equal(t, 5*time.Second, (*slept)[0]) + assert.Equal(t, 0*time.Second, (*slept)[1]) + assert.Equal(t, 5*time.Second, (*slept)[2]) +} + +// TestRequestDeviceCode_PacingDoesNotLeakAcrossCodes covers F4: interval and +// expires_in are bound to the code they were issued with, so a second request +// that omits them must fall back to defaults rather than inherit the first. +func TestRequestDeviceCode_PacingDoesNotLeakAcrossCodes(t *testing.T) { + var call int + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + if call == 0 { + _, _ = w.Write([]byte(`{"device_code":"dc1","user_code":"AAAA-BBBB","verification_uri":"https://github.com/login/device","expires_in":120,"interval":55}`)) + } else { + _, _ = w.Write([]byte(`{"device_code":"dc2","user_code":"CCCC-DDDD","verification_uri":"https://github.com/login/device"}`)) + } + call++ + })) + t.Cleanup(srv.Close) + + p := &GitHubATProvider{clientID: testClientID, deviceCodeURL: srv.URL, pollInterval: defaultPollInterval, expiresIn: defaultExpiresIn} + + _, _, _, err := p.requestDeviceCode(context.Background()) + require.NoError(t, err) + assert.Equal(t, 55, p.pollInterval) + assert.Equal(t, 120, p.expiresIn) + + _, _, _, err = p.requestDeviceCode(context.Background()) + require.NoError(t, err) + assert.Equal(t, defaultPollInterval, p.pollInterval, "second code must not inherit the first's interval") + assert.Equal(t, defaultExpiresIn, p.expiresIn, "second code must not inherit the first's expires_in") +} + +// TestLogin_ClientIDStableAcrossDeviceCodeAndPolls covers the whole device flow +// end to end and pins the one invariant that makes incorrect_device_code +// meaningful: the health endpoint is read once, and the client_id the device +// code was issued under is the one every poll carries. The mock token endpoint +// answers incorrect_device_code for any other pairing. +func TestLogin_ClientIDStableAcrossDeviceCodeAndPolls(t *testing.T) { + var mu sync.Mutex + healthCalls := 0 + deviceClientID := "" + pollClientIDs := []string{} + pollCount := 0 + const issued = "dc-login" + + registry := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if r.URL.Path != "/v0/health" { + http.NotFound(w, r) + return + } + mu.Lock() + healthCalls++ + id := fmt.Sprintf("Iv23liCLIENT%04d", healthCalls) + mu.Unlock() + w.Header().Set("Content-Type", "application/json") + _, _ = fmt.Fprintf(w, `{"status":"ok","github_client_id":"%s"}`, id) + })) + t.Cleanup(registry.Close) + + device := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var req map[string]string + // assert, not require: t.FailNow from a handler goroutine is unsupported. + if !assert.NoError(t, json.NewDecoder(r.Body).Decode(&req)) { + http.Error(w, "bad request body", http.StatusBadRequest) + return + } + mu.Lock() + deviceClientID = req["client_id"] + mu.Unlock() + w.Header().Set("Content-Type", "application/json") + _, _ = fmt.Fprintf(w, `{"device_code":"%s","user_code":"CCCC-DDDD","verification_uri":"https://github.com/login/device","expires_in":900,"interval":5}`, issued) + })) + t.Cleanup(device.Close) + + tokenSrv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + var req map[string]string + // assert, not require: t.FailNow from a handler goroutine is unsupported. + if !assert.NoError(t, json.NewDecoder(r.Body).Decode(&req)) { + http.Error(w, "bad request body", http.StatusBadRequest) + return + } + mu.Lock() + pollClientIDs = append(pollClientIDs, req["client_id"]) + bound := req["client_id"] == deviceClientID && req["device_code"] == issued + pollCount++ + first := pollCount == 1 + mu.Unlock() + + w.Header().Set("Content-Type", "application/json") + switch { + case !bound: + _, _ = w.Write([]byte(incorrectBody)) + case first: + _, _ = w.Write([]byte(pendingBody)) + default: + _, _ = w.Write([]byte(tokenBody)) + } + })) + t.Cleanup(tokenSrv.Close) + + p := &GitHubATProvider{ + registryURL: registry.URL, + deviceCodeURL: device.URL, + accessTokenURL: tokenSrv.URL, + pollInterval: defaultPollInterval, + expiresIn: defaultExpiresIn, + sleep: func(time.Duration) {}, + } + + require.NoError(t, p.Login(context.Background())) + assert.Equal(t, "gho_test_token", p.githubToken) + + mu.Lock() + defer mu.Unlock() + assert.Equal(t, 1, healthCalls, "Login must read the health endpoint exactly once") + assert.Equal(t, "Iv23liCLIENT0001", deviceClientID) + for _, id := range pollClientIDs { + assert.Equal(t, deviceClientID, id, + "every poll must carry the client_id the device code was issued under") + } +} diff --git a/cmd/publisher/auth/github_at_poll_internal_test.go b/cmd/publisher/auth/github_at_poll_internal_test.go new file mode 100644 index 0000000..41de749 --- /dev/null +++ b/cmd/publisher/auth/github_at_poll_internal_test.go @@ -0,0 +1,131 @@ +package auth + +import ( + "context" + "encoding/json" + "net/http" + "net/http/httptest" + "testing" + "time" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// newMockTokenServer returns an httptest.Server that serves the given sequence +// of AccessTokenResponse values, one per request. Once the sequence is +// exhausted the final response is reused for any extra requests. +func newMockTokenServer(t *testing.T, responses []AccessTokenResponse) *httptest.Server { + t.Helper() + var i int + srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + resp := responses[len(responses)-1] + if i < len(responses) { + resp = responses[i] + } + i++ + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(resp) // #nosec G117 -- test fixture token, not a real secret + })) + t.Cleanup(srv.Close) + return srv +} + +// newPollTestProvider builds a provider wired to a mock token endpoint. The +// initial poll interval is 0 (so the back-off starts from a known base) and +// sleeps are captured rather than performed, making the tests deterministic and +// instant. The returned slice records every interval passed to sleep. +func newPollTestProvider(tokenURL string) (*GitHubATProvider, *[]time.Duration) { + slept := &[]time.Duration{} + p := &GitHubATProvider{ + clientID: "test-client-id", + accessTokenURL: tokenURL, + pollInterval: 0, + sleep: func(d time.Duration) { *slept = append(*slept, d) }, + } + return p, slept +} + +// TestPollForToken_SlowDownThenSuccess confirms that a slow_down response is +// treated as retriable: polling continues and the success path is reached. +func TestPollForToken_SlowDownThenSuccess(t *testing.T) { + srv := newMockTokenServer(t, []AccessTokenResponse{ + {Error: "slow_down"}, + {AccessToken: "gh-token"}, + }) + p, slept := newPollTestProvider(srv.URL) + + token, err := p.pollForToken(context.Background(), "device-code") + require.NoError(t, err) + assert.Equal(t, "gh-token", token) + + // One slow_down => one back-off, interval bumped 0 -> 5. + require.Len(t, *slept, 1) + assert.Equal(t, 5*time.Second, (*slept)[0]) +} + +// TestPollForToken_MixedRetryableErrorsCompoundInterval confirms the interval +// increment compounds correctly across mixed retryable errors. Per RFC 8628 +// ยง3.5 the interval is increased by 5 seconds on each slow_down and is NOT +// reset between slow_down instances, while authorization_pending leaves it +// unchanged. +func TestPollForToken_MixedRetryableErrorsCompoundInterval(t *testing.T) { + srv := newMockTokenServer(t, []AccessTokenResponse{ + {Error: "slow_down"}, // 0 -> 5 + {Error: "authorization_pending"}, // stays 5 + {Error: "slow_down"}, // 5 -> 10 + {AccessToken: "gh-token"}, + }) + p, slept := newPollTestProvider(srv.URL) + + token, err := p.pollForToken(context.Background(), "device-code") + require.NoError(t, err) + assert.Equal(t, "gh-token", token) + + require.Len(t, *slept, 3) + assert.Equal(t, 5*time.Second, (*slept)[0]) // after first slow_down + assert.Equal(t, 5*time.Second, (*slept)[1]) // authorization_pending: unchanged + assert.Equal(t, 10*time.Second, (*slept)[2]) // second slow_down: compounded +} + +// TestPollForToken_IntervalCappedAtMax confirms the polling interval is capped +// so a misbehaving auth server returning slow_down repeatedly cannot grow it +// without bound. +func TestPollForToken_IntervalCappedAtMax(t *testing.T) { + // 13 slow_downs starting from interval 0 would otherwise reach 65s + // (5, 10, ..., 60, 65); the cap holds it at 60. + responses := make([]AccessTokenResponse, 0, 14) + for range [13]struct{}{} { + responses = append(responses, AccessTokenResponse{Error: "slow_down"}) + } + responses = append(responses, AccessTokenResponse{AccessToken: "gh-token"}) + + srv := newMockTokenServer(t, responses) + p, slept := newPollTestProvider(srv.URL) + + token, err := p.pollForToken(context.Background(), "device-code") + require.NoError(t, err) + assert.Equal(t, "gh-token", token) + + require.Len(t, *slept, 13) + for _, d := range *slept { + assert.LessOrEqual(t, d, time.Duration(maxPollInterval)*time.Second) + } + // The last two back-offs are both pinned at the cap. + assert.Equal(t, time.Duration(maxPollInterval)*time.Second, (*slept)[11]) + assert.Equal(t, time.Duration(maxPollInterval)*time.Second, (*slept)[12]) +} + +// TestPollForToken_FatalErrorStopsPolling confirms a non-retryable error ends +// polling immediately with an error. +func TestPollForToken_FatalErrorStopsPolling(t *testing.T) { + srv := newMockTokenServer(t, []AccessTokenResponse{ + {Error: "access_denied"}, + }) + p, slept := newPollTestProvider(srv.URL) + + _, err := p.pollForToken(context.Background(), "device-code") + require.Error(t, err) + assert.Contains(t, err.Error(), "access_denied") + assert.Empty(t, *slept, "fatal error should not trigger a back-off sleep") +} diff --git a/cmd/publisher/commands/init.go b/cmd/publisher/commands/init.go index 8d0b505..92d6c8a 100644 --- a/cmd/publisher/commands/init.go +++ b/cmd/publisher/commands/init.go @@ -27,7 +27,10 @@ func InitCommand() error { // Try to detect values from environment name := detectServerName(subfolder) description := detectDescription() - version := "1.0.0" + version := getVersionFromPackageJSON() + if version == "" { + version = "1.0.0" + } repoURL := detectRepoURL() repoSource := MethodGitHub if repoURL != "" && !strings.Contains(repoURL, "github.com") { @@ -129,6 +132,26 @@ func detectSubfolder() string { return filepath.ToSlash(relPath) } +// getMcpNameFromPackageJSON returns the `mcpName` field from package.json, or +// "" if not set. mcpName is the authoritative MCP server name when present โ€” +// see docs/modelcontextprotocol-io/quickstart.mdx. +func getMcpNameFromPackageJSON() string { + data, err := os.ReadFile("package.json") + if err != nil { + return "" + } + + var pkg map[string]any + if err := json.Unmarshal(data, &pkg); err != nil { + return "" + } + + if mcpName, ok := pkg["mcpName"].(string); ok && mcpName != "" { + return mcpName + } + return "" +} + func getNameFromPackageJSON() string { data, err := os.ReadFile("package.json") if err != nil { @@ -146,7 +169,7 @@ func getNameFromPackageJSON() string { } // Convert npm package name to MCP server name - // @org/package -> io.npm.org/package + // @org/package -> io.github.org/package if strings.HasPrefix(name, "@") { parts := strings.Split(name[1:], "/") if len(parts) == 2 { @@ -156,7 +179,33 @@ func getNameFromPackageJSON() string { return fmt.Sprintf("io.github./%s", name) } +func getVersionFromPackageJSON() string { + data, err := os.ReadFile("package.json") + if err != nil { + return "" + } + + var pkg map[string]any + if err := json.Unmarshal(data, &pkg); err != nil { + return "" + } + + version, ok := pkg["version"].(string) + if !ok || version == "" { + return "" + } + + return version +} + func detectServerName(subfolder string) string { + // mcpName in package.json is the authoritative server name when set, so it + // takes precedence over names inferred from the git remote or the npm + // `name` field. + if name := getMcpNameFromPackageJSON(); name != "" { + return name + } + // Try to get from git remote repoURL := detectRepoURL() if repoURL != "" && strings.Contains(repoURL, "github.com") { diff --git a/cmd/publisher/commands/init_test.go b/cmd/publisher/commands/init_test.go new file mode 100644 index 0000000..e7f3fdb --- /dev/null +++ b/cmd/publisher/commands/init_test.go @@ -0,0 +1,92 @@ +package commands_test + +import ( + "encoding/json" + "os" + "path/filepath" + "testing" + + "github.com/modelcontextprotocol/registry/cmd/publisher/commands" + apiv0 "github.com/modelcontextprotocol/registry/pkg/api/v0" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestInitCommand_PackageJSON(t *testing.T) { + tests := []struct { + name string + pkgJSON string + expectedName string + expectedVersion string + }{ + { + name: "mcpName is returned as-is without transformation", + pkgJSON: `{"name": "@acme/weather", "mcpName": "io.github.acme/weather-mcp", "version": "2.3.4", "repository": "https://gitlab.com/acme/weather"}`, + expectedName: "io.github.acme/weather-mcp", + expectedVersion: "2.3.4", + }, + { + name: "empty mcpName falls back to scoped name transformation", + pkgJSON: `{"name": "@acme/weather", "mcpName": "", "version": "1.2.3", "repository": "https://gitlab.com/acme/weather"}`, + expectedName: "io.github.acme/weather", + expectedVersion: "1.2.3", + }, + { + name: "missing mcpName falls back to scoped name transformation", + pkgJSON: `{"name": "@acme/weather", "version": "1.2.3", "repository": "https://gitlab.com/acme/weather"}`, + expectedName: "io.github.acme/weather", + expectedVersion: "1.2.3", + }, + { + name: "missing version falls back to 1.0.0", + pkgJSON: `{"name": "@acme/weather", "mcpName": "io.github.acme/weather", "repository": "https://gitlab.com/acme/weather"}`, + expectedName: "io.github.acme/weather", + expectedVersion: "1.0.0", + }, + { + name: "mcpName takes precedence over GitHub repository URL", + pkgJSON: `{"name": "weather", "mcpName": "io.github.acme/weather-mcp", "version": "1.0.0", "repository": "https://github.com/someone-else/some-repo"}`, + expectedName: "io.github.acme/weather-mcp", + expectedVersion: "1.0.0", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + dir := withIsolatedPackageJSON(t, tt.pkgJSON) + + require.NoError(t, commands.InitCommand()) + + data, err := os.ReadFile(filepath.Join(dir, "server.json")) + require.NoError(t, err) + + var got apiv0.ServerJSON + require.NoError(t, json.Unmarshal(data, &got)) + + assert.Equal(t, tt.expectedName, got.Name) + assert.Equal(t, tt.expectedVersion, got.Version) + require.Len(t, got.Packages, 1) + assert.Equal(t, tt.expectedVersion, got.Packages[0].Version, + "package version should match server version") + }) + } +} + +// withIsolatedPackageJSON creates a temp dir outside any git repository, +// writes package.json with the given contents, chdirs into it, and returns +// the directory path. The HOME override prevents init from detecting the +// host repo's git state. +func withIsolatedPackageJSON(t *testing.T, contents string) string { + t.Helper() + + dir := t.TempDir() + require.NoError(t, os.WriteFile(filepath.Join(dir, "package.json"), []byte(contents), 0600)) + + originalDir, err := os.Getwd() + require.NoError(t, err) + t.Cleanup(func() { _ = os.Chdir(originalDir) }) + + require.NoError(t, os.Chdir(dir)) + + return dir +} diff --git a/cmd/publisher/commands/publish.go b/cmd/publisher/commands/publish.go index c93621a..cccf2c8 100644 --- a/cmd/publisher/commands/publish.go +++ b/cmd/publisher/commands/publish.go @@ -28,6 +28,9 @@ func PublishCommand(args []string) error { } return fmt.Errorf("failed to read server.json: %w", err) } + if err := validateJSONUnicode(serverFile, serverData); err != nil { + return err + } // Validate JSON var serverJSON apiv0.ServerJSON @@ -61,7 +64,7 @@ func PublishCommand(args []string) error { } // Publish to registry - _, _ = fmt.Fprintf(os.Stdout, "Publishing to %s...\n", registryURL) + _, _ = fmt.Fprintf(os.Stdout, "Publishing %s@%s to %s...\n", serverJSON.Name, serverJSON.Version, registryURL) response, statusCode, err := publishToRegistry(registryURL, serverData, token) if err != nil { // If publish failed with 422, call validate endpoint to show detailed errors @@ -99,6 +102,10 @@ func PublishCommand(args []string) error { } func publishToRegistry(registryURL string, serverData []byte, token string) (*apiv0.ServerResponse, int, error) { + if err := validateJSONUnicode("server.json", serverData); err != nil { + return nil, 0, err + } + // Parse the server JSON data var serverJSON apiv0.ServerJSON err := json.Unmarshal(serverData, &serverJSON) diff --git a/cmd/publisher/commands/publish_test.go b/cmd/publisher/commands/publish_test.go index 27fcdfa..745198d 100644 --- a/cmd/publisher/commands/publish_test.go +++ b/cmd/publisher/commands/publish_test.go @@ -4,6 +4,8 @@ import ( "encoding/json" "io" "net/http" + "os" + "path/filepath" "testing" "github.com/modelcontextprotocol/registry/cmd/publisher/commands" @@ -37,6 +39,87 @@ func TestPublishCommand_Success(t *testing.T) { assert.NoError(t, err) } +func TestPublishCommand_PrintsSubmittedIdentityOnFailure(t *testing.T) { + server := SetupMockRegistryServer(t, func(w http.ResponseWriter, _ *http.Request) { + http.Error(w, "duplicate version", http.StatusBadRequest) + }, nil) + SetupTestToken(t, server.URL, "test-token") + CreateTestServerJSON(t, apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "io.github.BargLabs/cejel", + Description: "A test server", + Version: "0.4.5", + }) + + output, err := os.CreateTemp(t.TempDir(), "stdout") + require.NoError(t, err) + originalStdout := os.Stdout + os.Stdout = output + t.Cleanup(func() { + os.Stdout = originalStdout + _ = output.Close() + }) + + err = commands.PublishCommand(nil) + require.ErrorContains(t, err, "duplicate version") + _, err = output.Seek(0, io.SeekStart) + require.NoError(t, err) + data, err := io.ReadAll(output) + require.NoError(t, err) + assert.Equal(t, "Publishing io.github.BargLabs/cejel@0.4.5 to "+server.URL+"...\n", string(data)) +} + +func TestPublishCommand_PreservesNonASCIIDescription(t *testing.T) { + server := SetupMockRegistryServer(t, + func(w http.ResponseWriter, r *http.Request) { + var req apiv0.ServerJSON + require.NoError(t, json.NewDecoder(r.Body).Decode(&req)) + assert.Equal(t, "Tools for agents โ€” safely", req.Description) + + w.WriteHeader(http.StatusCreated) + _ = json.NewEncoder(w).Encode(apiv0.ServerResponse{ + Server: apiv0.ServerJSON{ + Name: req.Name, + Version: req.Version, + }, + }) + }, + nil, + ) + SetupTestToken(t, server.URL, "test-token") + + CreateTestServerJSON(t, apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "com.example/test-server", + Description: "Tools for agents โ€” safely", + Version: "1.0.0", + }) + + require.NoError(t, commands.PublishCommand([]string{})) +} + +func TestPublishCommand_RejectsInvalidUTF8ServerJSON(t *testing.T) { + createRawServerJSON(t, []byte{ + '{', '"', '$', 's', 'c', 'h', 'e', 'm', 'a', '"', ':', '"', '"', ',', + '"', 'n', 'a', 'm', 'e', '"', ':', '"', 'c', 'o', 'm', '.', 'e', 'x', 'a', 'm', 'p', 'l', 'e', '/', 't', 'e', 's', 't', '"', ',', + '"', 'd', 'e', 's', 'c', 'r', 'i', 'p', 't', 'i', 'o', 'n', '"', ':', '"', 'b', 'a', 'd', ' ', 0xe2, '"', ',', + '"', 'v', 'e', 'r', 's', 'i', 'o', 'n', '"', ':', '"', '1', '.', '0', '.', '0', '"', '}', + }) + + err := commands.PublishCommand([]string{}) + require.Error(t, err) + assert.Contains(t, err.Error(), "UTF-8") +} + +func TestPublishCommand_RejectsUnpairedSurrogateEscape(t *testing.T) { + createRawServerJSON(t, []byte(`{"$schema":"","name":"com.example/test","description":"bad \udc94","version":"1.0.0"}`)) + + err := commands.PublishCommand([]string{}) + require.Error(t, err) + assert.Contains(t, err.Error(), "unpaired UTF-16 surrogate") + assert.Contains(t, err.Error(), "$.description") +} + func TestPublishCommand_422ValidationFlow(t *testing.T) { validateCallCount := 0 publishCallCount := 0 @@ -102,6 +185,20 @@ func TestPublishCommand_422ValidationFlow(t *testing.T) { assert.Equal(t, 1, validateCallCount, "validate endpoint should be called once after 422") } +func createRawServerJSON(t *testing.T, data []byte) { + t.Helper() + + tempDir := t.TempDir() + serverFile := filepath.Join(tempDir, "server.json") + require.NoError(t, os.WriteFile(serverFile, data, 0600)) + + originalDir, err := os.Getwd() + require.NoError(t, err) + t.Cleanup(func() { _ = os.Chdir(originalDir) }) + + require.NoError(t, os.Chdir(tempDir)) +} + func TestPublishCommand_422WithMultipleIssues(t *testing.T) { validateCallCount := 0 diff --git a/cmd/publisher/commands/testutil_test.go b/cmd/publisher/commands/testutil_test.go index e69027b..c103f82 100644 --- a/cmd/publisher/commands/testutil_test.go +++ b/cmd/publisher/commands/testutil_test.go @@ -68,9 +68,10 @@ func SetupMockRegistryServer(t *testing.T, publishHandler func(w http.ResponseWr func SetupTestToken(t *testing.T, registryURL, token string) string { t.Helper() - // Override $HOME so tokenFilePath() resolves to a temp directory + // Override the home directory so tokenFilePath() resolves to a temp directory. tempHome := t.TempDir() t.Setenv("HOME", tempHome) + t.Setenv("USERPROFILE", tempHome) dir := filepath.Join(tempHome, ".config", "mcp-publisher") require.NoError(t, os.MkdirAll(dir, 0700)) @@ -94,9 +95,7 @@ func SetupTestToken(t *testing.T, registryURL, token string) string { func CreateTestServerJSON(t *testing.T, serverJSON apiv0.ServerJSON) (string, string) { t.Helper() - tempDir, err := os.MkdirTemp("", "mcp-publisher-test") - require.NoError(t, err) - t.Cleanup(func() { os.RemoveAll(tempDir) }) + tempDir := t.TempDir() jsonData, err := json.MarshalIndent(serverJSON, "", " ") require.NoError(t, err) diff --git a/cmd/publisher/commands/unicode.go b/cmd/publisher/commands/unicode.go new file mode 100644 index 0000000..11f5153 --- /dev/null +++ b/cmd/publisher/commands/unicode.go @@ -0,0 +1,107 @@ +package commands + +import ( + "bytes" + "encoding/json" + "fmt" + "strconv" + "unicode/utf8" +) + +func validateJSONUnicode(filename string, data []byte) error { + if !utf8.Valid(data) { + return fmt.Errorf("%s must be encoded as UTF-8", filename) + } + + if path, ok := findUnpairedSurrogate(data, "$"); ok { + return fmt.Errorf("%s contains an unpaired UTF-16 surrogate escape at %s", filename, path) + } + + return nil +} + +func findUnpairedSurrogate(raw json.RawMessage, path string) (string, bool) { + raw = bytes.TrimSpace(raw) + if len(raw) == 0 { + return "", false + } + + switch raw[0] { + case '"': + if hasUnpairedSurrogateEscape(raw) { + return path, true + } + case '{': + var obj map[string]json.RawMessage + if err := json.Unmarshal(raw, &obj); err != nil { + return "", false + } + for key, value := range obj { + if badPath, ok := findUnpairedSurrogate(value, path+"."+key); ok { + return badPath, true + } + } + case '[': + var items []json.RawMessage + if err := json.Unmarshal(raw, &items); err != nil { + return "", false + } + for i, item := range items { + if badPath, ok := findUnpairedSurrogate(item, fmt.Sprintf("%s[%d]", path, i)); ok { + return badPath, true + } + } + } + + return "", false +} + +func hasUnpairedSurrogateEscape(s []byte) bool { + for i := 1; i < len(s)-1; i++ { + if s[i] != '\\' || i+5 >= len(s) || s[i+1] != 'u' { + continue + } + + code, ok := parseHex4(s[i+2 : i+6]) + if !ok { + continue + } + + if isLowSurrogate(code) { + return true + } + + if !isHighSurrogate(code) { + i += 5 + continue + } + + if i+11 >= len(s) || s[i+6] != '\\' || s[i+7] != 'u' { + return true + } + + next, ok := parseHex4(s[i+8 : i+12]) + if !ok || !isLowSurrogate(next) { + return true + } + i += 11 + } + + return false +} + +func parseHex4(b []byte) (rune, bool) { + v, err := strconv.ParseInt(string(b), 16, 32) + if err != nil { + return 0, false + } + return rune(v), true +} + +func isHighSurrogate(r rune) bool { + return r >= 0xD800 && r <= 0xDBFF +} + +func isLowSurrogate(r rune) bool { + return r >= 0xDC00 && r <= 0xDFFF +} diff --git a/cmd/publisher/commands/validate.go b/cmd/publisher/commands/validate.go index 1e360ae..012e8fe 100644 --- a/cmd/publisher/commands/validate.go +++ b/cmd/publisher/commands/validate.go @@ -142,6 +142,9 @@ func ValidateCommand(args []string) error { } return fmt.Errorf("failed to read %s: %w", serverFile, err) } + if err := validateJSONUnicode(serverFile, serverData); err != nil { + return err + } // Validate JSON var serverJSON apiv0.ServerJSON @@ -188,6 +191,10 @@ func ValidateCommand(args []string) error { // validateViaAPI calls the /validate endpoint on the registry func validateViaAPI(registryURL string, serverData []byte) (*validators.ValidationResult, error) { + if err := validateJSONUnicode("server.json", serverData); err != nil { + return nil, err + } + // Parse the server JSON data to ensure it's valid JSON var serverJSON apiv0.ServerJSON err := json.Unmarshal(serverData, &serverJSON) diff --git a/cmd/publisher/commands/validate_test.go b/cmd/publisher/commands/validate_test.go index b56b22d..1827ffe 100644 --- a/cmd/publisher/commands/validate_test.go +++ b/cmd/publisher/commands/validate_test.go @@ -140,16 +140,13 @@ func TestValidateCommand_NoServerFile(t *testing.T) { server := SetupMockRegistryServer(t, nil, nil) SetupTestToken(t, server.URL, "test-token") - // Don't create server.json - tempDir, err := os.MkdirTemp("", "mcp-publisher-test") - require.NoError(t, err) - defer os.RemoveAll(tempDir) + tempDir := t.TempDir() originalDir, err := os.Getwd() require.NoError(t, err) defer func() { _ = os.Chdir(originalDir) }() - _ = os.Chdir(tempDir) + require.NoError(t, os.Chdir(tempDir)) err = commands.ValidateCommand([]string{}) @@ -161,15 +158,13 @@ func TestValidateCommand_InvalidJSON(t *testing.T) { server := SetupMockRegistryServer(t, nil, nil) SetupTestToken(t, server.URL, "test-token") - tempDir, err := os.MkdirTemp("", "mcp-publisher-test") - require.NoError(t, err) - defer os.RemoveAll(tempDir) + tempDir := t.TempDir() originalDir, err := os.Getwd() require.NoError(t, err) defer func() { _ = os.Chdir(originalDir) }() - _ = os.Chdir(tempDir) + require.NoError(t, os.Chdir(tempDir)) // Create invalid JSON file err = os.WriteFile("server.json", []byte("{ invalid json }"), 0600) diff --git a/cmd/publisher/main.go b/cmd/publisher/main.go index 20cea2b..8f7de09 100644 --- a/cmd/publisher/main.go +++ b/cmd/publisher/main.go @@ -27,10 +27,12 @@ func main() { os.Exit(1) } - // Check for help flag for subcommands + // Check for help flag for subcommands. Commands without an entry in + // printCommandHelp handle --help themselves, so fall through to dispatch. if len(os.Args) >= 3 && (os.Args[2] == "--help" || os.Args[2] == "-h") { - printCommandHelp(os.Args[1]) - return + if printCommandHelp(os.Args[1]) { + return + } } var err error @@ -81,7 +83,10 @@ func printUsage() { _, _ = fmt.Fprintln(os.Stdout, "Use 'mcp-publisher --help' for more information about a command.") } -func printCommandHelp(command string) { +// printCommandHelp prints help for a specific command and reports whether it had +// an entry here. Commands without one parse --help themselves, so the caller +// should fall through to normal dispatch when this returns false. +func printCommandHelp(command string) bool { switch command { case "init": _, _ = fmt.Fprintln(os.Stdout, "Create a server.json file template") @@ -165,7 +170,8 @@ func printCommandHelp(command string) { _, _ = fmt.Fprintln(os.Stdout, "You must be logged in before updating status. Run 'mcp-publisher login' first.") default: - fmt.Fprintf(os.Stderr, "Unknown command: %s\n", command) - printUsage() + return false } + + return true } diff --git a/cmd/registry/main.go b/cmd/registry/main.go index 3eee551..ed68abf 100644 --- a/cmd/registry/main.go +++ b/cmd/registry/main.go @@ -57,15 +57,31 @@ func main() { // Initialize configuration cfg := config.NewConfig() - // Create a context with timeout for PostgreSQL connection - ctx, cancel := context.WithTimeout(context.Background(), 10*time.Second) - defer cancel() - - // Connect to PostgreSQL - db, err = database.NewPostgreSQL(ctx, cfg.DatabaseURL) - if err != nil { - log.Printf("Failed to connect to PostgreSQL: %v", err) - return + // Connect to PostgreSQL with bounded retry. The DB endpoint can flap briefly + // during voluntary disruptions (node drains, rollouts) and without retry the + // pod exits cleanly, restarts, then races with the still-recovering service + // โ€” turning a transient blip into a multi-minute outage. + const ( + maxStartupAttempts = 8 + perAttemptTimeout = 10 * time.Second + initialBackoff = 1 * time.Second + maxBackoff = 8 * time.Second + ) + backoff := initialBackoff + for attempt := 1; ; attempt++ { + attemptCtx, attemptCancel := context.WithTimeout(context.Background(), perAttemptTimeout) + db, err = database.NewPostgreSQL(attemptCtx, cfg.DatabaseURL) + attemptCancel() + if err == nil { + break + } + if attempt >= maxStartupAttempts { + log.Printf("Failed to connect to PostgreSQL after %d attempts: %v", attempt, err) + return + } + log.Printf("PostgreSQL not reachable (attempt %d/%d): %v, retrying in %s", attempt, maxStartupAttempts, err, backoff) + time.Sleep(backoff) + backoff = min(backoff*2, maxBackoff) } // Store the PostgreSQL instance for later cleanup diff --git a/complete.md b/complete.md deleted file mode 100644 index 2355e4b..0000000 --- a/complete.md +++ /dev/null @@ -1,2949 +0,0 @@ -# Complete Documentation - -This file contains all documentation from the docs/ directory compiled into a single markdown file. - ---- - -## File: docs/README.md - -# MCP Registry Documentation - -The MCP registry provides MCP clients with a list of MCP servers, like an app store for MCP servers. - -## I want to... - -- **๐Ÿ“ค Publish my MCP server** โ†’ [Publishing Guide](guides/publishing/publish-server.md) -- **๐Ÿ“ฅ Consume registry data** โ†’ [API Usage Guide](guides/consuming/use-rest-api.md) -- **๐Ÿ”Œ Understand the registry's purpose** โ†’ [Ecosystem vision](explanations/ecosystem-vision.md) -- **๐Ÿ“‹ Look up specific information** โ†’ [server.json spec](reference/server-json/generic-server-json.md) | [API spec](reference/api/generic-registry-api.md) | [CLI reference](reference/cli/commands.md) - -## Documentation Index - -- ๐Ÿ› ๏ธ [How-To Guides: Task-focused instructions](./guides/) -- ๐Ÿ’ก [Explanations: Understanding-oriented content](./explanations/) -- ๐Ÿ“– [Reference: Technical specifications and lookup material](./reference/) - ---- - -## File: docs/explanations/README.md - -# Explanations - -Understanding-oriented documentation that clarifies and illuminates the MCP Registry. - -- [Design principles](design-principles.md) -- [Ecosystem vision](ecosystem-vision.md) -- [Roadmap](roadmap.md) -- [Tech architecture](tech-architecture.md) -- [Namespacing](namespacing.md) -- [Versioning](versioning.md) - ---- - -## File: docs/explanations/design-principles.md - -# MCP Registry Design Principles - -These are the core constraints that guide the design of the MCP Registry. They are not exhaustive, but they are the most important principles that we will use to evaluate design decisions. - -## 1. Single Source of Truth - -The registry serves as the authoritative metadata repository for publicly-available MCP servers, both locally-run and remote, open source and closed source. Server creators publish once, and all consumers (MCP clients, aggregators, etc.) reference the same canonical data. - -## 2. Minimal Operational Burden - -- Design for low maintenance and operational overhead -- Delegate complexity to existing services where possible (GitHub for auth, npm/PyPI/NuGet for packages) -- Avoid features that require constant human intervention or moderation -- Build for reasonable downtime tolerance (24h acceptable) by having consumers cache data for their end-users - -## 3. Vendor Neutrality - -- No preferential treatment for specific servers or organizations -- No built-in ranking, curation, or quality judgments -- Let consumers (MCP clients, aggregators) make their own curation decisions - -## 4. Meets Industry Security Standards - -- Leverage existing package registries (npm, PyPI, NuGet, Docker Hub, etc.) for source code distribution, obviating the need to reinvent source code security -- Use mechanisms like DNS verification, OAuth to provide base layer of authentication and trust -- Implement rate limiting, field validation, and blacklisting to prevent abuse - -## 6. Reusable, Extensible Shapes; Not Infrastructure - -- API shapes (OpenAPI, server.json) designed for reuse -- Enable private/internal registries using same formats -- Don't mandate infrastructure reuse - focus on interface compatibility - -## 7. Progressive Enhancement - -- Start with MVP that provides immediate value -- Build foundation that supports future features -- Don't over-engineer for hypothetical needs -- Each milestone should be independently valuable - ---- - -## File: docs/explanations/ecosystem-vision.md - -# Ecosystem Vision - -How the MCP Registry fits into the broader ecosystem and our vision for the future. - -## The Registry Ecosystem - -The MCP registry provides MCP clients with a list of MCP servers, like an app store for MCP servers. (In the future it might do more, like also hosting a list of clients). - -There are two parts to the registry project: - -1. ๐ŸŸฆ **The MCP registry spec**: An [API specification](../reference/api/) that allows anyone to implement a registry. -2. ๐ŸŸฅ **The Official MCP registry**: A hosted registry following the MCP registry spec at [`registry.modelcontextprotocol.io`](https://registry.modelcontextprotocol.io). This serves as the **authoritative repository** for publicly-available MCP servers. Server creators publish once, and all consumers (MCP clients, aggregators, marketplaces) reference the same canonical data. This is owned by the MCP open-source community, backed by major trusted contributors to the MCP ecosystem such as Anthropic, GitHub, PulseMCP and Microsoft. - -The registry is built around the [`server.json`](../reference/server-json/) format - a standardized way to describe MCP servers that works across discovery, initialization, and packaging scenarios. - -In time, we expect the ecosystem to look a bit like this: - -![](./ecosystem-diagram.excalidraw.svg) - -Note that MCP registries are _metaregistries_. They host metadata about packages, but not the package code or binaries. Instead, they reference other package registries (like NPM, PyPi or Docker) for this. - -Additionally, we expect clients pull from _subregistries_. These subregistries add value to the registry ecosystem by providing curation, or extending it with additional metadata. The Official MCP registry expects a lot of API requests from ETL jobs from these subregistries. - -## Registry vs Package Registry - -Key distinction: MCP Registries are **metaregistries**. - -- **Package registries** (npm, PyPI, Docker Hub) host actual code/binaries -- **The MCP Registry** hosts metadata pointing to those packages - -``` -MCP Registry: "weather-server v1.2.0 is at npm:weather-mcp" -NPM Registry: [actual weather-mcp package code] -``` - -## Official vs Community Registries - -**Official MCP Registry** (`registry.modelcontextprotocol.io`): -- Canonical source for publicly-available servers -- Community-owned, backed by trusted contributors -- Focuses on discoverability and basic metadata - -**Subregistries** (Smithery, PulseMCP, etc.): -- Add value through curation, ratings, enhanced metadata -- ETL from official registry + additional annotations -- Serve specific communities or use cases - -## How Servers Are Represented - -Each server entry contains: -- **Identity**: Unique name (`io.github.user/server-name`) -- **Packages**: Where to download it (`npm`, `pypi`, `docker`, etc.) -- **Runtime**: How to execute it (args, env vars) -- **Metadata**: Description, capabilities, version - -This is stored in a standardized `server.json` format that works across discovery, installation, and execution. - ---- - -## File: docs/explanations/roadmap.md - -# MCP Registry Roadmap - -This is a high-level roadmap for the MCP Registry. It is subject to change and not exhaustive, but it outlines the general thinking of the sequencing and scope of our work in this repository. - -This roadmap may occasionally drift out of date. Please review [Issues](https://github.com/modelcontextprotocol/registry/issues) (and corresponding Labels) for the most current work in progress. - -## Current Status - -The initial version of the MCP Registry is actively being developed. The initial focus is on delivering a REST API to which server creators can publish, and aggregator/marketplace consumers can ETL. - -## Phase 1: MVP/Go-Live (Current Focus) - -See the [go-live blocker issues](https://github.com/modelcontextprotocol/registry/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22go-live%20blocker%22). - -## Backlog (Future Work, may be moved to out of scope) - -- [ ] UI implementation -- [ ] Store and surface other data besides servers (e.g. [clients](https://modelcontextprotocol.io/clients), resources) -- [ ] Download count tracking -- [ ] Internationalization (i18n) - -## Out of Scope (Not Planned) - -- **Source code hosting**: The registry will never host actual server code -- **Quality rankings**: No built-in server quality assessments or rankings -- **Curation**: No editorial decisions about which servers are "better" -- **Unified runtime**: Not solving how servers are executed -- **Server hosting**: The registry does not provide hosting for servers -- **Search engine**: The registry will not provide a commercial grade search engine for servers -- **Server tags or categories**: Not supported, to reduce moderation burden -- **Server rankings**: The registry will not rank servers by subjective measures of quality - ---- - -## File: docs/explanations/tech-architecture.md - -# MCP Registry Technical Architecture - -This document describes the technical architecture of the MCP Registry, including system components, deployment strategies, and data flows. - -## System Overview - -The MCP Registry is designed as a lightweight metadata service that bridges MCP server creators with consumers (MCP clients and aggregators). - -## Core Components - -### REST API (Go) - -The main application server implemented in Go, providing: -- Public read endpoints for server discovery -- Authenticated write endpoints for server publication -- GitHub OAuth integration (extensible to other providers) -- DNS verification system (optional for custom namespaces) - -### Database (PostgreSQL) - -Primary data store for: -- Versioned server metadata (server.json contents) -- User authentication state -- DNS verification records - -### CDN Layer - -Critical for scalability: -- Caches all public read endpoints -- Reduces load on origin servers -- Enables global distribution -- Designed for daily consumer polling patterns - -### CLI Tool - -Developer interface for: -- Server publication workflow -- GitHub OAuth flow -- DNS verification - -## Deployment Architecture - -### Kubernetes Deployment (Helm) - -The registry is designed to run on Kubernetes using Helm charts: - -```mermaid -graph TB - subgraph "Kubernetes Cluster" - subgraph "Namespace: mcp-registry" - subgraph "Registry Service" - LB[Load Balancer
:80] - RS[Registry Service
:8080] - RP1[Registry Pod 1] - RP2[Registry Pod 2] - RP3[Registry Pod N] - end - - subgraph "Database Service" - DBS[DB Service
:27017] - SS[StatefulSet] - PV[Persistent Volume] - end - - subgraph "Secrets" - GHS[GitHub OAuth Secret] - end - end - end - - LB --> RS - RS --> RP1 - RS --> RP2 - RS --> RP3 - RP1 --> DBS - RP2 --> DBS - RP3 --> DBS - DBS --> SS - SS --> PV - RP1 -.-> GHS - RP2 -.-> GHS - RP3 -.-> GHS -``` - -## Data Flow Patterns - -### 1. Server Publication Flow - -```mermaid -sequenceDiagram - participant Dev as Developer - participant CLI as CLI Tool - participant API as Registry API - participant DB as Database - participant GH as GitHub - participant DNS as DNS Provider - - Dev->>CLI: mcp publish server.json - CLI->>CLI: Validate server.json - CLI->>GH: OAuth flow - GH-->>CLI: Access token - CLI->>API: POST /servers - API->>GH: Verify token - API->>DNS: Verify domain (if applicable) - API->>DB: Store metadata - API-->>CLI: Success - CLI-->>Dev: Published! -``` - -### 2. Consumer Discovery Flow - -```mermaid -sequenceDiagram - participant Client as MCP Client Host App - participant INT as Intermediary
(Marketplace/Aggregator) - participant CDN as CDN Cache - participant API as Registry API - participant DB as Database - - Note over INT,CDN: Daily ETL Process - INT->>CDN: GET /servers - alt Cache Hit - CDN-->>INT: Cached response - else Cache Miss - CDN->>API: GET /servers - API->>DB: Query servers - DB-->>API: Server list - API-->>CDN: Response + cache headers - CDN-->>INT: Response - end - INT->>INT: Process & enhance data - INT->>INT: Store in local cache - - Note over Client,INT: Real-time Client Access - Client->>INT: Request server list - INT-->>Client: Curated/enhanced data -``` - -### 3. DNS Verification Flow - -```mermaid -sequenceDiagram - participant User as User - participant CLI as CLI Tool - participant API as Registry API - participant DNS as DNS Provider - participant DB as Database - - User->>CLI: mcp verify-domain example.com - CLI->>API: POST /verify-domain - API->>API: Generate verification token - API->>DB: Store pending verification - API-->>CLI: TXT record: mcp-verify=abc123 - CLI-->>User: Add TXT record to DNS - User->>DNS: Configure TXT record - User->>CLI: Confirm added - CLI->>API: POST /verify-domain/check - API->>DNS: Query TXT records - DNS-->>API: TXT records - API->>API: Validate token - API->>DB: Store verification - API-->>CLI: Domain verified - CLI-->>User: Success! -``` - -### 4. Admin OIDC Authentication Flow - -For registry administration, users with @modelcontextprotocol.io Google Cloud Identity accounts can authenticate using OIDC: - -```mermaid -sequenceDiagram - participant Admin as Admin User - participant CLI as Admin CLI - participant GCP as Google Cloud Identity - participant API as Registry API - - Admin->>CLI: Request admin token - CLI->>GCP: gcloud auth print-identity-token --audiences=mcp-registry - GCP-->>CLI: ID Token (with hd: "modelcontextprotocol.io") - CLI->>API: POST /v0/auth/oidc {"oidc_token": "eyJ..."} - API->>GCP: Verify token signature (JWKS) - API->>API: Validate claims (issuer, audience, hd) - API->>API: Grant admin permissions (edit: *, publish: *) - API-->>CLI: Registry JWT Token - CLI->>API: POST /admin/* (with Registry JWT) - API->>API: Validate JWT + permissions - API-->>CLI: Admin operation success -``` - -**Usage:** -```bash -# Get Google Cloud Identity token -ID_TOKEN=$(gcloud auth print-identity-token) - -# Exchange for Registry JWT token -REGISTRY_TOKEN=$(curl -X POST /v0/auth/oidc \ - -H "Content-Type: application/json" \ - -d '{"oidc_token": "'$ID_TOKEN'"}' | jq -r .registry_token) - -# Use for admin operations -curl -H "Authorization: Bearer $REGISTRY_TOKEN" /v0/... -``` - ---- - -## File: docs/guides/README.md - -# How-To Guides - -Problem-oriented guides for specific tasks with the MCP Registry. - -## Publishing Servers - -- [Publish a server](publishing/publish-server.md) -- [GitHub Actions](publishing/github-actions.md) - -## Consuming Registry Data - -- [Use the REST API](consuming/use-rest-api.md) - -## Contributing - -- [Add package registry](contributing/add-package-registry.md) - -## Administration - -- [Admin operations](administration/admin-operations.md) -- [Moderation guidelines](administration/moderation-guidelines.md) - ---- - -## File: docs/guides/administration/admin-operations.md - -# Admin Operations - -This is a brief guide for admins and moderators managing content on the registry. All actions should be taken in line with the [moderation guidelines](moderation-guidelines.md). - -## Prerequisites - -- Admin account with @modelcontextprotocol.io email - - If you are a maintainer and would like an account, ask in the Discord -- `gcloud` CLI installed and configured -- `curl` and `jq` installed - -## Authentication - -```bash -# Run this, then run the export command it outputs -./tools/admin/auth.sh -``` - -## Edit a Server - -Step 1: Download Server - -```bash -export SERVER_ID="" -curl -s "https://registry.modelcontextprotocol.io/v0/servers/${SERVER_ID}" > server.json -``` - -Step 2: Open `server.json` and make changes. You cannot change the server name. - -Step 3: Push Changes - -```bash -curl -X PUT "https://registry.modelcontextprotocol.io/v0/servers/${SERVER_ID}" \ - -H "Authorization: Bearer ${REGISTRY_TOKEN}" \ - -H "Content-Type: application/json" \ - -d "{\"server\": $(cat server.json)}" -``` - -## Takedown a Server - -```bash -export SERVER_ID="" -./tools/admin/takedown.sh -``` - -This soft deletes the server. If you need to delete the content of a server (usually only where legally necessary), use the edit workflow above to scrub it all. - ---- - -## File: docs/guides/administration/moderation-guidelines.md - -# Moderation Guidelines - -Guidelines for server publishers on the Official MCP Registry. - -## TL;DR - -We're quite permissive! We only remove illegal content, malware, spam and completely broken servers. - -We don't make guarantees about our moderation, and subregistries should take our data "as is", assuming minimal to no moderation. - -## Scope - -These guidelines apply to the **Official MCP Registry** at `registry.modelcontextprotocol.io`. - -Subregistries may have their own moderation policies. If you have questions about content on a specific subregistry, please contact them directly. - -## Disclaimer - -We have limited active moderation capabilities, and this is a community supported projects. We largely rely on upstream package registries (like NPM, PyPi, and Docker) or downstream subregistries (like the GitHub MCP Registry) to do more in-depth moderation. - -This means there may be content in the registry that should be removed under these guidelines, which we haven't yet removed. You should treat registry data accordingly. - -## What We Remove - -We'll remove servers that contain: - -- Illegal content, which includes obscene content, copyright violations, and hacking tools -- Malware, regardless of intentions -- Spam, especially mass-created servers that disrupt the registry. Examples: - - The same server being submitted multiple times under different names. - - The server doesn't do anything but provide a fixed response with some marketing copy. - - The server description is stuffed with marketing copy, and its implementation is unrelated to its name or description. -- Non-functioning servers - -## What We Don't Remove - -Generally, we believe in keeping the registry open and pushing moderation to subregistries. We therefore **won't** remove servers that are: - -- Low quality or buggy servers -- Servers with security vulnerabilities -- Do the same thing as other servers -- Provide or contain adult content - -## How Removal Works - -When we remove a server: - -- It's set to "deleted" status but remains accessible via the API -- This allows subregistries to remove it from their indexes -- In extreme cases, we may overwrite or erase details of a server, e.g. where the metadata itself is unlawful - -## Appeals - -Think we made a mistake? Open an issue on our [GitHub repository](https://github.com/modelcontextprotocol/registry) with: -- The ID and name of your server -- Why you believe it doesn't meet the criteria for removal above - -## Changes to this policy - -We're still learning how to best run the MCP registry! As such, we might end up changing this policy in the future. - ---- - -## File: docs/guides/contributing/add-package-registry.md - -# Adding a new package registry - -The MCP Registry project is a **metaregistry**, meaning that it hosts metadata for MCP servers but does not host the code for the servers directly. - -For local MCP servers, the MCP Registry has pointers in the `packages` node of the [`server.json`](../../reference/server-json/generic-server-json.md) schema that refer to packages in supported package managers. - -The list of supported package managers for hosting MCP servers is defined by the `properties.packages[N].properties.registry_type` string enum in the [`server.json` schema](../../reference/server-json/draft/server.schema.json). For example, this could be "npm" (for npmjs.com packages) or "pypi" (for PyPI packages). - -For remote MCP servers, the package registry is not relevant. The MCP client consumes the server via a URL instead of by downloading and running a package. In other words, this document only applies to local MCP servers. - -For the sake of illustration, this document will use npm (the Node.js package manager) as an example at each step. - -## Prerequisites - -The package registry must meet the following requirements: - -1. The package registry supports packaging and executing CLI apps. Local MCP servers use the [stdio transport](https://modelcontextprotocol.io/docs/concepts/transports#standard-input%2Foutput-stdio). - - npm CLI tools typically express their CLI commands in the [`bin` property of the package.json](https://docs.npmjs.com/cli/v11/configuring-npm/package-json#bin) -1. The package registry (or associated client tooling) has a widely accepted **single-shot** CLI command. - - npm's `npx` tool executes CLI commands using a [documented execution heuristic](https://docs.npmjs.com/cli/v11/commands/npx#description) - - For example, the MCP client can map the `server.json` metadata to an `npx` CLI execution, with args and environment variables populated via user input. -1. The package registry supports anonymous package downloads. This allows the MCP client software to use the metadata found in the MCP registry to discover, download, and execute package-based local MCP servers with minimal user intervention. - - `npx` by default connects to the public npmjs.com registry, allowing simple consumption of public npm packages. -1. The package registry should support a validation mechanism to verify ownership of the server name. This prevents misattribution and ensures that only the actual package owner can reference their packages in server registrations. For example: - - npm requires an `mcpName` field in `package.json` that matches the server name being registered - - PyPI requires a `mcp-name:` line in the package README/description - - Each registry type must implement a validation mechanism accessible via public API - -## Steps - -These steps may evolve as additional validations or details are discovered and mandated. - -1. [Create a feature request issue](https://github.com/modelcontextprotocol/registry/issues/new?template=feature_request.md) on the MCP Registry repository to begin the discussion about adding the package registry. - - Example for NuGet: https://github.com/modelcontextprotocol/registry/issues/126 -1. Open a PR with the following changes: - - Update the [`server.json` schema](../../reference/server-json/draft/server.schema.json) - - Add your package registry name to the `registry_type` example array. - - Add your package registry base url to the `registry_base_url` example array. - - Add the single-shot CLI command name to the `runtime_hint` example value array. - - Update the [`openapi.yaml`](../../reference/api/openapi.yaml) - - Add your package registry name to the `registry_type` enum value array. - - Add your package registry base url to the `registry_base_url` enum value array. - - Add the single-shot CLI command name to the `runtime_hint` example value array. - - Add a sample, minimal `server.json` to the [`server.json` examples](../../reference/server-json/generic-server-json.md). - - Implement a registry validator: - - Create a new validator file: `internal/validators/registries/yourregistry.go`, following the pattern of existing validators. Examples: - - **npm**: Checks for an `mcpName` field in `package.json` that matches the server name - - **PyPI**: Searches for `mcp-name: server-name` format in the package README content - - **NuGet**: Looks for `mcp-name: server-name` format in the package README file - - **Docker/OCI**: Validates a Docker image label `io.modelcontextprotocol.server.name` in the image manifest - - Add corresponding unit tests: `internal/validators/registries/yourregistry_test.go` - - Register your validator in `internal/validators/validators.go` - - Update the publishing documentation: - - Add a new publishing guide: `docs/guides/publishing/publish-[yourregistry].md`, following the pattern of existing publishing guides (e.g., `publish-npm.md`, `publish-pypi.md`) - - Include instructions on how to prepare packages for your registry, including any specific validation requirements - - Update `docs/guides/publishing/README.md` to reference your new publishing guide - ---- - -## File: docs/reference/README.md - -# Reference Documentation - -Technical specifications and quick lookups for the MCP Registry. - -## API Reference - -- [Generic Registry API](./api/generic-registry-api.md) -- [Official Registry API](./api/official-registry-api.md) - -## server.json Reference - -- [Generic server.json Format](./server-json/generic-server-json.md) -- [Official Registry Requirements](./server-json/official-registry-requirements.md) - -## CLI Reference - -- [Commands](./cli/commands.md) - -## Quick Reference - -- [FAQ](./faq.md) - ---- - -## File: docs/reference/server-json/official-registry-requirements.md - -# Official Registry Server.json Requirements - -This document describes the additional requirements and validation rules that apply when publishing to the official MCP Registry at `registry.modelcontextprotocol.io`. - -For step-by-step publishing instructions, see the [publishing guide](../../guides/publishing/publish-server.md). - -## Overview - -While the [generic server.json format](./generic-server-json.md) defines the base specification, the official registry enforces additional validation to ensure: - -- **Namespace authentication** - Servers are published under appropriate namespaces -- **Package ownership verification** - Publishers actually control referenced packages -- **Remote server URL match** - Remote server base urls match namespaces -- **Restricted registry base urls** - Packages are from trusted public registries -- **`_meta` namespace restrictions** - Restricted to `publisher` key only - -## Namespace Authentication - -Publishers must prove ownership of their namespace. For example to publish to `com.example/server`, the publisher must prove they own the `example.com` domain. - -See the [publishing guide](../../guides/publishing/publish-server.md) for authentication details for GitHub and domain namespaces. - -## Package Ownership Verification - -All packages must include metadata proving the publisher owns them. This prevents impersonation and ensures authenticity (see more reasoning in [#96](https://github.com/modelcontextprotocol/registry/issues/96)). - -For detailed verification requirements for each registry type, see the [publishing guide](../../guides/publishing/publish-server.md). - -## Remote Server URL Match - -Remote servers must use URLs that match the publisher's domain from their namespace. For example, `com.example/server` can only use remote URLs on `example.com` or its subdomains. - -## Restricted Registry Base URLs - -Only trusted public registries are supported. Private registries and alternative mirrors are not allowed. - -**Supported registries:** -- **NPM**: `https://registry.npmjs.org` only -- **PyPI**: `https://pypi.org` only -- **NuGet**: `https://api.nuget.org/v3/index.json` -- **Docker/OCI**: `https://docker.io` only -- **MCPB**: `https://github.com` releases and `https://gitlab.com` releases only - -## `_meta` Namespace Restrictions - -The `_meta` field is restricted to the `publisher` key only during publishing. This `_meta.publisher` extension is currently limited to 4KB. - -Registry metadata is added automatically and cannot be overridden. - ---- - -## File: docs/terms.md - -# Official MCP Registry Terms - -Effective date: 2025-09-02 - -## Overview - -These terms ("Terms") govern your access to and use of the official MCP Registry (the service hosted at [https://registry.modelcontextprotocol.io/](https://registry.modelcontextprotocol.io/) or a successor location) ("Registry"), including submissions or publications of MCP servers, references to MCP servers or to data about such servers and/or their developers ("Registry Data"), and related conduct. The Registry is intended to be a centralized repository of MCP servers developed by community members to facilitate easy access by AI applications. - -These terms are governed by the laws of the State of California. - -## For All Users - -1. No Warranties. The Registry is provided "as is" with no warranties of any kind. That means we don't guarantee the accuracy, completeness, safety, durability, or availability of the Registry, servers included in the registry, or Registry Data. In short, we're also not responsible for any MCP servers or Registry Data, and we highly recommend that you evaluate each MCP server and its suitability for your intended use case(s) before deciding whether to use it. - -2. Access and Use Requirements. To access or use the Registry, you must: - 1. Be at least 18 years old. - 2. Use the Registry, MCP servers in the Registry, and Registry Data only in ways that are legal under the applicable laws of the United States or other countries including the country in which you are a resident or from which you access and use the Registry, and not be barred from accessing or using the Registry under such laws. You will comply with all applicable law, regulation, and third party rights (including, without limitation, laws regarding the import or export of data or software, privacy, intellectual property, and local laws). You will not use the Registry, MCP servers, or Registry Data to encourage or promote illegal activity or the violation of third party rights or terms of service. - 3. Log in via method(s) approved by the Registry maintainers, which may involve using applications or other software owned by third parties. - -3. Entity Use. If you are accessing or using the Registry on behalf of an entity, you represent and warrant that you have authority to bind that entity to these Terms. By accepting these Terms, you are doing so on behalf of that entity (and all references to "you" in these Terms refer to that entity). - -4. Account Information. In order to access or use the Registry, you may be required to provide certain information (such as identification or contact details) as part of a registration process or in connection with your access or use of the Registry or MCP servers therein. Any information you give must be accurate and up-to-date, and you agree to inform us promptly of any updates. You understand that your use of the Registry may be monitored to ensure quality and verify your compliance with these Terms. - -5. Feedback. You are under no obligation to provide feedback or suggestions. If you provide feedback or suggestions about the Registry or the Model Context Protocol, then we (and those we allow) may use such information without obligation to you. - -6. Branding. Only use the term "Official MCP Registry" where it is clear it refers to the Registry, and does not imply affiliation, endorsement, or sponsorship. For example, you can permissibly say "Acme Inc. keeps its data up to date by automatically pulling data from the Official MCP Registry" or "This data comes from the Official MCP Registry," but cannot say "This is the website for the Official MCP Registry," "We're the premier destination to view Official MCP Registry data," or "We've partnered with the Official MCP Registry to provide this data." - -7. Modification. We may modify the Terms or any portion to, for example, reflect changes to the law or changes to the Model Context Protocol. We'll post notice of modifications to the Terms to this website or a successor location. If you do not agree to the modified Terms, you should discontinue your access to and/or use of the Registry. Your continued access to and/or use of the Registry constitutes your acceptance of any modified Terms. - -8. Additional Terms. Depending on your intended use case(s), you must also abide by applicable terms below. - -## For MCP Developers - -9. Prohibitions. By accessing and using the Registry, including by submitting MCP servers and/or Registry Data, you agree not to: - 1. Share malicious or harmful content, such as malware, even in good faith or for research purposes, or perform any action with the intent of introducing any viruses, worms, defects, Trojan horses, malware, or any items of a destructive nature; - 2. Defame, abuse, harass, stalk, or threaten others; - 3. Interfere with or disrupt the Registry or any associated servers or networks; - 4. Submit data with the intent of confusing or misleading others, including but not limited to via spam, posting off-topic marketing content, posting MCP servers in a way that falsely implies affiliation with or endorsement by a third party, or repeatedly posting the same or similar MCP servers under different names; - 5. Promote or facilitate unlawful online gambling or disruptive commercial messages or advertisements; - 6. Use the Registry for any activities where the use or failure of the Registry could lead to death, personal injury, or environmental damage; - 7. Use the Registry to process or store any data that is subject to the International Traffic in Arms Regulations maintained by the U.S. Department of State. - -10. License. You agree that metadata about MCP servers you submit (e.g., schema name and description, URLs, identifiers) and other Registry Data is intended to be public, and will be dedicated to the public domain under [CC0 1.0 Universal](https://creativecommons.org/publicdomain/zero/1.0/). By submitting such data, you agree that you have the legal right to make this dedication (i.e., you own the copyright to these submissions or have permission from the copyright owner(s) to do so) and intend to do so. You understand that this dedication is perpetual, irrevocable, and worldwide, and you waive any moral rights you may have in your contributions to the fullest extent permitted by law. This dedication applies only to Registry Data and not to packages in third party registries that you might point to. - -11. Privacy and Publicity. You understand that any MCP server metadata you publish may be made public. This includes personal data such as your GitHub username, domain name, or details from your server description. Moreover, you understand that others may process personal information included in your MCP server metadata. For example, subregistries might enrich this data by adding how many stars your GitHub repository has, or perform automated security scanning on your code. By publishing a server, you agree that others may engage in this sort of processing, and you waive rights you might have in some jurisdictions to access, rectify, erase, restrict, or object to such processing. - ---- - -## File: docs/guides/contributing/releasing.md - -# Release Guide - -## Creating a Release - -1. **Go to GitHub**: Navigate to https://github.com/modelcontextprotocol/registry/releases -2. **Click "Draft a new release"** -3. **Choose a tag**: Click "Choose a tag" and type a new semantic version that follows the last one available (e.g., `v1.0.0`) -5. **Generate notes**: Click "Generate release notes" to auto-populate the name and description -6. **Publish**: Click "Publish release" - -The release workflow will automatically: -- Build binaries for 6 platforms (Linux, macOS, Windows ร— amd64, arm64) -- Create and push Docker images with `:latest` and `:vX.Y.Z` tags -- Attach all artifacts to the GitHub release -- Generate checksums and signatures - -## After Release - -- Docker images will be available at: - - `ghcr.io/modelcontextprotocol/registry:latest` - Latest stable release - - `ghcr.io/modelcontextprotocol/registry:vX.Y.Z` - Specific release version -- Binaries can be downloaded from the GitHub release page - -## Docker Image Tags - -The registry publishes different Docker image tags for different use cases: - -- **`:latest`** - Latest stable release (updated only on releases) -- **`:vX.Y.Z`** - Specific release versions (e.g., `:v1.0.0`) -- **`:main`** - Rolling tag updated on every push to main branch (continuous deployment) -- **`:main-YYYYMMDD-sha`** - Specific development builds from main branch - -## Versioning - -We use semantic versioning (SemVer): -- `v1.0.0` - Major release with breaking changes -- `v1.1.0` - Minor release with new features -- `v1.0.1` - Patch release with bug fixes - ---- - -## File: docs/reference/api/official-registry-api.md - -# Official MCP Registry API - -This document describes the API for the official MCP Registry hosted at `registry.modelcontextprotocol.io`. - -This API is based on the [generic registry API](./generic-registry-api.md) with additional endpoints and authentication. For practical examples of consuming the API, see the [API usage guide](../../guides/consuming/use-rest-api.md). For publishing servers using the API, see the [publishing guide](../../guides/publishing/publish-server.md). - -## Base URLs - -- **Production**: `https://registry.modelcontextprotocol.io` -- **Staging**: `https://staging.registry.modelcontextprotocol.io` - -## Interactive Documentation - -- **[Live API Docs](https://registry.modelcontextprotocol.io/docs)** - Stoplight elements with try-it-now functionality -- **[OpenAPI Spec](https://registry.modelcontextprotocol.io/openapi.yaml)** - Complete machine-readable specification - -## Extensions - -The official registry implements the [Generic Registry API](./generic-registry-api.md) with the following specific configurations and extensions: - -### Authentication - -Publishing requires namespace-based authentication: - -- **GitHub OAuth** - For `io.github.*` namespaces -- **GitHub OIDC** - For publishing from GitHub Actions -- **DNS verification** - For domain-based namespaces (`com.example.*`) -- **HTTP verification** - For domain-based namespaces (`com.example.*`) - -See [Publisher Commands](../cli/commands.md) for authentication setup. - -### Package Validation - -The official registry enforces additional [package validation requirements](../server-json/official-registry-requirements.md) when publishing. - -### Server List Filtering - -The official registry extends the `GET /v0/servers` endpoint with additional query parameters for improved discovery and synchronization: - -- `updated_since` - Filter servers updated after RFC3339 timestamp (e.g., `2025-08-07T13:15:04.280Z`) -- `search` - Case-insensitive substring search on server names (e.g., `filesystem`) - - This is intentionally simple. For more advanced searching and filtering, use a subregistry. -- `version` - Filter by version (currently supports `latest` for latest versions only) - -These extensions enable efficient incremental synchronization for downstream registries and improved server discovery. Parameters can be combined and work with standard cursor-based pagination. - -Example: `GET /v0/servers?search=filesystem&updated_since=2025-08-01T00:00:00Z&version=latest` - -### Additional endpoints -- POST `/v0/auth/dns` - Exchange signed DNS challenge for auth token -- POST `/v0/auth/http` - Exchange signed HTTP challenge for auth token -- POST `/v0/auth/github-at` - Exchange GitHub access token for auth token -- POST `/v0/auth/github-oidc` - Exchange GitHub OIDC token for auth token -- POST `/v0/auth/oidc` - Exchange Google OIDC token for auth token (for admins) - -#### Admin endpoints -- GET `/metrics` - Prometheus metrics endpoint -- GET `/v0/health` - Basic health check endpoint -- PUT `/v0/servers/{id}` - Edit existing server - ---- - -## File: docs/explanations/namespacing.md - -# Namespacing and Security - -Namespacing prevents name squatting, makes impersonation and typo squatting much harder, and provides attribution through domain-based identity. - -For practical steps on how to authenticate for different namespaces, see the [publishing guide](../guides/publishing/publish-server.md#authenticate). - -## Namespace Format - -All server names follow reverse-DNS format. Examples: -- `io.github.alice/weather-server` - GitHub user `alice` -- `com.acme/internal-tool` - Company domain `acme.com` -- `org.nonprofit.research/data-analyzer` - Subdomain `research.nonprofit.org` - -## Security Model - -### Ownership Verification - -Publishing to a namespace requires proving you control the corresponding identity: - -**GitHub namespaces** (`io.github.*`): -- OAuth login to GitHub account/organization -- OIDC tokens in GitHub Actions workflows - -**Domain namespaces** (`com.company.*`): -- DNS verification: TXT record at `company.com` -- HTTP verification: File at `https://company.com/.well-known/mcp-registry-auth` - -## Namespace Scoping - -Different authentication methods grant different namespace access: - -**GitHub OAuth/OIDC**: -- `io.github.username/*` (for personal accounts) -- `io.github.orgname/*` (for organizations) - -**DNS verification**: -- `com.domain/*` and `com.domain.*/*` (domain + all subdomains) - -**HTTP verification**: -- `com.domain/*` only (exact domain, no subdomains) - -## Limitations - -**Domain ownership changes**: If someone loses/sells a domain, they lose publishing rights. Similarly if someone gains a domain, they gain publishing rights. -**Package validation**: Registry validates namespace ownership, but actual packages may still be malicious etc. - ---- - -## File: docs/explanations/versioning.md - -# Server Versioning Guide - -This document describes the versioning approach for MCP servers published to the registry. - -## Overview - -The MCP Registry supports flexible versioning while encouraging semantic versioning best practices. The registry attempts to parse versions as semantic versions for ordering and comparison, but falls back gracefully for non-semantic versions. - -## Version Requirements - -1. **Version String**: `version` MUST be a string up to 255 characters -2. **Uniqueness**: Each version for a given server name must be unique -3. **Immutability**: Once published, version metadata cannot be changed - -## Best Practices - -### 1. Use Semantic Versioning -Server authors SHOULD use [semantic versions](https://semver.org/) following the `MAJOR.MINOR.PATCH` format: - -```json -{ - "version": "1.2.3" -} -``` - -### 2. Align with Package Versions -Server authors SHOULD use versions aligned with their underlying packages to reduce confusion: - -```json -{ - "version": "1.2.3", - "packages": [{ - "registry_name": "npm", - "name": "@myorg/my-server", - "version": "1.2.3" - }] -} -``` - -### 3. Multiple Registry Versions -If server authors expect to have multiple registry versions for the same package version, they SHOULD follow the semantic version spec using the prerelease label: - -```json -{ - "version": "1.2.3-1", - "packages": [{ - "registry_name": "npm", - "name": "@myorg/my-server", - "version": "1.2.3" - }] -} -``` - -**Note**: According to semantic versioning, `1.2.3-1` is considered lower than `1.2.3`, so if you expect to need a `1.2.3-1`, you should publish that before `1.2.3`. - -## Version Ordering and "Latest" Determination - -### For Semantic Versions -The registry attempts to parse versions as semantic versions. If successful, it uses semantic version comparison rules to determine: -- Version ordering in lists -- Which version is marked as `is_latest` - -### For Non-Semantic Versions -If version parsing as semantic version fails: -- The registry will always mark the version as latest (overriding any previous version) -- Clients should fall back to using publish timestamp for ordering - -**Important Note**: This behavior means that for servers with mixed semantic and non-semantic versions, the `is_latest` flag may not align with the total ordering. A non-semantic version published after semantic versions will be marked as latest, even if semantic versions are considered "higher" in the ordering. - -## Implementation Details - -### Registry Behavior -1. **Validation**: Versions are validated for uniqueness within a server name -2. **Parsing**: The registry attempts to parse each version as semantic version -3. **Comparison**: Uses semantic version rules when possible, falls back to timestamp -4. **Latest Flag**: The `is_latest` field is set based on the comparison results - -### Client Recommendations -Registry clients SHOULD: -1. Attempt to interpret versions as semantic versions when possible -2. Use the following ordering rules: - - If one version is marked as is_latest: it is later - - If both versions are valid semver: use semver comparison - - If neither are valid semver: use publish timestamp - - If one is semver and one is not: semver version is considered higher - -## Examples - -### Valid Semantic Versions -```javascript -"1.0.0" // Basic semantic version -"2.1.3-alpha" // Prerelease version -"1.0.0-beta.1" // Prerelease with numeric suffix -"3.0.0-rc.2" // Release candidate -``` - -### Non-Semantic Versions (Allowed) -```javascript -"v1.0" // Version with prefix -"2021.03.15" // Date-based versioning -``` - -### Not Allowed: Version Ranges -The registry requires specific versions for both the top-level `version` and any `packages[].version`. Version ranges or wildcard versions are rejected during publish, including but not limited to: - -```javascript -"^1.2.3" -"~1.2.3" -">=1.2.3" -"<=1.2.3" -">1.2.3" -"<1.2.3" -"1.x" -"1.2.*" -"1 - 2" -"1.2 || 1.3" -``` - -### Alignment Examples -```json -{ - "version": "1.2.3-1", - "packages": [{ - "registry_name": "npm", - "name": "@myorg/k8s-server", - "version": "1.2.3" - }] -} -``` - -## Migration Path - -Existing servers with non-semantic versions will continue to work without changes. However, to benefit from proper version ordering, server maintainers are encouraged to: - -1. Adopt semantic versioning for new releases -2. Consider the ordering implications when transitioning from non-semantic to semantic versions -3. Use prerelease labels for registry-specific versioning needs - -## Common Scenarios - -### Standard Releases -**Package and server versions aligned**: -```json -{ - "version": "1.2.3", - "packages": [ - { - "registry_type": "npm", - "identifier": "@myorg/server", - "version": "1.2.3" - } - ] -} -``` - -### Registry-Only Updates -**Server metadata changes without package updates**: -```json -{ - "version": "1.2.3-1", - "packages": [ - { - "registry_type": "npm", - "identifier": "@myorg/server", - "version": "1.2.3" - } - ] -} -``` - -Note: `1.2.3-1` is considered lower than `1.2.3` in semver ordering. Publish prerelease versions first. - -### Remote Server Versioning -**Remote servers without package dependencies**: -```json -{ - "version": "2.1.0", - "remotes": [ - { - "transport_type": "sse", - "url": "https://api.myservice.com/mcp/v2.1" - } - ] -} -``` - -Version strategy options: -- **API versioning**: Match your service API version -- **Semantic versioning**: Standard semver for feature changes -- **Date-based**: `2024.03.15` for regular releases - -### Multi-Package Versioning -**Different package versions**: -```json -{ - "version": "1.3.0", - "packages": [ - { - "registry_type": "npm", - "identifier": "@myorg/server", - "version": "1.3.0" - }, - { - "registry_type": "oci", - "identifier": "myorg/server", - "version": "1.2.5" - } - ] -} -``` - -Use server version to indicate the overall release. - -## Decision Guide - -**Which version strategy should I use?** - -``` -Do you have underlying packages? -โ”œโ”€ Yes: Align with package version -โ”‚ โ”œโ”€ Same package version โ†’ Use package version -โ”‚ โ””โ”€ Different package versions โ†’ Use highest + indicate relationship -โ””โ”€ No (remote server): Choose versioning scheme - โ”œโ”€ API versioning โ†’ Match service API version - โ”œโ”€ Feature-based โ†’ Use semantic versioning - โ””โ”€ Regular releases โ†’ Consider date-based versioning -``` - -## Future Considerations - -This versioning approach is designed to be compatible with potential future changes to the MCP specification's `Implementation.version` field. Any SHOULD requirements introduced here may be proposed as updates to the specification through the SEP (Specification Enhancement Proposal) process. - ---- - -## File: docs/guides/consuming/use-rest-api.md - -# Consuming Registry Data via REST API - -Integration patterns and best practices for building applications that consume MCP registry data. - -## Key details - -**Base URL**: `https://registry.modelcontextprotocol.io` - -**Authentication**: Not required for read-only access - -- **`GET /v0/servers`** - List all servers with pagination -- **`GET /v0/servers/{id}`** - Get server details by UUID - -See the [interactive API documentation](https://registry.modelcontextprotocol.io/docs) for complete request/response schemas. - -**Disclaimer**: The official registry provides no uptime or data durability guarantees. You should design your applications to handle service downtime via caching. - -## Building a subregistry -**Create enhanced registries** - ETL official registry data and add your own metadata like ratings, security scans, or compatibility info. - -For now we recommend scraping the `GET /v0/servers` endpoint on some regular basis. In the future we might provide a filter for updated_at ([#291](https://github.com/modelcontextprotocol/registry/issues/291)) to get only recently changed servers. - -Servers are generally immutable, except for the `status` field which can be updated to `deleted` (among other states). For these packages, we recommend you also update the status field to `deleted` or remove the package from your registry quickly. This is because this status generally indicates it has violated our permissive [moderation guidelines](../administration/moderation-guidelines.md), suggesting it is illegal, malware or spam. - -### Filtering & Enhancement - -The official registry has a [permissive moderation policy](../administration/moderation-guidelines.md), so you may want to implement your own filtering on top of registry data. - -You can also add custom metadata to servers using the `_meta` field. For example, user ratings, download counts, or security scan results. If you do this, we recommend you put this under a key that is namespaced to your organization, for example: - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.github.yourname/weather-server", - "description": "MCP server for weather data access", - "status": "active", - "version": "1.0.0", - "packages": [ - { - "registry_type": "npm", - "identifier": "weather-mcp-server", - "version": "1.0.0" - } - ], - "_meta": { - "com.example.subregistry/custom": { - "user_rating": 4.5, - "download_count": 12345, - "security_scan": { - "last_scanned": "2024-06-01T12:00:00Z", - "vulnerabilities_found": 0 - } - } - } -} -``` - -### Providing an API - -We recommend that your subregistry provides an API meeting the registry API specification, so it's easy for clients to switch between registries. See the [registry API documentation](../../reference/api/) for details. - -## MCP Client Integration -**Convert registry data to client configuration** - Fetch servers and transform package information into your MCP client's config format. - -We highly recommend using a subregistry rather than fetching data from the official registry directly. You might want to make this configurable so that users of your client can choose their preferred registry, for example we expect that some enterprise users may have their own registry. - -Your client should gracefully handle registries that meet the minimum spec, i.e. avoid hard dependencies on `_meta` fields. - -### Filtering - -You likely should filter out servers that are not `active` in the `status` field. - -### Running servers - -You can use the `packages` or `remotes` field to determine how to run a server. More details of these fields are in the [server.json documentation](../../reference/server-json/generic-server-json.md). - ---- - -## File: docs/guides/publishing/github-actions.md - -# Automate Publishing with GitHub Actions - -Set up automated MCP server publishing using GitHub Actions. - -## What You'll Learn - -By the end of this tutorial, you'll have: - -- A GitHub Actions workflow that automatically publishes your server -- Understanding of GitHub OIDC authentication -- Knowledge of best practices for automated publishing -- Working examples for Node.js, Python, and Docker projects - -## Prerequisites - -- Understand general publishing requirements like package verification (see the [publishing guide](publish-server.md)) -- GitHub repository with your MCP server code - -## GitHub Actions Setup - -### Step 1: Create Workflow File - -Create `.github/workflows/publish-mcp.yml`. Here's an example for NPM-based packages, but the MCP registry publishing steps are the same for all package types: - -```yaml -name: Publish to MCP Registry - -on: - push: - tags: ["v*"] # Triggers on version tags like v1.0.0 - -jobs: - publish: - runs-on: ubuntu-latest - permissions: - id-token: write # Required for OIDC authentication - contents: read - - steps: - - name: Checkout code - uses: actions/checkout@v5 - - - name: Setup Node.js # Adjust for your language - uses: actions/setup-node@v5 - with: - node-version: "lts/*" - - - name: Install dependencies - run: npm ci - - - name: Run tests - run: npm run test --if-present - - - name: Build package - run: npm run build --if-present - - - name: Publish to npm - run: npm publish - env: - NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }} - - - name: Install MCP Publisher - run: | - curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher - - - name: Login to MCP Registry - run: ./mcp-publisher login github-oidc - - - name: Publish to MCP Registry - run: ./mcp-publisher publish -``` - -### Step 2: Configure Secrets - -You don't need any secrets for publishing to the MCP Registry using GitHub OIDC. - -However you might need to add secrets for your package registry. For example the workflow above needs a `NPM_TOKEN` (which you can add in Settings โ†’ Secrets and variables โ†’ Actions). - -### Step 3: Tag and Release - -Create a version tag to trigger the workflow: - -```bash -git tag v1.0.0 -git push origin v1.0.0 -``` - -The workflow runs tests, builds your package, publishes to npm, and publishes to the MCP Registry. - -## Authentication Methods - -### GitHub Actions OIDC (Recommended) - -```yaml -- name: Login to MCP Registry - run: mcp-publisher login github-oidc -``` - -### GitHub Personal Access Token - -```yaml -- name: Login to MCP Registry - run: mcp-publisher login github --token ${{ secrets.GITHUB_TOKEN }} - env: - GITHUB_TOKEN: ${{ secrets.MCP_GITHUB_TOKEN }} -``` - -Add `MCP_GITHUB_TOKEN` secret with a GitHub PAT that has repo access. - -### DNS Authentication - -For custom domain namespaces (`com.yourcompany/*`): - -```yaml -- name: Login to MCP Registry - run: | - echo "${{ secrets.MCP_PRIVATE_KEY }}" > key.pem - mcp-publisher login dns --domain yourcompany.com --private-key-file key.pem -``` - -Add your Ed25519 private key as `MCP_PRIVATE_KEY` secret. - -## Examples - -See these real-world examples of automated publishing workflows: -- [NPM, Docker and MCPB](https://github.com/domdomegg/airtable-mcp-server) -- [NuGet](https://github.com/domdomegg/time-mcp-nuget) -- [PyPI](https://github.com/domdomegg/time-mcp-pypi) - -## Tips - -You can keep your package version and server.json version in sync automatically with something like: -```yaml -- run: | - VERSION=${GITHUB_REF#refs/tags/v} - jq --arg v "$VERSION" '.version = $v' server.json > tmp && mv tmp server.json -``` - -## Troubleshooting -- **"Authentication failed"**: Ensure `id-token: write` permission is set for OIDC, or check secrets -- **"Package validation failed"**: Verify your package published to your registry (NPM, PyPi etc.) successfully first, and that you have done the necessary validation steps in the [Publishing Tutorial](publish-server.md) - ---- - -## File: docs/guides/publishing/publish-server.md - -# Publish Your MCP Server - -Complete guide to publishing an MCP server to the registry. - -> [!TIP] -> Using an agentic AI coding assistant? Just use this prompt: -> ``` -> Read https://raw.githubusercontent.com/modelcontextprotocol/registry/refs/heads/main/docs/guides/publishing/publish-server.md and https://raw.githubusercontent.com/modelcontextprotocol/registry/refs/heads/main/docs/guides/publishing/github-actions.md. Evaluate the best way to publish this server to the registry (prefer automated CI flows over manual flows where possible), and implement that. If possible, validate the server.json against the $schema before telling the user you are done, using a proper json schema library or tool available on the user's machine. If you get stuck, guide the user through the parts of the publishing process they need to do (e.g. logging into the publisher CLI if doing manual pubishing). -> ``` - -## What You'll Learn - -By the end of this tutorial, you'll have: -- Created a server.json file for your MCP server -- Authenticated with the registry -- Successfully published your server -- Verified your server appears in the registry - -## Prerequisites - -- An MCP server you've already built ([follow this guide if you don't have one already](https://modelcontextprotocol.io/quickstart/server)) - -## Deployment Options - -You can make your MCP server available in multiple ways: - -- **๐Ÿ“ฆ Package deployment**: Published to registries (npm, PyPI, Docker Hub, etc.) and run locally by clients -- **๐ŸŒ Remote deployment**: Hosted as a web service that clients connect to directly -- **๐Ÿ”„ Hybrid deployment**: Offer both package and remote options for maximum flexibility - -Learn more about [MCP server architecture](https://modelcontextprotocol.io/docs/concepts/servers) in the official docs. - -## Step 1: Install the Publisher CLI - -
-๐Ÿบ macOS/Linux/WSL: With Homebrew (recommended) - -Requires [Homebrew](https://brew.sh): - -```bash -brew install mcp-publisher -``` - -
- -
-โฌ‡๏ธ macOS/Linux/WSL: Pre-built binaries - -```bash -curl -L "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_$(uname -s | tr '[:upper:]' '[:lower:]')_$(uname -m | sed 's/x86_64/amd64/;s/aarch64/arm64/').tar.gz" | tar xz mcp-publisher && sudo mv mcp-publisher /usr/local/bin/ -``` - -
- -
-๐Ÿ—๏ธ macOS/Linux/WSL: From source - -Requires Git, Make and Go 1.24+: - -```bash -# Clone the registry repository -git clone https://github.com/modelcontextprotocol/registry -cd registry -make publisher - -# The binary will be at bin/mcp-publisher -export PATH=$PATH:$(pwd)/bin -``` - -
- -
-๐ŸชŸ Windows PowerShell: Pre-built binaries - -```powershell -$arch = if ([System.Runtime.InteropServices.RuntimeInformation]::ProcessArchitecture -eq "Arm64") { "arm64" } else { "amd64" }; Invoke-WebRequest -Uri "https://github.com/modelcontextprotocol/registry/releases/latest/download/mcp-publisher_windows_$arch.tar.gz" -OutFile "mcp-publisher.tar.gz"; tar xf mcp-publisher.tar.gz mcp-publisher.exe; rm mcp-publisher.tar.gz -# Move mcp-publisher.exe to a directory in your PATH -``` - -
- -## Step 2: Initialize Your server.json - -Navigate to your server's directory and create a template: - -```bash -cd /path/to/your/mcp-server -mcp-publisher init -``` - -This creates a `server.json` with auto-detected values. You'll see something like: - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.github.yourname/your-server", - "description": "A description of your MCP server", - "version": "1.0.0", - "packages": [ - { - "registry_type": "npm", - "identifier": "your-package-name", - "version": "1.0.0" - } - ] -} -``` - -## Step 3: Configure Your Server Details - -Edit the generated `server.json`: - -### Choose Your Namespace - -The `name` field determines authentication requirements: - -- **`io.github.yourname/*`** - Requires GitHub authentication -- **`com.yourcompany/*`** - Requires DNS or HTTP domain verification - -### Configure Deployment Methods - -Configure your server to support packages, remotes, or both: - -#### Package Deployment - -Add package validation metadata to prove ownership of your packages. - - -
-๐Ÿ“ฆ NPM Packages - -### Requirements -Add an `mcpName` field to your `package.json`: - -```json -{ - "name": "your-npm-package", - "version": "1.0.0", - "mcpName": "io.github.username/server-name" -} -``` - -### How It Works -- Registry fetches `https://registry.npmjs.org/your-npm-package` -- Checks that `mcpName` field matches your server name -- Fails if field is missing or doesn't match - -### Example server.json -```json -{ - "name": "io.github.username/server-name", - "packages": [ - { - "registry_type": "npm", - "identifier": "your-npm-package", - "version": "1.0.0" - } - ] -} -``` - -The official MCP registry currently only supports the NPM public registry (`https://registry.npmjs.org`). - -
- -
-๐Ÿ PyPI Packages - -### Requirements -Include your server name in your package README file using this format: - -**MCP name format**: `mcp-name: io.github.username/server-name` - -Add it to your README.md file (which becomes the package description on PyPI). This can be in a comment if you want to hide it from display elsewhere. - -### How It Works -- Registry fetches `https://pypi.org/pypi/your-package/json` -- Passes if `mcp-name: server-name` is in the README content - -### Example server.json -```json -{ - "name": "io.github.username/server-name", - "packages": [ - { - "registry_type": "pypi", - "identifier": "your-pypi-package", - "version": "1.0.0" - } - ] -} -``` - -The official MCP registry currently only supports the official PyPI registry (`https://pypi.org`). - -
- -
-๐Ÿ“‹ NuGet Packages - -### Requirements -Include your server name in your package's README using this format: - -**MCP name format**: `mcp-name: io.github.username/server-name` - -Add a README file to your NuGet package that includes the server name. This can be in a comment if you want to hide it from display elsewhere. - -### How It Works -- Registry fetches and cached service index `https://api.nuget.org/v3/index.json` -- Registry uses `ReadmeUriTemplate/6.13.0` URL template in service index to fetch README -- Passes if `mcp-name: server-name` is found in the README content - -### Example server.json -```json -{ - "name": "io.github.username/server-name", - "packages": [ - { - "registry_type": "nuget", - "identifier": "Your.NuGet.Package", - "version": "1.0.0" - } - ] -} -``` - -The official MCP registry currently only supports the official NuGet registry (`https://api.nuget.org/v3/index.json`). - -
- -
-๐Ÿณ Docker/OCI Images - -### Requirements -Add an annotation to your Docker image: - -```dockerfile -LABEL io.modelcontextprotocol.server.name="io.github.username/server-name" -``` - -### How It Works -- Registry authenticates with Docker Hub using public token -- Fetches image manifest using Docker Registry v2 API -- Checks that `io.modelcontextprotocol.server.name` annotation matches your server name -- Fails if annotation is missing or doesn't match - -### Example server.json -```json -{ - "name": "io.github.username/server-name", - "packages": [ - { - "registry_type": "oci", - "identifier": "yourusername/your-mcp-server", - "version": "1.0.0" - } - ] -} -``` - -The identifier is `namespace/repository`, and version is the tag and optionally digest. - -The official MCP registry currently only supports the official Docker registry (`https://docker.io`). - -
- -
-๐Ÿ“ MCPB Packages - -### Requirements -**MCP reference** - MCPB package URLs must contain "mcp" somewhere within them, to ensure the correct artifact has been uploaded. This may be with the `.mcpb` extension or in the name of your repository. - -**File integrity** - MCPB packages must include a SHA-256 hash for file integrity verification. This is required at publish time and MCP clients will validate this hash before installation. - -### How to Generate File Hashes -Calculate the SHA-256 hash of your MCPB file: - -```bash -openssl dgst -sha256 server.mcpb -``` - -### Example server.json -```json -{ - "name": "io.github.username/server-name", - "packages": [ - { - "registry_type": "mcpb", - "identifier": "https://github.com/you/your-repo/releases/download/v1.0.0/server.mcpb", - "file_sha256": "fe333e598595000ae021bd27117db32ec69af6987f507ba7a63c90638ff633ce" - } - ] -} -``` - -### File Hash Validation -- **Authors** are responsible for generating correct SHA-256 hashes when creating server.json -- **MCP clients** validate the hash before installing packages to ensure file integrity -- **The official registry** stores hashes but does not validate them -- **Subregistries** may choose to implement their own validation. This enables them to perform security scanning on MCPB files, and ensure clients get the same security scanned content. - -The official MCP registry currently only supports artifacts hosted on GitHub or GitLab releases. - -
- -#### Remote Deployment - -Add the `remotes` field to your `server.json` (can coexist with `packages`): - -
-๐ŸŒ Remote Server Configuration - -### Requirements - -- **Service endpoint**: Your MCP server must be accessible at the specified URL -- **Transport protocol**: Choose from `sse` (Server-Sent Events) or `streamable-http` -- **URL validation**: For domain namespaces only (see URL requirements below) - -### Example server.json - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "com.yourcompany/api-server", - "description": "Cloud-hosted MCP server for API operations", - "version": "2.0.0", - "remotes": [ - { - "type": "sse", - "url": "https://mcp.yourcompany.com/sse" - } - ] -} -``` - -### Multiple Transport Options - -You can offer multiple connection methods: - -```json -{ - "remotes": [ - { - "type": "sse", - "url": "https://mcp.yourcompany.com/sse" - }, - { - "type": "streamable-http", - "url": "https://mcp.yourcompany.com/http" - } - ] -} -``` - -### URL Validation Requirements - -- For `com.yourcompany/*` namespaces: URLs must be on `yourcompany.com` or its subdomains -- For `io.github.username/*` namespaces: No URL restrictions (but you must authenticate via GitHub) - -### Authentication Headers (Optional) - -Configure headers that clients should send when connecting: - -```json -{ - "remotes": [ - { - "type": "sse", - "url": "https://mcp.yourcompany.com/sse", - "headers": [ - { - "name": "X-API-Key", - "description": "API key for authentication", - "is_required": true, - "is_secret": true - } - ] - } - ] -} -``` - -
- -## Step 4: Authenticate - -Choose your authentication method based on your namespace: - -### GitHub Authentication (for io.github.* namespaces) - -```bash -mcp-publisher login github -``` - -This opens your browser for OAuth authentication. - -### DNS Authentication (for custom domains) - -```bash -# Generate keypair -openssl genpkey -algorithm Ed25519 -out key.pem - -# Get public key for DNS record -echo "yourcompany.com. IN TXT \"v=MCPv1; k=ed25519; p=$(openssl pkey -in key.pem -pubout -outform DER | tail -c 32 | base64)\"" - -# Add the TXT record to your DNS, then login -mcp-publisher login dns --domain yourcompany.com --private-key $(openssl pkey -in key.pem -noout -text | grep -A3 "priv:" | tail -n +2 | tr -d ' :\n') -``` - -## Step 5: Publish Your Server - -With authentication complete, publish your server: - -```bash -mcp-publisher publish -``` - -You'll see output like: -``` -โœ“ Successfully published -``` - -## Step 6: Verify Publication - -Check that your server appears in the registry by searching for it: - -```bash -curl "https://registry.modelcontextprotocol.io/v0/servers?search=io.github.yourname/weather-server" -``` - -You should see your server metadata returned in the JSON response. - -## Troubleshooting - -**"Package validation failed"** - Ensure your package includes the required validation metadata (mcpName field, README mention, or Docker label). - -**"Authentication failed"** - Verify you've correctly set up DNS records or are logged into the right GitHub account. - -**"Namespace not authorized"** - Your authentication method doesn't match your chosen namespace format. - -## Examples - -See these real-world examples of published servers: -- [NPM, Docker and MCPB example](https://github.com/domdomegg/airtable-mcp-server) -- [NuGet example](https://github.com/domdomegg/time-mcp-nuget) -- [PyPI example](https://github.com/domdomegg/time-mcp-pypi) - -## Next Steps - -- **Update your server**: Publish new versions with updated server.json files -- **Set up CI/CD**: Automate publishing with [GitHub Actions](github-actions.md) -- **Learn more**: Understand [server.json format](../../reference/server-json/generic-server-json.md) in depth -- **More examples**: See [remote server configurations](../../reference/server-json/generic-server-json.md#remote-server-example) and [hybrid deployments](../../reference/server-json/generic-server-json.md#server-with-remote-and-package-options) in the schema documentation - -## What You've Accomplished - -You've successfully published your first MCP server to the registry! Your server is now discoverable by MCP clients and can be installed by users worldwide. - ---- - -## File: docs/reference/api/generic-registry-api.md - -# Generic Registry API Specification - -A standardized RESTful HTTP API for MCP registries to provide consistent endpoints for discovering and retrieving MCP servers. - -Also see: -- For guidance consuming the API, see the [consuming guide](../../guides/consuming/use-rest-api.md). - -## Browse the Complete API Specification - -**๐Ÿ“‹ View the full API specification interactively**: Open [openapi.yaml](./openapi.yaml) in an OpenAPI viewer like [Stoplight Elements](https://elements-demo.stoplight.io/?spec=https://raw.githubusercontent.com/modelcontextprotocol/registry/refs/heads/main/docs/reference/api/openapi.yaml). - -The official registry has some more endpoints and restrictions on top of this. See the [official registry API spec](./official-registry-api.md) for details. - -## Quick Reference - -### Core Endpoints -- **`GET /v0/servers`** - List all servers with pagination -- **`GET /v0/servers/{id}`** - Get server details by UUID -- **`POST /v0/publish`** - Publish new server (optional, registry-specific authentication) - -### Authentication -- **Read operations**: No authentication required -- **Write operations**: Registry-specific authentication (if supported) - -### Content Type -All requests and responses use `application/json` - -### Basic Example: List Servers - -```bash -curl https://registry.example.com/v0/servers?limit=10 -``` - -```json -{ - "servers": [ - { - "name": "io.modelcontextprotocol/filesystem", - "description": "Filesystem operations server", - "status": "active", - "version": "1.0.2" - } - ], - "metadata": { - "count": 10, - "next_cursor": "eyJ..." - } -} -``` - -For complete endpoint documentation, view the OpenAPI specification in a schema viewer. - ---- - -## File: docs/reference/cli/commands.md - -# Publisher CLI Commands Reference - -Complete command reference for the `mcp-publisher` CLI tool. - -See the [publishing guide](../../guides/publishing/publish-server.md) for a walkthrough of using the CLI to publish a server. - -## Installation - -Install via Homebrew (macOS/Linux): - -```bash -$ brew install mcp-publisher -``` - -## Global Options - -All commands support: -- `--help`, `-h` - Show command help -- `--registry` - Registry URL (default: `https://registry.modelcontextprotocol.io`) - -## Commands - -### `mcp-publisher init` - -Generate a `server.json` template with automatic detection. - -**Usage:** -```bash -mcp-publisher init [options] -``` - -**Behavior:** -- Creates `server.json` in current directory -- Auto-detects package managers (`package.json`, `setup.py`, etc.) -- Pre-fills fields where possible -- Prompts for missing required fields - -**Example output:** -```json -{ - "name": "io.github.username/server-name", - "description": "TODO: Add server description", - "version": "1.0.0", - "packages": [ - { - "registry_type": "npm", - "identifier": "detected-package-name", - "version": "1.0.0" - } - ] -} -``` - -### `mcp-publisher login ` - -Authenticate with the registry. - -**Authentication Methods:** - -#### GitHub Interactive -```bash -mcp-publisher login github [--registry=URL] -``` -- Opens browser for GitHub OAuth flow -- Grants access to `io.github.{username}/*` and `io.github.{org}/*` namespaces - -#### GitHub OIDC (CI/CD) -```bash -mcp-publisher login github-oidc [--registry=URL] -``` -- Uses GitHub Actions OIDC tokens automatically -- Requires `id-token: write` permission in workflow -- No browser interaction needed - -Also see [the guide to publishing from GitHub Actions](../../guides/publishing/github-actions.md). - -#### DNS Verification -```bash -mcp-publisher login dns --domain=example.com --private-key=HEX_KEY [--registry=URL] -``` -- Verifies domain ownership via DNS TXT record -- Grants access to `com.example.*` namespaces -- Requires Ed25519 private key (64-character hex) - -**Setup:** -```bash -# Generate keypair -openssl genpkey -algorithm Ed25519 -out key.pem - -# Get public key for DNS record -openssl pkey -in key.pem -pubout -outform DER | tail -c 32 | base64 - -# Add DNS TXT record: -# example.com. IN TXT "v=MCPv1; k=ed25519; p=PUBLIC_KEY" - -# Extract private key for login -openssl pkey -in key.pem -noout -text | grep -A3 "priv:" | tail -n +2 | tr -d ' :\n' -``` - -#### HTTP Verification -```bash -mcp-publisher login http --domain=example.com --private-key=HEX_KEY [--registry=URL] -``` -- Verifies domain ownership via HTTPS endpoint -- Grants access to `com.example.*` namespaces -- Requires Ed25519 private key (64-character hex) - -**Setup:** -```bash -# Generate keypair (same as DNS) -openssl genpkey -algorithm Ed25519 -out key.pem - -# Host public key at: -# https://example.com/.well-known/mcp-registry-auth -# Content: v=MCPv1; k=ed25519; p=PUBLIC_KEY -``` - -#### Anonymous (Testing) -```bash -mcp-publisher login none [--registry=URL] -``` -- No authentication - for local testing only -- Only works with local registry instances - -### `mcp-publisher publish` - -Publish server to the registry. - -For detailed guidance on the publishing process, see the [publishing guide](../../guides/publishing/publish-server.md). - -**Usage:** -```bash -mcp-publisher publish [options] -``` - -**Options:** -- `--file=PATH` - Path to server.json (default: `./server.json`) -- `--registry=URL` - Registry URL override -- `--dry-run` - Validate without publishing - -**Process:** -1. Validates `server.json` against schema -2. Verifies package ownership (see [Official Registry Requirements](../server-json/official-registry-requirements.md)) -3. Checks namespace authentication -4. Publishes to registry - -**Example:** -```bash -# Basic publish -mcp-publisher publish - -# Dry run validation -mcp-publisher publish --dry-run - -# Custom file location -mcp-publisher publish --file=./config/server.json -``` - -### `mcp-publisher logout` - -Clear stored authentication credentials. - -**Usage:** -```bash -mcp-publisher logout -``` - -**Behavior:** -- Removes `~/.config/mcp-publisher/token.json` -- Also cleans up legacy token files (`~/.mcp_publisher_token`, `.mcpregistry_*`) -- Does not revoke tokens on server side - -## Configuration - -### Token Storage -Authentication tokens are stored in `~/.config/mcp-publisher/token.json` as JSON: -```json -{ - "token": "jwt-token-here", - "method": "github", - "registry": "https://registry.modelcontextprotocol.io" -} -``` - -> **Note:** Tokens were previously stored in `~/.mcp_publisher_token`. If you are upgrading, run `mcp-publisher logout` followed by `mcp-publisher login` to migrate to the new location. - ---- - -## File: docs/reference/faq.md - -# MCP Registry FAQ - -These questions come up often in discussions about the MCP Registry. If you have a question that isn't answered here, please start a discussion on the [MCP Registry Discussions page](https://github.com/modelcontextprotocol/registry/discussions). - -## General Questions - -### What is the MCP Registry? - -The MCP Registry is the official centralized metadata repository for publicly-accessible MCP servers. It provides: - -- A single place for server creators to publish metadata about their servers -- A REST API for MCP clients and aggregators to discover available servers -- Standardized installation and configuration information -- Namespace management through DNS verification - -### What is the difference between "Official MCP Registry", "MCP Registry", "MCP registry", "MCP Registry API", etc? - -There are four underlying concepts: -- "MCP Server Registry API" (or "MCP Registry API"): The OpenAPI specification defined in [openapi.yaml](./api/openapi.yaml). This is a reusable API specification that anyone building any sort of "MCP server registry" should consider adopting / aligning with. -- "Official MCP Registry" (or "MCP Registry"): The application that lives at `https://registry.modelcontextprotocol.io`. This registry currently only catalogs MCP servers, but may be extended in the future to also catalog MCP client/host apps and frameworks. -- "Official MCP Registry API": The REST API served at `https://registry.modelcontextprotocol.io`, which is a superset of the MCP Registry API. Its OpenAPI specification can be downloaded from [https://registry.modelcontextprotocol.io/openapi.yaml](https://registry.modelcontextprotocol.io/openapi.yaml) -- "MCP server registry" (or "MCP registry"): A third party, likely commercial, implementation of the MCP Server Registry API or derivative specification. - -### Is the MCP Registry a package registry? - -No. The MCP Registry stores metadata about MCP servers and references to where they're hosted (npm, PyPI, NuGet, Docker Hub, etc.), but does not host the actual source code or packages. - -### Who should use the MCP Registry directly? - -The registry is primarily designed for programmatic consumption by subregistries (Smithery, PulseMCP, Docker Hub, Anthropic, GitHub, etc.). It is NOT currently intended for individual clients or end-users (they should use subregistries). - -### Will there be feature X? - -See [roadmap.md](../explanations/roadmap.md). - -## Publishing Servers - -### How do I publish my MCP server? - -See the [publisher README](../../cmd/publisher/README.md) - -### What namespaces are available? - -- **With GitHub verification**: `io.github.yourusername/server-name`, `io.github.yourorg/server-name` -- **With DNS verification**: `com.yourcompany.*`, `com.yourcompany.*/*` -- **With HTTP verification**: `com.yourcompany/*` - -### Is open source required? - -No. While open source code is encouraged, it is not required for either locally or remotely run servers. - -### What package registries are supported? - -- npm (Node.js packages) -- PyPI (Python packages) -- NuGet.org (.NET packages) -- GitHub Container Registry (GHCR) -- Docker Hub - -More can be added as the community desires; feel free to open an issue if you are interested in building support for another registry. - -### Can I publish multiple versions? - -Yes, versioning is supported: - -- Each version gets its own immutable metadata -- Version strings must be unique for each server -- Old versions remain accessible for compatibility -- The registry tracks which version is "latest" based on semantic version ordering when possible - -### How do I update my server metadata? - -Submit a new `server.json` with a unique version string. Once published, version metadata is immutable (similar to npm). - -### What version format should I use? - -The registry accepts any version string up to 255 characters, but we recommend: - -- **SHOULD use semantic versioning** (e.g., "1.0.2", "2.1.0-alpha") for predictable ordering -- **SHOULD align with package versions** to reduce confusion -- **MAY use prerelease labels** (e.g., "1.0.0-1") for registry-specific versions - -The registry attempts to parse versions as semantic versions for proper ordering. Non-semantic versions are allowed but will be ordered by publication timestamp. Version ranges (e.g., `^1.2.3`, `~1.2.3`, `>=1.2.3`, `1.x`, `1.*`) are rejected; publish a specific version instead. See the [versioning guide](../explanations/versioning.md) for detailed guidance. - -### Can I add custom metadata when publishing? - -Yes, extensions under the `x-publisher` property are preserved when publishing to the registry. This allows you to include custom metadata specific to your publishing process. - -### Can I delete/unpublish my server? - -At time of last update, this was open for discussion in [#104](https://github.com/modelcontextprotocol/registry/issues/104). - -### Can I publish a private server? - -Private servers are those that are only accessible to a narrow set of users. For example, servers published on a private network (like `mcp.acme-corp.internal`) or on private package registries (e.g. `npx -y @acme/mcp --registry https://artifactory.acme-corp.internal/npm`). - -These are generally not supported on the official MCP registry, which is designed for publicly accessible MCP servers. - -If you want to publish private servers we recommend you host your own MCP subregistry, and add them there. - -## Security & Trust - -### How do I know a server is from the claimed organization? - -DNS verification ensures namespace ownership. For example: - -- `com.microsoft/server` requires DNS verification of microsoft.com -- `io.github.name/server` is tied to a GitHub account or GitHub organization `name` - -### Is there security scanning? - -The MVP delegates security scanning to: -- underlying package registries; and -- subregistries - -### How is spam prevented? - -- Namespace authentication requirements -- Character limits and regex validation on free-form fields -- Manual takedown of spam or malicious servers - -In future we might explore: -- Stricter rate limiting (e.g., 10 new servers per user per day) -- Potential AI-based spam detection -- Community reporting and admin blacklisting capabilities - -## API & Integration - -### How often should I poll the registry? - -Recommended polling frequency: - -- `/servers` endpoint: once per hour -- `/servers/:id` endpoint: once per version (results are immutable) -- Design assumes CDN caching between registry and consumers - -Also see [#291](https://github.com/modelcontextprotocol/registry/issues/291), which might mean the above can be more regular. - -### Will there be webhooks? - -Not in the initial MVP, but the architecture supports adding webhooks for update notifications in the future. - -### Can I run my own registry instance? - -Yes! The API shapes and data formats are intentionally designed for reuse by subregistries. Organizations needing private registries should: - -- Implement the same API shape -- Use the same `server.json` format -- Potentially mirror/filter the official registry data - -### Can I extend the registry API? - -Yes, we support `x-com.example` style extensions in a bunch of places - see the official MCP registry API spec. This can be used to add annotations to many objects, e.g. add security scanning details, enrich package metadata, etc. - -If you have a use case that can't be addressed here, raise a GitHub issue! - -### Can I use the code here to run my own registry instance? - -The registry implementation here is not designed for self-hosting, but you're welcome to try to use it/fork it as necessary. Note that this is not an intended use, and the registry maintainers cannot provide any support for this at this time. - -## Operations & Maintenance - -### What's the expected reliability? - -- This is a community maintained project without full time staffing. You should therefore expect downtime periods of up to 1 business day. No strict guarantees are provided. (Also see discussion in [#150](https://github.com/modelcontextprotocol/registry/issues/150)) -- Ideally clients should use subregistries with higher availability guarantees, to avoid direct end-user impact (as subregistries can cache data). - -### What if I need to report a spam or malicious server? - -1. Report it as abuse to the underlying package registry (e.g. NPM, PyPi, DockerHub, etc.); and -2. Raise a GitHub issue on the registry repo with a title beginning `Abuse report: ` - -### What if I need to report a security vulnerability in the registry itself? - -Follow [the MCP community SECURITY.md](https://github.com/modelcontextprotocol/.github/blob/main/SECURITY.md). - ---- - -## File: docs/reference/server-json/generic-server-json.md - -# server.json Format Specification - -A `server.json` file is a standardized way to describe MCP servers for registry publishing, client discovery, and package management. - -Also see: -- For step-by-step instructions on creating and using server.json files, see the [publishing guide](../../guides/publishing/publish-server.md). -- For understanding the validation requirements when publishing to the official registry, see [official registry requirements](./official-registry-requirements.md). - -## Browse the Complete Schema - -**๐Ÿ“‹ View the full specification interactively**: Open [server.schema.json](./server.schema.json) in a schema viewer like [json-schema.app](https://json-schema.app/view/%23?url=https%3A%2F%2Fstatic.modelcontextprotocol.io%2Fschemas%2F2025-07-09%2Fserver.schema.json). - -The schema contains all field definitions, validation rules, examples, and detailed descriptions. - -The official registry has some more restrictions on top of this. See the [official registry requirements](./official-registry-requirements.md) for details. - -## Examples - - - -### Basic Server with NPM Package - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.modelcontextprotocol.anonymous/brave-search", - "description": "MCP server for Brave Search API integration", - "status": "active", - "website_url": "https://anonymous.modelcontextprotocol.io/examples", - "repository": { - "url": "https://github.com/modelcontextprotocol/servers", - "source": "github" - }, - "version": "1.0.2", - "packages": [ - { - "registry_type": "npm", - "registry_base_url": "https://registry.npmjs.org", - "identifier": "@modelcontextprotocol/server-brave-search", - "version": "1.0.2", - "transport": { - "type": "stdio" - }, - "environment_variables": [ - { - "name": "BRAVE_API_KEY", - "description": "Brave Search API Key", - "is_required": true, - "is_secret": true - } - ] - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "npm-publisher", - "version": "1.0.1", - "build_info": { - "timestamp": "2023-12-01T10:30:00Z" - } - } - } -} -``` - -### Server in a Monorepo with Subfolder - -For MCP servers located within a subdirectory of a larger repository (monorepo structure), use the `subfolder` field to specify the relative path: - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.modelcontextprotocol/everything", - "description": "MCP server that exercises all the features of the MCP protocol", - "status": "active", - "repository": { - "url": "https://github.com/modelcontextprotocol/servers", - "source": "github", - "subfolder": "src/everything" - }, - "version": "0.6.2", - "packages": [ - { - "registry_type": "npm", - "registry_base_url": "https://registry.npmjs.org", - "identifier": "@modelcontextprotocol/everything", - "version": "0.6.2", - "transport": { - "type": "stdio" - } - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "npm-publisher", - "version": "1.0.1", - "build_info": { - "timestamp": "2023-12-01T10:30:00Z" - } - } - } -} -``` - -### Constant (fixed) arguments needed to start the MCP server - -Suppose your MCP server application requires a `mcp start` CLI arguments to start in MCP server mode. Express these as positional arguments like this: - -```json -{ - "name": "io.github.joelverhagen/knapcode-samplemcpserver", - "description": "Sample NuGet MCP server for a random number and random weather", - "version": "0.4.0-beta", - "packages": [ - { - "registry_type": "nuget", - "registry_base_url": "https://api.nuget.org/v3/index.json", - "identifier": "Knapcode.SampleMcpServer", - "version": "0.4.0-beta", - "transport": { - "type": "stdio" - }, - "package_arguments": [ - { - "type": "positional", - "value": "mcp" - }, - { - "type": "positional", - "value": "start" - } - ] - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "nuget-publisher", - "version": "2.1.0", - "build_info": { - "timestamp": "2023-11-15T14:22:00Z", - "pipeline_id": "nuget-build-456" - } - } - } -} -``` - -This will essentially instruct the MCP client to execute `dnx Knapcode.SampleMcpServer@0.4.0-beta -- mcp start` instead of the default `dnx Knapcode.SampleMcpServer@0.4.0-beta` (when no `package_arguments` are provided). - -### Filesystem Server with Multiple Packages - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.github.modelcontextprotocol/filesystem", - "description": "Node.js server implementing Model Context Protocol (MCP) for filesystem operations.", - "status": "active", - "repository": { - "url": "https://github.com/modelcontextprotocol/servers", - "source": "github", - "id": "b94b5f7e-c7c6-d760-2c78-a5e9b8a5b8c9" - }, - "version": "1.0.2", - "packages": [ - { - "registry_type": "npm", - "registry_base_url": "https://registry.npmjs.org", - "identifier": "@modelcontextprotocol/server-filesystem", - "version": "1.0.2", - "transport": { - "type": "stdio" - }, - "package_arguments": [ - { - "type": "positional", - "value_hint": "target_dir", - "description": "Path to access", - "default": "/Users/username/Desktop", - "is_required": true, - "is_repeated": true - } - ], - "environment_variables": [ - { - "name": "LOG_LEVEL", - "description": "Logging level (debug, info, warn, error)", - "default": "info" - } - ] - }, - { - "registry_type": "oci", - "registry_base_url": "https://docker.io", - "identifier": "mcp/filesystem", - "version": "1.0.2", - "transport": { - "type": "stdio" - }, - "runtime_arguments": [ - { - "type": "named", - "description": "Mount a volume into the container", - "name": "--mount", - "value": "type=bind,src={source_path},dst={target_path}", - "is_required": true, - "is_repeated": true, - "variables": { - "source_path": { - "description": "Source path on host", - "format": "filepath", - "is_required": true - }, - "target_path": { - "description": "Path to mount in the container. It should be rooted in `/project` directory.", - "is_required": true, - "default": "/project" - } - } - } - ], - "package_arguments": [ - { - "type": "positional", - "value_hint": "target_dir", - "value": "/project" - } - ], - "environment_variables": [ - { - "name": "LOG_LEVEL", - "description": "Logging level (debug, info, warn, error)", - "default": "info" - } - ] - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "ci-publisher", - "version": "3.2.1", - "build_info": { - "commit": "a1b2c3d4e5f6789", - "timestamp": "2023-12-01T10:30:00Z", - "pipeline_id": "filesystem-build-789", - "environment": "production" - } - } - } -} -``` - -### Remote Server Example - -```json -{ - "name": "io.modelcontextprotocol.anonymous/mcp-fs", - "description": "Cloud-hosted MCP filesystem server", - "repository": { - "url": "https://github.com/example/remote-fs", - "source": "github", - "id": "xyz789ab-cdef-0123-4567-890ghijklmno" - }, - "version": "2.0.0", - "remotes": [ - { - "type": "sse", - "url": "http://mcp-fs.anonymous.modelcontextprotocol.io/sse" - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "cloud-deployer", - "version": "2.4.0", - "build_info": { - "commit": "f7e8d9c2b1a0", - "timestamp": "2023-12-05T08:45:00Z", - "deployment_id": "remote-fs-deploy-456", - "region": "us-west-2" - } - } - } -} -``` - -### Python Package Example - -```json -{ - "name": "io.github.example/weather-mcp", - "description": "Python MCP server for weather data access", - "repository": { - "url": "https://github.com/example/weather-mcp", - "source": "github", - "id": "def456gh-ijkl-7890-mnop-qrstuvwxyz12" - }, - "version": "0.5.0", - "packages": [ - { - "registry_type": "pypi", - "registry_base_url": "https://pypi.org", - "identifier": "weather-mcp-server", - "version": "0.5.0", - "runtime_hint": "uvx", - "transport": { - "type": "stdio" - }, - "environment_variables": [ - { - "name": "WEATHER_API_KEY", - "description": "API key for weather service", - "is_required": true, - "is_secret": true - }, - { - "name": "WEATHER_UNITS", - "description": "Temperature units (celsius, fahrenheit)", - "default": "celsius" - } - ] - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "poetry-publisher", - "version": "1.8.3", - "build_info": { - "python_version": "3.11.5", - "timestamp": "2023-11-28T16:20:00Z", - "build_id": "pypi-weather-123", - "dependencies_hash": "sha256:a9b8c7d6e5f4" - } - } - } -} -``` - -### NuGet (.NET) Package Example - -The `dnx` tool ships with the .NET 10 SDK, starting with Preview 6. - -```json -{ - "name": "io.github.joelverhagen/knapcode-samplemcpserver", - "description": "Sample NuGet MCP server for a random number and random weather", - "repository": { - "url": "https://github.com/joelverhagen/Knapcode.SampleMcpServer", - "source": "github", - "id": "example-nuget-id-0000-1111-222222222222" - }, - "version": "0.5.0", - "packages": [ - { - "registry_type": "nuget", - "registry_base_url": "https://api.nuget.org/v3/index.json", - "identifier": "Knapcode.SampleMcpServer", - "version": "0.5.0", - "runtime_hint": "dnx", - "transport": { - "type": "stdio" - }, - "environment_variables": [ - { - "name": "WEATHER_CHOICES", - "description": "Comma separated list of weather descriptions to randomly select.", - "is_required": true, - "is_secret": false - } - ] - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "dotnet-publisher", - "version": "8.0.100", - "build_info": { - "dotnet_version": "8.0.0", - "timestamp": "2023-12-10T12:15:00Z", - "configuration": "Release", - "target_framework": "net8.0", - "build_number": "20231210.1" - } - } - } -} -``` - -### Complex Docker Server with Multiple Arguments - -```json -{ - "name": "io.github.example/database-manager", - "description": "MCP server for database operations with support for multiple database types", - "repository": { - "url": "https://github.com/example/database-manager-mcp", - "source": "github", - "id": "ghi789jk-lmno-1234-pqrs-tuvwxyz56789" - }, - "version": "3.1.0", - "packages": [ - { - "registry_type": "oci", - "registry_base_url": "https://docker.io", - "identifier": "example/database-manager-mcp", - "version": "3.1.0", - "transport": { - "type": "stdio" - }, - "runtime_arguments": [ - { - "type": "named", - "name": "--network", - "value": "host", - "description": "Use host network mode" - }, - { - "type": "named", - "name": "-e", - "value": "DB_TYPE={db_type}", - "description": "Database type to connect to", - "is_repeated": true, - "variables": { - "db_type": { - "description": "Type of database", - "choices": [ - "postgres", - "mysql", - "mongodb", - "redis" - ], - "is_required": true - } - } - } - ], - "package_arguments": [ - { - "type": "named", - "name": "--host", - "description": "Database host", - "default": "localhost", - "is_required": true - }, - { - "type": "named", - "name": "--port", - "description": "Database port", - "format": "number" - }, - { - "type": "positional", - "value_hint": "database_name", - "description": "Name of the database to connect to", - "is_required": true - } - ], - "environment_variables": [ - { - "name": "DB_USERNAME", - "description": "Database username", - "is_required": true - }, - { - "name": "DB_PASSWORD", - "description": "Database password", - "is_required": true, - "is_secret": true - }, - { - "name": "SSL_MODE", - "description": "SSL connection mode", - "default": "prefer", - "choices": [ - "disable", - "prefer", - "require" - ] - } - ] - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "docker-buildx", - "version": "0.12.1", - "build_info": { - "docker_version": "24.0.7", - "timestamp": "2023-12-08T14:30:00Z", - "platform": "linux/amd64,linux/arm64", - "registry": "docker.io", - "image_digest": "sha256:1a2b3c4d5e6f7890" - } - } - } -} -``` - -### Server with Remote and Package Options - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.modelcontextprotocol.anonymous/hybrid-mcp", - "description": "MCP server available as both local package and remote service", - "repository": { - "url": "https://github.com/example/hybrid-mcp", - "source": "github", - "id": "klm012no-pqrs-3456-tuvw-xyz789abcdef" - }, - "version": "1.5.0", - "packages": [ - { - "registry_type": "npm", - "registry_base_url": "https://registry.npmjs.org", - "identifier": "@example/hybrid-mcp-server", - "version": "1.5.0", - "runtime_hint": "npx", - "transport": { - "type": "stdio" - }, - "package_arguments": [ - { - "type": "named", - "name": "--mode", - "description": "Operation mode", - "default": "local", - "choices": [ - "local", - "cached", - "proxy" - ] - } - ] - } - ], - "remotes": [ - { - "type": "sse", - "url": "https://mcp.anonymous.modelcontextprotocol.io/sse", - "headers": [ - { - "name": "X-API-Key", - "description": "API key for authentication", - "is_required": true, - "is_secret": true - }, - { - "name": "X-Region", - "description": "Service region", - "default": "us-east-1", - "choices": [ - "us-east-1", - "eu-west-1", - "ap-southeast-1" - ] - } - ] - }, - { - "type": "streamable-http", - "url": "https://mcp.anonymous.modelcontextprotocol.io/http" - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "hybrid-deployer", - "version": "1.7.2", - "build_info": { - "timestamp": "2023-12-03T11:00:00Z", - "deployment_strategy": "blue-green", - "npm_version": "10.2.4", - "node_version": "20.10.0", - "service_endpoints": { - "sse": "deployed", - "streamable": "deployed" - } - } - } - } -} -``` - -### MCP Bundle (MCPB) Package Example - -```json -{ - "name": "io.modelcontextprotocol/text-editor", - "description": "MCP Bundle server for advanced text editing capabilities", - "repository": { - "url": "https://github.com/modelcontextprotocol/text-editor-mcpb", - "source": "github" - }, - "version": "1.0.2", - "packages": [ - { - "registry_type": "mcpb", - "registry_base_url": "https://github.com", - "identifier": "https://github.com/modelcontextprotocol/text-editor-mcpb/releases/download/v1.0.2/text-editor.mcpb", - "version": "1.0.2", - "file_sha256": "fe333e598595000ae021bd27117db32ec69af6987f507ba7a63c90638ff633ce", - "transport": { - "type": "stdio" - } - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "mcpb-publisher", - "version": "1.0.0", - "build_info": { - "timestamp": "2023-12-02T09:15:00Z", - "bundle_format": "mcpb-v1" - } - } - } -} -``` - -This example shows an MCPB (MCP Bundle) package that: -- Is hosted on GitHub Releases (an allowlisted provider) -- Includes a SHA-256 hash for integrity verification -- Can be downloaded and executed directly by MCP clients that support MCPB - -### Embedded MCP inside a CLI tool - -Some CLI tools bundle an MCP server, without a standalone MCP package or a public repository. In these cases, reuse the existing `packages` shape by pointing at the host CLI package and supplying the `package_arguments` and `runtime_hint` if needed to start the MCP server. - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.snyk/cli-mcp", - "description": "MCP server provided by the Snyk CLI", - "status": "active", - "version": "1.1298.0", - "packages": [ - { - "registry_type": "npm", - "registry_base_url": "https://registry.npmjs.org", - "identifier": "snyk", - "version": "1.1298.0", - "transport": { - "type": "stdio" - }, - "package_arguments": [ - { "type": "positional", "value": "mcp" }, - { - "type": "named", - "name": "-t", - "description": "Transport type for MCP server", - "default": "stdio", - "choices": ["stdio", "sse"] - } - ] - } - ] -} -``` - -### Server with Custom Installation Path - -For MCP servers that follow a custom installation path or are embedded in applications without standalone packages, use the `website_url` field to direct users to setup documentation: - -```json -{ - "$schema": "https://static.modelcontextprotocol.io/schemas/2025-07-09/server.schema.json", - "name": "io.modelcontextprotocol.anonymous/embedded-mcp", - "description": "MCP server embedded in a Desktop app", - "status": "active", - "website_url": "https://anonymous.modelcontextprotocol.io/embedded-mcp-guide", - "version": "0.1.0" -} -``` - -### Deprecated Server Example - -```json -{ - "name": "io.github.example/old-weather", - "description": "Legacy weather server - DEPRECATED: Use weather-v2 instead for new projects", - "status": "deprecated", - "repository": { - "url": "https://github.com/example/old-weather", - "source": "github", - "id": "legacy-abc123-def456-789012-345678-901234567890" - }, - "version": "0.9.5", - "packages": [ - { - "registry_type": "npm", - "registry_base_url": "https://registry.npmjs.org", - "identifier": "@legacy/old-weather-server", - "version": "0.9.5", - "transport": { - "type": "stdio" - }, - "environment_variables": [ - { - "name": "WEATHER_API_KEY", - "description": "Weather API key", - "is_required": true, - "is_secret": true - } - ] - } - ], - "_meta": { - "io.modelcontextprotocol.registry/publisher-provided": { - "tool": "legacy-publisher", - "version": "0.8.1", - "build_info": { - "timestamp": "2023-06-15T09:30:00Z", - "deprecation_notice": "This publisher is deprecated. Use npm-publisher v2.0+ for new projects.", - "maintenance_mode": true, - "final_version": true - } - } - } -} -``` \ No newline at end of file diff --git a/deploy/Pulumi.gcpProd.yaml b/deploy/Pulumi.gcpProd.yaml index 0aac0d7..6645551 100644 --- a/deploy/Pulumi.gcpProd.yaml +++ b/deploy/Pulumi.gcpProd.yaml @@ -1,7 +1,7 @@ config: mcp-registry:environment: prod mcp-registry:provider: gcp - mcp-registry:imageTag: 1.5.0 # Set specific image tag for production (change this to deploy different versions) + mcp-registry:imageTag: 1.8.1 # Set specific image tag for production (change this to deploy different versions) gcp:project: mcp-registry-prod mcp-registry:githubClientId: Iv23liUydBbI7Z2Q9bOZ mcp-registry:githubClientSecret: diff --git a/deploy/README.md b/deploy/README.md index 3125d61..7b407e7 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -65,8 +65,20 @@ Pre-requisites: 1. Create a project: `gcloud projects create mcp-registry-prod` 2. Set the project: `gcloud config set project mcp-registry-prod` -3. Enable required APIs: `gcloud services enable storage.googleapis.com && gcloud services enable container.googleapis.com` -4. Create a service account with necessary permissions, and get the key: +3. Enable the bootstrap APIs needed before Pulumi can run. The remaining APIs + (`cloudresourcemanager`, `compute`, `container`, `logging`, `monitoring`) are + adopted as Pulumi-managed `projects.Service` resources by `ensureRequiredAPIs` + in `pkg/providers/gcp/provider.go`, so they self-heal against drift but still + need to be reachable on the very first deploy: + ```bash + gcloud services enable storage.googleapis.com # for the Pulumi state bucket below + gcloud services enable cloudresourcemanager.googleapis.com # for the IAM bindings Pulumi creates + gcloud services enable container.googleapis.com # for the GKE cluster + ``` +4. Create the Pulumi service account and grant it the roles required to manage + the deploy. `projectIamAdmin` is needed because the deploy creates IAM bindings + on the project (for the default compute SA). The other four are general + resource management: ```bash gcloud iam service-accounts create pulumi-svc sleep 10 @@ -74,6 +86,7 @@ Pre-requisites: gcloud projects add-iam-policy-binding mcp-registry-prod --member="serviceAccount:pulumi-svc@mcp-registry-prod.iam.gserviceaccount.com" --role="roles/compute.admin" gcloud projects add-iam-policy-binding mcp-registry-prod --member="serviceAccount:pulumi-svc@mcp-registry-prod.iam.gserviceaccount.com" --role="roles/storage.admin" gcloud projects add-iam-policy-binding mcp-registry-prod --member="serviceAccount:pulumi-svc@mcp-registry-prod.iam.gserviceaccount.com" --role="roles/storage.hmacKeyAdmin" + gcloud projects add-iam-policy-binding mcp-registry-prod --member="serviceAccount:pulumi-svc@mcp-registry-prod.iam.gserviceaccount.com" --role="roles/resourcemanager.projectIamAdmin" gcloud iam service-accounts add-iam-policy-binding $(gcloud projects describe mcp-registry-prod --format="value(projectNumber)")-compute@developer.gserviceaccount.com --member="serviceAccount:pulumi-svc@mcp-registry-prod.iam.gserviceaccount.com" --role="roles/iam.serviceAccountUser" gcloud iam service-accounts keys create sa-key.json --iam-account=pulumi-svc@mcp-registry-prod.iam.gserviceaccount.com ``` @@ -134,15 +147,20 @@ Pre-requisites: ## Configuration +Configuration keys are namespaced. Set them with `pulumi config set [--secret]`. + | Parameter | Description | Required | |-----------|-------------|----------| -| `environment` | Deployment environment (local/staging/prod) | Yes | -| `provider` | Kubernetes provider (local/gcp) | No (default: local) | -| `githubClientId` | GitHub OAuth Client ID | Yes | -| `githubClientSecret` | GitHub OAuth Client Secret | Yes | -| `imageTag` | Docker image tag for production environment | Yes (prod only) | -| `gcpProjectId` | GCP Project ID (required when provider=gcp) | No | -| `gcpRegion` | GCP Region (default: us-central1) | No | +| `mcp-registry:environment` | Deployment environment (local/staging/prod) | Yes | +| `mcp-registry:provider` | Kubernetes provider (local/gcp) | No (default: local) | +| `mcp-registry:githubClientId` | GitHub OAuth Client ID | Yes | +| `mcp-registry:githubClientSecret` | GitHub OAuth Client Secret | Yes (secret) | +| `mcp-registry:jwtPrivateKey` | Ed25519 seed used to sign registry JWTs | Yes (secret) | +| `mcp-registry:googleOauthClientSecret` | Google OAuth client secret for Grafana login | Yes (secret) | +| `mcp-registry:imageTag` | Docker image tag for production environment | Yes (prod only) | +| `gcp:project` | GCP Project ID | Yes when `provider=gcp` | +| `gcp:region` | GCP Region | No (default: us-central1) | +| `gcp:credentials` | GCP service account credentials JSON | No (secret; set in staging/prod) | ## Database Backups diff --git a/deploy/go.mod b/deploy/go.mod index 07de0a8..031069c 100644 --- a/deploy/go.mod +++ b/deploy/go.mod @@ -1,65 +1,65 @@ module github.com/modelcontextprotocol/registry/deploy/infra -go 1.26 +go 1.26.6 require ( github.com/pulumi/pulumi-gcp/sdk/v8 v8.41.1 - github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.28.0 - github.com/pulumi/pulumi/sdk/v3 v3.230.0 + github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.34.0 + github.com/pulumi/pulumi/sdk/v3 v3.261.0 gopkg.in/yaml.v2 v2.4.0 ) require ( - dario.cat/mergo v1.0.0 // indirect + github.com/BurntSushi/toml v1.6.0 // indirect github.com/Microsoft/go-winio v0.6.2 // indirect - github.com/ProtonMail/go-crypto v1.1.6 // indirect + github.com/ProtonMail/go-crypto v1.4.1 // indirect github.com/agext/levenshtein v1.2.3 // indirect - github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect github.com/apparentlymart/go-textseg/v15 v15.0.0 // indirect - github.com/atotto/clipboard v0.1.4 // indirect github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect github.com/blang/semver v3.5.1+incompatible // indirect github.com/cenkalti/backoff/v5 v5.0.3 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/charmbracelet/bubbles v1.0.0 // indirect github.com/charmbracelet/bubbletea v1.3.10 // indirect - github.com/charmbracelet/colorprofile v0.4.2 // indirect + github.com/charmbracelet/colorprofile v0.4.3 // indirect github.com/charmbracelet/lipgloss v1.1.0 // indirect - github.com/charmbracelet/x/ansi v0.11.6 // indirect + github.com/charmbracelet/x/ansi v0.11.8 // indirect github.com/charmbracelet/x/cellbuf v0.0.15 // indirect github.com/charmbracelet/x/term v0.2.2 // indirect - github.com/cheggaaa/pb v1.0.29 // indirect github.com/clipperhouse/displaywidth v0.11.0 // indirect github.com/clipperhouse/uax29/v2 v2.7.0 // indirect github.com/cloudflare/circl v1.6.3 // indirect - github.com/cyphar/filepath-securejoin v0.4.1 // indirect + github.com/danieljoos/wincred v1.2.3 // indirect + github.com/deckarep/golang-set/v2 v2.5.0 // indirect github.com/djherbis/times v1.5.0 // indirect + github.com/ebitengine/purego v0.10.2 // indirect github.com/emirpasic/gods v1.18.1 // indirect github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f // indirect - github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 // indirect - github.com/go-git/go-billy/v5 v5.8.0 // indirect - github.com/go-git/go-git/v5 v5.17.2 // indirect - github.com/go-logr/logr v1.4.3 // indirect + github.com/go-git/gcfg/v2 v2.0.2 // indirect + github.com/go-git/go-billy/v6 v6.0.0-alpha.2 // indirect + github.com/go-git/go-git/v6 v6.0.0-alpha.5 // indirect + github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect + github.com/godbus/dbus/v5 v5.2.2 // indirect github.com/gogo/protobuf v1.3.2 // indirect github.com/golang/glog v1.2.5 // indirect - github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect + github.com/google/go-tpm v0.9.8 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 // indirect + github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 // indirect github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 // indirect github.com/hashicorp/errwrap v1.1.0 // indirect github.com/hashicorp/go-multierror v1.1.1 // indirect - github.com/hashicorp/go-version v1.8.0 // indirect - github.com/hashicorp/hcl/v2 v2.22.0 // indirect + github.com/hashicorp/go-version v1.9.0 // indirect + github.com/hashicorp/hcl/v2 v2.24.0 // indirect github.com/inconshreveable/mousetrap v1.1.0 // indirect - github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 // indirect github.com/json-iterator/go v1.1.12 // indirect - github.com/kevinburke/ssh_config v1.2.0 // indirect - github.com/klauspost/compress v1.18.0 // indirect - github.com/lucasb-eyer/go-colorful v1.3.0 // indirect - github.com/mattn/go-isatty v0.0.20 // indirect + github.com/kevinburke/ssh_config v1.6.0 // indirect + github.com/klauspost/compress v1.18.7 // indirect + github.com/klauspost/cpuid/v2 v2.3.0 // indirect + github.com/lucasb-eyer/go-colorful v1.4.1 // indirect + github.com/mattn/go-isatty v0.0.24 // indirect github.com/mattn/go-localereader v0.0.1 // indirect - github.com/mattn/go-runewidth v0.0.20 // indirect + github.com/mattn/go-runewidth v0.0.28 // indirect github.com/mitchellh/go-ps v1.0.0 // indirect github.com/mitchellh/go-wordwrap v1.0.1 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -70,52 +70,52 @@ require ( github.com/opentracing/basictracer-go v1.1.0 // indirect github.com/opentracing/opentracing-go v1.2.0 // indirect github.com/pgavlin/fx v0.1.6 // indirect - github.com/pjbgf/sha1cd v0.3.2 // indirect + github.com/pgavlin/fx/v2 v2.0.12 // indirect + github.com/pjbgf/sha1cd v0.6.0 // indirect github.com/pkg/errors v0.9.1 // indirect github.com/pkg/term v1.1.0 // indirect github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 // indirect - github.com/pulumi/esc v0.17.0 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/rogpeppe/go-internal v1.14.1 // indirect github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 // indirect github.com/sergi/go-diff v1.4.0 // indirect - github.com/skeema/knownhosts v1.3.1 // indirect github.com/spf13/cast v1.4.1 // indirect github.com/spf13/cobra v1.10.2 // indirect github.com/spf13/pflag v1.0.10 // indirect - github.com/stretchr/objx v0.2.0 // indirect github.com/texttheater/golang-levenshtein v1.0.1 // indirect github.com/uber/jaeger-client-go v2.30.0+incompatible // indirect github.com/uber/jaeger-lib v2.4.1+incompatible // indirect - github.com/xanzy/ssh-agent v0.3.3 // indirect - github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect - github.com/zclconf/go-cty v1.13.2 // indirect + github.com/xo/terminfo v1.0.0 // indirect + github.com/zalando/go-keyring v0.2.8 // indirect + github.com/zclconf/go-cty v1.16.3 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.opentelemetry.io/collector/featuregate v1.53.0 // indirect - go.opentelemetry.io/collector/pdata v1.53.0 // indirect - go.opentelemetry.io/otel v1.43.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.41.0 // indirect - go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.41.0 // indirect - go.opentelemetry.io/otel/metric v1.43.0 // indirect - go.opentelemetry.io/otel/sdk v1.43.0 // indirect - go.opentelemetry.io/otel/trace v1.43.0 // indirect - go.opentelemetry.io/proto/otlp v1.9.0 // indirect + go.opentelemetry.io/collector/featuregate v1.65.0 // indirect + go.opentelemetry.io/collector/pdata v1.65.0 // indirect + go.opentelemetry.io/contrib/bridges/otelslog v0.20.0 // indirect + go.opentelemetry.io/otel v1.45.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.21.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 // indirect + go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0 // indirect + go.opentelemetry.io/otel/log v0.21.0 // indirect + go.opentelemetry.io/otel/metric v1.45.0 // indirect + go.opentelemetry.io/otel/sdk v1.45.0 // indirect + go.opentelemetry.io/otel/sdk/log v0.21.0 // indirect + go.opentelemetry.io/otel/trace v1.45.0 // indirect + go.opentelemetry.io/proto/otlp v1.11.0 // indirect go.uber.org/atomic v1.11.0 // indirect go.uber.org/multierr v1.11.0 // indirect - golang.org/x/crypto v0.48.0 // indirect - golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 // indirect - golang.org/x/mod v0.32.0 // indirect - golang.org/x/net v0.51.0 // indirect - golang.org/x/sync v0.19.0 // indirect - golang.org/x/sys v0.42.0 // indirect - golang.org/x/term v0.40.0 // indirect - golang.org/x/text v0.34.0 // indirect - golang.org/x/tools v0.41.0 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect - google.golang.org/grpc v1.80.0 // indirect - google.golang.org/protobuf v1.36.11 // indirect - gopkg.in/warnings.v0 v0.1.2 // indirect + golang.org/x/crypto v0.55.0 // indirect + golang.org/x/mod v0.38.0 // indirect + golang.org/x/net v0.58.0 // indirect + golang.org/x/sync v0.22.0 // indirect + golang.org/x/sys v0.47.0 // indirect + golang.org/x/term v0.45.0 // indirect + golang.org/x/text v0.41.0 // indirect + golang.org/x/tools v0.48.0 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 // indirect + google.golang.org/grpc v1.83.2 // indirect + google.golang.org/protobuf v1.36.12 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect lukechampine.com/frand v1.5.1 // indirect ) diff --git a/deploy/go.sum b/deploy/go.sum index 418aa21..14ce36c 100644 --- a/deploy/go.sum +++ b/deploy/go.sum @@ -1,24 +1,19 @@ -dario.cat/mergo v1.0.0 h1:AGCNq9Evsj31mOgNPcLyXc+4PNABt905YmuqPYYpBWk= -dario.cat/mergo v1.0.0/go.mod h1:uNxQE+84aUszobStD9th8a29P2fMDhsBdgRYvZOxGmk= +github.com/BurntSushi/toml v1.6.0 h1:dRaEfpa2VI55EwlIW72hMRHdWouJeRF7TPYhI+AUQjk= +github.com/BurntSushi/toml v1.6.0/go.mod h1:ukJfTF/6rtPPRCnwkur4qwRxa8vTRFBF0uk2lLoLwho= github.com/HdrHistogram/hdrhistogram-go v1.1.2 h1:5IcZpTvzydCQeHzK4Ef/D5rrSqwxob0t8PQPMybUNFM= github.com/HdrHistogram/hdrhistogram-go v1.1.2/go.mod h1:yDgFjdqOqDEKOvasDdhWNXYg9BVp4O+o5f6V/ehm6Oo= -github.com/Microsoft/go-winio v0.5.2/go.mod h1:WpS1mjBmmwHBEWmogvA2mj8546UReBk4v8QkMxJ6pZY= github.com/Microsoft/go-winio v0.6.2 h1:F2VQgta7ecxGYO8k3ZZz3RS8fVIXVxONVUPlNERoyfY= github.com/Microsoft/go-winio v0.6.2/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= -github.com/ProtonMail/go-crypto v1.1.6 h1:ZcV+Ropw6Qn0AX9brlQLAUXfqLBc7Bl+f/DmNxpLfdw= -github.com/ProtonMail/go-crypto v1.1.6/go.mod h1:rA3QumHc/FZ8pAHreoekgiAbzpNsfQAosU5td4SnOrE= +github.com/ProtonMail/go-crypto v1.4.1 h1:9RfcZHqEQUvP8RzecWEUafnZVtEvrBVL9BiF67IQOfM= +github.com/ProtonMail/go-crypto v1.4.1/go.mod h1:e1OaTyu5SYVrO9gKOEhTc+5UcXtTUa+P3uLudwcgPqo= github.com/agext/levenshtein v1.2.3 h1:YB2fHEn0UJagG8T1rrWknE3ZQzWM06O8AMAatNn7lmo= github.com/agext/levenshtein v1.2.3/go.mod h1:JEDfjyjHDjOF/1e4FlBE/PkbqA9OfWu2ki2W0IB5558= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be h1:9AeTilPcZAjCFIImctFaOjnTIavg87rW78vTPkQqLI8= github.com/anmitsu/go-shlex v0.0.0-20200514113438-38f4b401e2be/go.mod h1:ySMOLuWl6zY27l47sB3qLNK6tF2fkHG55UZxx8oIVo4= -github.com/apparentlymart/go-textseg/v13 v13.0.0 h1:Y+KvPE1NYz0xl601PVImeQfFyEy6iT90AvPUL1NNfNw= -github.com/apparentlymart/go-textseg/v13 v13.0.0/go.mod h1:ZK2fH7c4NqDTLtiYLvIkEghdlcqw7yxLeM89kiTRPUo= github.com/apparentlymart/go-textseg/v15 v15.0.0 h1:uYvfpb3DyLSCGWnctWKGj857c6ew1u1fNQOlOtuGxQY= github.com/apparentlymart/go-textseg/v15 v15.0.0/go.mod h1:K8XmNZdhEBkdlyDdvbmmsvpAG721bKi0joRfFdHIWJ4= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5 h1:0CwZNZbxp69SHPdPJAN/hZIm0C4OItdklCFmMRWYpio= github.com/armon/go-socks5 v0.0.0-20160902184237-e75332964ef5/go.mod h1:wHh0iHkYZB8zMSxRWpUBQtwG5a7fFgvEO+odwuTv2gs= -github.com/atotto/clipboard v0.1.4 h1:EH0zSVneZPSuFR11BlR9YppQTVDbh5+16AmcJi4g1z4= -github.com/atotto/clipboard v0.1.4/go.mod h1:ZY9tmq7sm5xIbd9bOK4onWV4S6X0u6GY7Vn0Yu86PYI= github.com/aymanbagabas/go-osc52/v2 v2.0.1 h1:HwpRHbFMcZLEVr42D4p7XBqjyuxQH5SMiErDT4WkJ2k= github.com/aymanbagabas/go-osc52/v2 v2.0.1/go.mod h1:uYgXzlJ7ZpABp8OJ+exZzJJhRNQ2ASbcXHWsFqH8hp8= github.com/blang/semver v3.5.1+incompatible h1:cQNTCjp13qL8KC3Nbxr/y2Bqb63oX6wdnnjpJbkM4JQ= @@ -31,18 +26,16 @@ github.com/charmbracelet/bubbles v1.0.0 h1:12J8/ak/uCZEMQ6KU7pcfwceyjLlWsDLAxB5f github.com/charmbracelet/bubbles v1.0.0/go.mod h1:9d/Zd5GdnauMI5ivUIVisuEm3ave1XwXtD1ckyV6r3E= github.com/charmbracelet/bubbletea v1.3.10 h1:otUDHWMMzQSB0Pkc87rm691KZ3SWa4KUlvF9nRvCICw= github.com/charmbracelet/bubbletea v1.3.10/go.mod h1:ORQfo0fk8U+po9VaNvnV95UPWA1BitP1E0N6xJPlHr4= -github.com/charmbracelet/colorprofile v0.4.2 h1:BdSNuMjRbotnxHSfxy+PCSa4xAmz7szw70ktAtWRYrY= -github.com/charmbracelet/colorprofile v0.4.2/go.mod h1:0rTi81QpwDElInthtrQ6Ni7cG0sDtwAd4C4le060fT8= +github.com/charmbracelet/colorprofile v0.4.3 h1:QPa1IWkYI+AOB+fE+mg/5/4HRMZcaXex9t5KX76i20Q= +github.com/charmbracelet/colorprofile v0.4.3/go.mod h1:/zT4BhpD5aGFpqQQqw7a+VtHCzu+zrQtt1zhMt9mR4Q= github.com/charmbracelet/lipgloss v1.1.0 h1:vYXsiLHVkK7fp74RkV7b2kq9+zDLoEU4MZoFqR/noCY= github.com/charmbracelet/lipgloss v1.1.0/go.mod h1:/6Q8FR2o+kj8rz4Dq0zQc3vYf7X+B0binUUBwA0aL30= -github.com/charmbracelet/x/ansi v0.11.6 h1:GhV21SiDz/45W9AnV2R61xZMRri5NlLnl6CVF7ihZW8= -github.com/charmbracelet/x/ansi v0.11.6/go.mod h1:2JNYLgQUsyqaiLovhU2Rv/pb8r6ydXKS3NIttu3VGZQ= +github.com/charmbracelet/x/ansi v0.11.8 h1:JMFwp0CgDC2+jcOB162HH5k7I3FVbgFSMMYg7dSPBQQ= +github.com/charmbracelet/x/ansi v0.11.8/go.mod h1:ZNN+3mXny/516oTQPLMPIBeSINvNJJQ8uQXDgbeJxY0= github.com/charmbracelet/x/cellbuf v0.0.15 h1:ur3pZy0o6z/R7EylET877CBxaiE1Sp1GMxoFPAIztPI= github.com/charmbracelet/x/cellbuf v0.0.15/go.mod h1:J1YVbR7MUuEGIFPCaaZ96KDl5NoS0DAWkskup+mOY+Q= github.com/charmbracelet/x/term v0.2.2 h1:xVRT/S2ZcKdhhOuSP4t5cLi5o+JxklsoEObBSgfgZRk= github.com/charmbracelet/x/term v0.2.2/go.mod h1:kF8CY5RddLWrsgVwpw4kAa6TESp6EB5y3uxGLeCqzAI= -github.com/cheggaaa/pb v1.0.29 h1:FckUN5ngEk2LpvuG0fw1GEFx6LtyY2pWI/Z2QgCnEYo= -github.com/cheggaaa/pb v1.0.29/go.mod h1:W40334L7FMC5JKWldsTWbdGjLo0RxUKK73K+TuPxX30= github.com/clipperhouse/displaywidth v0.11.0 h1:lBc6kY44VFw+TDx4I8opi/EtL9m20WSEFgwIwO+UVM8= github.com/clipperhouse/displaywidth v0.11.0/go.mod h1:bkrFNkf81G8HyVqmKGxsPufD3JhNl3dSqnGhOoSD/o0= github.com/clipperhouse/uax29/v2 v2.7.0 h1:+gs4oBZ2gPfVrKPthwbMzWZDaAFPGYK72F0NJv2v7Vk= @@ -50,53 +43,57 @@ github.com/clipperhouse/uax29/v2 v2.7.0/go.mod h1:EFJ2TJMRUaplDxHKj1qAEhCtQPW2tJ github.com/cloudflare/circl v1.6.3 h1:9GPOhQGF9MCYUeXyMYlqTR6a5gTrgR/fBLXvUgtVcg8= github.com/cloudflare/circl v1.6.3/go.mod h1:2eXP6Qfat4O/Yhh8BznvKnJ+uzEoTQ6jVKJRn81BiS4= github.com/cpuguy83/go-md2man/v2 v2.0.6/go.mod h1:oOW0eioCTA6cOiMLiUPZOpcVxMig6NIQQ7OS05n1F4g= -github.com/cyphar/filepath-securejoin v0.4.1 h1:JyxxyPEaktOD+GAnqIqTf9A8tHyAG22rowi7HkoSU1s= -github.com/cyphar/filepath-securejoin v0.4.1/go.mod h1:Sdj7gXlvMcPZsbhwhQ33GguGLDGQL7h7bg04C/+u9jI= +github.com/danieljoos/wincred v1.2.3 h1:v7dZC2x32Ut3nEfRH+vhoZGvN72+dQ/snVXo/vMFLdQ= +github.com/danieljoos/wincred v1.2.3/go.mod h1:6qqX0WNrS4RzPZ1tnroDzq9kY3fu1KwE7MRLQK4X0bs= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= +github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/deckarep/golang-set/v2 v2.5.0 h1:hn6cEZtQ0h3J8kFrHR/NrzyOoTnjgW1+FmNJzQ7y/sA= +github.com/deckarep/golang-set/v2 v2.5.0/go.mod h1:VAky9rY/yGXJOLEDv3OMci+7wtDpOF4IN+y82NBOac4= github.com/djherbis/times v1.5.0 h1:79myA211VwPhFTqUk8xehWrsEO+zcIZj0zT8mXPVARU= github.com/djherbis/times v1.5.0/go.mod h1:5q7FDLvbNg1L/KaBmPcWlVR9NmoKo3+ucqUA3ijQhA0= -github.com/elazarl/goproxy v1.7.2 h1:Y2o6urb7Eule09PjlhQRGNsqRfPmYI3KKQLFpCAV3+o= -github.com/elazarl/goproxy v1.7.2/go.mod h1:82vkLNir0ALaW14Rc399OTTjyNREgmdL2cVoIbS6XaE= +github.com/ebitengine/purego v0.10.2 h1:W809HbnvzAxgdm+aOvlSekrM16wGCdT/e76+9tS7gzE= +github.com/ebitengine/purego v0.10.2/go.mod h1:iIjxzd6CiRiOG0UyXP+V1+jWqUXVjPKLAI0mRfJZTmQ= github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc= github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f h1:Y/CXytFA4m6baUTXGLOoWe4PQhGxaX0KpnayAqC48p4= github.com/erikgeiser/coninput v0.0.0-20211004153227-1c3628e74d0f/go.mod h1:vw97MGsxSvLiUE2X8qFplwetxpGLQrlU1Q9AUEIzCaM= -github.com/fatih/color v1.9.0/go.mod h1:eQcE1qtQxscV5RaZvpXrrb8Drkc3/DdQ+uUYCNjL+zU= -github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM= -github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE= github.com/gliderlabs/ssh v0.3.8 h1:a4YXD1V7xMF9g5nTkdfnja3Sxy1PVDCj1Zg4Wb8vY6c= github.com/gliderlabs/ssh v0.3.8/go.mod h1:xYoytBv1sV0aL3CavoDuJIQNURXkkfPA/wxQ1pL1fAU= -github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376 h1:+zs/tPmkDkHx3U66DAb0lQFJrpS6731Oaa12ikc+DiI= -github.com/go-git/gcfg v1.5.1-0.20230307220236-3a3c6141e376/go.mod h1:an3vInlBmSxCcxctByoQdvwPiA7DTK7jaaFDBTtu0ic= -github.com/go-git/go-billy/v5 v5.8.0 h1:I8hjc3LbBlXTtVuFNJuwYuMiHvQJDq1AT6u4DwDzZG0= -github.com/go-git/go-billy/v5 v5.8.0/go.mod h1:RpvI/rw4Vr5QA+Z60c6d6LXH0rYJo0uD5SqfmrrheCY= -github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399 h1:eMje31YglSBqCdIqdhKBW8lokaMrL3uTkpGYlE2OOT4= -github.com/go-git/go-git-fixtures/v4 v4.3.2-0.20231010084843-55a94097c399/go.mod h1:1OCfN199q1Jm3HZlxleg+Dw/mwps2Wbk9frAWm+4FII= -github.com/go-git/go-git/v5 v5.17.2 h1:B+nkdlxdYrvyFK4GPXVU8w1U+YkbsgciIR7f2sZJ104= -github.com/go-git/go-git/v5 v5.17.2/go.mod h1:pW/VmeqkanRFqR6AljLcs7EA7FbZaN5MQqO7oZADXpo= +github.com/go-git/gcfg/v2 v2.0.2 h1:MY5SIIfTGGEMhdA7d7JePuVVxtKL7Hp+ApGDJAJ7dpo= +github.com/go-git/gcfg/v2 v2.0.2/go.mod h1:/lv2NsxvhepuMrldsFilrgct6pxzpGdSRC13ydTLSLs= +github.com/go-git/go-billy/v6 v6.0.0-alpha.2 h1:1Sv5WemXL8CxKrAx1gioJ+uHNb2bZJhiQLfwSZ4Et8c= +github.com/go-git/go-billy/v6 v6.0.0-alpha.2/go.mod h1:r/bsv9i/iDyyEU8/Z6mjC+YraOVwie1ddfUqBCElKXQ= +github.com/go-git/go-git-fixtures/v6 v6.0.0-alpha.1 h1:gmqi2jvsreu0s8JMLylYDFq4sbjHwwlhktMw0DUg3mA= +github.com/go-git/go-git-fixtures/v6 v6.0.0-alpha.1/go.mod h1:ECf1MqJlBdYpKggBrOXjo/0EnvRZx6D++I86UYjPgAQ= +github.com/go-git/go-git/v6 v6.0.0-alpha.5 h1:sE+OlkHgYWNMVmN1s9sR7uyFgsWLtxcNWse/vBYKxRE= +github.com/go-git/go-git/v6 v6.0.0-alpha.5/go.mod h1:3IjhiZnM+uBmUrOGSeqrJpsmi4Vd0H2NZO/uK2a7d0s= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= -github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= +github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= +github.com/godbus/dbus/v5 v5.2.2 h1:TUR3TgtSVDmjiXOgAAyaZbYmIeP3DPkld3jgKGV8mXQ= +github.com/godbus/dbus/v5 v5.2.2/go.mod h1:3AAv2+hPq5rdnr5txxxRwiGjPXamgoIHgz9FPBfOp3c= github.com/gogo/protobuf v1.3.1/go.mod h1:SlYgWuQ5SjCEi6WLHjHCa1yvBfUnHcTbrrZtXPKa29o= github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q= github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q= github.com/golang/glog v1.2.5 h1:DrW6hGnjIhtvhOIiAKT6Psh/Kd/ldepEa81DKeiRJ5I= github.com/golang/glog v1.2.5/go.mod h1:6AhwSGph0fcJtXVM/PEHPqZlFeoLxhs7/t5UDAwmO+w= -github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= -github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= +github.com/google/go-tpm v0.9.8 h1:slArAR9Ft+1ybZu0lBwpSmpwhRXaa85hWtMinMyRAWo= +github.com/google/go-tpm v0.9.8/go.mod h1:h9jEsEECg7gtLis0upRBQU+GhYVH6jMjrFxI8u6bVUY= +github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba h1:qJEJcuLzH5KDR0gKc0zcktin6KSAwL7+jWKBYceddTc= +github.com/google/go-tpm-tools v0.3.13-0.20230620182252-4639ecce2aba/go.mod h1:EFYHy8/1y2KfgTAsx7Luu7NGhoxtuVHnNo8jE7FikKc= github.com/google/gofuzz v1.0.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0 h1:HWRh5R2+9EifMyIHV7ZV+MIZqgz+PMpZ14Jynv3O2Zs= -github.com/grpc-ecosystem/grpc-gateway/v2 v2.28.0/go.mod h1:JfhWUomR1baixubs02l85lZYYOm7LV6om4ceouMv45c= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0 h1:/Tnpcb2E0Pz/tN9s3bfEY2Q8ePCEX9iuS+cneUwncnw= +github.com/grpc-ecosystem/grpc-gateway/v2 v2.30.0/go.mod h1:zOBXOsUaBSjKgmH4OGzV1esUpR3oUSCPYVd2cUBjKYY= github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645 h1:MJG/KsmcqMwFAkh8mTnAwhyKoB+sTAnY4CACC110tbU= github.com/grpc-ecosystem/grpc-opentracing v0.0.0-20180507213350-8e809c8a8645/go.mod h1:6iZfnjpejD4L/4DwD7NryNaJyCQdzwWwH2MWhCA90Kw= github.com/hashicorp/errwrap v1.0.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= @@ -104,23 +101,23 @@ github.com/hashicorp/errwrap v1.1.0 h1:OxrOeh75EUXMY8TBjag2fzXGZ40LB6IKw45YeGUDY github.com/hashicorp/errwrap v1.1.0/go.mod h1:YH+1FKiLXxHSkmPseP+kNlulaMuP3n2brvKWEqk/Jc4= github.com/hashicorp/go-multierror v1.1.1 h1:H5DkEtf6CXdFp0N0Em5UCwQpXMWke8IA0+lD48awMYo= github.com/hashicorp/go-multierror v1.1.1/go.mod h1:iw975J/qwKPdAO1clOe2L8331t/9/fmwbPZ6JB6eMoM= -github.com/hashicorp/go-version v1.8.0 h1:KAkNb1HAiZd1ukkxDFGmokVZe1Xy9HG6NUp+bPle2i4= -github.com/hashicorp/go-version v1.8.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= -github.com/hashicorp/hcl/v2 v2.22.0 h1:hkZ3nCtqeJsDhPRFz5EA9iwcG1hNWGePOTw6oyul12M= -github.com/hashicorp/hcl/v2 v2.22.0/go.mod h1:62ZYHrXgPoX8xBnzl8QzbWq4dyDsDtfCRgIq1rbJEvA= +github.com/hashicorp/go-version v1.9.0 h1:CeOIz6k+LoN3qX9Z0tyQrPtiB1DFYRPfCIBtaXPSCnA= +github.com/hashicorp/go-version v1.9.0/go.mod h1:fltr4n8CU8Ke44wwGCBoEymUuxUHl09ZGVZPK5anwXA= +github.com/hashicorp/hcl/v2 v2.24.0 h1:2QJdZ454DSsYGoaE6QheQZjtKZSUs9Nh2izTWiwQxvE= +github.com/hashicorp/hcl/v2 v2.24.0/go.mod h1:oGoO1FIQYfn/AgyOhlg9qLC6/nOJPX3qGbkZpYAcqfM= github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99 h1:BQSFePA1RWJOlocH6Fxy8MmwDt+yVQYULKfN0RoTN8A= -github.com/jbenet/go-context v0.0.0-20150711004518-d14ea06fba99/go.mod h1:1lJo3i6rXxKeerYnT8Nvf0QmHCRC1n8sfWVwXF2Frvo= github.com/json-iterator/go v1.1.12 h1:PV8peI4a0ysnczrg+LtxykD8LfKY9ML6u2jnxaEnrnM= github.com/json-iterator/go v1.1.12/go.mod h1:e30LSqwooZae/UwlEbR2852Gd8hjQvJoHmT4TnhNGBo= -github.com/kevinburke/ssh_config v1.2.0 h1:x584FjTGwHzMwvHx18PXxbBVzfnxogHaAReU4gf13a4= -github.com/kevinburke/ssh_config v1.2.0/go.mod h1:CT57kijsi8u/K/BOFA39wgDQJ9CxiF4nAY/ojJ6r6mM= +github.com/kevinburke/ssh_config v1.6.0 h1:J1FBfmuVosPHf5GRdltRLhPJtJpTlMdKTBjRgTaQBFY= +github.com/kevinburke/ssh_config v1.6.0/go.mod h1:q2RIzfka+BXARoNexmF9gkxEX7DmvbW9P4hIVx2Kg4M= github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00= github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8= github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck= -github.com/klauspost/compress v1.18.0 h1:c/Cqfb0r+Yi+JtIEq73FWXVkRonBlf0CRNYc8Zttxdo= -github.com/klauspost/compress v1.18.0/go.mod h1:2Pp+KzxcywXVXMr50+X0Q/Lsb43OQHYWRCY2AiWywWQ= +github.com/klauspost/compress v1.18.7 h1:aUyZsS4kH3QTKurYhAOwAHxllVPnOthb3vPfnF1Ehjw= +github.com/klauspost/compress v1.18.7/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/cpuid/v2 v2.3.0 h1:S4CRMLnYUhGeDFDqkGriYKdfoFlDnMtqTiI/sFzhA9Y= +github.com/klauspost/cpuid/v2 v2.3.0/go.mod h1:hqwkgyIinND0mEev00jJYCxPNVRVXFQeu1XKlok6oO0= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= @@ -128,20 +125,14 @@ github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ= github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= -github.com/lucasb-eyer/go-colorful v1.3.0 h1:2/yBRLdWBZKrf7gB40FoiKfAWYQ0lqNcbuQwVHXptag= -github.com/lucasb-eyer/go-colorful v1.3.0/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= -github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= -github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= -github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE= -github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= -github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= +github.com/lucasb-eyer/go-colorful v1.4.1 h1:1EO+WB73+EH8EVbzlrG3KLAfEypQWVHIBqlTf+2hNss= +github.com/lucasb-eyer/go-colorful v1.4.1/go.mod h1:R4dSotOR9KMtayYi1e77YzuveK+i7ruzyGqttikkLy0= +github.com/mattn/go-isatty v0.0.24 h1:tGZZoVgT/KiqK1c8ocVLeDS8BSWMRd47J3Lbz7vsReI= +github.com/mattn/go-isatty v0.0.24/go.mod h1:nMCL3Zebbrt45jsMDgnfIwz6ydEQApk5oEI3HqDio6A= github.com/mattn/go-localereader v0.0.1 h1:ygSAOl7ZXTx4RdPYinUpg6W99U8jWvWi9Ye2JC/oIi4= github.com/mattn/go-localereader v0.0.1/go.mod h1:8fBrzywKY7BI3czFoHkuzRoWE9C+EiG4R1k4Cjx5p88= -github.com/mattn/go-runewidth v0.0.4/go.mod h1:LwmH8dsx7+W8Uxz3IHJYH5QSwggIsqBzpuz5H//U1FU= -github.com/mattn/go-runewidth v0.0.20 h1:WcT52H91ZUAwy8+HUkdM3THM6gXqXuLJi9O3rjcQQaQ= -github.com/mattn/go-runewidth v0.0.20/go.mod h1:XBkDxAl56ILZc9knddidhrOlY5R/pDhgLpndooCuJAs= +github.com/mattn/go-runewidth v0.0.28 h1:rPyg2ybwEKPebvpzVWe1gKBkH8EQFkxO4Y0hjBeLaBU= +github.com/mattn/go-runewidth v0.0.28/go.mod h1:3qAiGCV4Koz/yuveO58qUefmUTRm8r0IGEXZ9jeHp/8= github.com/mitchellh/go-ps v1.0.0 h1:i6ampVEEF4wQFF+bkYfwYgY+F/uYJDktmvLPf7qIgjc= github.com/mitchellh/go-ps v1.0.0/go.mod h1:J4lOc8z8yJs6vUwklHw2XEIiT4z4C40KtWVN3nvg8Pg= github.com/mitchellh/go-wordwrap v1.0.1 h1:TLuKupo69TCn6TQSyGxwI1EblZZEsQ0vMlAFQflz0v0= @@ -158,8 +149,6 @@ github.com/muesli/cancelreader v0.2.2 h1:3I4Kt4BQjOR54NavqnDogx/MIoWBFa0StPA8ELU github.com/muesli/cancelreader v0.2.2/go.mod h1:3XuTXfFS2VjM+HTLZY9Ak0l6eUKfijIfMUZ4EgX0QYo= github.com/muesli/termenv v0.16.0 h1:S5AlUN9dENB57rsbnkPyfdGuWIlkmzJjbFf0Tf5FWUc= github.com/muesli/termenv v0.16.0/go.mod h1:ZRfOIKPFDYQoDFF4Olj7/QJbW60Ol/kL1pU3VfY/Cnk= -github.com/onsi/gomega v1.34.1 h1:EUMJIKUjM8sKjYbtxQI9A4z2o+rruxnzNvpknOXie6k= -github.com/onsi/gomega v1.34.1/go.mod h1:kU1QgUvBDLXBJq618Xvm2LUX6rSAfRaFRTcdOeDLwwY= github.com/opentracing/basictracer-go v1.1.0 h1:Oa1fTSBvAl8pa3U+IJYqrKm0NALwH9OsgwOqDv4xJW0= github.com/opentracing/basictracer-go v1.1.0/go.mod h1:V2HZueSJEp879yv285Aap1BS69fQMD+MNP1mRs6mBQc= github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o= @@ -167,26 +156,25 @@ github.com/opentracing/opentracing-go v1.2.0 h1:uEJPy/1a5RIPAJ0Ov+OIO8OxWu77jEv+ github.com/opentracing/opentracing-go v1.2.0/go.mod h1:GxEUsuufX4nBwe+T+Wl9TAgYrxe9dPLANfrWvHYVTgc= github.com/pgavlin/fx v0.1.6 h1:r9jEg69DhNoCd3Xh0+5mIbdbS3PqWrVWujkY76MFRTU= github.com/pgavlin/fx v0.1.6/go.mod h1:KWZJ6fqBBSh8GxHYqwYCf3rYE7Gp2p0N8tJp8xv9u9M= -github.com/pgavlin/fx/v2 v2.0.10 h1:ggyQ6pB+lEQEbEae48Wh/X221eLOamMD7i01ISe88u4= -github.com/pgavlin/fx/v2 v2.0.10/go.mod h1:M/nF/ooAOy+NUBooYYXl2REARzJ/giPJxfMs8fINfKc= -github.com/pjbgf/sha1cd v0.3.2 h1:a9wb0bp1oC2TGwStyn0Umc/IGKQnEgF0vVaZ8QF8eo4= -github.com/pjbgf/sha1cd v0.3.2/go.mod h1:zQWigSxVmsHEZow5qaLtPYxpcKMMQpa09ixqBxuCS6A= +github.com/pgavlin/fx/v2 v2.0.12 h1:SjjaJ68Dt8Z4zHwOpY/RPijd7lShs6xYupJbF9ra00M= +github.com/pgavlin/fx/v2 v2.0.12/go.mod h1:M/nF/ooAOy+NUBooYYXl2REARzJ/giPJxfMs8fINfKc= +github.com/pjbgf/sha1cd v0.6.0 h1:3WJ8Wz8gvDz29quX1OcEmkAlUg9diU4GxJHqs0/XiwU= +github.com/pjbgf/sha1cd v0.6.0/go.mod h1:lhpGlyHLpQZoxMv8HcgXvZEhcGs0PG/vsZnEJ7H0iCM= github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4= github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0= github.com/pkg/term v1.1.0 h1:xIAAdCMh3QIAy+5FrE8Ad8XoDhEU4ufwbaSozViP9kk= github.com/pkg/term v1.1.0/go.mod h1:E25nymQcrSllhX42Ok8MRm1+hyBdHY0dCeiKZ9jpNGw= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= +github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231 h1:vkHw5I/plNdTr435cARxCW6q9gc0S/Yxz7Mkd38pOb0= github.com/pulumi/appdash v0.0.0-20231130102222-75f619a67231/go.mod h1:murToZ2N9hNJzewjHBgfFdXhZKjY3z5cYC1VXk+lbFE= -github.com/pulumi/esc v0.17.0 h1:oaVOIyFTENlYDuqc3pW75lQT9jb2cd6ie/4/Twxn66w= -github.com/pulumi/esc v0.17.0/go.mod h1:XnSxlt5NkmuAj304l/gK4pRErFbtqq6XpfX1tYT9Jbc= github.com/pulumi/pulumi-gcp/sdk/v8 v8.41.1 h1:w6OnO3d4j5yVf2vpm8OzXFC/xHOEGqt+9FjWCUBCq6U= github.com/pulumi/pulumi-gcp/sdk/v8 v8.41.1/go.mod h1:UyZyv7hz4knpFx6/Sh+SkZe6hT6sJHtDvw9A0TbvEsk= -github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.28.0 h1:muCE6cUJ4YmAaNLiOhbjEicxT+10i/EGsZrx2ZZQQ+o= -github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.28.0/go.mod h1:B998wofejDKAvvpLwsi4UMfWDFHHBnzYiM8mZ9e7OSo= -github.com/pulumi/pulumi/sdk/v3 v3.230.0 h1:0TtF82Hlor39DLU0QtM7RZPwRaOmjn5UtQKPi1Mxo9M= -github.com/pulumi/pulumi/sdk/v3 v3.230.0/go.mod h1:u0fgmmPGwV5b4rmfuNABuYfRoqckuaTivufPn4EtfTk= +github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.34.0 h1:r00p17ecoDVWqBg38/Is/9jU/JsWLPxnWzhfYqKitx0= +github.com/pulumi/pulumi-kubernetes/sdk/v4 v4.34.0/go.mod h1:/klrd3ib4AMRlFMjrxkv5r76x3Bdr68wIMEKfRkRzHU= +github.com/pulumi/pulumi/sdk/v3 v3.261.0 h1:1C2V6bxzO9UBe91PRebO/zeiUIQ2C05eRNkVFvJuuqc= +github.com/pulumi/pulumi/sdk/v3 v3.261.0/go.mod h1:xlOo55i2hj5tDyMY8diTS5LfFAn2sFew+50d67sVNdg= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= @@ -196,9 +184,6 @@ github.com/santhosh-tekuri/jsonschema/v5 v5.0.0 h1:TToq11gyfNlrMFZiYujSekIsPd9Am github.com/santhosh-tekuri/jsonschema/v5 v5.0.0/go.mod h1:FKdcjfQW6rpZSnxxUvEA5H/cDPdvJ/SZJQLWWXWGrZ0= github.com/sergi/go-diff v1.4.0 h1:n/SP9D5ad1fORl+llWyN+D6qoUETXNZARKjyY2/KVCw= github.com/sergi/go-diff v1.4.0/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4= -github.com/sirupsen/logrus v1.7.0/go.mod h1:yWOB1SBYBC5VeMP7gHvWumXLIWorT60ONWic61uBYv0= -github.com/skeema/knownhosts v1.3.1 h1:X2osQ+RAjK76shCbvhHHHVl3ZlgDm8apHEHFqRjnBY8= -github.com/skeema/knownhosts v1.3.1/go.mod h1:r7KTdC8l4uxWRyK2TpQZ/1o5HaSzh06ePQNxPwTcfiY= github.com/spf13/cast v1.4.1 h1:s0hze+J0196ZfEMTs80N7UlFt0BDuQ7Q+JDnHiMWKdA= github.com/spf13/cast v1.4.1/go.mod h1:Qx5cxh0v+4UWYiBimWS+eyWzqEqokIECu5etghLkUJE= github.com/spf13/cobra v1.10.2 h1:DMTTonx5m65Ic0GOoRY2c16WCbHxOOw6xxezuLaBpcU= @@ -207,8 +192,8 @@ github.com/spf13/pflag v1.0.9/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An github.com/spf13/pflag v1.0.10 h1:4EBh2KAYBwaONj6b2Ye1GiHfwjqyROoF4RwYO+vPwFk= github.com/spf13/pflag v1.0.10/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= -github.com/stretchr/objx v0.2.0 h1:Hbg2NidpLE8veEBkEZTL3CvlkUIVzuU9jDplZO54c48= -github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE= +github.com/stretchr/objx v0.5.2 h1:xuMeJ0Sdp5ZMRXx/aWO6RZxdr3beISkG5/G/aIRr3pY= +github.com/stretchr/objx v0.5.2/go.mod h1:FRsXN1f5AsAjCGJKqEizvkpNtU+EGNCLh3NxZ/8L+MA= github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4= @@ -221,44 +206,54 @@ github.com/uber/jaeger-client-go v2.30.0+incompatible h1:D6wyKGCecFaSRUpo8lCVbaO github.com/uber/jaeger-client-go v2.30.0+incompatible/go.mod h1:WVhlPFC8FDjOFMMWRy2pZqQJSXxYSwNYOkTr/Z6d3Kk= github.com/uber/jaeger-lib v2.4.1+incompatible h1:td4jdvLcExb4cBISKIpHuGoVXh+dVKhn2Um6rjCsSsg= github.com/uber/jaeger-lib v2.4.1+incompatible/go.mod h1:ComeNDZlWwrWnDv8aPp0Ba6+uUTzImX/AauajbLI56U= -github.com/xanzy/ssh-agent v0.3.3 h1:+/15pJfg/RsTxqYcX6fHqOXZwwMP+2VyYWJeWM2qQFM= -github.com/xanzy/ssh-agent v0.3.3/go.mod h1:6dzNDKs0J9rVPHPhaGCukekBHKqfl+L3KghI1Bc68Uw= -github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e h1:JVG44RsyaB9T2KIHavMF/ppJZNG9ZpyihvCd0w101no= -github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= +github.com/xo/terminfo v1.0.0 h1:2ZpYzqWzyyytjk3TP6aJVDhkMAkc99/1xKQdA3TDTBY= +github.com/xo/terminfo v1.0.0/go.mod h1:RbqR21r5mrJuqunuUZ/Dhy/avygyECGrLceyNeo4LiM= github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74= -github.com/zclconf/go-cty v1.13.2 h1:4GvrUxe/QUDYuJKAav4EYqdM47/kZa672LwmXFmEKT0= -github.com/zclconf/go-cty v1.13.2/go.mod h1:YKQzy/7pZ7iq2jNFzy5go57xdxdWoLLpaEp4u238AE0= +github.com/zalando/go-keyring v0.2.8 h1:6sD/Ucpl7jNq10rM2pgqTs0sZ9V3qMrqfIIy5YPccHs= +github.com/zalando/go-keyring v0.2.8/go.mod h1:tsMo+VpRq5NGyKfxoBVjCuMrG47yj8cmakZDO5QGii0= +github.com/zclconf/go-cty v1.16.3 h1:osr++gw2T61A8KVYHoQiFbFd1Lh3JOCXc/jFLJXKTxk= +github.com/zclconf/go-cty v1.16.3/go.mod h1:VvMs5i0vgZdhYawQNq5kePSpLAoz8u1xvZgrPIxfnZE= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/collector/featuregate v1.53.0 h1:cgjXdtl7jezWxq6V0eohe/JqjY4PBotZGb5+bTR2OJw= -go.opentelemetry.io/collector/featuregate v1.53.0/go.mod h1:PS7zY/zaCb28EqciePVwRHVhc3oKortTFXsi3I6ee4g= -go.opentelemetry.io/collector/internal/testutil v0.147.0 h1:DFlRxBRp23/sZnpTITK25yqe0d56yNvK+63IaWc6OsU= -go.opentelemetry.io/collector/internal/testutil v0.147.0/go.mod h1:Jkjs6rkqs973LqgZ0Fe3zrokQRKULYXPIf4HuqStiEE= -go.opentelemetry.io/collector/pdata v1.53.0 h1:DlYDbRwammEZaxDZHINx5v0n8SEOVNniPbi6FRTlVkA= -go.opentelemetry.io/collector/pdata v1.53.0/go.mod h1:LRSYGNjKXaUrZEwZv3Yl+8/zV2HmRGKXW62zB2bysms= -go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= -go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.41.0 h1:ao6Oe+wSebTlQ1OEht7jlYTzQKE+pnx/iNywFvTbuuI= -go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.41.0/go.mod h1:u3T6vz0gh/NVzgDgiwkgLxpsSF6PaPmo2il0apGJbls= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.41.0 h1:mq/Qcf28TWz719lE3/hMB4KkyDuLJIvgJnFGcd0kEUI= -go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.41.0/go.mod h1:yk5LXEYhsL2htyDNJbEq7fWzNEigeEdV5xBF/Y+kAv0= -go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= -go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= -go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= -go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= -go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= -go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= -go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= -go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= -go.opentelemetry.io/proto/otlp v1.9.0 h1:l706jCMITVouPOqEnii2fIAuO3IVGBRPV5ICjceRb/A= -go.opentelemetry.io/proto/otlp v1.9.0/go.mod h1:xE+Cx5E/eEHw+ISFkwPLwCZefwVjY+pqKg1qcK03+/4= -go.opentelemetry.io/proto/slim/otlp v1.9.0 h1:fPVMv8tP3TrsqlkH1HWYUpbCY9cAIemx184VGkS6vlE= -go.opentelemetry.io/proto/slim/otlp v1.9.0/go.mod h1:xXdeJJ90Gqyll+orzUkY4bOd2HECo5JofeoLpymVqdI= -go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.2.0 h1:o13nadWDNkH/quoDomDUClnQBpdQQ2Qqv0lQBjIXjE8= -go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.2.0/go.mod h1:Gyb6Xe7FTi/6xBHwMmngGoHqL0w29Y4eW8TGFzpefGA= -go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.2.0 h1:EiUYvtwu6PMrMHVjcPfnsG3v+ajPkbUeH+IL93+QYyk= -go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.2.0/go.mod h1:mUUHKFiN2SST3AhJ8XhJxEoeVW12oqfXog0Bo8W3Ec4= +go.opentelemetry.io/collector/featuregate v1.65.0 h1:Dh+uYVB+POc5DTebZRWjtKJolGhevkiIpbHn+zhkq2o= +go.opentelemetry.io/collector/featuregate v1.65.0/go.mod h1:4ga1QBMPEejXXmpyJS8lmaRpknJ3Lb9Bvk6e420bUFU= +go.opentelemetry.io/collector/internal/testutil v0.159.0 h1:/OfAv3ZRIc3eVFFq4bFc+Ju5HQBebiWywgvAcysIX4M= +go.opentelemetry.io/collector/internal/testutil v0.159.0/go.mod h1:Jkjs6rkqs973LqgZ0Fe3zrokQRKULYXPIf4HuqStiEE= +go.opentelemetry.io/collector/pdata v1.65.0 h1:6bQ3sIrEzOdapetxYFjdCns90kKXg1qCoIZ3la1aR5E= +go.opentelemetry.io/collector/pdata v1.65.0/go.mod h1:r5vRY0p7nZcEif06twUW09Sf6vaNsyPzij+EpwI/xeI= +go.opentelemetry.io/contrib/bridges/otelslog v0.20.0 h1:oEl2Pw/i4OQwhAuda2pAHFAcOMivA+Xa+iTccBfab/g= +go.opentelemetry.io/contrib/bridges/otelslog v0.20.0/go.mod h1:yMSQaiiq5dpfrSJCYLBcqFeJkFFI67seT4ngvx6jfVo= +go.opentelemetry.io/otel v1.45.0 h1:pdrWmLHofpubmArBv1LgFSv1Z0Ie/ppdZzu+kUN5EeU= +go.opentelemetry.io/otel v1.45.0/go.mod h1:XZxIqPapzEYnhNSScF5DIqXhm/rYi0FzCe2XddAwZfQ= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.21.0 h1:WseeVYf5dJZTsyPiyW5L14k5qsSibqXAMTSiFEDiWr0= +go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploggrpc v0.21.0/go.mod h1:SiLZnQS6Qk2eCpvr2CH/XMAOa64TWGXxEZJZCpD2Lmc= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0 h1:QRefszxJmfPdjXUUm3j6iDzY03mTPXMjqErFqQ67vUg= +go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.45.0/go.mod h1:Tiz03lTBVBrm7eWZBOidzEaYaJa8tjwGUGv6d8mlTyk= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0 h1:fG5MCxGz8+2VtrN/WgqSpJFctVz24gpxj8CxkKmc8Ww= +go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracegrpc v1.45.0/go.mod h1:BmAYTn+3ysbRe+IU2msxmf5Rx3g6DHvex+tWI3LdhYI= +go.opentelemetry.io/otel/log v0.21.0 h1:SLsVDGmtyBrdw8/a2Z0bOIxou/+bN4z56GebH7T0LvA= +go.opentelemetry.io/otel/log v0.21.0/go.mod h1:iReetQrZL9Wyg84cCkOoCmqDHS5RCFfyxC7J+r8fn8g= +go.opentelemetry.io/otel/metric v1.45.0 h1:7Eg1uH7CJ5cXv9is6tnBe1FI6rj1nwUdbFypRm3br/M= +go.opentelemetry.io/otel/metric v1.45.0/go.mod h1:HAPbm1nd3p1PmFH7v2dR+6BjXxw+Lq4a2+pndMAm08s= +go.opentelemetry.io/otel/sdk v1.45.0 h1:4VVSMgQ83dUgW2aoX5f6JgLvHwIvzcuLnF9lUdCSpCw= +go.opentelemetry.io/otel/sdk v1.45.0/go.mod h1:Sr40LgXV7DsKMMJMKOhUWOgMWTfAaqvm2kF0g7ilwuA= +go.opentelemetry.io/otel/sdk/log v0.21.0 h1:QsE7XSR0ktQdKmRKGnR+f1ObGF32WG+7MER/P9KgmYc= +go.opentelemetry.io/otel/sdk/log v0.21.0/go.mod h1:m9mApjCoD2/1QuKCAptjv+BrG9WKOvQLVdNx+iBldTo= +go.opentelemetry.io/otel/sdk/log/logtest v0.21.0 h1:X+JBBgKlswCGYsmgL0CnoUUtlE//VB345c84jYAYkdQ= +go.opentelemetry.io/otel/sdk/log/logtest v0.21.0/go.mod h1:HD1575K8e6sIFBBDd5tZB3t9DlMytWXq9FuR+Y4rfjE= +go.opentelemetry.io/otel/sdk/metric v1.45.0 h1:oVFszMfyj1Am6s24Vtc7wBb8BKLcwepJjNEYILuiE3o= +go.opentelemetry.io/otel/sdk/metric v1.45.0/go.mod h1:vUWUxDZvu1WVRj8JA8S0AdhsPrZoDpA2DdZauIh4mDA= +go.opentelemetry.io/otel/trace v1.45.0 h1:l/mP6Uv7oNO7/TblbhpbgMidxhq1uO/rPsikOyVhxag= +go.opentelemetry.io/otel/trace v1.45.0/go.mod h1:qoJJA2xNMnxRrdISU/kLtfUH2wNeQbiv+jhs/CxI8bc= +go.opentelemetry.io/proto/otlp v1.11.0 h1:5rrYs0Ykyj50sdU/JU0x8etU+LubXWb+gED6TbEdMIk= +go.opentelemetry.io/proto/otlp v1.11.0/go.mod h1:SmVizdCOAm3XBtG1g1NnOdhW6jtddT72hLMhv8VwA8E= +go.opentelemetry.io/proto/slim/otlp v1.11.0 h1:zB37f+f99+y6UIZR4h7UpwbXd5kFNyip35U7GaJ/Jik= +go.opentelemetry.io/proto/slim/otlp v1.11.0/go.mod h1:mI3DeND+VXZuA4keqFPKDJ3BklwveYm1JqBcEWKDEOM= +go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.4.0 h1:mt+DWtks0biKnz0jXMpDbxWN0CHJi6OJDKe4GcREkcs= +go.opentelemetry.io/proto/slim/otlp/collector/profiles/v1development v0.4.0/go.mod h1:7UXaX/7uT+kumUHd3LIWyjMlklEp0mPlrE9xmtbG6/8= +go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.4.0 h1:rLHkdB6eHDiRSIoz0cvNuTJsVJBxaL6IyS1e9BSaXLY= +go.opentelemetry.io/proto/slim/otlp/profiles/v1development v0.4.0/go.mod h1:BrX0dmOGsMuWNXXbFafTD7Gb6F3yK+2czVQ6+c24Cnk= go.uber.org/atomic v1.11.0 h1:ZvwS0R+56ePWxUNi+Atn9dWONBPp/AUETXlHW0DxSjE= go.uber.org/atomic v1.11.0/go.mod h1:LUxbIzbOniOlMKjJjyPfpl4v+PKK2cNJn91OQbhoJI0= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= @@ -269,82 +264,68 @@ go.yaml.in/yaml/v3 v3.0.4/go.mod h1:DhzuOOF2ATzADvBadXxruRBLzYTpT36CKvDb3+aBEFg= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= -golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= -golang.org/x/crypto v0.48.0 h1:/VRzVqiRSggnhY7gNRxPauEQ5Drw9haKdM0jqfcCFts= -golang.org/x/crypto v0.48.0/go.mod h1:r0kV5h3qnFPlQnBSrULhlsRfryS2pmewsg+XfMgkVos= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56 h1:2dVuKD2vS7b0QIHQbpyTISPd0LeHDbnYEryqj5Q1ug8= -golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56/go.mod h1:M4RDyNAINzryxdtnbRXRL/OHtkFuWGRjvuhBJpk2IlY= +golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M= +golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis= +golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f h1:W3F4c+6OLc6H2lb//N1q4WpJkhzJCK5J6kUi1NTVXfM= +golang.org/x/exp v0.0.0-20260410095643-746e56fc9e2f/go.mod h1:J1xhfL/vlindoeF/aINzNzt2Bket5bjo9sdOYzOsU80= golang.org/x/lint v0.0.0-20200302205851-738671d3881b/go.mod h1:3xt1FjdF8hUf6vQPIChWIBhFzV8gjjsPE/fR3IyQdNY= golang.org/x/mod v0.1.1-0.20191105210325-c90efee705ee/go.mod h1:QqPTAvyqsEbceGzBzNggFXnrqF1CaUcvgkdR5Ot7KZg= golang.org/x/mod v0.2.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= golang.org/x/mod v0.3.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA= -golang.org/x/mod v0.32.0 h1:9F4d3PHLljb6x//jOyokMv3eX+YDeepZSEo3mFJy93c= -golang.org/x/mod v0.32.0/go.mod h1:SgipZ/3h2Ci89DlEtEXWUk/HteuRin+HHhN+WbNhguU= +golang.org/x/mod v0.38.0 h1:MECBjubtXD7yj4HrhIUcywNaGeNVUdfVnxmPajOk4yk= +golang.org/x/mod v0.38.0/go.mod h1:V6Xz0pq8TQ3dGqVQ1FVHuelZpAL0uNhSkk9ogYP3c40= golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200226121028-0de0cce0169b/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= golang.org/x/net v0.0.0-20200421231249-e086a090c8fd/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= golang.org/x/net v0.0.0-20201021035429-f5854403a974/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= -golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y= -golang.org/x/net v0.51.0 h1:94R/GTO7mt3/4wIKpcR5gkGmRLOuE/2hNGeWq/GBIFo= -golang.org/x/net v0.51.0/go.mod h1:aamm+2QF5ogm02fjy5Bb7CQ0WMt1/WVM7FtyaTLlA9Y= +golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= +golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4= -golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI= +golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= +golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= -golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200909081042-eff7692f9009/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210809222454-d867a43fc93e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.42.0 h1:omrd2nAlyT5ESRdCLYdm3+fMfNFE/+Rf4bDIQImRJeo= -golang.org/x/sys v0.42.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= -golang.org/x/term v0.40.0 h1:36e4zGLqU4yhjlmxEaagx2KuYbJq3EwY8K943ZsHcvg= -golang.org/x/term v0.40.0/go.mod h1:w2P8uVp06p2iyKKuvXIm7N/y0UCRt3UfJTfZ7oOpglM= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/term v0.45.0 h1:NwWyBmoJCbfTHpxrWoZ9C6/VxOf7ic219I8xZZFdrf0= +golang.org/x/term v0.45.0/go.mod h1:9aqxs0blBcrm/n0L9QW0aRVD+ktan8ssZromtqJC43w= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= -golang.org/x/text v0.34.0 h1:oL/Qq0Kdaqxa1KbNeMKwQq0reLCCaFtqu2eNuSeNHbk= -golang.org/x/text v0.34.0/go.mod h1:homfLqTYRFyVYemLBFl5GgL/DWEiH5wcsQ5gSh1yziA= +golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= +golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20181030221726-6c7e314b6563/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= golang.org/x/tools v0.0.0-20200130002326-2f3ba24bd6e7/go.mod h1:TB2adYChydJhpapKDTa4BR/hXlZSLoq2Wpct/0txZ28= golang.org/x/tools v0.0.0-20200619180055-7c47624df98f/go.mod h1:EkVYQZoAsY45+roYkvgYkIh4xh/qjgUK9TdY2XT94GE= golang.org/x/tools v0.0.0-20210106214847-113979e3529a/go.mod h1:emZCQorbCU4vsT4fOWvOPXz4eW1wZW4PmDk9uLelYpA= -golang.org/x/tools v0.41.0 h1:a9b8iMweWG+S0OBnlU36rzLp20z1Rp10w+IY2czHTQc= -golang.org/x/tools v0.41.0/go.mod h1:XSY6eDqxVNiYgezAVqqCeihT4j1U2CCsqvH3WhQpnlg= +golang.org/x/tools v0.48.0 h1:3+hClM1aLL5mjMKm5ovokw9epgRXPuu2tILgismM6RE= +golang.org/x/tools v0.48.0/go.mod h1:08xX0orndb/F7jJxGDicx061tyd5pcMto75YMAXr6lk= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171 h1:tu/dtnW1o3wfaxCOjSLn5IRX4YDcJrtlpzYkhHhGaC4= -google.golang.org/genproto/googleapis/api v0.0.0-20260226221140-a57be14db171/go.mod h1:M5krXqk4GhBKvB596udGL3UyjL4I1+cTbK0orROM9ng= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 h1:ggcbiqK8WWh6l1dnltU4BgWGIGo+EVYxCaAPih/zQXQ= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= -google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= -google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= -google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688 h1:ax2KzoSRIZU/M0cIxri3pKxy99vniH1PVxWC6si/eZI= +google.golang.org/genproto/googleapis/api v0.0.0-20260819154853-08b0e4226688/go.mod h1:1RJ9BQGyNdZwkGc1eTqkErfRZ6RJyYPHZo73BZ1vQqI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688 h1:cYNAzI2sUwhmCcoj9TxvihSrqsxt6uIkj3rDRhSDmW4= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260819154853-08b0e4226688/go.mod h1:DjtHYE8FKJLivXcBEjGwndXfIC23G0VpXiXKqG179uA= +google.golang.org/grpc v1.83.2 h1:EManeRomTObA0BU7I8vXgg/78uE5MJ9M8B39EX2WscU= +google.golang.org/grpc v1.83.2/go.mod h1:YPI1hK3kDked6iHvgX3tR0y+nX/qpMFKhPgFsokw1S8= +google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= +google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= -gopkg.in/warnings.v0 v0.1.2 h1:wFXVbFY8DY5/xOe1ECiWdKCzZlxgshcYVNkBHstARME= -gopkg.in/warnings.v0 v0.1.2/go.mod h1:jksf8JmL6Qr/oQM2OXTHunEvvTAsrWBLb6OOjuVWRNI= gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY= gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ= @@ -352,5 +333,5 @@ gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= lukechampine.com/frand v1.5.1 h1:fg0eRtdmGFIxhP5zQJzM1lFDbD6CUfu/f+7WgAZd5/w= lukechampine.com/frand v1.5.1/go.mod h1:4VstaWc2plN4Mjr10chUD46RAVGWhpkZ5Nja8+Azp0Q= -pgregory.net/rapid v0.6.1 h1:4eyrDxyht86tT4Ztm+kvlyNBLIk071gR+ZQdhphc9dQ= -pgregory.net/rapid v0.6.1/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= +pgregory.net/rapid v1.2.0 h1:keKAYRcjm+e1F0oAuU5F5+YPAWcyxNNRK2wud503Gnk= +pgregory.net/rapid v1.2.0/go.mod h1:PY5XlDGj0+V1FCq0o192FdRhpKHGTRIWBgqjDBTrq04= diff --git a/deploy/pkg/k8s/ingress.go b/deploy/pkg/k8s/ingress.go index 4a24961..175cb17 100644 --- a/deploy/pkg/k8s/ingress.go +++ b/deploy/pkg/k8s/ingress.go @@ -65,6 +65,31 @@ func SetupIngressController(ctx *pulumi.Context, cluster *providers.ProviderInfo "annotations": pulumi.Map{}, }, "config": pulumi.Map{ + // Cache the public list endpoints at the ingress. Registry consumers + // repeatedly walk the same cursor pages, so sending every walk to the + // application needlessly consumes application CPU and database pool + // connections. The cache is intentionally short-lived so newly + // published servers become visible quickly. + // + // Use a variable cache zone so this global location snippet remains a + // no-op for publish, auth, mutation, and individual-server routes. + "http-snippet": pulumi.String(` +proxy_cache_path /tmp/registry-read-cache levels=1:2 keys_zone=registry_read_cache:20m max_size=1g inactive=5m use_temp_path=off; +map "$request_method:$uri" $registry_read_cache_zone { + default off; + ~^GET:/v0(?:\.1)?/servers$ registry_read_cache; +} +`), + "location-snippet": pulumi.String(` +proxy_cache $registry_read_cache_zone; +proxy_cache_key "$scheme$request_method$host$request_uri"; +proxy_cache_valid 200 30s; +proxy_cache_lock on; +proxy_cache_lock_timeout 5s; +proxy_cache_background_update on; +proxy_cache_use_stale updating error timeout http_500 http_502 http_503 http_504; +add_header X-Registry-Cache $upstream_cache_status always; +`), // Disable strict path validation, to work around a bug in ingress-nginx // https://cert-manager.io/docs/releases/release-notes/release-notes-1.18/#acme-http01-challenge-paths-now-use-pathtype-exact-in-ingress-routes // https://github.com/kubernetes/ingress-nginx/issues/11176 diff --git a/deploy/pkg/k8s/postgres.go b/deploy/pkg/k8s/postgres.go index 57a28aa..0b5e407 100644 --- a/deploy/pkg/k8s/postgres.go +++ b/deploy/pkg/k8s/postgres.go @@ -59,6 +59,47 @@ func DeployPostgresDatabases(ctx *pulumi.Context, cluster *providers.ProviderInf "storage": map[string]any{ "size": "50Gi", }, + // Explicit resource budget. PG was previously unlimited which made + // node-level OOM behaviour unpredictable. With max_connections=200 + // the worst-case per-connection memory (~10โ€“15MB each) plus + // shared_buffers and overhead lands around 3โ€“4GiB; 4Gi limit gives + // headroom for query workspaces (work_mem) and OS-level effects. + "resources": map[string]any{ + "requests": map[string]any{ + "memory": "512Mi", + "cpu": "200m", + }, + "limits": map[string]any{ + "memory": "4Gi", + "cpu": "1500m", + }, + }, + // Enable pg_stat_statements so we can attribute slow time to specific + // queries (the 2026-04-27 incident took an EXPLAIN-the-one-query-I-saw + // approach because we had no aggregate visibility). CNPG triggers a PG + // restart on shared_preload_libraries change โ€” with instances: 1 this + // is brief downtime. CREATE EXTENSION still needs to run once as a + // superuser on existing clusters; new clusters get it via the + // postInitApplicationSQL hook below. + // + // max_connections raised from default 100 to 200 because the registry + // pgxpool was bumped from 30 to 60 per pod (120 total across 2 pods) + // + ~10 reserved for PG internals and ad-hoc admin = 130, with 70 + // headroom for future scale or burst. + "postgresql": map[string]any{ + "shared_preload_libraries": []any{"pg_stat_statements"}, + "parameters": map[string]any{ + "pg_stat_statements.track": "all", + "max_connections": "200", + }, + }, + "bootstrap": map[string]any{ + "initdb": map[string]any{ + "postInitApplicationSQL": []any{ + "CREATE EXTENSION IF NOT EXISTS pg_stat_statements", + }, + }, + }, }, }, }, pulumi.Provider(cluster.Provider), pulumi.DependsOnInputs(cloudNativePG.Ready), pulumi.RetainOnDelete(true)) diff --git a/deploy/pkg/k8s/registry.go b/deploy/pkg/k8s/registry.go index 4655203..09ebea4 100644 --- a/deploy/pkg/k8s/registry.go +++ b/deploy/pkg/k8s/registry.go @@ -10,6 +10,7 @@ import ( "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/helm/v3" metav1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/meta/v1" networkingv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/networking/v1" + policyv1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/policy/v1" "github.com/pulumi/pulumi/sdk/v3/go/pulumi" "github.com/pulumi/pulumi/sdk/v3/go/pulumi/config" @@ -95,6 +96,22 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env }, }, Spec: &corev1.PodSpecArgs{ + // Soft-spread pods across nodes so the PodDisruptionBudget below can't + // deadlock a node drain when both pods happen to co-locate. + // `ScheduleAnyway` keeps single-node clusters (e.g. constrained dev + // envs) schedulable while still preferring spread under normal load. + TopologySpreadConstraints: corev1.TopologySpreadConstraintArray{ + &corev1.TopologySpreadConstraintArgs{ + MaxSkew: pulumi.Int(1), + TopologyKey: pulumi.String("kubernetes.io/hostname"), + WhenUnsatisfiable: pulumi.String("ScheduleAnyway"), + LabelSelector: &metav1.LabelSelectorArgs{ + MatchLabels: pulumi.StringMap{ + "app": pulumi.String("mcp-registry"), + }, + }, + }, + }, Containers: corev1.ContainerArray{ &corev1.ContainerArgs{ Name: pulumi.String("mcp-registry"), @@ -168,6 +185,27 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env Name: pulumi.String("MCP_REGISTRY_OIDC_PUBLISH_PERMISSIONS"), Value: pulumi.String("*"), }, + &corev1.EnvVarArgs{ + Name: pulumi.String("MCP_REGISTRY_GITHUB_OIDC_AUDIENCE"), + Value: pulumi.String(func() string { + if environment == "prod" { + return "https://registry.modelcontextprotocol.io" + } + return "https://" + environment + ".registry.modelcontextprotocol.io" + }()), + }, + }, + // StartupProbe protects the DB-retry budget in cmd/registry/main.go: + // 30 ร— 5s = 150s allowed before liveness/readiness take over, which + // covers the worst-case retry budget (8 attempts ร— 10s + ~40s sleep). + StartupProbe: &corev1.ProbeArgs{ + HttpGet: &corev1.HTTPGetActionArgs{ + Path: pulumi.String("/v0/health"), + Port: pulumi.Int(8080), + }, + PeriodSeconds: pulumi.Int(5), + FailureThreshold: pulumi.Int(30), + TimeoutSeconds: pulumi.Int(3), }, LivenessProbe: &corev1.ProbeArgs{ HttpGet: &corev1.HTTPGetActionArgs{ @@ -186,12 +224,20 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env TimeoutSeconds: pulumi.Int(3), }, Resources: &corev1.ResourceRequirementsArgs{ + // Memory was 256Mi/512Mi when pgxpool MaxConns was 30. After + // #1221 doubled MaxConns to 60 per pod, peak per-pod memory + // shifted from ~330MB to ~450MB under scraper load and one + // pod was OOMKilled at 17:01 UTC on 2026-04-29. pgxpool keeps + // per-connection state (prepared statement cache, scratch + // buffers, row iteration state) so memory scales roughly + // linearly with the connection count. Doubled both request + // and limit to match. Requests: pulumi.StringMap{ - "memory": pulumi.String("128Mi"), + "memory": pulumi.String("512Mi"), "cpu": pulumi.String("100m"), }, Limits: pulumi.StringMap{ - "memory": pulumi.String("256Mi"), + "memory": pulumi.String("1Gi"), }, }, }, @@ -204,6 +250,31 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env return nil, err } + // Keep at least one registry pod available during voluntary disruptions + // (node drains, evictions, etc.) so a synchronized eviction can't take both + // pods down at once. + _, err = policyv1.NewPodDisruptionBudget(ctx, "mcp-registry", &policyv1.PodDisruptionBudgetArgs{ + Metadata: &metav1.ObjectMetaArgs{ + Name: pulumi.String("mcp-registry"), + Namespace: pulumi.String("default"), + Labels: pulumi.StringMap{ + "app": pulumi.String("mcp-registry"), + "environment": pulumi.String(environment), + }, + }, + Spec: &policyv1.PodDisruptionBudgetSpecArgs{ + MinAvailable: pulumi.Int(1), + Selector: &metav1.LabelSelectorArgs{ + MatchLabels: pulumi.StringMap{ + "app": pulumi.String("mcp-registry"), + }, + }, + }, + }, pulumi.Provider(cluster.Provider)) + if err != nil { + return nil, err + } + // Create Service service, err := corev1.NewService(ctx, "mcp-registry", &corev1.ServiceArgs{ Metadata: &metav1.ObjectMetaArgs{ @@ -253,11 +324,12 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env Annotations: pulumi.StringMap{ "cert-manager.io/cluster-issuer": pulumi.String("letsencrypt-prod"), "kubernetes.io/ingress.class": pulumi.String("nginx"), - // Rate limiting to protect against abuse - // Allows 180 requests/minute (3 req/sec avg), with bursts up to 540 requests - // Status code 429 is set globally via NGINX ConfigMap (per-Ingress annotation doesn't work) - "nginx.ingress.kubernetes.io/limit-rpm": pulumi.String("180"), - "nginx.ingress.kubernetes.io/limit-burst-multiplier": pulumi.String("3"), + // Rate limiting to protect against abuse. The exact bulk-list paths get a + // separate, higher budget below; all other routes retain this limit. + // Allows 180 requests/minute (3 req/sec avg), with bursts up to 540 requests. + // Status code 429 is set globally via NGINX ConfigMap (per-Ingress annotation doesn't work). + "nginx.ingress.kubernetes.io/limit-rpm": pulumi.String("180"), + "nginx.ingress.kubernetes.io/limit-burst-multiplier": pulumi.String("3"), }, }, Spec: &networkingv1.IngressSpecArgs{ @@ -298,6 +370,87 @@ func DeployMCPRegistry(ctx *pulumi.Context, cluster *providers.ProviderInfo, env return nil, err } + // Bulk registry consumers paginate the complete server list. Production + // traffic analysis on 2026-08-06 showed legitimate consumers sustaining + // roughly 10 requests/second per source IP while the catch-all Ingress only + // allowed 3 requests/second per controller replica. That caused NGINX to + // reject healthy pagination requests before they reached the application. + // The ingress controller caches these exact public paths for 30 seconds, so + // the higher client budget does not translate into the same increase in + // application and database load. + // + // ingress-nginx merges different paths for the same host across Ingress + // resources and applies each resource's annotations only to its own paths. + // Keep the canonical list endpoints on exact paths so publish, auth, edit, + // status, and individual-server reads remain protected by the lower limit. + _, err = networkingv1.NewIngress(ctx, "mcp-registry-bulk-read", &networkingv1.IngressArgs{ + Metadata: &metav1.ObjectMetaArgs{ + Name: pulumi.String("mcp-registry-bulk-read"), + Namespace: pulumi.String("default"), + Labels: pulumi.StringMap{ + "app": pulumi.String("mcp-registry"), + "environment": pulumi.String(environment), + }, + Annotations: pulumi.StringMap{ + // ingress-nginx disables response buffering by default, but NGINX + // needs it to populate the on-disk proxy cache for these paths. + "nginx.ingress.kubernetes.io/proxy-buffering": pulumi.String("on"), + // Limits are maintained independently by each ingress-nginx replica. + // At two production replicas this permits up to 1,200 requests/minute + // per source IP, while a single replica still accommodates the observed + // 10 requests/second pagination rate. + "nginx.ingress.kubernetes.io/limit-rpm": pulumi.String("600"), + "nginx.ingress.kubernetes.io/limit-burst-multiplier": pulumi.String("3"), + }, + }, + Spec: &networkingv1.IngressSpecArgs{ + IngressClassName: pulumi.String("nginx"), + Rules: pulumi.ToStringArray(hosts).ToStringArrayOutput().ApplyT(func(hosts []string) networkingv1.IngressRuleArray { + rules := make(networkingv1.IngressRuleArray, 0, len(hosts)) + for _, host := range hosts { + rules = append(rules, &networkingv1.IngressRuleArgs{ + Host: pulumi.String(host), + Http: &networkingv1.HTTPIngressRuleValueArgs{ + Paths: networkingv1.HTTPIngressPathArray{ + // Exact prevents the higher budget from applying to edit/status + // subpaths. The v0.1 dot is accepted because ingress.go disables + // strict path validation for this controller. + &networkingv1.HTTPIngressPathArgs{ + Path: pulumi.String("/v0/servers"), + PathType: pulumi.String("Exact"), + Backend: &networkingv1.IngressBackendArgs{ + Service: &networkingv1.IngressServiceBackendArgs{ + Name: service.Metadata.Name().Elem(), + Port: &networkingv1.ServiceBackendPortArgs{ + Number: pulumi.Int(80), + }, + }, + }, + }, + &networkingv1.HTTPIngressPathArgs{ + Path: pulumi.String("/v0.1/servers"), + PathType: pulumi.String("Exact"), + Backend: &networkingv1.IngressBackendArgs{ + Service: &networkingv1.IngressServiceBackendArgs{ + Name: service.Metadata.Name().Elem(), + Port: &networkingv1.ServiceBackendPortArgs{ + Number: pulumi.Int(80), + }, + }, + }, + }, + }, + }, + }) + } + return rules + }).(networkingv1.IngressRuleArrayOutput), + }, + }, pulumi.Provider(cluster.Provider), pulumi.DependsOnInputs(ingressNginx.Ready)) + if err != nil { + return nil, err + } + ctx.Export("ingressHosts", ingress.Spec.Rules().ApplyT(func(rules []networkingv1.IngressRule) []string { hosts := make([]string, 0, len(rules)) for _, rule := range rules { diff --git a/deploy/pkg/providers/gcp/provider.go b/deploy/pkg/providers/gcp/provider.go index 108a209..e4f1e76 100644 --- a/deploy/pkg/providers/gcp/provider.go +++ b/deploy/pkg/providers/gcp/provider.go @@ -3,9 +3,12 @@ package gcp import ( "encoding/base64" "fmt" + "strings" "github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp" + "github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/compute" "github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/container" + "github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/projects" "github.com/pulumi/pulumi-gcp/sdk/v8/go/gcp/storage" "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes" corev1 "github.com/pulumi/pulumi-kubernetes/sdk/v4/go/kubernetes/core/v1" @@ -58,6 +61,125 @@ func createGCPProvider(ctx *pulumi.Context, name string) (*gcp.Provider, error) return nil, nil } +// ensureRequiredAPIs adopts the GCP APIs the deploy depends on as Pulumi-managed +// services. Encoding them as Pulumi resources makes the dependency explicit and +// protects against drift (an org policy reset or accidental disable). +// +// Note: bootstrap APIs (storage, cloudresourcemanager, container โ€” see +// deploy/README.md) must already be enabled before this runs, because the +// resources that need them are created earlier in the stack. For those, this +// function adopts them into Pulumi state after the fact. For the rest (logging, +// monitoring), the adoption happens before any consumer runs. +// +// DisableOnDestroy and DisableDependentServices are both false โ€” a Pulumi destroy +// or refactor must never disable a shared API that other resources (and humans) +// rely on. Enable-only. +// +// Returns the Cloud Resource Manager API resource specifically, since the node-SA +// IAM bindings need to DependsOn it (SetIamPolicy is gated on CRM). +func ensureRequiredAPIs(ctx *pulumi.Context, projectID string, resourceOpts []pulumi.ResourceOption) (*projects.Service, error) { + // Service Usage API (which projects.NewService itself uses) is enabled by default + // on GCP projects, so we don't need to manage it here. + + // CRM is created explicitly (not in the loop below) because callers need a + // direct reference to it for DependsOn โ€” projects.NewIAMMember calls + // SetIamPolicy under the hood, which is gated on CRM. + crm, err := projects.NewService(ctx, "crm-api", &projects.ServiceArgs{ + Project: pulumi.String(projectID), + Service: pulumi.String("cloudresourcemanager.googleapis.com"), + DisableOnDestroy: pulumi.Bool(false), + DisableDependentServices: pulumi.Bool(false), + }, resourceOpts...) + if err != nil { + return nil, fmt.Errorf("failed to ensure cloudresourcemanager.googleapis.com is enabled: %w", err) + } + + otherAPIs := []struct { + resourceName string + serviceName string + }{ + // Required for compute.GetDefaultServiceAccount and the GKE cluster. + {"compute-api", "compute.googleapis.com"}, + // Required for the GKE cluster. + {"container-api", "container.googleapis.com"}, + // Required for fluentbit-gke to ship container logs. + {"logging-api", "logging.googleapis.com"}, + // Required for the managed Prometheus collector to ship metrics. + {"monitoring-api", "monitoring.googleapis.com"}, + } + + for _, api := range otherAPIs { + _, err := projects.NewService(ctx, api.resourceName, &projects.ServiceArgs{ + Project: pulumi.String(projectID), + Service: pulumi.String(api.serviceName), + DisableOnDestroy: pulumi.Bool(false), + DisableDependentServices: pulumi.Bool(false), + }, resourceOpts...) + if err != nil { + return nil, fmt.Errorf("failed to ensure %s is enabled: %w", api.serviceName, err) + } + } + return crm, nil +} + +// grantNodeServiceAccountRoles grants the default compute service account the standard +// GKE node roles required for log shipping (fluentbit-gke) and metrics scraping +// (managed Prometheus). New GCP projects no longer auto-grant Editor to the default +// compute SA, so these have to be set explicitly or every pod log/metric is dropped. +// +// The IAM bindings depend on Cloud Resource Manager API being enabled (managed by +// ensureRequiredAPIs above) โ€” without it, projects.NewIAMMember fails because +// SetIamPolicy lives behind that API. +func grantNodeServiceAccountRoles(ctx *pulumi.Context, projectID string, gcpProvider *gcp.Provider) error { + invokeOpts := []pulumi.InvokeOption{} + resourceOpts := []pulumi.ResourceOption{} + if gcpProvider != nil { + invokeOpts = append(invokeOpts, pulumi.Provider(gcpProvider)) + resourceOpts = append(resourceOpts, pulumi.Provider(gcpProvider)) + } + + crmAPI, err := ensureRequiredAPIs(ctx, projectID, resourceOpts) + if err != nil { + return err + } + + // Get the default compute SA email directly from the Compute API instead of + // constructing it from the project number โ€” avoids needing CRM API just for + // the project lookup, and matches whatever GCP actually returns. + defaultSA, err := compute.GetDefaultServiceAccount(ctx, &compute.GetDefaultServiceAccountArgs{ + Project: pulumi.StringRef(projectID), + }, invokeOpts...) + if err != nil { + return fmt.Errorf("failed to look up default compute service account: %w", err) + } + + nodeSA := "serviceAccount:" + defaultSA.Email + + roles := []string{ + "roles/logging.logWriter", + "roles/monitoring.metricWriter", + "roles/monitoring.viewer", + "roles/stackdriver.resourceMetadata.writer", + } + + bindingOpts := make([]pulumi.ResourceOption, 0, len(resourceOpts)+1) + bindingOpts = append(bindingOpts, resourceOpts...) + bindingOpts = append(bindingOpts, pulumi.DependsOn([]pulumi.Resource{crmAPI})) + for _, role := range roles { + name := fmt.Sprintf("node-sa-%s", strings.ReplaceAll(strings.TrimPrefix(role, "roles/"), ".", "-")) + _, err := projects.NewIAMMember(ctx, name, &projects.IAMMemberArgs{ + Project: pulumi.String(projectID), + Role: pulumi.String(role), + Member: pulumi.String(nodeSA), + }, bindingOpts...) + if err != nil { + return fmt.Errorf("failed to grant %s to node SA: %w", role, err) + } + } + + return nil +} + // CreateCluster creates a Google Kubernetes Engine cluster func (p *Provider) CreateCluster(ctx *pulumi.Context, environment string) (*providers.ProviderInfo, error) { // Get configuration @@ -152,6 +274,13 @@ func (p *Provider) CreateCluster(ctx *pulumi.Context, environment string) (*prov return nil, fmt.Errorf("failed to create node pool: %w", err) } + // Grant the default compute service account the standard GKE node roles so the + // fluentbit-gke and managed Prometheus collectors can ship logs and metrics. + // Without these, every pod log line and time series fails with IAM_PERMISSION_DENIED. + if err := grantNodeServiceAccountRoles(ctx, projectID, gcpProvider); err != nil { + return nil, err + } + // Create Kubernetes provider using the cluster directly k8sProvider, err := kubernetes.NewProvider(ctx, "k8s-provider", &kubernetes.ProviderArgs{ Kubeconfig: pulumi.All(cluster.Endpoint, cluster.MasterAuth).ApplyT(func(args []any) (string, error) { diff --git a/docker-compose.yml b/docker-compose.yml index 7eb71c2..3fff7bc 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -10,7 +10,6 @@ services: # See .env.example for more documentation environment: - MCP_REGISTRY_DATABASE_URL=${MCP_REGISTRY_DATABASE_URL:-postgres://mcpregistry:mcpregistry@postgres:5432/mcp-registry} - - MCP_REGISTRY_ENVIRONMENT=${MCP_REGISTRY_ENVIRONMENT:-test} - MCP_REGISTRY_GITHUB_CLIENT_ID=${MCP_REGISTRY_GITHUB_CLIENT_ID:-Iv23licy3GSiM9Km5jtd} - MCP_REGISTRY_GITHUB_CLIENT_SECRET=${MCP_REGISTRY_GITHUB_CLIENT_SECRET:-0e8db54879b02c29adef51795586f3c510a9341d} - MCP_REGISTRY_JWT_PRIVATE_KEY=${MCP_REGISTRY_JWT_PRIVATE_KEY:-8103179d8ef955f6d3de6d6217224a909ec4060529dfeb1d4ca5a994537658cd} diff --git a/docs/README.md b/docs/README.md index cb06d3e..d276482 100644 --- a/docs/README.md +++ b/docs/README.md @@ -17,3 +17,4 @@ The MCP registry provides MCP clients with a list of MCP servers, like an app st - ๐Ÿ“– [Reference](./reference/) - Technical specifications - ๐Ÿ”ง [Contributing guides](./contributing/) - How to contribute - ๐Ÿ”’ [Administration](./administration/) - Admin operations +- ๐Ÿค [Community projects](./community-projects.md) - Notable registry-related work from the community diff --git a/docs/administration/admin-operations.md b/docs/administration/admin-operations.md index 6b3a04d..f3131bf 100644 --- a/docs/administration/admin-operations.md +++ b/docs/administration/admin-operations.md @@ -1,6 +1,6 @@ # Admin Operations -This is a brief guide for admins and moderators managing content on the registry. All actions should be taken in line with the [moderation guidelines](moderation-guidelines.md). +This is a brief guide for admins and moderators managing content on the registry. All actions should be taken in line with the [moderation policy](../modelcontextprotocol-io/moderation-policy.mdx). ## Prerequisites @@ -33,8 +33,8 @@ ENCODED_SERVER_NAME=$(echo "$SERVER_NAME" | sed 's|/|%2F|g') # Get specific version curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/${VERSION}" > server.json -# Or get latest version (omit /versions/VERSION) -curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}" > server.json +# Or get the latest version (use the special version "latest") +curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/latest" > server.json ``` ### Step 2: Make Changes @@ -44,19 +44,46 @@ Open `server.json` and edit the specific version details. You cannot change the ### Step 3: Update Version ```bash -# Update specific version +# Update specific version (requires the full server.json body) curl -X PUT "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/${VERSION}" \ -H "Authorization: Bearer ${REGISTRY_TOKEN}" \ -H "Content-Type: application/json" \ -d "$(cat server.json)" +``` +To change **only** the status of a version, use the status endpoint instead โ€” it does not require +the full server configuration: + +```bash +curl -X PATCH "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/${VERSION}/status" \ + -H "Authorization: Bearer ${REGISTRY_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{"status": "deprecated", "statusMessage": "Superseded by v2"}' ``` ## Edit an Entire Server (All Versions) -Use this when you need to apply changes across all versions of a server (e.g., mark entire server as deleted, apply content scrubbing). +### Status Changes Across All Versions -### Step 1: List All Versions +A status change applies to every version of a server in a single request. The response reports +how many versions were updated in `updatedCount`. + +```bash +export SERVER_NAME="" # e.g., "com.example/my-server" +ENCODED_SERVER_NAME=$(echo "$SERVER_NAME" | sed 's|/|%2F|g') + +curl -X PATCH "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/status" \ + -H "Authorization: Bearer ${REGISTRY_TOKEN}" \ + -H "Content-Type: application/json" \ + -d '{"status": "deleted", "statusMessage": "Removed per moderation policy"}' +``` + +### Content Changes Across All Versions + +Content edits (e.g. scrubbing sensitive text from descriptions) have no bulk endpoint and must be +applied per version using the edit endpoint, which takes the full server configuration. + +#### Step 1: List All Versions ```bash export SERVER_NAME="" # e.g., "com.example/my-server" @@ -65,29 +92,32 @@ ENCODED_SERVER_NAME=$(echo "$SERVER_NAME" | sed 's|/|%2F|g') curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions" > all_versions.json ``` -### Step 2: Extract Versions +#### Step 2: Extract Versions ```bash # Extract all versions from the server jq -r '.servers[].server.version' all_versions.json > versions.txt ``` -### Step 3: Apply Changes to All Versions +#### Step 3: Apply Changes to Each Version ```bash -# For each version, apply changes using the edit endpoint while read VERSION; do echo "Processing version: $VERSION" - # Apply your changes here (e.g., set status to "deleted") - curl -X PUT "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/${VERSION}?status=deleted" \ + # Download the version, edit it, then send the full body back + curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/${VERSION}" > version.json + + # Apply your changes to version.json here, then: + curl -X PUT "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/${VERSION}" \ -H "Authorization: Bearer ${REGISTRY_TOKEN}" \ - -H "Content-Type: application/json" + -H "Content-Type: application/json" \ + -d "$(cat version.json)" done < versions.txt # Clean up temporary files -rm versions.txt all_versions.json +rm -f versions.txt all_versions.json version.json ``` ## Quick Operations @@ -98,7 +128,7 @@ rm versions.txt all_versions.json export SERVER_NAME="" # e.g., "com.example/my-server" ENCODED_SERVER_NAME=$(echo "$SERVER_NAME" | sed 's|/|%2F|g') -curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}" > latest_version.json +curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/latest" > latest_version.json export VERSION=$(jq -r '.server.version' latest_version.json) echo "Latest version: $VERSION" ``` @@ -113,30 +143,37 @@ export REGISTRY_TOKEN="" REGISTRY_TOKEN="$REGISTRY_TOKEN" SERVER_NAME="$SERVER_NAME" VERSION="$VERSION" ./tools/admin/takedown.sh ``` -### Takedown Latest Version (Entire Server) +### Takedown All Versions of a Server + +`ALL_VERSIONS=true` marks every version as deleted in a single request. The script requires either +`VERSION` or `ALL_VERSIONS` to be set explicitly, so a forgotten `VERSION` cannot take down a whole +server by accident. ```bash export SERVER_NAME="" # e.g., "com.example/my-server" export REGISTRY_TOKEN="" -# This marks the latest version as deleted -REGISTRY_TOKEN="$REGISTRY_TOKEN" SERVER_NAME="$SERVER_NAME" ./tools/admin/takedown.sh +REGISTRY_TOKEN="$REGISTRY_TOKEN" SERVER_NAME="$SERVER_NAME" ALL_VERSIONS=true ./tools/admin/takedown.sh ``` -### Takedown All Versions of a Server +### Takedown the Latest Version Only ```bash export SERVER_NAME="" # e.g., "com.example/my-server" export REGISTRY_TOKEN="" ENCODED_SERVER_NAME=$(echo "$SERVER_NAME" | sed 's|/|%2F|g') -# Get all versions and takedown each one -curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions" | \ - jq -r '.servers[].server.version' | \ - while read VERSION; do - echo "Taking down version: $VERSION" - REGISTRY_TOKEN="$REGISTRY_TOKEN" SERVER_NAME="$SERVER_NAME" VERSION="$VERSION" ./tools/admin/takedown.sh - done +# Resolve the latest version, then take down that specific version +VERSION=$(curl -s "https://registry.modelcontextprotocol.io/v0/servers/${ENCODED_SERVER_NAME}/versions/latest" | jq -r '.server.version') + +REGISTRY_TOKEN="$REGISTRY_TOKEN" SERVER_NAME="$SERVER_NAME" VERSION="$VERSION" ./tools/admin/takedown.sh +``` + +### Record a Reason with a Takedown + +```bash +REGISTRY_TOKEN="$REGISTRY_TOKEN" SERVER_NAME="$SERVER_NAME" ALL_VERSIONS=true \ + STATUS_MESSAGE="Removed per moderation policy" ./tools/admin/takedown.sh ``` ## Connecting to the Production Database @@ -179,6 +216,8 @@ Any write attempts will fail with an error until you disconnect. ## Notes - **Version-specific changes**: Only affect that particular version -- **Server-wide changes**: Must be applied to each version individually +- **Server-wide status changes**: `PATCH /v0/servers/{serverName}/status` updates every version in one request +- **Server-wide content changes**: Have no bulk endpoint and must be applied to each version individually +- **Status vs. edit**: Use `PATCH .../status` to change status alone; the `PUT` edit endpoint requires the full server configuration - **Content scrubbing**: Use the version-specific edit workflow to scrub sensitive content - **Server name**: Cannot be changed in any version (it's the immutable identifier) diff --git a/docs/administration/maintainer-onboarding.md b/docs/administration/maintainer-onboarding.md index f6e3871..aab0bea 100644 --- a/docs/administration/maintainer-onboarding.md +++ b/docs/administration/maintainer-onboarding.md @@ -16,7 +16,7 @@ When onboarding a new maintainer, complete the following steps: ### 3. README.md -- [ ] Add them to the "Current key maintainers" section in [README.md](../../README.md) +- [ ] Add them to the "Registry Working Group" section in [README.md](../../README.md) ### 4. Discord diff --git a/docs/community-projects.md b/docs/community-projects.md index ef59bf5..2708839 100644 --- a/docs/community-projects.md +++ b/docs/community-projects.md @@ -20,6 +20,13 @@ Browse the official MCP Registry in your browser! - [mcp-registry-spec-sdk](https://www.npmjs.com/package/mcp-registry-spec-sdk) - TypeScript client for the MCP Registry - [LangChain4j MCP Registry Java client](https://docs.langchain4j.dev/tutorials/mcp/#mcp-registry-client) - Java API +### Registry Implementations + +Self-hostable servers that implement the MCP Registry API specification. + +- [ToolSDK MCP Registry](https://github.com/toolsdk-ai/toolsdk-mcp-registry) - Extends the MCP Registry with **API-based MCP execution, private deployment**, and **secure sandbox isolation**. +- [ToolHive Registry Server](https://github.com/stacklok/toolhive-registry-server) - Enterprise-grade MCP Registry API implementation with Kubernetes-native CRD discovery, OIDC/JWT claim-based access control, multi-source aggregation (Git, K8s, upstream registries), SIEM-compliant audit logging, and OpenTelemetry observability. + ### Other - [MCP Registry Cheat Sheet](https://github.com/subbyte/mcp-registry-cheatsheet) - MCP Registry Cheat Sheet for MCP server developers, client developers, and registry admin @@ -28,7 +35,8 @@ Browse the official MCP Registry in your browser! - [mcp-insights](https://github.com/joelverhagen/mcp-insights/) - Analytics and insights for the MCP Registry - [mcp-registry-cli](https://pypi.org/project/mcp-registry-cli/) - CLI tool to navigate the MCP registry servers - [OtherVibes/mcp-publish-action](https://github.com/OtherVibes/mcp-publish-action) - GitHub Action for publishing MCP servers to the official registry -- [ToolSDK MCP Registry](https://github.com/toolsdk-ai/toolsdk-mcp-registry) - Extends the MCP Registry with **API-based MCP execution, private deployment**, and **secure sandbox isolation**. +- [polygraph](https://polygraph.so) - Independent behavioral security grades (Aโ€“F) for MCP servers from an open, reproducible harness, published as an adoption-ranked index with per-server reports +- [PulseFeed MCP Drift Watch](https://pulsefeed.dev/mcp/drift) - Daily external diff of the whole registry population, recording what changed in a server *after* it was listed: package ownership transferred, install script added in a later version, repository removed, package unpublished, a removed name republished by someone else. Free JSON/RSS feed filterable to your own packages, a README badge, and webhook alerts; series runs from 2026-07-30 and each day's manifest is timestamped into Bitcoin. ## Adding Your Project diff --git a/docs/contributing/add-package-registry.md b/docs/contributing/add-package-registry.md index be0a6ea..f6e07c8 100644 --- a/docs/contributing/add-package-registry.md +++ b/docs/contributing/add-package-registry.md @@ -2,9 +2,9 @@ The MCP Registry project is a **metaregistry**, meaning that it hosts metadata for MCP servers but does not host the code for the servers directly. -For local MCP servers, the MCP Registry has pointers in the `packages` node of the [`server.json`](../../reference/server-json/generic-server-json.md) schema that refer to packages in supported package managers. +For local MCP servers, the MCP Registry has pointers in the `packages` node of the [`server.json`](../reference/server-json/generic-server-json.md) schema that refer to packages in supported package managers. -The list of supported package managers for hosting MCP servers is defined by the `properties.packages[N].properties.registryType` string enum in the [`server.json` schema](../../reference/server-json/draft/server.schema.json). For example, this could be "npm" (for npmjs.com packages) or "pypi" (for PyPI packages). +The list of supported package managers for hosting MCP servers is defined by the `properties.packages[N].properties.registryType` string enum in the [`server.json` schema](../reference/server-json/draft/server.schema.json). For example, this could be "npm" (for npmjs.com packages) or "pypi" (for PyPI packages). For remote MCP servers, the package registry is not relevant. The MCP client consumes the server via a URL instead of by downloading and running a package. In other words, this document only applies to local MCP servers. @@ -33,15 +33,15 @@ These steps may evolve as additional validations or details are discovered and m 1. [Create a feature request issue](https://github.com/modelcontextprotocol/registry/issues/new?template=feature_request.md) on the MCP Registry repository to begin the discussion about adding the package registry. - Example for NuGet: https://github.com/modelcontextprotocol/registry/issues/126 1. Open a PR with the following changes: - - Update the [`server.json` schema](../../reference/server-json/draft/server.schema.json) + - Update the [`server.json` schema](../reference/server-json/draft/server.schema.json) - Add your package registry name to the `registryType` example array. - Add your package registry base url to the `registryBaseUrl` example array. - Add the single-shot CLI command name to the `runtimeHint` example value array. - - Update the [`openapi.yaml`](../../reference/api/openapi.yaml) + - Update the [`openapi.yaml`](../reference/api/openapi.yaml) - Add your package registry name to the `registryType` enum value array. - Add your package registry base url to the `registryBaseUrl` enum value array. - Add the single-shot CLI command name to the `runtimeHint` example value array. - - Add a sample, minimal `server.json` to the [`server.json` examples](../../reference/server-json/generic-server-json.md). + - Add a sample, minimal `server.json` to the [`server.json` examples](../reference/server-json/generic-server-json.md). - Implement a registry validator: - Create a new validator file: `internal/validators/registries/yourregistry.go`, following the pattern of existing validators. Examples: - **npm**: Checks for an `mcpName` field in `package.json` that matches the server name @@ -51,6 +51,5 @@ These steps may evolve as additional validations or details are discovered and m - Add corresponding unit tests: `internal/validators/registries/yourregistry_test.go` - Register your validator in `internal/validators/validators.go` - Update the publishing documentation: - - Add a new publishing guide: `docs/guides/publishing/publish-[yourregistry].md`, following the pattern of existing publishing guides (e.g., `publish-npm.md`, `publish-pypi.md`) - - Include instructions on how to prepare packages for your registry, including any specific validation requirements - - Update `docs/guides/publishing/README.md` to reference your new publishing guide + - Add a section for your registry to `docs/modelcontextprotocol-io/package-types.mdx`, following the pattern of the existing registries (npm, PyPI, NuGet, ...) + - Include instructions on how to prepare packages for your registry, and an `### Ownership Verification` subsection describing the validation your registry requires diff --git a/docs/contributing/releasing.md b/docs/contributing/releasing.md index bbf9345..56f205b 100644 --- a/docs/contributing/releasing.md +++ b/docs/contributing/releasing.md @@ -5,8 +5,8 @@ 1. **Go to GitHub**: Navigate to https://github.com/modelcontextprotocol/registry/releases 2. **Click "Draft a new release"** 3. **Choose a tag**: Click "Choose a tag" and type a new semantic version that follows the last one available (e.g., `v1.0.0`) -5. **Generate notes**: Click "Generate release notes" to auto-populate the name and description -6. **Publish**: Click "Publish release" +4. **Generate notes**: Click "Generate release notes" to auto-populate the name and description +5. **Publish**: Click "Publish release" The release workflow will automatically: - Build binaries for 6 platforms (Linux, macOS, Windows ร— amd64, arm64) @@ -27,13 +27,13 @@ Releases do not automatically deploy to production. To deploy a release: 1. Update `mcp-registry:imageTag` in `deploy/Pulumi.gcpProd.yaml` to the desired version (e.g., `1.2.3` - note: no 'v' prefix) 2. Commit and push the change to the `main` branch (either through a PR or by pushing directly to main) -3. The [deploy-production.yml](../../../.github/workflows/deploy-production.yml) workflow will automatically trigger and deploy the specified version +3. The [deploy-production.yml](../../.github/workflows/deploy-production.yml) workflow will automatically trigger and deploy the specified version -See the [deployment documentation](../../../deploy/README.md) for more details. +See the [deployment documentation](../../deploy/README.md) for more details. ## Staging -Staging auto-deploys from `main` via [deploy-staging.yml](../../../.github/workflows/deploy-staging.yml). It always runs the latest `main` branch code. +Staging auto-deploys from `main` via [deploy-staging.yml](../../.github/workflows/deploy-staging.yml). It always runs the latest `main` branch code. ## Rollback diff --git a/docs/design/design-principles.md b/docs/design/design-principles.md index d76627a..7d805be 100644 --- a/docs/design/design-principles.md +++ b/docs/design/design-principles.md @@ -25,13 +25,13 @@ The registry serves as the authoritative metadata repository for publicly-availa - Use mechanisms like DNS verification, OAuth to provide base layer of authentication and trust - Implement rate limiting, field validation, and blacklisting to prevent abuse -## 6. Reusable, Extensible Shapes; Not Infrastructure +## 5. Reusable, Extensible Shapes; Not Infrastructure - API shapes (OpenAPI, server.json) designed for reuse - Enable private/internal registries using same formats - Don't mandate infrastructure reuse - focus on interface compatibility -## 7. Progressive Enhancement +## 6. Progressive Enhancement - Start with MVP that provides immediate value - Build foundation that supports future features diff --git a/docs/design/roadmap.md b/docs/design/roadmap.md index 93b552b..8a14ca1 100644 --- a/docs/design/roadmap.md +++ b/docs/design/roadmap.md @@ -6,9 +6,15 @@ This roadmap may occasionally drift out of date. Please review [Issues](https:// ## Current Status +> [!NOTE] +> **The phase labelling below is out of date as of 2026-08-10.** The registry launched in preview on +> 2025-09-08 and the v0.1 API entered a freeze on 2025-10-24, so "Go-Live" has already happened. The +> phases are retained for historical context. See +> [Issues](https://github.com/modelcontextprotocol/registry/issues) for current work. + The initial version of the MCP Registry is actively being developed. The initial focus is on delivering a REST API to which server creators can publish, and aggregator/marketplace consumers can ETL. -## Phase 1: MVP/Go-Live (Current Focus) +## Phase 1: MVP/Go-Live See the [go-live blocker issues](https://github.com/modelcontextprotocol/registry/issues?q=is%3Aissue%20state%3Aopen%20label%3A%22go-live%20blocker%22). diff --git a/docs/design/tech-architecture.md b/docs/design/tech-architecture.md index 03097f7..f7fab72 100644 --- a/docs/design/tech-architecture.md +++ b/docs/design/tech-architecture.md @@ -1,5 +1,26 @@ # MCP Registry Technical Architecture +> [!WARNING] +> **This document has drifted from the shipped system and is kept as a design record.** +> For the architecture as deployed, see [deploy/README.md](../../deploy/README.md); for the API as +> implemented, see the [API reference](../reference/api/official-registry-api.md). +> +> Known inaccuracies below, as of 2026-08-10: +> - The registry is not deployed via a Helm chart. It is a plain Kubernetes `Deployment` created by +> Pulumi; Helm is used only for third-party components (ingress-nginx, cert-manager, +> cloudnative-pg, k8up, monitoring). +> - The database diagram shows a `StatefulSet` on port `27017` (MongoDB). The database is PostgreSQL +> on `5432`, provisioned by the CloudNativePG operator. +> - The DNS verification sequence (`mcp verify-domain`, `POST /verify-domain`, +> `POST /verify-domain/check`, server-issued challenge tokens) describes a design that was never +> built. The shipped flow signs a timestamp with the operator's key and posts it to +> `POST /v0/auth/dns`, with the public key published in a `v=MCPv1; k=...; p=...` TXT record. +> - No `/admin/*` routes exist. Admin actions use the regular server endpoints with an +> admin-permissioned token. +> - The CLI is `mcp-publisher`, not `mcp`, and publishing posts to `/v0/publish`. +> - The database stores servers and server extensions only; it holds no user authentication state +> and no DNS verification records. + This document describes the technical architecture of the MCP Registry, including system components, deployment strategies, and data flows. ## System Overview diff --git a/docs/modelcontextprotocol-io/authentication.mdx b/docs/modelcontextprotocol-io/authentication.mdx index c18268c..59d7218 100644 --- a/docs/modelcontextprotocol-io/authentication.mdx +++ b/docs/modelcontextprotocol-io/authentication.mdx @@ -47,12 +47,35 @@ Successfully authenticated! โœ“ Successfully logged in ``` +### Personal vs. organization namespaces + +GitHub authentication always grants your personal namespace, `io.github./*`. + +To publish under an **organization** namespace (`io.github./*`), you must be an **Owner** of that organization. Ordinary org membership is no longer sufficient: the registry checks your membership role and only grants the org namespace to admins. This prevents anyone who merely belongs to an org from publishing โ€” or overwriting โ€” servers under the org's name. + +If you authenticate with a Personal Access Token (for example in CI), the token must let the registry read your organization role. A token that can't will still publish to your personal namespace, but org publishing will be silently unavailable. The exact requirement depends on the token type: + +- **Classic PAT**: grant the `read:org` scope. +- **Fine-grained PAT**: grant the **Organization permissions โ†’ Members โ†’ Read-only** permission (the fine-grained equivalent of `read:org`). Without it, GitHub returns no organization membership for the token and you'll get your personal namespace only. Note that a fine-grained PAT is bound to a single resource owner, so it can only see the organization it was created for. + +Either way the token needs **no** repository scopes โ€” the registry never reads or writes your code. + ## DNS Authentication DNS authentication is a domain-based authentication method that relies on a DNS TXT record. + + The TXT record must be placed on the **apex** of your domain (e.g. `example.com`), **not** under a selector like `_mcp-auth.example.com` or `_mcp-registry.example.com`. MCP DNS auth follows SPF-style placement (apex), not DKIM-style (selector). If you put the record under a selector, the registry will not see it and authentication will fail with a generic signature error. + + If you rotate keys, also remember to remove the previous TXT record from the apex โ€” a stale record left behind will be tried first and cause verification to fail. + + To perform DNS authentication using the `mcp-publisher` CLI tool, run the following commands in your server project directory to generate a TXT record based on a public/private key pair: + + The Ed25519 codepath requires **OpenSSL 3.0 or later**. macOS ships with LibreSSL by default (the system `openssl` binary), which does not implement Ed25519 in `genpkey` and fails with `Algorithm Ed25519 not found`. On macOS, install OpenSSL 3 (`brew install openssl@3`) and invoke it explicitly โ€” for example, replace `openssl` with `/opt/homebrew/opt/openssl@3/bin/openssl` (Apple Silicon) or `/usr/local/opt/openssl@3/bin/openssl` (Intel) in the commands below. The ECDSA P-384 codepath works on LibreSSL. + + ```bash Ed25519 @@ -151,7 +174,7 @@ mcp-publisher login dns --domain "${MY_DOMAIN}" --private-key "${PRIVATE_KEY}" MY_DOMAIN="example.com" PRIVATE_KEY="$(openssl ec -in key.pem -noout -text | grep -A4 "priv:" | tail -n +2 | tr -d ' :\n')" -mcp-publisher login dns --domain "${MY_DOMAIN}" --private-key "${PRIVATE_KEY}" +mcp-publisher login dns --algorithm ecdsap384 --domain "${MY_DOMAIN}" --private-key "${PRIVATE_KEY}" ``` ```bash Google KMS @@ -179,6 +202,10 @@ HTTP authentication is a domain-based authentication method that relies on a `/. To perform HTTP authentication using the `mcp-publisher` CLI tool, run the following commands in your server project directory to generate an `mcp-registry-auth` file based on a public/private key pair: + + As with DNS authentication, the Ed25519 codepath requires **OpenSSL 3.0 or later**. macOS's system LibreSSL does not support Ed25519 in `genpkey`. See the note in the [DNS Authentication](#dns-authentication) section for the macOS workaround. + + ```bash Ed25519 @@ -271,7 +298,7 @@ mcp-publisher login http --domain "${MY_DOMAIN}" --private-key "${PRIVATE_KEY}" ```bash ECDSA P-384 MY_DOMAIN="example.com" PRIVATE_KEY="$(openssl ec -in key.pem -noout -text | grep -A4 "priv:" | tail -n +2 | tr -d ' :\n')" -mcp-publisher login http --domain "${MY_DOMAIN}" --private-key "${PRIVATE_KEY}" +mcp-publisher login http --algorithm ecdsap384 --domain "${MY_DOMAIN}" --private-key "${PRIVATE_KEY}" ``` ```bash Google KMS diff --git a/docs/modelcontextprotocol-io/faq.mdx b/docs/modelcontextprotocol-io/faq.mdx index 078ae45..d6c8aab 100644 --- a/docs/modelcontextprotocol-io/faq.mdx +++ b/docs/modelcontextprotocol-io/faq.mdx @@ -52,7 +52,7 @@ There is a 4KB size limit (4096 bytes of JSON). Publishing will fail if this lim ### What if I need to report a spam or malicious server? -1. Report it as abuse to the underlying package registry (e.g. NPM, PyPi, DockerHub, etc.); and +1. Report it as abuse to the underlying package registry (e.g. NPM, PyPI, DockerHub, etc.); and 2. Raise a GitHub issue on the registry repo with a title beginning `Abuse report: ` ### What if I need to report a security vulnerability in the registry itself? diff --git a/docs/modelcontextprotocol-io/github-actions.mdx b/docs/modelcontextprotocol-io/github-actions.mdx index 311b28f..7fcf275 100644 --- a/docs/modelcontextprotocol-io/github-actions.mdx +++ b/docs/modelcontextprotocol-io/github-actions.mdx @@ -81,6 +81,10 @@ on: jobs: publish: runs-on: ubuntu-latest + # Source MCP_GITHUB_TOKEN from a protected Environment, not a plain repo + # secret, and restrict that environment to your default branch / release + # tags. See "Securing your registry token in CI" below for why this matters. + environment: mcp-registry-publish permissions: contents: read @@ -192,16 +196,37 @@ jobs: ## Step 2: Add Secrets -You may need to add a secret to the repository depending on which authentication method you choose: +You may need to add a secret depending on which authentication method you choose: - **GitHub OIDC Authentication**: No dedicated secret necessary. -- **GitHub PAT Authentication**: Add a `MCP_GITHUB_TOKEN` secret with a GitHub Personal Access Token (PAT) that has `read:org` and `read:user` scopes. +- **GitHub PAT Authentication**: Add a `MCP_GITHUB_TOKEN` secret with a GitHub Personal Access Token. The registry only needs to read your organization role to confirm you are an **Owner** before granting its namespace, so grant the minimum for that and **no** repository scopes (the registry never reads or writes your code): + - **Classic PAT**: the `read:org` scope (`read:user` is *not* needed; a bare token still authenticates and publishes to your personal namespace). + - **Fine-grained PAT**: the **Organization permissions โ†’ Members โ†’ Read-only** permission (the equivalent of `read:org`). Without it you'll get your personal namespace only. A fine-grained PAT is scoped to one resource owner, so create it for the organization you're publishing to. + + For an **organization** token, store it as an **Environment secret** on the `mcp-registry-publish` environment rather than a plain repository secret โ€” see "Securing your registry token in CI" below for why this matters and how to configure the environment. - **DNS Authentication**: Add a `MCP_PRIVATE_KEY` secret with your Ed25519 private key. You may also need to add secrets for your package registry. For example, the workflow above needs an `NPM_TOKEN` secret with your npm token. For information about how to add secrets to a repository, see [Using secrets in GitHub Actions](https://docs.github.com/en/actions/how-tos/write-workflows/choose-what-workflows-do/use-secrets). +### Securing your registry token in CI + +Whichever token you use to authenticate, treat it as a high-value credential. When you authenticate to an **organization** namespace, the resulting registry token can publish โ€” and overwrite โ€” **any** server under `io.github./*`, not just the one in this repository. The relevant question for your threat model is therefore: *who can cause code to run in a job where this secret is exposed?* By default that is **every repository writer** (via branch or tag pushes), not only org Owners โ€” so a plain repo secret quietly widens publish access to everyone with write access. + +GitHub gives you the tools to close that gap. We recommend, in increasing order of strength: + +1. **Store the token as an [Environment secret](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments), not a repository or organization secret.** A job can only read an environment secret when it declares `environment:` (as the PAT example above does). Note that the `environment:` key alone protects nothing: if the environment does not exist yet, GitHub **auto-creates it with no protection rules** on first run, and a job that declares `environment:` still also receives ordinary repository and organization secrets. The protection comes from storing the token *as a secret on that environment* and configuring the environment (steps 2โ€“3 below) โ€” not from the `environment:` key by itself. +2. **Restrict that environment to your default branch and/or release tags** with a [deployment branch rule](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments#deployment-branches-and-tags), and protect that branch with [required pull request reviews](https://docs.github.com/en/repositories/configuring-branches-and-merges-in-your-repository/managing-protected-branches/about-protected-branches). Now only reviewed, maintainer-approved code can ever reach the token. +3. **(Strongest) Add a [required reviewer](https://docs.github.com/en/actions/how-tos/deploy/configure-and-manage-deployments/manage-environments#required-reviewers) to the environment** so each publish pauses for an explicit human approval. + +Two pitfalls to avoid regardless of the above: + +- **Never publish from a `pull_request_target` workflow that checks out PR-head code.** That trigger runs with your secrets in the base-repo context, so an untrusted fork PR could exfiltrate the token. Environment branch rules do **not** protect you here (the ref is still your base branch) โ€” only required reviewers do. +- **Avoid self-hosted runners for the publish job on public repositories**, where fork PRs may be able to schedule jobs onto them. + +By default, pull requests **from forks** receive no secrets and cannot push branches, so external contributors cannot reach the token without one of the misconfigurations above. + ## Step 3: Tag and Release Create and push a version tag to trigger the workflow: @@ -220,6 +245,7 @@ The workflow will run tests, build the package, publish the package to npm, and | Error Message | Action | | --- | --- | | "Authentication failed" | Ensure `id-token: write` permission is set for OIDC, or check secrets. | +| "invalid audience" | Your `mcp-publisher` binary is too old for this registry deployment. Re-run the install step shown above so you pick up the latest release. | | "Package validation failed" | Verify your package successfully published to the package registry (e.g., npm, PyPI), and that your package has the [necessary verification information](./package-types). | {/* prettier-ignore-end */} diff --git a/docs/modelcontextprotocol-io/package-types.mdx b/docs/modelcontextprotocol-io/package-types.mdx index 9014302..0367fac 100644 --- a/docs/modelcontextprotocol-io/package-types.mdx +++ b/docs/modelcontextprotocol-io/package-types.mdx @@ -87,6 +87,8 @@ This MCP server executes SQL queries and manages database connections. ``` +The `mcp-name:` token must be followed by a boundary โ€” a newline, whitespace, an HTML tag, or the comment close `-->`. Keep it on its own line or inside ``; do not glue it directly to trailing characters such as a sentence-ending period (`โ€ฆ/database-query-mcp.`), which prevents the match. + ## NuGet Packages For NuGet packages, the MCP Registry currently supports the official NuGet registry (`https://api.nuget.org/v3/index.json`) only. @@ -125,12 +127,66 @@ This MCP server manages Azure DevOps work items and pipelines. ``` +The `mcp-name:` token must be followed by a boundary โ€” a newline, whitespace, an HTML tag, or the comment close `-->`. Keep it on its own line or inside ``; do not glue it directly to trailing characters such as a sentence-ending period (`โ€ฆ/azure-devops-mcp.`), which prevents the match. + +## Cargo (Rust) Packages + +For Cargo packages, the MCP Registry currently supports the official crates.io registry (`https://crates.io`) only. + +Cargo packages use `"registryType": "cargo"` in `server.json`. For example: + +```json server.json highlight={9} +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "io.github.username/widget-mcp", + "title": "Widget", + "description": "Rust-native MCP server", + "version": "0.3.0", + "packages": [ + { + "registryType": "cargo", + "identifier": "widget-mcp", + "version": "0.3.0", + "transport": { + "type": "stdio" + } + } + ] +} +``` + +### Runtime Model + +Cargo's runtime model differs from npm/PyPI/NuGet. `cargo install ` places the compiled binary on PATH at `~/.cargo/bin`, after which MCP clients invoke it directly by name. There is no per-invocation runner equivalent to `npx` (npm), `uvx` (PyPI), or `dnx` (NuGet, .NET 10 SDK Preview 6+) โ€” install is one-time, execution is by binary name. The Cargo example above intentionally omits `runtimeHint` for this reason. + +Rust MCP authors have two first-class distribution paths: + +- **Cargo (`registryType: cargo`)** โ€” source-distributed via crates.io. End users need the Rust toolchain (`rustup`) to run `cargo install`. Idiomatic for the Rust ecosystem and consistent with how Rust CLIs are typically published. +- **MCPB (`registryType: mcpb`)** โ€” prebuilt binary distributed via GitHub or GitLab Releases. End users need no toolchain. Right choice if the priority is "no Rust toolchain required." + +Both paths are supported; the choice is the author's. Cargo native support exists so Rust authors who prefer source distribution are not forced into the MCPB binary-packaging workaround. + +### Ownership Verification + +The MCP Registry verifies ownership of Cargo packages by checking for the existence of an `mcp-name: $SERVER_NAME` string in the package README (which is rendered to HTML and served by crates.io's static CDN). The `$SERVER_NAME` portion **MUST** match the server name from `server.json`. For example: + +```markdown README.md highlight={5} +# Widget MCP Server + +A Rust-native MCP server for widget operations. + +- MCP Registry name: `mcp-name: io.github.username/widget-mcp` +``` + +**Cargo-specific gotcha:** Unlike PyPI and NuGet (which preserve HTML comments in their README rendering), **crates.io strips HTML comments during markdownโ†’HTML conversion**. The `` hidden-comment form that works for PyPI/NuGet **does not work for cargo** โ€” the token will not appear in the rendered HTML the validator inspects. Cargo authors must include the `mcp-name:` token as visible markdown text. A simple bullet in the Links section is the recommended pattern. + ## Docker/OCI Images For Docker/OCI images, the MCP Registry currently supports: - Docker Hub (`docker.io`) - GitHub Container Registry (`ghcr.io`) +- Quay.io (`quay.io`) - Google Artifact Registry (any `*.pkg.dev` domain) - Azure Container Registry (`*.azurecr.io`) - Microsoft Container Registry (`mcr.microsoft.com`) @@ -156,7 +212,7 @@ Docker/OCI images use `"registryType": "oci"` in `server.json`. For example: } ``` -The format of `identifier` is `registry/namespace/repository:tag`. For example, `docker.io/user/app:1.0.0` or `ghcr.io/user/app:1.0.0`. The tag can also be specified as a digest. +The format of `identifier` is `registry/namespace/repository:tag`. For example, `docker.io/user/app:1.0.0`, `ghcr.io/user/app:1.0.0`, or `quay.io/myorg/my-mcp-server:1.0.0`. The tag can also be specified as a digest. ### Ownership Verification diff --git a/docs/modelcontextprotocol-io/quickstart.mdx b/docs/modelcontextprotocol-io/quickstart.mdx index b33fc17..6988689 100644 --- a/docs/modelcontextprotocol-io/quickstart.mdx +++ b/docs/modelcontextprotocol-io/quickstart.mdx @@ -9,6 +9,10 @@ sidebarTitle: "Quickstart: Publish a Server" This tutorial will show you how to publish an MCP server written in TypeScript to the MCP Registry using the official `mcp-publisher` CLI tool. + + If you are publishing a non-npm package (PyPI, NuGet, OCI, MCPB), the overall flow is identical, but the ownership-verification step in [Step 1](#step-1-add-verification-information-to-the-package) is different per package type. See [Package Types](./package-types) for the verification mechanism that applies to your package, then return here and follow the remaining steps. + + ## Prerequisites - **Node.js** โ€” This tutorial assumes the MCP server is written in TypeScript. @@ -131,6 +135,10 @@ Commands: login Authenticate with the registry logout Clear saved authentication publish Publish server.json to the registry + status Update the status of a server version + validate Validate server.json without publishing + +Use 'mcp-publisher --help' for more information about a command. ``` ## Step 4: Create `server.json` @@ -279,7 +287,7 @@ You should see your server's metadata in the search results JSON: | Error Message | Action | | --- | --- | -|"Registry validation failed for package"|Ensure your package includes the required validation information (e.g, `mcpName` property in `package.json`).| +|"Registry validation failed for package"|Ensure your package includes the required ownership-verification marker for its package type. For npm this is `mcpName` in `package.json`; for PyPI and NuGet it is an `mcp-name: ` line (or HTML comment) in the package README; for other types see [Package Types](./package-types).| |"Invalid or expired Registry JWT token"|Re-authenticate by running `mcp-publisher login github`.| |"You do not have permission to publish this server"|Your authentication method doesn't match your server's namespace format. With GitHub auth, your server name must start with `io.github.your-username/`.| diff --git a/docs/modelcontextprotocol-io/remote-servers.mdx b/docs/modelcontextprotocol-io/remote-servers.mdx index be2bdc5..eecad51 100644 --- a/docs/modelcontextprotocol-io/remote-servers.mdx +++ b/docs/modelcontextprotocol-io/remote-servers.mdx @@ -29,7 +29,7 @@ A remote server **MUST** be publicly accessible at its specified URL. ## Transport Type -Remote servers can use the Streamable HTTP transport (recommended) or the SSE transport. Remote servers can also support both transports simultaneously at different URLs. +Remote servers should use the Streamable HTTP transport. The SSE transport is [deprecated](/specification/draft/deprecated), so publish an `"sse"` remote only to support existing clients. Remote servers can also support both transports simultaneously at different URLs. Specify the transport by setting the `type` property of the `remotes` entry to either `"streamable-http"` or `"sse"`: diff --git a/docs/reference/README.md b/docs/reference/README.md index 73f3518..5e5b0b0 100644 --- a/docs/reference/README.md +++ b/docs/reference/README.md @@ -7,11 +7,17 @@ Technical specifications and quick lookups for the MCP Registry. - [Generic Registry API](./api/generic-registry-api.md) - [Registry Authorization](./api/registry-authorization.md) - [Official Registry API](./api/official-registry-api.md) +- [API Extensions](./api/extensions.md) - The `_meta` extension namespaces +- [OpenAPI Specification](./api/openapi.yaml) +- [API Changelog](./api/CHANGELOG.md) ## server.json Reference - [Generic server.json Format](./server-json/generic-server-json.md) - [Official Registry Requirements](./server-json/official-registry-requirements.md) +- [Schema Changelog](./server-json/CHANGELOG.md) +- [Schema Change Process](./server-json/CONTRIBUTING.md) - How to propose a schema change +- [Draft Schema](./server-json/draft/) - The in-progress next schema version ## CLI Reference @@ -19,4 +25,4 @@ Technical specifications and quick lookups for the MCP Registry. ## Quick Reference -- [FAQ](./faq.md) \ No newline at end of file +- [FAQ](../modelcontextprotocol-io/faq.mdx) diff --git a/docs/reference/api/generic-registry-api.md b/docs/reference/api/generic-registry-api.md index f351021..a4476bd 100644 --- a/docs/reference/api/generic-registry-api.md +++ b/docs/reference/api/generic-registry-api.md @@ -18,7 +18,7 @@ The official registry has some more endpoints and restrictions on top of this. S - **`GET /v0.1/servers/{serverName}/versions`** - List all versions of a server - **`GET /v0.1/servers/{serverName}/versions/{version}`** - Get specific version of server. Use the special version `latest` to get the latest version. - **`POST /v0.1/publish`** - Publish new server (optional, registry-specific authentication) -- **`PUT /v0.1/servers/{serverName}/versions/{version}`** - Update specific server version (optional, not implemented by official registry) +- **`PUT /v0.1/servers/{serverName}/versions/{version}`** - Update specific server version (optional; the official registry implements this as an admin endpoint) - **`DELETE /v0.1/servers/{serverName}/versions/{version}`** - Delete specific server version (optional, not implemented by official registry) - **`PATCH /v0.1/servers/{serverName}/versions/{version}/status`** - Update server version status (optional) - **`PATCH /v0.1/servers/{serverName}/status`** - Update status for all versions (optional) diff --git a/docs/reference/api/official-registry-api.md b/docs/reference/api/official-registry-api.md index 2012885..47e461d 100644 --- a/docs/reference/api/official-registry-api.md +++ b/docs/reference/api/official-registry-api.md @@ -109,7 +109,17 @@ The `GET /v0.1/servers/{serverName}/versions` endpoint returns all versions of a **Authentication:** Requires `publish` or `edit` permission for the server namespace. +#### Validation endpoint +- POST `/v0.1/validate` - Validate a `server.json` without publishing it. Used by `mcp-publisher validate`. + +#### Service endpoints +- GET `/v0.1/ping` - Liveness check +- GET `/v0.1/version` - Registry version information + #### Admin endpoints - GET `/metrics` - Prometheus metrics endpoint - GET `/v0.1/health` - Basic health check endpoint - PUT `/v0.1/servers/{serverName}/versions/{version}` - Edit specific server version + +Note that `/v0.1/validate`, `/v0.1/ping`, `/v0.1/version` and `/v0.1/health` are not described in +[openapi.yaml](./openapi.yaml), which covers the server and publish endpoints only. diff --git a/docs/reference/api/openapi.yaml b/docs/reference/api/openapi.yaml index 947ab24..61cae2d 100644 --- a/docs/reference/api/openapi.yaml +++ b/docs/reference/api/openapi.yaml @@ -659,10 +659,11 @@ components: properties: registryType: type: string - description: Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'oci', 'nuget', 'mcpb') + description: Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'cargo', 'oci', 'nuget', 'mcpb') examples: - "npm" - "pypi" + - "cargo" - "oci" - "nuget" - "mcpb" @@ -673,6 +674,7 @@ components: examples: - "https://registry.npmjs.org" - "https://pypi.org" + - "https://crates.io" - "https://docker.io" - "https://api.nuget.org/v3/index.json" - "https://github.com" @@ -688,6 +690,7 @@ components: description: "Package version. Must be a specific version. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '>=1.2.3', '1.x', '1.*')." example: "1.0.2" minLength: 1 + maxLength: 255 not: const: "latest" fileSha256: @@ -1039,6 +1042,11 @@ components: description: Optional message explaining the status (e.g., deprecation reason) example: "Please upgrade to version 2.0.0" maxLength: 500 + statusChangedAt: + type: string + format: date-time + description: Timestamp when the server status was last updated + example: "2023-12-01T10:30:00Z" publishedAt: type: string format: date-time diff --git a/docs/reference/cli/commands.md b/docs/reference/cli/commands.md index 0f44b7b..690a7f4 100644 --- a/docs/reference/cli/commands.md +++ b/docs/reference/cli/commands.md @@ -16,7 +16,10 @@ $ brew install mcp-publisher All commands support: - `--help`, `-h` - Show command help -- `--registry` - Registry URL (default: `https://registry.modelcontextprotocol.io`) + +`--registry` is a flag on `login` only (default: `https://registry.modelcontextprotocol.io`). The +other commands read the registry URL from the stored login token, so passing `--registry` to +`publish` would be interpreted as the `server.json` path. ## Commands @@ -26,14 +29,14 @@ Generate a `server.json` template with automatic detection. **Usage:** ```bash -mcp-publisher init [options] +mcp-publisher init ``` **Behavior:** - Creates `server.json` in current directory - Auto-detects package managers (`package.json`, `setup.py`, etc.) - Pre-fills fields where possible -- Prompts for missing required fields +- Writes `TODO:` placeholders for fields it cannot detect โ€” it is non-interactive and takes no flags **Example output:** ```json @@ -59,10 +62,17 @@ Authenticate with the registry. #### GitHub Interactive ```bash -mcp-publisher login github [--registry=URL] +mcp-publisher login github [--token=PAT] [--registry=URL] ``` - Opens browser for GitHub OAuth flow - Grants access to `io.github.{username}/*` and `io.github.{org}/*` namespaces +- `--token` supplies a GitHub Personal Access Token instead of the interactive flow, which is how + [publishing from GitHub Actions](../../modelcontextprotocol-io/github-actions.mdx) authenticates + without a browser. This flag is accepted by `login github` only. + +Interactive login handles retryable OAuth errors in both HTTP 200 and HTTP 400 responses. +Access denial, expired codes, and unrecognized OAuth errors still stop polling; an +`incorrect_device_code` error receives at most two additional attempts per login. #### GitHub OIDC (CI/CD) ```bash @@ -72,16 +82,24 @@ mcp-publisher login github-oidc [--registry=URL] - Requires `id-token: write` permission in workflow - No browser interaction needed +The CLI derives the OIDC `aud` claim from `--registry` (scheme + host, e.g. +`https://registry.modelcontextprotocol.io`) so tokens are bound to the specific +deployment they were minted for. Self-hosters must set +`MCP_REGISTRY_GITHUB_OIDC_AUDIENCE` on the registry to the matching value; +publishers running an older `mcp-publisher` will fail with `invalid audience` +and need to upgrade. + Also see [the guide to publishing from GitHub Actions](../../modelcontextprotocol-io/github-actions.mdx). #### DNS Verification ```bash -mcp-publisher login dns --domain=example.com --private-key=HEX_KEY [--registry=URL] +mcp-publisher login dns --domain=example.com --private-key=HEX_KEY [--algorithm=ed25519|ecdsap384] [--registry=URL] ``` - Verifies domain ownership via DNS TXT record - Grants access to `com.example.*` namespaces - Requires Ed25519 private key (64-character hex) or ECDSA P-384 private key (96-character hex) - - The private key can be stored in a cloud signing provider like Google KMS or Azure Key Vault. + - `--algorithm` defaults to `ed25519`. **For an ECDSA P-384 key you must pass `--algorithm ecdsap384`**, otherwise the key is rejected with `invalid seed length: expected 32 bytes, got 48`. + - The private key can be stored in a cloud signing provider like Google KMS or Azure Key Vault. Cloud providers derive the algorithm from the key itself, so `--algorithm` does not apply to them. **Setup:** (for Ed25519, recommended) ```bash @@ -111,6 +129,9 @@ openssl ec -in key.pem -text -noout -conv_form compressed | grep -A4 "pub:" | ta # Extract private key for login openssl ec -in -noout -text | grep -A4 "priv:" | tail -n +2 | tr -d ' :\n' + +# Log in, selecting the ECDSA P-384 algorithm explicitly +mcp-publisher login dns --algorithm ecdsap384 --domain=example.com --private-key=HEX_KEY ``` **Setup:** (for Google KMS signing) @@ -171,12 +192,13 @@ mcp-publisher login dns azure-key-vault --domain=example.com --vault MyKeyVault #### HTTP Verification ```bash -mcp-publisher login http --domain=example.com --private-key=HEX_KEY [--registry=URL] +mcp-publisher login http --domain=example.com --private-key=HEX_KEY [--algorithm=ed25519|ecdsap384] [--registry=URL] ``` - Verifies domain ownership via HTTPS endpoint - Grants access to `com.example.*` namespaces - Requires Ed25519 private key (64-character hex) or ECDSA P-384 private key (96-character hex) - - The private key can be stored in a cloud signing provider like Google KMS or Azure Key Vault. + - `--algorithm` defaults to `ed25519`. **For an ECDSA P-384 key you must pass `--algorithm ecdsap384`**. + - The private key can be stored in a cloud signing provider like Google KMS or Azure Key Vault. Cloud providers derive the algorithm from the key itself, so `--algorithm` does not apply to them. **Setup:** (for Ed25519, recommended) ```bash @@ -196,6 +218,9 @@ openssl genpkey -algorithm EC -pkeyopt ec_paramgen_curve:secp384r1 -out key.pem # Host public key at: # https://example.com/.well-known/mcp-registry-auth # Content: v=MCPv1; k=ecdsap384; p=PUBLIC_KEY + +# Log in, selecting the ECDSA P-384 algorithm explicitly +mcp-publisher login http --algorithm ecdsap384 --domain=example.com --private-key=HEX_KEY ``` Cloud signing is also supported for HTTP authentication, similar to the DNS examples above. Just swap out the `dns` positional argument for `http`. diff --git a/docs/reference/server-json/draft/server.schema.json b/docs/reference/server-json/draft/server.schema.json index 5c59335..e3aeab6 100644 --- a/docs/reference/server-json/draft/server.schema.json +++ b/docs/reference/server-json/draft/server.schema.json @@ -239,6 +239,7 @@ "examples": [ "https://registry.npmjs.org", "https://pypi.org", + "https://crates.io", "https://docker.io", "https://api.nuget.org/v3/index.json", "https://github.com", @@ -248,10 +249,11 @@ "type": "string" }, "registryType": { - "description": "Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'oci', 'nuget', 'mcpb')", + "description": "Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'cargo', 'oci', 'nuget', 'mcpb')", "examples": [ "npm", "pypi", + "cargo", "oci", "nuget", "mcpb" @@ -282,6 +284,7 @@ "version": { "description": "Package version. Must be a specific version. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '\u003e=1.2.3', '1.x', '1.*').", "example": "1.0.2", + "maxLength": 255, "minLength": 1, "not": { "const": "latest" diff --git a/docs/reference/server-json/generic-server-json.md b/docs/reference/server-json/generic-server-json.md index 1b1aff1..7415988 100644 --- a/docs/reference/server-json/generic-server-json.md +++ b/docs/reference/server-json/generic-server-json.md @@ -264,6 +264,26 @@ This will essentially instruct the MCP client to execute `dnx Knapcode.SampleMcp } ``` +The same `registryType` / `identifier` pattern works for other supported OCI hosts. For example, an image on Quay.io: + +```json +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "io.github.example/quay-sample-mcp", + "description": "Example MCP server distributed as an OCI image on Quay.io", + "version": "1.0.0", + "packages": [ + { + "registryType": "oci", + "identifier": "quay.io/myorg/my-mcp-server:1.0.0", + "transport": { + "type": "stdio" + } + } + ] +} +``` + ### Remote Server Example ```json @@ -352,6 +372,35 @@ This will essentially instruct the MCP client to execute `dnx Knapcode.SampleMcp } ``` +### Cargo (Rust) Package Example + +`cargo install ` places the binary on PATH (via `~/.cargo/bin`); MCP clients invoke it directly by name. There is no single-shot equivalent of `npx` (npm), `uvx` (PyPI), or `dnx` (NuGet, .NET 10 SDK) for cargo โ€” install once, run by name. + +```json +{ + "$schema": "https://static.modelcontextprotocol.io/schemas/2025-12-11/server.schema.json", + "name": "io.github.example/widget-mcp", + "description": "Rust-native MCP server", + "title": "Widget", + "repository": { + "url": "https://github.com/example/widget-mcp", + "source": "github" + }, + "version": "0.3.0", + "packages": [ + { + "registryType": "cargo", + "registryBaseUrl": "https://crates.io", + "identifier": "widget-mcp", + "version": "0.3.0", + "transport": { + "type": "stdio" + } + } + ] +} +``` + ### NuGet (.NET) Package Example The `dnx` tool ships with the .NET 10 SDK, starting with Preview 6. diff --git a/docs/reference/server-json/official-registry-requirements.md b/docs/reference/server-json/official-registry-requirements.md index 494458f..ac87d85 100644 --- a/docs/reference/server-json/official-registry-requirements.md +++ b/docs/reference/server-json/official-registry-requirements.md @@ -23,7 +23,7 @@ See the [publishing guide](../../modelcontextprotocol-io/quickstart.mdx) for aut All packages must include metadata proving the publisher owns them. This prevents impersonation and ensures authenticity (see more reasoning in [#96](https://github.com/modelcontextprotocol/registry/issues/96)). -For detailed verification requirements for each registry type, see the [publishing guide](../../modelcontextprotocol-io/quickstart.mdx). +For detailed verification requirements for each registry type, see [package types](../../modelcontextprotocol-io/package-types.mdx), which has an "Ownership Verification" section per registry. ## Restricted Registry Base URLs @@ -33,9 +33,11 @@ Only trusted public registries are supported. Private registries and alternative - **NPM**: `https://registry.npmjs.org` only - **PyPI**: `https://pypi.org` only - **NuGet**: `https://api.nuget.org/v3/index.json` only +- **Cargo**: `https://crates.io` only - **Docker/OCI**: - Docker Hub (`docker.io`) - GitHub Container Registry (`ghcr.io`) + - Quay.io (`quay.io`) - Google Artifact Registry (`*.pkg.dev`) - Azure Container Registry (`*.azurecr.io`) - Microsoft Container Registry (`mcr.microsoft.com`) @@ -68,6 +70,28 @@ When publishing to the official registry, **only data under the specific key `io **Size limit:** The publisher-provided extension is limited to 4KB (4096 bytes) of JSON. If the marshaled JSON exceeds this limit, publishing will fail with an error indicating the actual size. +#### Recommended: Namespaced Subkeys + +When your `publisher-provided` metadata gets large or comes from multiple sources (e.g. GitHub-specific hints alongside your own CI tool's metadata), grouping keys under reverse-DNS subkeys is a useful convention to avoid accidental collisions: + +```jsonc +{ + "_meta": { + "io.modelcontextprotocol.registry/publisher-provided": { + "com.github": { + "serverDisplayName": "My Server" + }, + "io.example.ci-publisher": { + "tool": "ci-publisher", + "version": "1.0.0" + } + } + } +} +``` + +This is **not enforced**; flat keys work fine for simple cases, and existing examples in this repo use the flat form. Use the namespaced form when organizing metadata from more than one source. + ### Registry API Metadata vs server.json Metadata The `_meta` field in `server.json` is **different** from the `_meta` field returned in registry API responses: diff --git a/go.mod b/go.mod index dccf238..b482a15 100644 --- a/go.mod +++ b/go.mod @@ -1,90 +1,86 @@ module github.com/modelcontextprotocol/registry -go 1.26 +go 1.26.0 require ( - cloud.google.com/go/kms v1.29.0 - github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1 - github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.4.0 - github.com/caarlos0/env/v11 v11.4.0 - github.com/coreos/go-oidc/v3 v3.18.0 - github.com/danielgtaylor/huma/v2 v2.37.3 + cloud.google.com/go/kms v1.33.0 + github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.14.1 + github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.5.0 + github.com/caarlos0/env/v11 v11.4.1 + github.com/coreos/go-oidc/v3 v3.21.0 + github.com/danielgtaylor/huma/v2 v2.39.1 github.com/golang-jwt/jwt/v5 v5.3.1 - github.com/google/go-containerregistry v0.21.5 - github.com/jackc/pgx/v5 v5.9.1 - github.com/prometheus/client_golang v1.23.2 + github.com/google/go-containerregistry v0.22.1 + github.com/jackc/pgx/v5 v5.10.0 + github.com/prometheus/client_golang v1.24.1 github.com/rs/cors v1.11.1 github.com/santhosh-tekuri/jsonschema/v5 v5.3.1 - github.com/stretchr/testify v1.11.1 - go.opentelemetry.io/contrib/instrumentation/runtime v0.68.0 - go.opentelemetry.io/otel v1.43.0 - go.opentelemetry.io/otel/exporters/prometheus v0.65.0 - go.opentelemetry.io/otel/metric v1.43.0 - go.opentelemetry.io/otel/sdk v1.43.0 - go.opentelemetry.io/otel/sdk/metric v1.43.0 - golang.org/x/mod v0.35.0 + github.com/stretchr/testify v1.12.1 + go.opentelemetry.io/contrib/instrumentation/runtime v0.71.0 + go.opentelemetry.io/otel v1.46.0 + go.opentelemetry.io/otel/exporters/prometheus v0.68.0 + go.opentelemetry.io/otel/metric v1.46.0 + go.opentelemetry.io/otel/sdk v1.46.0 + go.opentelemetry.io/otel/sdk/metric v1.46.0 + golang.org/x/mod v0.41.0 gopkg.in/yaml.v3 v3.0.1 ) require ( cloud.google.com/go v0.123.0 // indirect - cloud.google.com/go/auth v0.18.2 // indirect + cloud.google.com/go/auth v0.20.0 // indirect cloud.google.com/go/auth/oauth2adapt v0.2.8 // indirect cloud.google.com/go/compute/metadata v0.9.0 // indirect - cloud.google.com/go/iam v1.7.0 // indirect - cloud.google.com/go/longrunning v0.9.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0 // indirect - github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 // indirect + cloud.google.com/go/iam v1.11.0 // indirect + cloud.google.com/go/longrunning v1.2.0 // indirect + github.com/Azure/azure-sdk-for-go/sdk/azcore v1.23.1 // indirect + github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0 // indirect github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0 // indirect - github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 // indirect + github.com/AzureAD/microsoft-authentication-library-for-go v1.8.0 // indirect github.com/beorn7/perks v1.0.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect - github.com/containerd/stargz-snapshotter/estargz v0.18.2 // indirect - github.com/davecgh/go-spew v1.1.1 // indirect - github.com/docker/cli v29.4.0+incompatible // indirect + github.com/docker/cli v29.7.2+incompatible // indirect github.com/docker/docker-credential-helpers v0.9.3 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/go-jose/go-jose/v4 v4.1.4 // indirect - github.com/go-logr/logr v1.4.3 // indirect + github.com/go-logr/logr v1.4.4 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/google/s2a-go v0.1.9 // indirect github.com/google/uuid v1.6.0 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.14 // indirect - github.com/googleapis/gax-go/v2 v2.21.0 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.17 // indirect + github.com/googleapis/gax-go/v2 v2.23.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 // indirect github.com/jackc/puddle/v2 v2.2.2 // indirect - github.com/klauspost/compress v1.18.5 // indirect + github.com/klauspost/compress v1.19.2 // indirect + github.com/kr/text v0.2.0 // indirect github.com/kylelemons/godebug v1.1.0 // indirect - github.com/mitchellh/go-homedir v1.1.0 // indirect github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect github.com/opencontainers/go-digest v1.0.0 // indirect github.com/opencontainers/image-spec v1.1.1 // indirect github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c // indirect - github.com/pmezard/go-difflib v1.0.0 // indirect github.com/prometheus/client_model v0.6.2 // indirect - github.com/prometheus/common v0.67.5 // indirect + github.com/prometheus/common v0.70.1 // indirect github.com/prometheus/otlptranslator v1.0.0 // indirect - github.com/prometheus/procfs v0.20.1 // indirect + github.com/prometheus/procfs v0.21.1 // indirect github.com/sirupsen/logrus v1.9.4 // indirect - github.com/vbatts/tar-split v0.12.2 // indirect go.opentelemetry.io/auto/sdk v1.2.1 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 // indirect - go.opentelemetry.io/otel/trace v1.43.0 // indirect - go.yaml.in/yaml/v2 v2.4.4 // indirect - golang.org/x/crypto v0.49.0 // indirect - golang.org/x/net v0.52.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 // indirect + go.opentelemetry.io/otel/trace v1.46.0 // indirect + go.yaml.in/yaml/v3 v3.0.5 // indirect + golang.org/x/crypto v0.55.0 // indirect + golang.org/x/net v0.58.0 // indirect golang.org/x/oauth2 v0.36.0 // indirect - golang.org/x/sync v0.20.0 // indirect - golang.org/x/sys v0.43.0 // indirect - golang.org/x/text v0.35.0 // indirect + golang.org/x/sync v0.22.0 // indirect + golang.org/x/sys v0.47.0 // indirect + golang.org/x/text v0.41.0 // indirect golang.org/x/time v0.15.0 // indirect - google.golang.org/api v0.274.0 // indirect + google.golang.org/api v0.287.1 // indirect google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20260401001100-f93e5f3e9f0f // indirect - google.golang.org/grpc v1.80.0 // indirect - google.golang.org/protobuf v1.36.11 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20260630182238-925bb5da69e7 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20260630182238-925bb5da69e7 // indirect + google.golang.org/grpc v1.83.1 // indirect + google.golang.org/protobuf v1.36.12 // indirect gotest.tools/v3 v3.5.2 // indirect ) diff --git a/go.sum b/go.sum index 0a61c79..2a677e7 100644 --- a/go.sum +++ b/go.sum @@ -1,68 +1,67 @@ cloud.google.com/go v0.123.0 h1:2NAUJwPR47q+E35uaJeYoNhuNEM9kM8SjgRgdeOJUSE= cloud.google.com/go v0.123.0/go.mod h1:xBoMV08QcqUGuPW65Qfm1o9Y4zKZBpGS+7bImXLTAZU= -cloud.google.com/go/auth v0.18.2 h1:+Nbt5Ev0xEqxlNjd6c+yYUeosQ5TtEUaNcN/3FozlaM= -cloud.google.com/go/auth v0.18.2/go.mod h1:xD+oY7gcahcu7G2SG2DsBerfFxgPAJz17zz2joOFF3M= +cloud.google.com/go/auth v0.20.0 h1:kXTssoVb4azsVDoUiF8KvxAqrsQcQtB53DcSgta74CA= +cloud.google.com/go/auth v0.20.0/go.mod h1:942/yi/itH1SsmpyrbnTMDgGfdy2BUqIKyd0cyYLc5Q= cloud.google.com/go/auth/oauth2adapt v0.2.8 h1:keo8NaayQZ6wimpNSmW5OPc283g65QNIiLpZnkHRbnc= cloud.google.com/go/auth/oauth2adapt v0.2.8/go.mod h1:XQ9y31RkqZCcwJWNSx2Xvric3RrU88hAYYbjDWYDL+c= cloud.google.com/go/compute/metadata v0.9.0 h1:pDUj4QMoPejqq20dK0Pg2N4yG9zIkYGdBtwLoEkH9Zs= cloud.google.com/go/compute/metadata v0.9.0/go.mod h1:E0bWwX5wTnLPedCKqk3pJmVgCBSM6qQI1yTBdEb3C10= -cloud.google.com/go/iam v1.7.0 h1:JD3zh0C6LHl16aCn5Akff0+GELdp1+4hmh6ndoFLl8U= -cloud.google.com/go/iam v1.7.0/go.mod h1:tetWZW1PD/m6vcuY2Zj/aU0eCHNPuxedbnbRTyKXvdY= -cloud.google.com/go/kms v1.29.0 h1:bAW1C5FQf+6GhPkywQzPlsULALCG7c16qpXLFGV9ivY= -cloud.google.com/go/kms v1.29.0/go.mod h1:YIyXZym11R5uovJJt4oN5eUL3oPmirF3yKeIh6QAf4U= -cloud.google.com/go/longrunning v0.9.0 h1:0EzbDEGsAvOZNbqXopgniY0w0a1phvu5IdUFq8grmqY= -cloud.google.com/go/longrunning v0.9.0/go.mod h1:pkTz846W7bF4o2SzdWJ40Hu0Re+UoNT6Q5t+igIcb8E= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0 h1:JXg2dwJUmPB9JmtVmdEB16APJ7jurfbY5jnfXpJoRMc= -github.com/Azure/azure-sdk-for-go/sdk/azcore v1.20.0/go.mod h1:YD5h/ldMsG0XiIw7PdyNhLxaM317eFh5yNLccNfGdyw= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1 h1:Hk5QBxZQC1jb2Fwj6mpzme37xbCDdNTxU7O9eb5+LB4= -github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.13.1/go.mod h1:IYus9qsFobWIc2YVwe/WPjcnyCkPKtnHAqUYeebc8z0= -github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2 h1:yz1bePFlP5Vws5+8ez6T3HWXPmwOK7Yvq8QxDBD3SKY= -github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.3.2/go.mod h1:Pa9ZNPuoNu/GztvBSKk9J1cDJW6vk/n0zLtV4mgd8N8= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2 h1:9iefClla7iYpfYWdzPCRDozdmndjTm8DXdpCzPajMgA= -github.com/Azure/azure-sdk-for-go/sdk/internal v1.11.2/go.mod h1:XtLgD3ZD34DAaVIIAyG3objl5DynM3CQ/vMcbBNJZGI= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.4.0 h1:E4MgwLBGeVB5f2MdcIVD3ELVAWpr+WD6MUe1i+tM/PA= -github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.4.0/go.mod h1:Y2b/1clN4zsAoUd/pgNAQHjLDnTis/6ROkUfyob6psM= +cloud.google.com/go/iam v1.11.0 h1:KieQ9Pb+LLPak1O3Rv3GgCxhnmkYf7Xyh0P5HfF1jFM= +cloud.google.com/go/iam v1.11.0/go.mod h1:KP+nKGugNJW4LcLx1uEZcq1ok5sQHFaQehQNl4QDgV4= +cloud.google.com/go/kms v1.33.0 h1:pG0X78m212b2pv9N4fdMoUO69LuZGQ9kSvn8sHBOFAo= +cloud.google.com/go/kms v1.33.0/go.mod h1:CSGvW6GnMQbY+1nOHcIzhMtHSbExXlOmCKjWtYVjcpA= +cloud.google.com/go/longrunning v1.2.0 h1:WjYH3YHBGCxGJP9M4dWGHBfXr/cFIjMkNgWcJj7/iMM= +cloud.google.com/go/longrunning v1.2.0/go.mod h1:5KMQALFGOCtFoi2xSOA1u3H7WKlhmckgiyFw7+LGQp0= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.23.1 h1:zvXfGJCWvywnCA814d8ZiVyt+fm9nnTE8xSb99zRyfo= +github.com/Azure/azure-sdk-for-go/sdk/azcore v1.23.1/go.mod h1:iptorS+VYKFL2N6PnebpS91dubG35eAOEERnT4PJbQU= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.14.1 h1:u93s+zU2JD62im61Bm5CZIc1ZrOJaIAWEg0WOrMVkEo= +github.com/Azure/azure-sdk-for-go/sdk/azidentity v1.14.1/go.mod h1:oXtinPO4OLj9d1DOTrqrL1oRwGhcqadvAmrl6wTeGlk= +github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.4.0 h1:xFaZZ+IubdftrDHnGGwZ6QvQ3KHTtWl2MCK+GMt2vxs= +github.com/Azure/azure-sdk-for-go/sdk/azidentity/cache v0.4.0/go.mod h1:mCBhUhlMjLLJKr5aqw2TNS/VqJOie8MzWq3DAMJeKso= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0 h1:fhqpLE3UEXi9lPaBRpQ6XuRW0nU7hgg4zlmZZa+a9q4= +github.com/Azure/azure-sdk-for-go/sdk/internal v1.12.0/go.mod h1:7dCRMLwisfRH3dBupKeNCioWYUZ4SS09Z14H+7i8ZoY= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.5.0 h1:MaKvxE6D0KkjOg6Wd9M00iqP5PR0kUxCfiezes4JweM= +github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/azkeys v1.5.0/go.mod h1:i2h9fsTFKZorh8RdV2IcSUf/Qj98GlTkrTvUbX/s8as= github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0 h1:nCYfgcSyHZXJI8J0IWE5MsCGlb2xp9fJiXyxWgmOFg4= github.com/Azure/azure-sdk-for-go/sdk/security/keyvault/internal v1.2.0/go.mod h1:ucUjca2JtSZboY8IoUqyQyuuXvwbMBVwFOm0vdQPNhA= github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1 h1:WJTmL004Abzc5wDB5VtZG2PJk5ndYDgVacGqfirKxjM= github.com/AzureAD/microsoft-authentication-extensions-for-go/cache v0.1.1/go.mod h1:tCcJZ0uHAmvjsVYzEFivsRTN00oz5BEsRgQHu5JZ9WE= -github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0 h1:XRzhVemXdgvJqCH0sFfrBUTnUJSBrBf7++ypk+twtRs= -github.com/AzureAD/microsoft-authentication-library-for-go v1.6.0/go.mod h1:HKpQxkWaGLJ+D/5H8QRpyQXA1eKjxkFlOMwck5+33Jk= +github.com/AzureAD/microsoft-authentication-library-for-go v1.8.0 h1:Nljr4q1GRA/5vCrMONS+g4u4LRHNgOXVSh3O43J2CnI= +github.com/AzureAD/microsoft-authentication-library-for-go v1.8.0/go.mod h1:Y33QHnf0FfdVewFFISOGe20mkZbxX4H839o955/PoeI= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/caarlos0/env/v11 v11.4.0 h1:Kcb6t5kIIr4XkoQC9AF2j+8E1Jsrl3Wz/hhm1LtoGAc= -github.com/caarlos0/env/v11 v11.4.0/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U= +github.com/caarlos0/env/v11 v11.4.1 h1:fYwH0sWEsBSMPG7t4e/PEfTFzrWrpjyygXyUnWiSwEw= +github.com/caarlos0/env/v11 v11.4.1/go.mod h1:qupehSf/Y0TUTsxKywqRt/vJjN5nz6vauiYEUUr8P4U= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= -github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 h1:6xNmx7iTtyBRev0+D/Tv1FZd4SCg8axKApyNyRsAt/w= -github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5/go.mod h1:KdCmV+x/BuvyMxRnYBlmVaq4OLiKW6iRQfvC62cvdkI= -github.com/containerd/stargz-snapshotter/estargz v0.18.2 h1:yXkZFYIzz3eoLwlTUZKz2iQ4MrckBxJjkmD16ynUTrw= -github.com/containerd/stargz-snapshotter/estargz v0.18.2/go.mod h1:XyVU5tcJ3PRpkA9XS2T5us6Eg35yM0214Y+wvrZTBrY= -github.com/coreos/go-oidc/v3 v3.18.0 h1:V9orjXynvu5wiC9SemFTWnG4F45v403aIcjWo0d41+A= -github.com/coreos/go-oidc/v3 v3.18.0/go.mod h1:DYCf24+ncYi+XkIH97GY1+dqoRlbaSI26KVTCI9SrY4= -github.com/danielgtaylor/huma/v2 v2.37.3 h1:6Av0Vj45Vk5lDxRVfoO2iPlEdvCvwLc7pl5nbqGOkYM= -github.com/danielgtaylor/huma/v2 v2.37.3/go.mod h1:OeHHtCEAaNiuVbAVdYu4IQ0UOmnb4x3yMUOShNlZ53g= +github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2 h1:aBangftG7EVZoUb69Os8IaYg++6uMOdKK83QtkkvJik= +github.com/cncf/xds/go v0.0.0-20260202195803-dba9d589def2/go.mod h1:qwXFYgsP6T7XnJtbKlf1HP8AjxZZyzxMmc+Lq5GjlU4= +github.com/coreos/go-oidc/v3 v3.21.0 h1:wZo4Q9Pum8dYEj0eMUPrqR+kvuGkeUplbLpNCkBqoWM= +github.com/coreos/go-oidc/v3 v3.21.0/go.mod h1:DYCf24+ncYi+XkIH97GY1+dqoRlbaSI26KVTCI9SrY4= +github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/danielgtaylor/huma/v2 v2.39.1 h1:0kwF4ltQoYZ+IU55VPy+BcGekzgF44R64daTGde1H+g= +github.com/danielgtaylor/huma/v2 v2.39.1/go.mod h1:zcnQ38duIJ3VUHwFaBoZ6x8T+KN/mr33oyqxcj0HTug= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= -github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/docker/cli v29.4.0+incompatible h1:+IjXULMetlvWJiuSI0Nbor36lcJ5BTcVpUmB21KBoVM= -github.com/docker/cli v29.4.0+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= +github.com/docker/cli v29.7.2+incompatible h1:dlkwallR8XqfeVnA2ELEhdwvb4lsSwuB4IgsG8Q9cLY= +github.com/docker/cli v29.7.2+incompatible/go.mod h1:JLrzqnKDaYBop7H2jaqPtU4hHvMKP+vjCwu2uszcLI8= github.com/docker/docker-credential-helpers v0.9.3 h1:gAm/VtF9wgqJMoxzT3Gj5p4AqIjCBS4wrsOh9yRqcz8= github.com/docker/docker-credential-helpers v0.9.3/go.mod h1:x+4Gbw9aGmChi3qTLZj8Dfn0TD20M/fuWy0E5+WDeCo= github.com/envoyproxy/go-control-plane v0.14.0 h1:hbG2kr4RuFj222B6+7T83thSPqLjwBIfQawTkC++2HA= -github.com/envoyproxy/go-control-plane/envoy v1.36.0 h1:yg/JjO5E7ubRyKX3m07GF3reDNEnfOboJ0QySbH736g= -github.com/envoyproxy/go-control-plane/envoy v1.36.0/go.mod h1:ty89S1YCCVruQAm9OtKeEkQLTb+Lkz0k8v9W0Oxsv98= -github.com/envoyproxy/protoc-gen-validate v1.3.0 h1:TvGH1wof4H33rezVKWSpqKz5NXWg5VPuZ0uONDT6eb4= -github.com/envoyproxy/protoc-gen-validate v1.3.0/go.mod h1:HvYl7zwPa5mffgyeTUHA9zHIH36nmrm7oCbo4YKoSWA= +github.com/envoyproxy/go-control-plane/envoy v1.37.0 h1:u3riX6BoYRfF4Dr7dwSOroNfdSbEPe9Yyl09/B6wBrQ= +github.com/envoyproxy/go-control-plane/envoy v1.37.0/go.mod h1:DReE9MMrmecPy+YvQOAOHNYMALuowAnbjjEMkkWOi6A= +github.com/envoyproxy/protoc-gen-validate v1.3.3 h1:MVQghNeW+LZcmXe7SY1V36Z+WFMDjpqGAGacLe2T0ds= +github.com/envoyproxy/protoc-gen-validate v1.3.3/go.mod h1:TsndJ/ngyIdQRhMcVVGDDHINPLWB7C82oDArY51KfB0= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fxamacker/cbor/v2 v2.9.0 h1:NpKPmjDBgUfBms6tr6JZkTHtfFGcMKsw3eGcmD/sapM= -github.com/fxamacker/cbor/v2 v2.9.0/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= +github.com/fxamacker/cbor/v2 v2.9.2 h1:X4Ksno9+x3cz0TZv69ec1hxP/+tymuR8PXQJyDwfh78= +github.com/fxamacker/cbor/v2 v2.9.2/go.mod h1:vM4b+DJCtHn+zz7h3FFp/hDAI9WNWCsZj23V5ytsSxQ= +github.com/go-chi/chi/v5 v5.3.1 h1:3j4HZLGZQ3JpMCrPJF/Jl3mYJfWLKBfNJ6quurUGCf8= +github.com/go-chi/chi/v5 v5.3.1/go.mod h1:R+tYY2hNuVUUjxoPtqUdgBqevM9s9njzkTLutVsOCto= github.com/go-jose/go-jose/v4 v4.1.4 h1:moDMcTHmvE6Groj34emNPLs/qtYXRVcd6S7NHbHz3kA= github.com/go-jose/go-jose/v4 v4.1.4/go.mod h1:x4oUasVrzR7071A4TnHLGSPpNOm2a21K9Kf04k1rs08= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.3 h1:CjnDlHq8ikf6E492q6eKboGOC0T8CDaOvkHCIg8idEI= -github.com/go-logr/logr v1.4.3/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.4 h1:tG4xh9yMsRCAiodLVTxyrkzSZ9+o0L1Kg/+cPVcbP/8= +github.com/go-logr/logr v1.4.4/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= github.com/golang-jwt/jwt/v5 v5.3.1 h1:kYf81DTWFe7t+1VvL7eS+jKFVWaUnK9cB1qbwn63YCY= @@ -71,36 +70,34 @@ github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= -github.com/google/go-containerregistry v0.21.5 h1:KTJG9Pn/jC0VdZR6ctV3/jcN+q6/Iqlx0sTVz3ywZlM= -github.com/google/go-containerregistry v0.21.5/go.mod h1:ySvMuiWg+dOsRW0Hw8GYwfMwBlNRTmpYBFJPlkco5zU= +github.com/google/go-containerregistry v0.22.1 h1:RZuuSYhTvlDvtsK+NkutoCZ//C0X2ebLK8X8l3ULs84= +github.com/google/go-containerregistry v0.22.1/go.mod h1:bJR35SK8XgisYmhg/FMQ/5RK0S/XrOAqLBV5/LR2XE0= github.com/google/s2a-go v0.1.9 h1:LGD7gtMgezd8a/Xak7mEWL0PjoTQFvpRudN895yqKW0= github.com/google/s2a-go v0.1.9/go.mod h1:YA0Ei2ZQL3acow2O62kdp9UlnvMmU7kA6Eutn0dXayM= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.3.14 h1:yh8ncqsbUY4shRD5dA6RlzjJaT4hi3kII+zYw8wmLb8= -github.com/googleapis/enterprise-certificate-proxy v0.3.14/go.mod h1:vqVt9yG9480NtzREnTlmGSBmFrA+bzb0yl0TxoBQXOg= -github.com/googleapis/gax-go/v2 v2.21.0 h1:h45NjjzEO3faG9Lg/cFrBh2PgegVVgzqKzuZl/wMbiI= -github.com/googleapis/gax-go/v2 v2.21.0/go.mod h1:But/NJU6TnZsrLai/xBAQLLz+Hc7fHZJt/hsCz3Fih4= +github.com/googleapis/enterprise-certificate-proxy v0.3.17 h1:73NfMHdiqo9JFU9+7a5ExpVa10/R29pXfZIaW559nrg= +github.com/googleapis/enterprise-certificate-proxy v0.3.17/go.mod h1:rSEsBUemEBZEexP2y6jPp16LUmUbjmSbcPMQizR0o4k= +github.com/googleapis/gax-go/v2 v2.23.0 h1:Tchl7qkvE7Ip3y+ztvNufYFvkfqTe7NfLTYGIdJRLuE= +github.com/googleapis/gax-go/v2 v2.23.0/go.mod h1:rBQKOVJCdb8IFEzg+FCwlt1LP/xMDGuqUXhUG+XMXEg= github.com/jackc/pgpassfile v1.0.0 h1:/6Hmqy13Ss2zCq62VdNG8tM1wchn8zjSGOBJ6icpsIM= github.com/jackc/pgpassfile v1.0.0/go.mod h1:CEx0iS5ambNFdcRtxPj5JhEz+xB6uRky5eyVu/W2HEg= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761 h1:iCEnooe7UlwOQYpKFhBabPMi4aNAfoODPEFNiAnClxo= github.com/jackc/pgservicefile v0.0.0-20240606120523-5a60cdf6a761/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= -github.com/jackc/pgx/v5 v5.9.1 h1:uwrxJXBnx76nyISkhr33kQLlUqjv7et7b9FjCen/tdc= -github.com/jackc/pgx/v5 v5.9.1/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= +github.com/jackc/pgx/v5 v5.10.0 h1:VhSvgU2jSli8o3AqIEOTJr7rZwAEUVo4E4XhR94Zfr0= +github.com/jackc/pgx/v5 v5.10.0/go.mod h1:mal1tBGAFfLHvZzaYh77YS/eC6IX9OWbRV1QIIM0Jn4= github.com/jackc/puddle/v2 v2.2.2 h1:PR8nw+E/1w0GLuRFSmiioY6UooMp6KJv0/61nB7icHo= github.com/jackc/puddle/v2 v2.2.2/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/keybase/go-keychain v0.0.1 h1:way+bWYa6lDppZoZcgMbYsvC7GxljxrskdNInRtuthU= github.com/keybase/go-keychain v0.0.1/go.mod h1:PdEILRW3i9D8JcdM+FmY6RwkHGnhHxXwkPPMeUgOK1k= -github.com/klauspost/compress v1.18.5 h1:/h1gH5Ce+VWNLSWqPzOVn6XBO+vJbCNGvjoaGBFW2IE= -github.com/klauspost/compress v1.18.5/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= +github.com/klauspost/compress v1.19.2 h1:hMRETovs/pu/dVWN7zIT1PGG8t509MwT6bO7XSi26R8= +github.com/klauspost/compress v1.19.2/go.mod h1:cwPg85FWrGar70rWktvGQj8/hthj3wpl0PGDogxkrSQ= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc= github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw= -github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y= -github.com/mitchellh/go-homedir v1.1.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 h1:C3w9PqII01/Oq1c1nUAm88MOHcQC9l5mIlSMApZMrHA= github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822/go.mod h1:+n7T8mK8HuQTcFwEeznm/DIxMOiR9yIdICNftLE1DvQ= github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U= @@ -111,18 +108,17 @@ github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c h1:+mdjkGKdHQG3305AYmd github.com/pkg/browser v0.0.0-20240102092130-5ac0b6a4141c/go.mod h1:7rwL4CYBLnjLxUqIJNnCWiEdr3bn6IUYi15bNlnbCCU= github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo= github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= -github.com/prometheus/client_golang v1.23.2 h1:Je96obch5RDVy3FDMndoUsjAhG5Edi49h0RJWRi/o0o= -github.com/prometheus/client_golang v1.23.2/go.mod h1:Tb1a6LWHB3/SPIzCoaDXI4I8UHKeFTEQ1YCr+0Gyqmg= +github.com/prometheus/client_golang v1.24.1 h1:JnJkREXzWxUdCuPFpIWZiPispT9xVV59uiuyR2bPlnU= +github.com/prometheus/client_golang v1.24.1/go.mod h1:F+oSRECHg4sse5ucfYpYDeIv/hu68Zo0uoHKetWnzcE= github.com/prometheus/client_model v0.6.2 h1:oBsgwpGs7iVziMvrGhE53c/GrLUsZdHnqNwqPLxwZyk= github.com/prometheus/client_model v0.6.2/go.mod h1:y3m2F6Gdpfy6Ut/GBsUqTWZqCUvMVzSfMLjcu6wAwpE= -github.com/prometheus/common v0.67.5 h1:pIgK94WWlQt1WLwAC5j2ynLaBRDiinoAb86HZHTUGI4= -github.com/prometheus/common v0.67.5/go.mod h1:SjE/0MzDEEAyrdr5Gqc6G+sXI67maCxzaT3A2+HqjUw= +github.com/prometheus/common v0.70.1 h1:1HvjP4D5oL3t8RsPlwxA9onvvStjtIHYE5XuuwOi/PY= +github.com/prometheus/common v0.70.1/go.mod h1:VdFUQDMZK3VLkurFUVhia6uys/0suUp86TJz5qbJRhc= github.com/prometheus/otlptranslator v1.0.0 h1:s0LJW/iN9dkIH+EnhiD3BlkkP5QVIUVEoIwkU+A6qos= github.com/prometheus/otlptranslator v1.0.0/go.mod h1:vRYWnXvI6aWGpsdY/mOT/cbeVRBlPWtBNDb7kGR3uKM= -github.com/prometheus/procfs v0.20.1 h1:XwbrGOIplXW/AU3YhIhLODXMJYyC1isLFfYCsTEycfc= -github.com/prometheus/procfs v0.20.1/go.mod h1:o9EMBZGRyvDrSPH1RqdxhojkuXstoe4UlK79eF5TGGo= +github.com/prometheus/procfs v0.21.1 h1:GljZCt+zSTS+NZq88cyQ1LjZ+RCHp3uVuabBWA5+OJI= +github.com/prometheus/procfs v0.21.1/go.mod h1:aB55Cww9pdSJVHk0hUf0inxWyyjPogFIjmHKYgMKmtY= github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ= github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc= github.com/rs/cors v1.11.1 h1:eU3gRzXLRK57F5rKMGMZURNdIG4EoAmX8k94r9wXWHA= @@ -134,67 +130,69 @@ github.com/sirupsen/logrus v1.9.4/go.mod h1:ftWc9WdOfJ0a92nsE2jF5u5ZwH8Bv2zdeOC4 github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI= github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= -github.com/stretchr/testify v1.11.1 h1:7s2iGBzp5EwR7/aIZr8ao5+dra3wiQyKjjFuvgVKu7U= -github.com/stretchr/testify v1.11.1/go.mod h1:wZwfW3scLgRK+23gO65QZefKpKQRnfz6sD981Nm4B6U= -github.com/vbatts/tar-split v0.12.2 h1:w/Y6tjxpeiFMR47yzZPlPj/FcPLpXbTUi/9H7d3CPa4= -github.com/vbatts/tar-split v0.12.2/go.mod h1:eF6B6i6ftWQcDqEn3/iGFRFRo8cBIMSJVOpnNdfTMFA= +github.com/stretchr/testify v1.12.1 h1:EuwCh5fleGS7H32xRwO3wRGT7DxrDhLAT6FF8MpWDWE= +github.com/stretchr/testify v1.12.1/go.mod h1:MDEgiDPPsNp5cuIrHPPCyornHKgEVbtFUmoNlxoYthg= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= go.opentelemetry.io/auto/sdk v1.2.1 h1:jXsnJ4Lmnqd11kwkBV2LgLoFMZKizbCi5fNZ/ipaZ64= go.opentelemetry.io/auto/sdk v1.2.1/go.mod h1:KRTj+aOaElaLi+wW1kO/DZRXwkF4C5xPbEe3ZiIhN7Y= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0 h1:q4XOmH/0opmeuJtPsbFNivyl7bCt7yRBbeEm2sC/XtQ= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.61.0/go.mod h1:snMWehoOh2wsEwnvvwtDyFCxVeDAODenXHtn5vzrKjo= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0 h1:F7Jx+6hwnZ41NSFTO5q4LYDtJRXBf2PD0rNBkeB/lus= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.61.0/go.mod h1:UHB22Z8QsdRDrnAtX4PntOl36ajSxcdUMt1sF7Y6E7Q= -go.opentelemetry.io/contrib/instrumentation/runtime v0.68.0 h1:jhVIQEprwUTV+KfzzliLidclhoTOoHTgdz96kAyR8mU= -go.opentelemetry.io/contrib/instrumentation/runtime v0.68.0/go.mod h1:4HsdbLUbernaTnA8CNaNE+1g026SciXb3juRYe3l8EY= -go.opentelemetry.io/otel v1.43.0 h1:mYIM03dnh5zfN7HautFE4ieIig9amkNANT+xcVxAj9I= -go.opentelemetry.io/otel v1.43.0/go.mod h1:JuG+u74mvjvcm8vj8pI5XiHy1zDeoCS2LB1spIq7Ay0= -go.opentelemetry.io/otel/exporters/prometheus v0.65.0 h1:jOveH/b4lU9HT7y+Gfamf18BqlOuz2PWEvs8yM7Q6XE= -go.opentelemetry.io/otel/exporters/prometheus v0.65.0/go.mod h1:i1P8pcumauPtUI4YNopea1dhzEMuEqWP1xoUZDylLHo= -go.opentelemetry.io/otel/metric v1.43.0 h1:d7638QeInOnuwOONPp4JAOGfbCEpYb+K6DVWvdxGzgM= -go.opentelemetry.io/otel/metric v1.43.0/go.mod h1:RDnPtIxvqlgO8GRW18W6Z/4P462ldprJtfxHxyKd2PY= -go.opentelemetry.io/otel/sdk v1.43.0 h1:pi5mE86i5rTeLXqoF/hhiBtUNcrAGHLKQdhg4h4V9Dg= -go.opentelemetry.io/otel/sdk v1.43.0/go.mod h1:P+IkVU3iWukmiit/Yf9AWvpyRDlUeBaRg6Y+C58QHzg= -go.opentelemetry.io/otel/sdk/metric v1.43.0 h1:S88dyqXjJkuBNLeMcVPRFXpRw2fuwdvfCGLEo89fDkw= -go.opentelemetry.io/otel/sdk/metric v1.43.0/go.mod h1:C/RJtwSEJ5hzTiUz5pXF1kILHStzb9zFlIEe85bhj6A= -go.opentelemetry.io/otel/trace v1.43.0 h1:BkNrHpup+4k4w+ZZ86CZoHHEkohws8AY+WTX09nk+3A= -go.opentelemetry.io/otel/trace v1.43.0/go.mod h1:/QJhyVBUUswCphDVxq+8mld+AvhXZLhe+8WVFxiFff0= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0 h1:yI1/OhfEPy7J9eoa6Sj051C7n5dvpj0QX8g4sRchg04= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.67.0/go.mod h1:NoUCKYWK+3ecatC4HjkRktREheMeEtrXoQxrqYFeHSc= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 h1:OyrsyzuttWTSur2qN/Lm0m2a8yqyIjUVBZcxFPuXq2o= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0/go.mod h1:C2NGBr+kAB4bk3xtMXfZ94gqFDtg/GkI7e9zqGh5Beg= +go.opentelemetry.io/contrib/instrumentation/runtime v0.71.0 h1:v4KkRLVvE1cWqTJDfZZkTCG+Z4aolsa6RVos0FX7vqE= +go.opentelemetry.io/contrib/instrumentation/runtime v0.71.0/go.mod h1:g/xbuPC0XbgwMdKuyF5sKOUUEsorSkN6APydyFP/H9E= +go.opentelemetry.io/otel v1.46.0 h1:FHt5/CDyVxi/8IM1CH7VE/rRgq3kLHa2mSTVMO8AWyc= +go.opentelemetry.io/otel v1.46.0/go.mod h1:Gj3SEScelsNC45tp4nSxRYlS+f5iez7W8XPMCt905kE= +go.opentelemetry.io/otel/exporters/prometheus v0.68.0 h1:QOf2IftqQwITVRJpnn0M7M9ZCbgWfxz4P7i9C9yc2N4= +go.opentelemetry.io/otel/exporters/prometheus v0.68.0/go.mod h1:bgSvqu2TWGXiz7yr5UTMfObH8oqxJWHTnubQ3ef9BO4= +go.opentelemetry.io/otel/metric v1.46.0 h1:yBnkXvgV7AXFILZc5K6IZe/CBFF3OS7BJ8ov6/lj0K8= +go.opentelemetry.io/otel/metric v1.46.0/go.mod h1:iPmdWqifKUdzziPkvvzIJXITl56fQx2mGM/DHLB3/2o= +go.opentelemetry.io/otel/metric/x v0.68.0 h1:TA/cBT23D3MnxYPwHL7YFOdYGdx0A0v+s7Mzotpd1dU= +go.opentelemetry.io/otel/metric/x v0.68.0/go.mod h1:agudOmvWhwUTjgibWDzxD2PoWYnpw5Ht5jISYOD2Hd4= +go.opentelemetry.io/otel/sdk v1.46.0 h1:h5CNQQjEbuQXY/JfZtgt3i7HVFV3aHPO2OAwO2eTYPI= +go.opentelemetry.io/otel/sdk v1.46.0/go.mod h1:GAERFXFt5SYCEB+YiKUbMBeza6UaDH7GmGOZEfh2gSM= +go.opentelemetry.io/otel/sdk/metric v1.46.0 h1:0piZ26EG4RBfebb2jhDH6ERCYHoVWduc3kLgPCwSnSE= +go.opentelemetry.io/otel/sdk/metric v1.46.0/go.mod h1:I1PbKrdVc8Qu8HYVDNtqVIwLwjNrhsV/uFuxfwg8mO4= +go.opentelemetry.io/otel/trace v1.46.0 h1:OULy7ccdJnZtJ0UDYFOIGaCmiWzJ8Vi2G/Rsu60qs1c= +go.opentelemetry.io/otel/trace v1.46.0/go.mod h1:J7GAXweO77XSFkB/rmAqk9D6ihszhFjLU+d9WuUxDLI= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= go.yaml.in/yaml/v2 v2.4.4 h1:tuyd0P+2Ont/d6e2rl3be67goVK4R6deVxCUX5vyPaQ= go.yaml.in/yaml/v2 v2.4.4/go.mod h1:gMZqIpDtDqOfM0uNfy0SkpRhvUryYH0Z6wdMYcacYXQ= -golang.org/x/crypto v0.49.0 h1:+Ng2ULVvLHnJ/ZFEq4KdcDd/cfjrrjjNSXNzxg0Y4U4= -golang.org/x/crypto v0.49.0/go.mod h1:ErX4dUh2UM+CFYiXZRTcMpEcN8b/1gxEuv3nODoYtCA= -golang.org/x/mod v0.35.0 h1:Ww1D637e6Pg+Zb2KrWfHQUnH2dQRLBQyAtpr/haaJeM= -golang.org/x/mod v0.35.0/go.mod h1:+GwiRhIInF8wPm+4AoT6L0FA1QWAad3OMdTRx4tFYlU= -golang.org/x/net v0.52.0 h1:He/TN1l0e4mmR3QqHMT2Xab3Aj3L9qjbhRm78/6jrW0= -golang.org/x/net v0.52.0/go.mod h1:R1MAz7uMZxVMualyPXb+VaqGSa3LIaUqk0eEt3w36Sw= +go.yaml.in/yaml/v3 v3.0.5 h1:N6y/pJk8buWs9NY5ERU2HSMfm+IuD/OtfdAnq6kESPw= +go.yaml.in/yaml/v3 v3.0.5/go.mod h1:HVTZu1O7/Vkt2N+BFy8Zza+lnLsABggaTM2ZpNIGuKg= +golang.org/x/crypto v0.55.0 h1:+KWHjbgOaAQ66dh/YlkZKHlz9ZUlq61AFirAR9ntP8M= +golang.org/x/crypto v0.55.0/go.mod h1:uq0V9dE/fzQuJtbnL+2EhWOE63vo164FY8xqEnV9xis= +golang.org/x/mod v0.41.0 h1:qJmnOUb4YB+FsEuM3HcWucdZASCPGhsX6uljO6pog0c= +golang.org/x/mod v0.41.0/go.mod h1:Ek9pY8RKWXwsWvd3rQiHYtMqkjSUV+s1Rj7j4H5Ur6o= +golang.org/x/net v0.58.0 h1:ynWG7rqYi4ccpTEuPZ2QGWHktVEM9DMCj9yzDE0Q7To= +golang.org/x/net v0.58.0/go.mod h1:YwCddHnFlT7eLQqVprV19OnhLGtc5xOKgE0RyqgfWAU= golang.org/x/oauth2 v0.36.0 h1:peZ/1z27fi9hUOFCAZaHyrpWG5lwe0RJEEEeH0ThlIs= golang.org/x/oauth2 v0.36.0/go.mod h1:YDBUJMTkDnJS+A4BP4eZBjCqtokkg1hODuPjwiGPO7Q= -golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4= -golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= +golang.org/x/sync v0.22.0 h1:SZjpbeLmrCk4xhRSZFNZW5gFUeCeFgjekvI/+gfScek= +golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.1.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI= -golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= -golang.org/x/text v0.35.0 h1:JOVx6vVDFokkpaq1AEptVzLTpDe9KGpj5tR4/X+ybL8= -golang.org/x/text v0.35.0/go.mod h1:khi/HExzZJ2pGnjenulevKNX1W67CUy0AsXcNubPGCA= +golang.org/x/sys v0.47.0 h1:o7XGOvZQCADBQQ4Y7VNq2dRWQR7JmOUW8Kxx4ZsNgWs= +golang.org/x/sys v0.47.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw= +golang.org/x/text v0.41.0 h1:vz/seA0lnX87Othu2f/0L24RcgrXD9/YFTSuGjj3rH8= +golang.org/x/text v0.41.0/go.mod h1:jvf1O8ajNzZqhSrQBPbutR/EB83Cc0CFrezNQIwbb5M= golang.org/x/time v0.15.0 h1:bbrp8t3bGUeFOx08pvsMYRTCVSMk89u4tKbNOZbp88U= golang.org/x/time v0.15.0/go.mod h1:Y4YMaQmXwGQZoFaVFk4YpCt4FLQMYKZe9oeV/f4MSno= gonum.org/v1/gonum v0.17.0 h1:VbpOemQlsSMrYmn7T2OUvQ4dqxQXU+ouZFQsZOx50z4= gonum.org/v1/gonum v0.17.0/go.mod h1:El3tOrEuMpv2UdMrbNlKEh9vd86bmQ6vqIcDwxEOc1E= -google.golang.org/api v0.274.0 h1:aYhycS5QQCwxHLwfEHRRLf9yNsfvp1JadKKWBE54RFA= -google.golang.org/api v0.274.0/go.mod h1:JbAt7mF+XVmWu6xNP8/+CTiGH30ofmCmk9nM8d8fHew= +google.golang.org/api v0.287.1 h1:LiyJx32VU3cwQfLchn/513qKhc25hq0pEANYJoWNnnI= +google.golang.org/api v0.287.1/go.mod h1:lM2kYRzYUCBY91P9h6VF1PYmvhxii3O5hji37qRvIcY= google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7 h1:XzmzkmB14QhVhgnawEVsOn6OFsnpyxNPRY9QV01dNB0= google.golang.org/genproto v0.0.0-20260319201613-d00831a3d3e7/go.mod h1:L43LFes82YgSonw6iTXTxXUX1OlULt4AQtkik4ULL/I= -google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9 h1:VPWxll4HlMw1Vs/qXtN7BvhZqsS9cdAittCNvVENElA= -google.golang.org/genproto/googleapis/api v0.0.0-20260401024825-9d38bb4040a9/go.mod h1:7QBABkRtR8z+TEnmXTqIqwJLlzrZKVfAUm7tY3yGv0M= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401001100-f93e5f3e9f0f h1:Rka45QInERYknkHYfJEPBQaoobXl+YpxTMjAKgWUq2A= -google.golang.org/genproto/googleapis/rpc v0.0.0-20260401001100-f93e5f3e9f0f/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= -google.golang.org/grpc v1.80.0 h1:Xr6m2WmWZLETvUNvIUmeD5OAagMw3FiKmMlTdViWsHM= -google.golang.org/grpc v1.80.0/go.mod h1:ho/dLnxwi3EDJA4Zghp7k2Ec1+c2jqup0bFkw07bwF4= -google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE= -google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= +google.golang.org/genproto/googleapis/api v0.0.0-20260630182238-925bb5da69e7 h1:jQ9p21COKWjP3VwuFrNRiiOTMh3mPpN45R7SLrH/HUU= +google.golang.org/genproto/googleapis/api v0.0.0-20260630182238-925bb5da69e7/go.mod h1:KqHwBx2upmfa1XSi1WuRvC+2VGCLtooKkfmyvRbUmqA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260630182238-925bb5da69e7 h1:eM/YSd5bBFagF51o1E745Ta7RwzpW0h+z+QDNZOgmQ8= +google.golang.org/genproto/googleapis/rpc v0.0.0-20260630182238-925bb5da69e7/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8= +google.golang.org/grpc v1.83.1 h1:HIO0+BEtBP6soyqvqC8sNUjZ7bTs+0hFQuFF+RAy++Y= +google.golang.org/grpc v1.83.1/go.mod h1:kDyl6SKsiHKt0uylY5gtn5cEjkrIOhQOGDgIc4JGwzQ= +google.golang.org/protobuf v1.36.12 h1:pJOKDDOyeXErUroCihFAd5LQuwXBSpVnKGrj5o/fwxc= +google.golang.org/protobuf v1.36.12/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk= gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q= diff --git a/internal/api/cors_preflight_test.go b/internal/api/cors_preflight_test.go new file mode 100644 index 0000000..8ccec81 --- /dev/null +++ b/internal/api/cors_preflight_test.go @@ -0,0 +1,62 @@ +package api_test + +import ( + "crypto/ed25519" + "crypto/rand" + "encoding/hex" + "net/http" + "net/http/httptest" + "testing" + + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/modelcontextprotocol/registry/internal/api" + v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" + "github.com/modelcontextprotocol/registry/internal/config" + "github.com/modelcontextprotocol/registry/internal/telemetry" +) + +// TestCORSPreflightAllowedMethods checks that the CORS layer permits every HTTP +// method the API actually routes. The status endpoints +// (PATCH /v0/servers/{name}/status and .../versions/{version}/status) are served +// with PATCH, so a cross-origin browser preflight for PATCH has to be allowed or +// the browser refuses to send the real request. Guards against a routed method +// being missing from AllowedMethods. +func TestCORSPreflightAllowedMethods(t *testing.T) { + seed := make([]byte, ed25519.SeedSize) + _, err := rand.Read(seed) + require.NoError(t, err) + + cfg := config.NewConfig() + cfg.JWTPrivateKey = hex.EncodeToString(seed) + + shutdownTelemetry, metrics, err := telemetry.InitMetrics("test") + require.NoError(t, err) + defer func() { _ = shutdownTelemetry(nil) }() + + // registryService is nil on purpose: a CORS preflight is answered by the + // middleware before any route handler runs, so business logic is never hit. + srv := api.NewServer(cfg, nil, metrics, &v0.VersionBody{Version: "test"}) + + for _, method := range []string{ + http.MethodGet, + http.MethodPost, + http.MethodPut, + http.MethodPatch, + http.MethodDelete, + } { + t.Run(method, func(t *testing.T) { + req := httptest.NewRequest(http.MethodOptions, "/v0/servers/example/status", nil) + req.Header.Set("Origin", "https://example.com") + req.Header.Set("Access-Control-Request-Method", method) + + w := httptest.NewRecorder() + srv.Handler().ServeHTTP(w, req) + + allow := w.Header().Get("Access-Control-Allow-Methods") + assert.Contains(t, allow, method, + "CORS preflight for %s should be allowed, got Access-Control-Allow-Methods=%q", method, allow) + }) + } +} diff --git a/internal/api/cors_test.go b/internal/api/cors_test.go deleted file mode 100644 index 886ff9e..0000000 --- a/internal/api/cors_test.go +++ /dev/null @@ -1,190 +0,0 @@ -package api_test - -import ( - "crypto/ed25519" - "crypto/rand" - "encoding/hex" - "net/http" - "net/http/httptest" - "testing" - - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - - "github.com/modelcontextprotocol/registry/internal/api" - v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" - "github.com/modelcontextprotocol/registry/internal/config" - "github.com/modelcontextprotocol/registry/internal/database" - "github.com/modelcontextprotocol/registry/internal/service" - "github.com/modelcontextprotocol/registry/internal/telemetry" -) - -func TestCORSHeaders(t *testing.T) { - // Create test config with JWT private key - testSeed := make([]byte, ed25519.SeedSize) - _, err := rand.Read(testSeed) - require.NoError(t, err) - - cfg := config.NewConfig() - cfg.JWTPrivateKey = hex.EncodeToString(testSeed) - - // Create test services - db := database.NewTestDB(t) - registryService := service.NewRegistryService(db, cfg) - - shutdownTelemetry, metrics, err := telemetry.InitMetrics("test") - assert.NoError(t, err) - defer func() { _ = shutdownTelemetry(nil) }() - - versionInfo := &v0.VersionBody{ - Version: "test", - GitCommit: "test", - BuildTime: "test", - } - - // Create server - _ = api.NewServer(cfg, registryService, metrics, versionInfo) - - tests := []struct { - name string - method string - path string - expectCORS bool - checkPreflight bool - }{ - { - name: "GET request should have CORS headers", - method: http.MethodGet, - path: "/v0/health", - expectCORS: true, - }, - { - name: "POST request should have CORS headers", - method: http.MethodPost, - path: "/v0/servers", - expectCORS: true, - }, - { - name: "OPTIONS preflight request should succeed", - method: http.MethodOptions, - path: "/v0/servers", - expectCORS: true, - checkPreflight: true, - }, - { - name: "PUT request should have CORS headers", - method: http.MethodPut, - path: "/v0/servers/test", - expectCORS: true, - }, - { - name: "DELETE request should have CORS headers", - method: http.MethodDelete, - path: "/v0/servers/test", - expectCORS: true, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - req := httptest.NewRequest(tt.method, tt.path, nil) - - // Add origin header to trigger CORS - req.Header.Set("Origin", "https://example.com") - - // For preflight requests, add required headers - if tt.method == http.MethodOptions { - req.Header.Set("Access-Control-Request-Method", "POST") - req.Header.Set("Access-Control-Request-Headers", "Content-Type") - } - - w := httptest.NewRecorder() - - // Get the handler from the server (we need to access it through reflection or make it public) - // For now, we'll create a minimal test by checking the middleware directly - - // Create a simple handler to wrap - handler := http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { - w.WriteHeader(http.StatusOK) - }) - - // We can't easily access the server's handler, so let's test the CORS behavior - // by making an actual request through the test server - // This is a bit of a hack but works for integration testing - - // Instead, let's verify CORS headers are present - handler.ServeHTTP(w, req) - - if tt.expectCORS { - // Note: This test is simplified. In a real scenario, we'd need to - // actually use the server's handler which includes the CORS middleware. - // For now, this tests the basic structure. - - // The rs/cors library should add these headers automatically - // We'll verify this in integration tests or by making real HTTP requests - t.Log("CORS headers should be present (verified via integration tests)") - } - - if tt.checkPreflight { - // Preflight responses should return 200 or 204 - assert.Contains(t, []int{http.StatusOK, http.StatusNoContent}, w.Code) - } - }) - } -} - -func TestCORSHeaderValues(t *testing.T) { - // Create test config with JWT private key - testSeed := make([]byte, ed25519.SeedSize) - _, err := rand.Read(testSeed) - require.NoError(t, err) - - cfg := config.NewConfig() - cfg.JWTPrivateKey = hex.EncodeToString(testSeed) - - // Create test services - db := database.NewTestDB(t) - registryService := service.NewRegistryService(db, cfg) - - shutdownTelemetry, metrics, err := telemetry.InitMetrics("test") - assert.NoError(t, err) - defer func() { _ = shutdownTelemetry(nil) }() - - versionInfo := &v0.VersionBody{ - Version: "test", - GitCommit: "test", - BuildTime: "test", - } - - // Create server - _ = api.NewServer(cfg, registryService, metrics, versionInfo) - - // Test that CORS is configured with correct values - // This is more of a documentation test to ensure we know what CORS settings we use - - t.Run("CORS should allow all origins", func(t *testing.T) { - // AllowedOrigins: []string{"*"} - // This is tested via integration tests - t.Log("CORS allows all origins (*)") - }) - - t.Run("CORS should allow standard HTTP methods", func(t *testing.T) { - // AllowedMethods: GET, POST, PUT, DELETE, OPTIONS - t.Log("CORS allows GET, POST, PUT, DELETE, OPTIONS") - }) - - t.Run("CORS should allow all headers", func(t *testing.T) { - // AllowedHeaders: []string{"*"} - t.Log("CORS allows all headers (*)") - }) - - t.Run("CORS should not allow credentials with wildcard origin", func(t *testing.T) { - // AllowCredentials: false (required when origin is *) - t.Log("CORS does not allow credentials (required for wildcard origin)") - }) - - t.Run("CORS should set max age to 24 hours", func(t *testing.T) { - // MaxAge: 86400 (24 hours) - t.Log("CORS max age is 86400 seconds (24 hours)") - }) -} diff --git a/internal/api/handlers/v0/auth/common.go b/internal/api/handlers/v0/auth/common.go index 40a6ba7..f1665e4 100644 --- a/internal/api/handlers/v0/auth/common.go +++ b/internal/api/handlers/v0/auth/common.go @@ -8,8 +8,11 @@ import ( "crypto/sha512" "encoding/base64" "encoding/hex" + "errors" "fmt" + "io" "math/big" + "net" "regexp" "strings" "time" @@ -18,6 +21,26 @@ import ( "github.com/modelcontextprotocol/registry/internal/config" ) +// readErrorBody reads an upstream error response body for inclusion in an +// error message. The cap protects against a misbehaving upstream returning a +// huge body โ€” error diagnostics never need more than a few KB. +func readErrorBody(r io.Reader) string { + const maxErrorBodySize = 8 * 1024 + b, _ := io.ReadAll(io.LimitReader(r, maxErrorBodySize)) + return string(b) +} + +// ErrSignatureMismatch is returned by VerifySignature when the signature is structurally +// valid but does not verify against the public key. Distinguishing this from structural +// failures (wrong size, bad key format) lets the caller add fingerprint hints only when +// the failure is actually a "wrong key" situation. +var ErrSignatureMismatch = errors.New("signature does not match public key") + +// MCPProofRecordPattern matches a well-formed MCPv1 DNS/HTTP proof record: +// "v=MCPv1; k=; p=". Shared so callers checking for the +// presence of a valid record see exactly what the parser will accept. +var MCPProofRecordPattern = regexp.MustCompile(`v=MCPv1;\s*k=([^;]+);\s*p=([A-Za-z0-9+/=]+)`) + // CryptoAlgorithm represents the cryptographic algorithm used for a public key type CryptoAlgorithm string @@ -66,6 +89,12 @@ func ValidateDomainAndTimestamp(domain, timestamp string) (*time.Time, error) { return nil, fmt.Errorf("invalid domain format") } + if isGitHubPagesDomain(domain) { + return nil, fmt.Errorf( + "github.io domains cannot be used with DNS/HTTP authentication; " + + "use GitHub authentication for io.github.* namespaces") + } + ts, err := time.Parse(time.RFC3339, timestamp) if err != nil { return nil, fmt.Errorf("invalid timestamp format: %w", err) @@ -90,18 +119,72 @@ func DecodeAndValidateSignature(signedTimestamp string) ([]byte, error) { } func VerifySignatureWithKeys(publicKeys []PublicKeyInfo, messageBytes []byte, signature []byte) error { + var lastErr error + allMismatch := true for _, publicKeyInfo := range publicKeys { err := publicKeyInfo.VerifySignature(messageBytes, signature) if err == nil { return nil } - - if len(publicKeys) == 1 { - return err + lastErr = err + if !errors.Is(err, ErrSignatureMismatch) { + allMismatch = false } } - return fmt.Errorf("signature verification failed") + // If at least one key failed for a structural reason (wrong size, unsupported algorithm), + // surface that error directly โ€” it's more actionable than a generic "didn't match" message. + if !allMismatch { + return lastErr + } + + // Every key was tried and produced a clean cryptographic mismatch. Include short + // fingerprints of every key that was tried so users can tell which published keys the + // registry actually saw โ€” the most common cause of this error is a stale record left + // behind after a key rotation, which is otherwise indistinguishable from a generic + // crypto failure. + fingerprints := make([]string, 0, len(publicKeys)) + for _, publicKeyInfo := range publicKeys { + fingerprints = append(fingerprints, publicKeyInfo.Fingerprint()) + } + if len(publicKeys) == 1 { + return fmt.Errorf( + "signature verification failed (tried published key %s); "+ + "if this is not the key you are signing with, the published record may be stale", + fingerprints[0], + ) + } + return fmt.Errorf( + "signature verification failed against all %d published keys (tried: %s); "+ + "if you recently rotated keys, remove any stale records from the apex domain", + len(publicKeys), strings.Join(fingerprints, ", "), + ) +} + +// Fingerprint returns a short, human-readable identifier for the public key. +// Format: ":". Public keys are not secret, +// but truncating keeps error messages readable. +func (pki *PublicKeyInfo) Fingerprint() string { + const prefixLen = 8 + var raw []byte + switch pki.Algorithm { + case AlgorithmEd25519: + if k, ok := pki.Key.(ed25519.PublicKey); ok { + raw = k + } + case AlgorithmECDSAP384: + if k, ok := pki.Key.(ecdsa.PublicKey); ok { + raw = elliptic.MarshalCompressed(k.Curve, k.X, k.Y) //nolint:staticcheck // SA1019: matches the encoding used in DNS records + } + } + if len(raw) == 0 { + return fmt.Sprintf("%s:unknown", pki.Algorithm) + } + encoded := base64.StdEncoding.EncodeToString(raw) + if len(encoded) > prefixLen { + encoded = encoded[:prefixLen] + } + return fmt.Sprintf("%s:%s", pki.Algorithm, encoded) } // VerifySignature verifies a signature using the appropriate algorithm @@ -113,7 +196,7 @@ func (pki *PublicKeyInfo) VerifySignature(message, signature []byte) error { return fmt.Errorf("invalid signature size for Ed25519") } if !ed25519.Verify(ed25519Key, message, signature) { - return fmt.Errorf("Ed25519 signature verification failed") + return fmt.Errorf("Ed25519: %w", ErrSignatureMismatch) } return nil } @@ -126,7 +209,7 @@ func (pki *PublicKeyInfo) VerifySignature(message, signature []byte) error { s := new(big.Int).SetBytes(signature[48:]) digest := sha512.Sum384(message) if !ecdsa.Verify(&ecdsaKey, digest[:], r, s) { - return fmt.Errorf("ECDSA P-384 signature verification failed") + return fmt.Errorf("ECDSA P-384: %w", ErrSignatureMismatch) } return nil } @@ -246,11 +329,8 @@ func ParseMCPKeysFromStrings(inputs []string) []struct { error } - // proof record pattern: v=MCPv1; k=; p= - cryptoPattern := regexp.MustCompile(`v=MCPv1;\s*k=([^;]+);\s*p=([A-Za-z0-9+/=]+)`) - for _, record := range inputs { - if matches := cryptoPattern.FindStringSubmatch(record); len(matches) == 3 { + if matches := MCPProofRecordPattern.FindStringSubmatch(record); len(matches) == 3 { publicKey, err := ParsePublicKey(matches[1], matches[2]) publicKeys = append(publicKeys, struct { *PublicKeyInfo @@ -292,7 +372,7 @@ func ParsePublicKey(algorithm, publicKey string) (*PublicKeyInfo, error) { } return &PublicKeyInfo{ Algorithm: AlgorithmECDSAP384, - Key: ecdsa.PublicKey{Curve: curve, X: x, Y: y}, + Key: ecdsa.PublicKey{Curve: curve, X: x, Y: y}, //nolint:staticcheck // SA1019: needs crypto/ecdh refactor }, nil } @@ -308,11 +388,35 @@ func ReverseString(domain string) string { return strings.Join(parts, ".") } +// isGitHubPagesDomain reports whether domain is github.io or a subdomain of it. +// GitHub Pages serves .github.io from the /.github.io repository, +// so the HTTP proof only demonstrates push access to that one repository. For an +// organization that is a far weaker bar than the org-Owner ("admin") check the +// GitHub authentication method enforces for io.github./* namespaces โ€” accepting +// the proof here would let any member with write access to the Pages repo mint the +// whole org namespace. Users of io.github.* namespaces authenticate via GitHub. +func isGitHubPagesDomain(domain string) bool { + d := strings.ToLower(domain) + return d == "github.io" || strings.HasSuffix(d, ".github.io") +} + func IsValidDomain(domain string) bool { if len(domain) == 0 || len(domain) > 253 { return false } + // Reject IP literals โ€” this auth method proves domain ownership, not IP + // ownership, and IP literals are an SSRF vector into internal networks. + if net.ParseIP(domain) != nil { + return false + } + + // Require at least one dot โ€” rejects single-label names like "localhost" + // or "kubernetes" that resolve only inside private networks. + if !strings.Contains(domain, ".") { + return false + } + // Check for valid characters and structure domainPattern := regexp.MustCompile(`^[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?(\.[a-zA-Z0-9]([a-zA-Z0-9-]*[a-zA-Z0-9])?)*$`) return domainPattern.MatchString(domain) diff --git a/internal/api/handlers/v0/auth/common_test.go b/internal/api/handlers/v0/auth/common_test.go new file mode 100644 index 0000000..3570646 --- /dev/null +++ b/internal/api/handlers/v0/auth/common_test.go @@ -0,0 +1,80 @@ +package auth_test + +import ( + "testing" + "time" + + "github.com/modelcontextprotocol/registry/internal/api/handlers/v0/auth" +) + +func TestIsValidDomain(t *testing.T) { + tests := []struct { + domain string + want bool + }{ + // Valid + {"example.com", true}, + {"sub.example.com", true}, + {"a.b.c.d.example.com", true}, + {"foo-bar.example.com", true}, + {"123.example.com", true}, + + // Invalid โ€” empty / oversize + {"", false}, + + // Invalid โ€” IP literals (SSRF vector) + {"127.0.0.1", false}, + {"10.0.0.1", false}, + {"169.254.169.254", false}, + {"::1", false}, + {"fe80::1", false}, + + // Invalid โ€” single-label internal names (SSRF vector) + {"localhost", false}, + {"kubernetes", false}, + {"internal", false}, + + // Invalid โ€” bad characters / structure + {"-example.com", false}, + {"example.com-", false}, + {"exa mple.com", false}, + {"example..com", false}, + } + for _, tc := range tests { + t.Run(tc.domain, func(t *testing.T) { + if got := auth.IsValidDomain(tc.domain); got != tc.want { + t.Errorf("IsValidDomain(%q) = %v, want %v", tc.domain, got, tc.want) + } + }) + } +} + +func TestValidateDomainAndTimestampRejectsGitHubPages(t *testing.T) { + timestamp := time.Now().UTC().Format(time.RFC3339) + tests := []struct { + domain string + wantError bool + }{ + // GitHub Pages domains must not mint io.github.* namespaces via DNS/HTTP + {"my-org.github.io", true}, + {"my-org.GitHub.IO", true}, + {"github.io", true}, + {"sub.my-org.github.io", true}, + + // Lookalikes and ordinary domains stay allowed + {"github.io.evil-example.com", false}, + {"example.com", false}, + {"my-org.github.io.example.com", false}, + } + for _, tc := range tests { + t.Run(tc.domain, func(t *testing.T) { + _, err := auth.ValidateDomainAndTimestamp(tc.domain, timestamp) + if tc.wantError && err == nil { + t.Errorf("ValidateDomainAndTimestamp(%q) succeeded, want github.io rejection", tc.domain) + } + if !tc.wantError && err != nil { + t.Errorf("ValidateDomainAndTimestamp(%q) failed: %v", tc.domain, err) + } + }) + } +} diff --git a/internal/api/handlers/v0/auth/dns.go b/internal/api/handlers/v0/auth/dns.go index 5129486..73508c9 100644 --- a/internal/api/handlers/v0/auth/dns.go +++ b/internal/api/handlers/v0/auth/dns.go @@ -62,7 +62,7 @@ func RegisterDNSEndpoint(api huma.API, pathPrefix string, cfg *config.Config) { Path: pathPrefix + "/auth/dns", Summary: "Exchange DNS signature for Registry JWT", Description: "Authenticate using DNS TXT record public key and signed timestamp", - Tags: []string{"auth"}, + Tags: []string{tagAuth}, }, func(ctx context.Context, input *DNSTokenExchangeInput) (*v0.Response[auth.TokenResponse], error) { response, err := handler.ExchangeToken(ctx, input.Body.Domain, input.Body.Timestamp, input.Body.SignedTimestamp) if err != nil { @@ -75,6 +75,11 @@ func RegisterDNSEndpoint(api huma.API, pathPrefix string, cfg *config.Config) { }) } +// commonWrongSelectors lists subdomain prefixes that users frequently mistake for the +// MCP DNS auth record location (DKIM-style intuition). MCP DNS auth uses the apex, +// like SPF โ€” see #385, #1103, #1126 for the recurring confusion. +var commonWrongSelectors = []string{"_mcp-auth", "_mcp-registry"} + // ExchangeToken exchanges DNS signature for a Registry JWT token func (h *DNSAuthHandler) ExchangeToken(ctx context.Context, domain, timestamp, signedTimestamp string) (*auth.TokenResponse, error) { keyFetcher := func(ctx context.Context, domain string) ([]string, error) { @@ -90,9 +95,63 @@ func (h *DNSAuthHandler) ExchangeToken(ctx context.Context, domain, timestamp, s if err != nil { return nil, fmt.Errorf("failed to lookup DNS TXT records: %w", err) } + + if !hasMCPRecord(txtRecords) { + if found := h.findMisplacedSelector(timeoutCtx, domain); found != "" { + return nil, fmt.Errorf( + "no MCPv1 TXT record at %q, but one was found at %q โ€” "+ + "MCP DNS auth requires the record at the apex domain, not under a selector", + domain, found, + ) + } + } + return txtRecords, nil } allowSubdomains := true return h.CoreAuthHandler.ExchangeToken(ctx, domain, timestamp, signedTimestamp, keyFetcher, allowSubdomains, auth.MethodDNS) } + +// hasMCPRecord reports whether any of the supplied TXT records contains a well-formed +// MCPv1 proof record. Uses the same strict pattern as the parser so a malformed +// "v=MCPv1" string at the apex doesn't suppress the misplaced-selector probe. +func hasMCPRecord(records []string) bool { + for _, r := range records { + if MCPProofRecordPattern.MatchString(r) { + return true + } + } + return false +} + +// findMisplacedSelector probes a small fixed set of common wrong selectors and returns the +// first one that holds an MCPv1 record, or "" if none do. Lookups run in parallel with a +// short individual timeout so a slow/missing zone never delays the response by much. +func (h *DNSAuthHandler) findMisplacedSelector(ctx context.Context, domain string) string { + type result struct { + name string + found bool + } + results := make(chan result, len(commonWrongSelectors)) + for _, selector := range commonWrongSelectors { + name := selector + "." + domain + go func(name string) { + lookupCtx, cancel := context.WithTimeout(ctx, 2*time.Second) + defer cancel() + records, err := h.resolver.LookupTXT(lookupCtx, name) + if err != nil { + results <- result{name: name, found: false} + return + } + results <- result{name: name, found: hasMCPRecord(records)} + }(name) + } + for range commonWrongSelectors { + r := <-results + if r.found { + return r.name + } + } + return "" +} diff --git a/internal/api/handlers/v0/auth/dns_test.go b/internal/api/handlers/v0/auth/dns_test.go index f0f3a56..7ffda75 100644 --- a/internal/api/handlers/v0/auth/dns_test.go +++ b/internal/api/handlers/v0/auth/dns_test.go @@ -280,17 +280,6 @@ func TestDNSAuthHandler_Permissions(t *testing.T) { "v1.api.example.com/*", // should be reversed }, }, - { - name: "single part domain", - domain: "localhost", - expectedPatterns: []string{ - "localhost/*", // exact pattern (no reversal needed) - "localhost.*", // subdomain pattern - }, - unexpectedPatterns: []string{ - "*.localhost", // wrong wildcard position - }, - }, { name: "hyphenated domain", domain: "my-app.example-site.com", @@ -546,7 +535,7 @@ func TestDNSAuthHandler_ExchangeToken_ECDSAP384(t *testing.T) { timestamp: time.Now().UTC().Format(time.RFC3339), signedTimestamp: "abcdef1234", // too short for ECDSA P-384 expectError: true, - errorContains: "signature verification failed", // general error when trying all keys + errorContains: "invalid signature size for ECDSA P-384", }, { name: "wrong ECDSA P-384 key for signature", @@ -990,3 +979,100 @@ func TestDNSAuthHandler_Mixed_Algorithm_Support(t *testing.T) { assert.NotNil(t, result) }) } + +// TestDNSAuthHandler_WrongSelectorProbe covers the case where the user mistakenly placed +// the MCPv1 TXT record under a selector (e.g. _mcp-auth.) instead of the apex, +// which has been a recurring source of confusion (#385, #1103, #1126). +func TestDNSAuthHandler_WrongSelectorProbe(t *testing.T) { + cfg := &config.Config{ + JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + } + + publicKey, _, err := ed25519.GenerateKey(nil) + require.NoError(t, err) + publicKeyB64 := base64.StdEncoding.EncodeToString(publicKey) + mcpRecord := fmt.Sprintf("v=MCPv1; k=ed25519; p=%s", publicKeyB64) + + tests := []struct { + name string + txtRecords map[string][]string + expectInError string + }{ + { + name: "record placed at _mcp-auth selector", + txtRecords: map[string][]string{ + "_mcp-auth." + testDomain: {mcpRecord}, + }, + expectInError: "_mcp-auth." + testDomain, + }, + { + name: "record placed at _mcp-registry selector", + txtRecords: map[string][]string{ + "_mcp-registry." + testDomain: {mcpRecord}, + }, + expectInError: "_mcp-registry." + testDomain, + }, + { + name: "no record anywhere falls through to standard error", + txtRecords: map[string][]string{ + testDomain: {"v=spf1 ~all"}, + }, + expectInError: "no MCP public key found in DNS TXT records", + }, + { + name: "malformed MCPv1 string at apex still triggers selector probe", + txtRecords: map[string][]string{ + // Looks like an MCPv1 record but missing the public key field. + testDomain: {"v=MCPv1; k=ed25519"}, + "_mcp-auth." + testDomain: {mcpRecord}, + }, + expectInError: "_mcp-auth." + testDomain, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + handler := auth.NewDNSAuthHandler(cfg) + handler.SetResolver(&MockDNSResolver{txtRecords: tt.txtRecords}) + + timestamp := time.Now().UTC().Format(time.RFC3339) + _, err := handler.ExchangeToken(context.Background(), testDomain, timestamp, hex.EncodeToString(make([]byte, 64))) + + require.Error(t, err) + assert.Contains(t, err.Error(), tt.expectInError) + }) + } +} + +// TestDNSAuthHandler_StaleKeyFingerprintInError covers #1126: when only one apex record is +// published and it doesn't match the key being signed with (the typical "rotated and forgot +// to update DNS" failure), the error message should include a fingerprint of the published +// key so the user can tell their CLI is signing with a different key than what's published. +func TestDNSAuthHandler_StaleKeyFingerprintInError(t *testing.T) { + cfg := &config.Config{ + JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + } + + stalePublicKey, _, err := ed25519.GenerateKey(nil) + require.NoError(t, err) + stalePublicKeyB64 := base64.StdEncoding.EncodeToString(stalePublicKey) + + _, currentPrivateKey, err := ed25519.GenerateKey(nil) + require.NoError(t, err) + + handler := auth.NewDNSAuthHandler(cfg) + handler.SetResolver(&MockDNSResolver{ + txtRecords: map[string][]string{ + testDomain: {fmt.Sprintf("v=MCPv1; k=ed25519; p=%s", stalePublicKeyB64)}, + }, + }) + + timestamp := time.Now().UTC().Format(time.RFC3339) + signature := ed25519.Sign(currentPrivateKey, []byte(timestamp)) + _, err = handler.ExchangeToken(context.Background(), testDomain, timestamp, hex.EncodeToString(signature)) + + require.Error(t, err) + expectedFingerprint := "ed25519:" + stalePublicKeyB64[:8] + assert.Contains(t, err.Error(), expectedFingerprint, "error should expose the published key's fingerprint") + assert.Contains(t, err.Error(), "stale", "error should hint at the stale-record cause") +} diff --git a/internal/api/handlers/v0/auth/github_at.go b/internal/api/handlers/v0/auth/github_at.go index fbb950c..e11d4f0 100644 --- a/internal/api/handlers/v0/auth/github_at.go +++ b/internal/api/handlers/v0/auth/github_at.go @@ -4,7 +4,7 @@ import ( "context" "encoding/json" "fmt" - "io" + "log" "net/http" "regexp" "strings" @@ -54,11 +54,11 @@ func RegisterGitHubATEndpoint(api huma.API, pathPrefix string, cfg *config.Confi Path: pathPrefix + "/auth/github-at", Summary: "Exchange GitHub OAuth access token for Registry JWT", Description: "Exchange a GitHub OAuth access token for a short-lived Registry JWT token", - Tags: []string{"auth"}, + Tags: []string{tagAuth}, }, func(ctx context.Context, input *GitHubTokenExchangeInput) (*v0.Response[auth.TokenResponse], error) { response, err := handler.ExchangeToken(ctx, input.Body.GitHubToken) if err != nil { - return nil, huma.Error401Unauthorized("Token exchange failed", err) + return nil, tokenExchangeError(err) } return &v0.Response[auth.TokenResponse]{ @@ -67,6 +67,17 @@ func RegisterGitHubATEndpoint(api huma.API, pathPrefix string, cfg *config.Confi }) } +// tokenExchangeError maps an internal ExchangeToken failure to a client-facing +// 401 without leaking internal detail. huma serializes extra error args into the +// response body, and the wrapped err here can include the raw upstream GitHub +// response body captured by readErrorBody โ€” so passing it to huma would echo that +// detail back to the caller (CWE-209). We log it server-side (like the sibling +// handlers in servers.go) and return only a generic message. +func tokenExchangeError(err error) error { + log.Printf("github-at token exchange failed: %v", err) + return huma.Error401Unauthorized("Token exchange failed") +} + // ExchangeToken exchanges a GitHub OAuth token for a Registry JWT token func (h *GitHubHandler) ExchangeToken(ctx context.Context, githubToken string) (*auth.TokenResponse, error) { // Get GitHub user information @@ -75,8 +86,9 @@ func (h *GitHubHandler) ExchangeToken(ctx context.Context, githubToken string) ( return nil, fmt.Errorf("failed to get GitHub user: %w", err) } - // Get user's organizations - orgs, err := h.getGitHubUserOrgs(ctx, user.Login, githubToken) + // Get the organizations the user administers. Org namespaces are only granted + // to org Owners (membership role "admin"), not to ordinary members. + orgs, err := h.getGitHubAdminOrgs(ctx, githubToken) if err != nil { return nil, fmt.Errorf("failed to get GitHub organizations: %w", err) } @@ -123,8 +135,7 @@ func (h *GitHubHandler) getGitHubUser(ctx context.Context, token string) (*GitHu defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - body, _ := io.ReadAll(resp.Body) - return nil, fmt.Errorf("GitHub API error (status %d): %s", resp.StatusCode, body) + return nil, fmt.Errorf("GitHub API error (status %d): %s", resp.StatusCode, readErrorBody(resp.Body)) } var user GitHubUserOrOrg @@ -135,8 +146,87 @@ func (h *GitHubHandler) getGitHubUser(ctx context.Context, token string) (*GitHu return &user, nil } -func (h *GitHubHandler) getGitHubUserOrgs(ctx context.Context, username string, token string) ([]GitHubUserOrOrg, error) { - req, err := http.NewRequestWithContext(ctx, http.MethodGet, h.baseURL+"/users/"+username+"/orgs", nil) +// githubOrgRoleAdmin is the membership role GitHub returns for an organization +// Owner. It is the only role we treat as carrying publish authority for the org +// namespace. GET /user/memberships/orgs reports the caller's role as either +// "admin" (Owner) or "member" (GitHub has no org-level "maintainer" role); only +// "admin" carries publish authority, so a "member" is intentionally not granted. +const githubOrgRoleAdmin = "admin" + +// githubMembershipStateActive is the membership state for an accepted (as opposed +// to merely invited/pending) org membership. We only honor active memberships so a +// not-yet-accepted owner invitation never grants the org namespace. +const githubMembershipStateActive = "active" + +// orgMembershipsPageSize is the page size we request when listing the user's org +// memberships. 100 is GitHub's maximum. +const orgMembershipsPageSize = 100 + +// maxOrgMembershipPages bounds the pagination loop. At orgMembershipsPageSize=100 +// this covers 10,000 org memberships โ€” far beyond any real user โ€” and exists only +// as a backstop so a misbehaving or redirected upstream cannot drive an unbounded +// number of requests. +const maxOrgMembershipPages = 100 + +// githubOrgMembership is one entry from GET /user/memberships/orgs: the +// authenticated user's membership in a single organization, including their role. +type githubOrgMembership struct { + State string `json:"state"` + Role string `json:"role"` + Organization GitHubUserOrOrg `json:"organization"` +} + +// getGitHubAdminOrgs returns the organizations in which the authenticated user is +// an Owner (membership role "admin"). +// +// This deliberately uses GET /user/memberships/orgs rather than +// GET /users/{username}/orgs. The latter only returns *public* memberships and +// carries no role, so it cannot distinguish an Owner from an ordinary member โ€” +// historically every org a user belonged to was granted publish access to its +// namespace regardless of the user's role. The memberships endpoint returns the +// caller's role per org (and includes private memberships), letting us grant the +// org namespace only to people who actually administer the org. +// +// The endpoint requires the read:org scope. A minimal token used only for +// personal-namespace publishing won't have it and will get a 403 here; that is +// treated as "no admin orgs" (see fetchOrgMembershipsPage) so personal publishing +// keeps working without asking users to over-scope their token. +func (h *GitHubHandler) getGitHubAdminOrgs(ctx context.Context, token string) ([]GitHubUserOrOrg, error) { + var adminOrgs []GitHubUserOrOrg + + for page := 1; page <= maxOrgMembershipPages; page++ { + memberships, err := h.fetchOrgMembershipsPage(ctx, token, page) + if err != nil { + return nil, err + } + + for _, m := range memberships { + // state=active is already requested in the query string, but re-check it + // here as defense in depth: if that param is ever dropped or changed, this + // keeps a pending (not-yet-accepted) owner invitation from being granted + // the org namespace. + if m.State == githubMembershipStateActive && m.Role == githubOrgRoleAdmin { + adminOrgs = append(adminOrgs, m.Organization) + } + } + + // A short page is the last page: return the complete result. + if len(memberships) < orgMembershipsPageSize { + return adminOrgs, nil + } + } + + // Every page up to the cap was full. A real user never has this many org + // memberships, so rather than return a possibly-truncated set (which would + // silently strip a legitimate Owner's grant), fail closed. + return nil, fmt.Errorf("org memberships exceeded %d pages; refusing to issue a possibly-truncated grant", maxOrgMembershipPages) +} + +// fetchOrgMembershipsPage fetches a single page of the authenticated user's +// active organization memberships. +func (h *GitHubHandler) fetchOrgMembershipsPage(ctx context.Context, token string, page int) ([]githubOrgMembership, error) { + url := fmt.Sprintf("%s/user/memberships/orgs?state=active&per_page=%d&page=%d", h.baseURL, orgMembershipsPageSize, page) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) if err != nil { return nil, fmt.Errorf("failed to create request: %w", err) } @@ -147,45 +237,74 @@ func (h *GitHubHandler) getGitHubUserOrgs(ctx context.Context, username string, resp, err := http.DefaultClient.Do(req) if err != nil { - return nil, fmt.Errorf("failed to get user organizations: %w", err) + return nil, fmt.Errorf("failed to get user organization memberships: %w", err) } defer resp.Body.Close() + // GitHub returns 403 here for two very different reasons, which we must not + // conflate: + // 1. The token lacks the read:org scope. This is the common, benign case for a + // minimal personal-publishing token: GET /user still works, but org + // memberships are forbidden. We degrade gracefully to "no admin orgs" so + // personal-namespace publishing keeps working without over-scoping. + // 2. Rate limiting. GitHub signals primary/secondary rate limits with 403 (or + // 429), setting X-RateLimit-Remaining: 0 and/or Retry-After. Degrading here + // would silently strip a legitimate Owner's org grant, so we fail closed + // (return an error) rather than mistake a throttle for "not an admin". + if resp.StatusCode == http.StatusForbidden { + if resp.Header.Get("X-RateLimit-Remaining") == "0" || resp.Header.Get("Retry-After") != "" { + return nil, fmt.Errorf("GitHub API rate limit exceeded while listing org memberships (status 403): %s", readErrorBody(resp.Body)) + } + // Best-effort defense: GitHub uses the X-GitHub-SSO header to signal that a + // resource is behind SAML/SSO the token hasn't been authorized for. If we see + // it, treat that as an Owner being blocked (not a missing scope) and fail + // closed rather than silently degrading them to personal-only. NOTE: we have + // not confirmed that the memberships *list* endpoint emits this header on SSO + // enforcement (it may instead just omit the SSO-protected org); this check is + // safe either way โ€” if the header is absent we fall through to the same + // graceful degrade as before โ€” but it is not a proven guarantee that every + // SSO-blocked Owner is caught here. + if resp.Header.Get("X-GitHub-SSO") != "" { + return nil, fmt.Errorf("GitHub org memberships require SSO authorization for this token (status 403): %s", readErrorBody(resp.Body)) + } + return nil, nil + } + if resp.StatusCode != http.StatusOK { - body, _ := io.ReadAll(resp.Body) - return nil, fmt.Errorf("GitHub API error (status %d): %s", resp.StatusCode, body) + return nil, fmt.Errorf("GitHub API error (status %d): %s", resp.StatusCode, readErrorBody(resp.Body)) } - var orgs []GitHubUserOrOrg - if err := json.NewDecoder(resp.Body).Decode(&orgs); err != nil { - return nil, fmt.Errorf("failed to decode organizations response: %w", err) + var memberships []githubOrgMembership + if err := json.NewDecoder(resp.Body).Decode(&memberships); err != nil { + return nil, fmt.Errorf("failed to decode organization memberships response: %w", err) } - return orgs, nil + return memberships, nil } // buildPermissions builds permissions based on GitHub user and their organizations func (h *GitHubHandler) buildPermissions(username string, orgs []GitHubUserOrOrg) []auth.Permission { - permissions := []auth.Permission{} - - // Assert user and org names match expected regex, to harden against people doing weird things in names + // Assert the username matches the expected regex, to harden against people doing + // weird things in names. The username is the caller's own identity, so if it is + // invalid we grant nothing. if !isValidGitHubName(username) { return nil } - for _, org := range orgs { - if !isValidGitHubName(org.Login) { - return nil - } - } // Add permission for user's own namespace - permissions = append(permissions, auth.Permission{ + permissions := []auth.Permission{{ Action: auth.PermissionActionPublish, ResourcePattern: fmt.Sprintf("io.github.%s/*", username), - }) + }} - // Add permissions for each organization + // Add permissions for each organization the user administers (Owner role). Skip + // any org whose name fails validation rather than rejecting the whole set, so one + // unexpected org name can't strip the caller's personal namespace or their other + // (valid) org grants. for _, org := range orgs { + if !isValidGitHubName(org.Login) { + continue + } permissions = append(permissions, auth.Permission{ Action: auth.PermissionActionPublish, ResourcePattern: fmt.Sprintf("io.github.%s/*", org.Login), diff --git a/internal/api/handlers/v0/auth/github_at_internal_test.go b/internal/api/handlers/v0/auth/github_at_internal_test.go new file mode 100644 index 0000000..f2668bf --- /dev/null +++ b/internal/api/handlers/v0/auth/github_at_internal_test.go @@ -0,0 +1,33 @@ +package auth + +import ( + "encoding/json" + "errors" + "testing" + + "github.com/danielgtaylor/huma/v2" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +// The 401 returned to the client must not echo the internal error, which can +// include the raw upstream GitHub response body captured by readErrorBody +// (CWE-209). huma serializes extra error args into the response body, so the fix +// is to log server-side and return only a generic message. This mirrors the +// regression test added for the GET /v0/servers 500 leak (#1338). +func TestTokenExchangeError_doesNotLeakDetail(t *testing.T) { + const internal = `failed to get GitHub organizations: GitHub API error (status 500): {"message":"internal-host db detail"}` + + err := tokenExchangeError(errors.New(internal)) + require.Error(t, err) + + var se huma.StatusError + require.True(t, errors.As(err, &se)) + assert.Equal(t, 401, se.GetStatus()) + + body, marshalErr := json.Marshal(err) + require.NoError(t, marshalErr) + assert.NotContains(t, string(body), "internal-host db detail") + assert.NotContains(t, string(body), "status 500") + assert.Contains(t, string(body), "Token exchange failed") +} diff --git a/internal/api/handlers/v0/auth/github_at_test.go b/internal/api/handlers/v0/auth/github_at_test.go index c0fa4ac..148566d 100644 --- a/internal/api/handlers/v0/auth/github_at_test.go +++ b/internal/api/handlers/v0/auth/github_at_test.go @@ -22,9 +22,82 @@ import ( const ( githubUserEndpoint = "/user" - githubOrgsEndpoint = "/users/testuser/orgs" + // githubOrgsEndpoint is the endpoint used to list the authenticated user's org + // memberships (with role). It replaces the old public-only /users/{user}/orgs. + githubOrgsEndpoint = "/user/memberships/orgs" ) +// orgMembership mirrors a single entry of GET /user/memberships/orgs for use in +// mock GitHub API responses. Role is "admin" (Owner) or "member". +type orgMembership struct { + State string `json:"state"` + Role string `json:"role"` + Organization v0auth.GitHubUserOrOrg `json:"organization"` +} + +// adminMemberships wraps orgs as active "admin"-role memberships, the shape the +// memberships endpoint returns for an org Owner. +func adminMemberships(orgs []v0auth.GitHubUserOrOrg) []orgMembership { + memberships := make([]orgMembership, 0, len(orgs)) + for _, org := range orgs { + memberships = append(memberships, orgMembership{State: "active", Role: "admin", Organization: org}) + } + return memberships +} + +// newMockGitHubServer returns a mock GitHub API server that serves a fixed +// "testuser" on /user and delegates the org-memberships endpoint to orgsHandler. +// It keeps individual test cases small (only the memberships behavior varies), +// which also keeps their cyclomatic complexity down. +func newMockGitHubServer(orgsHandler http.HandlerFunc) *httptest.Server { + return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case githubUserEndpoint: + user := v0auth.GitHubUserOrOrg{Login: "testuser", ID: 12345} + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(user) //nolint:errcheck + case githubOrgsEndpoint: + orgsHandler(w, r) + default: + w.WriteHeader(http.StatusNotFound) + } + })) +} + +// grantedPatterns exchanges the token and returns the resource patterns granted +// in the resulting JWT. +func grantedPatterns(t *testing.T, cfg *config.Config, server *httptest.Server) []string { + t.Helper() + handler := v0auth.NewGitHubHandler(cfg) + handler.SetBaseURL(server.URL) + + ctx := context.Background() + response, err := handler.ExchangeToken(ctx, "valid-github-token") + require.NoError(t, err) + require.NotNil(t, response) + + claims, err := auth.NewJWTManager(cfg).ValidateToken(ctx, response.RegistryToken) + require.NoError(t, err) + + patterns := make([]string, 0, len(claims.Permissions)) + for _, perm := range claims.Permissions { + patterns = append(patterns, perm.ResourcePattern) + } + return patterns +} + +// assertExchangeFailsClosed asserts that a token exchange against server returns +// an error and no token (used for the fail-closed 403 variants). +func assertExchangeFailsClosed(t *testing.T, cfg *config.Config, server *httptest.Server) { + t.Helper() + handler := v0auth.NewGitHubHandler(cfg) + handler.SetBaseURL(server.URL) + + response, err := handler.ExchangeToken(context.Background(), "valid-github-token") + require.Error(t, err) + assert.Nil(t, response) +} + func TestGitHubHandler_ExchangeToken(t *testing.T) { // Create test handler with mock config testSeed := make([]byte, ed25519.SeedSize) @@ -96,12 +169,12 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(user) //nolint:errcheck case githubOrgsEndpoint: - orgs := []v0auth.GitHubUserOrOrg{ + memberships := adminMemberships([]v0auth.GitHubUserOrOrg{ {Login: "test-org-1", ID: 1}, {Login: "test-org-2", ID: 2}, - } + }) w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(orgs) //nolint:errcheck + json.NewEncoder(w).Encode(memberships) //nolint:errcheck default: w.WriteHeader(http.StatusNotFound) } @@ -225,10 +298,9 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) { } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(user) //nolint:errcheck - case "/users/user with spaces/orgs": - orgs := []v0auth.GitHubUserOrOrg{} + case githubOrgsEndpoint: w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(orgs) //nolint:errcheck + json.NewEncoder(w).Encode([]orgMembership{}) //nolint:errcheck } })) defer mockServer.Close() @@ -264,12 +336,12 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) { w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(user) //nolint:errcheck case githubOrgsEndpoint: - orgs := []v0auth.GitHubUserOrOrg{ + memberships := adminMemberships([]v0auth.GitHubUserOrOrg{ {Login: "valid-org", ID: 1}, {Login: "org with spaces", ID: 2}, // Invalid name - } + }) w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(orgs) //nolint:errcheck + json.NewEncoder(w).Encode(memberships) //nolint:errcheck } })) defer mockServer.Close() @@ -290,7 +362,15 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) { claims, err := jwtManager.ValidateToken(ctx, response.RegistryToken) require.NoError(t, err) assert.Equal(t, "testuser", claims.AuthMethodSubject) - assert.Empty(t, claims.Permissions) // No permissions because one org has invalid name + + // The invalid org is skipped, but the personal namespace and the valid org + // are still granted โ€” one weird org name must not strip everything else. + patterns := make([]string, 0, len(claims.Permissions)) + for _, perm := range claims.Permissions { + patterns = append(patterns, perm.ResourcePattern) + } + assert.ElementsMatch(t, []string{"io.github.testuser/*", "io.github.valid-org/*"}, patterns) + assert.NotContains(t, patterns, "io.github.org with spaces/*") }) t.Run("malformed JSON response", func(t *testing.T) { @@ -317,6 +397,302 @@ func TestGitHubHandler_ExchangeToken(t *testing.T) { }) } +func TestGitHubHandler_ExchangeToken_OrgRoles(t *testing.T) { + testSeed := make([]byte, ed25519.SeedSize) + _, err := rand.Read(testSeed) + require.NoError(t, err) + + cfg := &config.Config{ + JWTPrivateKey: hex.EncodeToString(testSeed), + } + + t.Run("member-role org is not granted, only admin orgs", func(t *testing.T) { + // The user is an Owner (admin) of one org and an ordinary member of another. + // Only the org they administer should yield a publish permission. + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case githubUserEndpoint: + user := v0auth.GitHubUserOrOrg{Login: "testuser", ID: 12345} + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(user) //nolint:errcheck + case githubOrgsEndpoint: + memberships := []orgMembership{ + {State: "active", Role: "admin", Organization: v0auth.GitHubUserOrOrg{Login: "admin-org", ID: 1}}, + {State: "active", Role: "member", Organization: v0auth.GitHubUserOrOrg{Login: "member-org", ID: 2}}, + } + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(memberships) //nolint:errcheck + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer mockServer.Close() + + handler := v0auth.NewGitHubHandler(cfg) + handler.SetBaseURL(mockServer.URL) + + ctx := context.Background() + response, err := handler.ExchangeToken(ctx, "valid-github-token") + require.NoError(t, err) + require.NotNil(t, response) + + jwtManager := auth.NewJWTManager(cfg) + claims, err := jwtManager.ValidateToken(ctx, response.RegistryToken) + require.NoError(t, err) + + patterns := make([]string, 0, len(claims.Permissions)) + for _, perm := range claims.Permissions { + patterns = append(patterns, perm.ResourcePattern) + } + assert.ElementsMatch(t, []string{"io.github.testuser/*", "io.github.admin-org/*"}, patterns) + assert.NotContains(t, patterns, "io.github.member-org/*") + }) + + t.Run("missing read:org scope (403) still grants personal namespace", func(t *testing.T) { + // A minimal token without read:org authenticates fine but is forbidden from + // reading org memberships. Personal-namespace publishing must still work. + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case githubUserEndpoint: + user := v0auth.GitHubUserOrOrg{Login: "testuser", ID: 12345} + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(user) //nolint:errcheck + case githubOrgsEndpoint: + w.WriteHeader(http.StatusForbidden) + w.Write([]byte(`{"message": "Token does not have the required scope"}`)) //nolint:errcheck + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer mockServer.Close() + + handler := v0auth.NewGitHubHandler(cfg) + handler.SetBaseURL(mockServer.URL) + + ctx := context.Background() + response, err := handler.ExchangeToken(ctx, "valid-github-token") + require.NoError(t, err) + require.NotNil(t, response) + + jwtManager := auth.NewJWTManager(cfg) + claims, err := jwtManager.ValidateToken(ctx, response.RegistryToken) + require.NoError(t, err) + assert.Len(t, claims.Permissions, 1) + assert.Equal(t, "io.github.testuser/*", claims.Permissions[0].ResourcePattern) + }) + + t.Run("admin org on a later page is still granted (pagination)", func(t *testing.T) { + // Page 1 is a full page (100) of member-role orgs; the only admin org is on + // page 2. The pagination loop must not stop at the first page, or the Owner's + // org grant would be silently dropped. + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case githubUserEndpoint: + user := v0auth.GitHubUserOrOrg{Login: "testuser", ID: 12345} + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(user) //nolint:errcheck + case githubOrgsEndpoint: + w.Header().Set("Content-Type", "application/json") + if r.URL.Query().Get("page") == "1" { + page1 := make([]orgMembership, 0, 100) + for i := 0; i < 100; i++ { + page1 = append(page1, orgMembership{ + State: "active", Role: "member", + Organization: v0auth.GitHubUserOrOrg{Login: fmt.Sprintf("member-org-%d", i), ID: 1000 + i}, + }) + } + json.NewEncoder(w).Encode(page1) //nolint:errcheck + return + } + // page 2: a single admin org, signalling the last (short) page. + page2 := []orgMembership{ + {State: "active", Role: "admin", Organization: v0auth.GitHubUserOrOrg{Login: "late-admin-org", ID: 2}}, + } + json.NewEncoder(w).Encode(page2) //nolint:errcheck + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer mockServer.Close() + + handler := v0auth.NewGitHubHandler(cfg) + handler.SetBaseURL(mockServer.URL) + + ctx := context.Background() + response, err := handler.ExchangeToken(ctx, "valid-github-token") + require.NoError(t, err) + require.NotNil(t, response) + + jwtManager := auth.NewJWTManager(cfg) + claims, err := jwtManager.ValidateToken(ctx, response.RegistryToken) + require.NoError(t, err) + + patterns := make([]string, 0, len(claims.Permissions)) + for _, perm := range claims.Permissions { + patterns = append(patterns, perm.ResourcePattern) + } + assert.ElementsMatch(t, []string{"io.github.testuser/*", "io.github.late-admin-org/*"}, patterns) + }) + + t.Run("memberships server error fails closed (no token issued)", func(t *testing.T) { + // A 5xx (or any non-200, non-scope-403) from the memberships endpoint must + // abort the exchange rather than silently degrade to personal-only perms. + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case githubUserEndpoint: + user := v0auth.GitHubUserOrOrg{Login: "testuser", ID: 12345} + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(user) //nolint:errcheck + case githubOrgsEndpoint: + w.WriteHeader(http.StatusInternalServerError) + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer mockServer.Close() + + handler := v0auth.NewGitHubHandler(cfg) + handler.SetBaseURL(mockServer.URL) + + ctx := context.Background() + response, err := handler.ExchangeToken(ctx, "valid-github-token") + require.Error(t, err) + assert.Nil(t, response) + }) + + t.Run("rate-limit 403 fails closed (not treated as missing scope)", func(t *testing.T) { + // A 403 with X-RateLimit-Remaining: 0 is a throttle, not a missing-scope + // signal. Degrading would strip a real Owner's org grant, so it must error. + mockServer := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + switch r.URL.Path { + case githubUserEndpoint: + user := v0auth.GitHubUserOrOrg{Login: "testuser", ID: 12345} + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(user) //nolint:errcheck + case githubOrgsEndpoint: + w.Header().Set("X-RateLimit-Remaining", "0") + w.WriteHeader(http.StatusForbidden) + w.Write([]byte(`{"message": "API rate limit exceeded"}`)) //nolint:errcheck + default: + w.WriteHeader(http.StatusNotFound) + } + })) + defer mockServer.Close() + + handler := v0auth.NewGitHubHandler(cfg) + handler.SetBaseURL(mockServer.URL) + + ctx := context.Background() + response, err := handler.ExchangeToken(ctx, "valid-github-token") + require.Error(t, err) + assert.Nil(t, response) + }) +} + +func TestGitHubHandler_ExchangeToken_MembershipFiltering(t *testing.T) { + testSeed := make([]byte, ed25519.SeedSize) + _, err := rand.Read(testSeed) + require.NoError(t, err) + + cfg := &config.Config{JWTPrivateKey: hex.EncodeToString(testSeed)} + + t.Run("pending admin membership is not granted (state filter)", func(t *testing.T) { + // A user invited as an Owner but who has not accepted has role "admin" with + // state "pending". They are not an Owner yet, so the org must not be granted + // even if the state=active query filter is somehow bypassed. + server := newMockGitHubServer(func(w http.ResponseWriter, _ *http.Request) { + memberships := []orgMembership{ + {State: "pending", Role: "admin", Organization: v0auth.GitHubUserOrOrg{Login: "pending-org", ID: 1}}, + {State: "active", Role: "admin", Organization: v0auth.GitHubUserOrOrg{Login: "active-org", ID: 2}}, + } + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(memberships) //nolint:errcheck + }) + defer server.Close() + + patterns := grantedPatterns(t, cfg, server) + assert.ElementsMatch(t, []string{"io.github.testuser/*", "io.github.active-org/*"}, patterns) + assert.NotContains(t, patterns, "io.github.pending-org/*") + }) + + t.Run("billing_manager role is not granted", func(t *testing.T) { + server := newMockGitHubServer(func(w http.ResponseWriter, _ *http.Request) { + memberships := []orgMembership{ + {State: "active", Role: "billing_manager", Organization: v0auth.GitHubUserOrOrg{Login: "billing-org", ID: 1}}, + } + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(memberships) //nolint:errcheck + }) + defer server.Close() + + patterns := grantedPatterns(t, cfg, server) + assert.Equal(t, []string{"io.github.testuser/*"}, patterns) + }) +} + +func TestGitHubHandler_ExchangeToken_403FailClosed(t *testing.T) { + testSeed := make([]byte, ed25519.SeedSize) + _, err := rand.Read(testSeed) + require.NoError(t, err) + + cfg := &config.Config{JWTPrivateKey: hex.EncodeToString(testSeed)} + + t.Run("Retry-After 403 fails closed (secondary rate limit)", func(t *testing.T) { + // A 403 carrying only Retry-After (no X-RateLimit-Remaining: 0) is a secondary + // rate limit, not a missing scope. Degrading would strip a real Owner's grant. + server := newMockGitHubServer(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Retry-After", "60") + w.WriteHeader(http.StatusForbidden) + w.Write([]byte(`{"message": "You have exceeded a secondary rate limit"}`)) //nolint:errcheck + }) + defer server.Close() + + assertExchangeFailsClosed(t, cfg, server) + }) + + t.Run("SSO-enforced 403 fails closed (not treated as missing scope)", func(t *testing.T) { + // A SAML/SSO-enforced org returns 403 with X-GitHub-SSO when the token is not + // SSO-authorized. That is an Owner being blocked, so it must fail closed rather + // than silently degrade to personal-only. + server := newMockGitHubServer(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("X-GitHub-SSO", "required; two_factor_authentication=false") + w.WriteHeader(http.StatusForbidden) + w.Write([]byte(`{"message": "Resource protected by organization SAML enforcement."}`)) //nolint:errcheck + }) + defer server.Close() + + assertExchangeFailsClosed(t, cfg, server) + }) +} + +func TestGitHubHandler_ExchangeToken_PaginationCap(t *testing.T) { + testSeed := make([]byte, ed25519.SeedSize) + _, err := rand.Read(testSeed) + require.NoError(t, err) + + cfg := &config.Config{JWTPrivateKey: hex.EncodeToString(testSeed)} + + t.Run("all-full pages past the cap fails closed", func(t *testing.T) { + // Every page comes back full (100), so the loop never sees a short final page + // and runs to maxOrgMembershipPages. Rather than return a possibly-truncated + // org set, the exchange must fail closed (error, no token). + server := newMockGitHubServer(func(w http.ResponseWriter, _ *http.Request) { + page := make([]orgMembership, 0, 100) + for i := 0; i < 100; i++ { + page = append(page, orgMembership{ + State: "active", Role: "member", + Organization: v0auth.GitHubUserOrOrg{Login: fmt.Sprintf("org-%d", i), ID: i}, + }) + } + w.Header().Set("Content-Type", "application/json") + json.NewEncoder(w).Encode(page) //nolint:errcheck + }) + defer server.Close() + + assertExchangeFailsClosed(t, cfg, server) + }) +} + func TestJWTTokenValidation(t *testing.T) { testSeed := make([]byte, ed25519.SeedSize) _, err := rand.Read(testSeed) @@ -521,7 +897,16 @@ func TestValidGitHubNames(t *testing.T) { orgs: []v0auth.GitHubUserOrOrg{ {Login: "invalid org", ID: 1}, }, - wantPerms: 0, // Should return nil if any name is invalid + wantPerms: 1, // Personal namespace kept; the invalid org is skipped + }, + { + name: "valid username with one valid and one invalid org", + username: "valid-user", + orgs: []v0auth.GitHubUserOrOrg{ + {Login: "valid-org", ID: 1}, + {Login: "invalid org", ID: 2}, + }, + wantPerms: 2, // Personal + valid org; the invalid org is skipped }, } @@ -537,9 +922,9 @@ func TestValidGitHubNames(t *testing.T) { } w.Header().Set("Content-Type", "application/json") json.NewEncoder(w).Encode(user) //nolint:errcheck - case "/users/" + tc.username + "/orgs": + case githubOrgsEndpoint: w.Header().Set("Content-Type", "application/json") - json.NewEncoder(w).Encode(tc.orgs) //nolint:errcheck + json.NewEncoder(w).Encode(adminMemberships(tc.orgs)) //nolint:errcheck } })) defer mockServer.Close() diff --git a/internal/api/handlers/v0/auth/github_oidc.go b/internal/api/handlers/v0/auth/github_oidc.go index e925fb5..de95c67 100644 --- a/internal/api/handlers/v0/auth/github_oidc.go +++ b/internal/api/handlers/v0/auth/github_oidc.go @@ -6,7 +6,6 @@ import ( "encoding/base64" "encoding/json" "fmt" - "io" "math/big" "net/http" "strings" @@ -149,8 +148,7 @@ func (v *GitHubOIDCValidator) fetchJWKS(ctx context.Context) (*JWKS, error) { defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - body, _ := io.ReadAll(resp.Body) - return nil, fmt.Errorf("JWKS endpoint returned status %d: %s", resp.StatusCode, body) + return nil, fmt.Errorf("JWKS endpoint returned status %d: %s", resp.StatusCode, readErrorBody(resp.Body)) } var jwks JWKS @@ -237,7 +235,7 @@ func RegisterGitHubOIDCEndpoint(api huma.API, pathPrefix string, cfg *config.Con Path: pathPrefix + "/auth/github-oidc", Summary: "Exchange GitHub OIDC token for Registry JWT", Description: "Exchange a GitHub Actions OIDC token for a short-lived Registry JWT token", - Tags: []string{"auth"}, + Tags: []string{tagAuth}, }, func(ctx context.Context, input *GitHubOIDCTokenExchangeInput) (*v0.Response[auth.TokenResponse], error) { response, err := handler.ExchangeToken(ctx, input.Body.OIDCToken) if err != nil { @@ -252,8 +250,10 @@ func RegisterGitHubOIDCEndpoint(api huma.API, pathPrefix string, cfg *config.Con // ExchangeToken exchanges a GitHub OIDC token for a Registry JWT token func (h *GitHubOIDCHandler) ExchangeToken(ctx context.Context, oidcToken string) (*auth.TokenResponse, error) { - // Validate OIDC token with audience "mcp-registry" - claims, err := h.validator.ValidateToken(ctx, oidcToken, "mcp-registry") + if h.config.GitHubOIDCAudience == "" { + return nil, fmt.Errorf("GitHub OIDC exchange disabled: this deployment has no audience configured") + } + claims, err := h.validator.ValidateToken(ctx, oidcToken, h.config.GitHubOIDCAudience) if err != nil { return nil, fmt.Errorf("failed to validate OIDC token: %w", err) } diff --git a/internal/api/handlers/v0/auth/github_oidc_test.go b/internal/api/handlers/v0/auth/github_oidc_test.go index a65ab95..37d07e8 100644 --- a/internal/api/handlers/v0/auth/github_oidc_test.go +++ b/internal/api/handlers/v0/auth/github_oidc_test.go @@ -26,7 +26,8 @@ func (m *MockOIDCValidator) ValidateToken(ctx context.Context, token string, aud func TestGitHubOIDCHandler_ExchangeToken(t *testing.T) { cfg := &config.Config{ - JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", // 32 bytes hex + JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", // 32 bytes hex + GitHubOIDCAudience: "https://registry.test", } handler := auth.NewGitHubOIDCHandler(cfg) @@ -118,9 +119,82 @@ func TestGitHubOIDCHandler_ExchangeToken(t *testing.T) { } } +func TestGitHubOIDCHandler_AudienceBinding(t *testing.T) { + t.Run("empty audience config fails closed", func(t *testing.T) { + cfg := &config.Config{ + JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + GitHubOIDCAudience: "", + } + handler := auth.NewGitHubOIDCHandler(cfg) + // Validator should never be called โ€” the audience precondition rejects first. + handler.SetValidator(&MockOIDCValidator{ + validateFunc: func(_ context.Context, _ string, _ string) (*auth.GitHubOIDCClaims, error) { + t.Fatal("validator must not be called when audience is unconfigured") + return nil, fmt.Errorf("unreachable") + }, + }) + + _, err := handler.ExchangeToken(context.Background(), "any-token") + require.Error(t, err) + assert.Contains(t, err.Error(), "no audience configured") + }) + + t.Run("configured audience is what the validator sees", func(t *testing.T) { + cfg := &config.Config{ + JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + GitHubOIDCAudience: "https://registry.example.com", + } + handler := auth.NewGitHubOIDCHandler(cfg) + + var seenAudience string + handler.SetValidator(&MockOIDCValidator{ + validateFunc: func(_ context.Context, _ string, audience string) (*auth.GitHubOIDCClaims, error) { + seenAudience = audience + return &auth.GitHubOIDCClaims{ + RegisteredClaims: jwt.RegisteredClaims{ + Subject: "repo:octo-org/octo-repo:environment:prod", + ExpiresAt: jwt.NewNumericDate(time.Now().Add(1 * time.Hour)), + Audience: jwt.ClaimStrings{audience}, + }, + RepositoryOwner: "octo-org", + }, nil + }, + }) + + _, err := handler.ExchangeToken(context.Background(), "any-token") + require.NoError(t, err) + assert.Equal(t, "https://registry.example.com", seenAudience) + }) + + t.Run("token issued for another deployment is rejected", func(t *testing.T) { + cfg := &config.Config{ + JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + GitHubOIDCAudience: "https://registry.modelcontextprotocol.io", + } + handler := auth.NewGitHubOIDCHandler(cfg) + + // The mock validator does what the real one does: reject if the + // expected audience is not present in the token's aud claim. + handler.SetValidator(&MockOIDCValidator{ + validateFunc: func(_ context.Context, _ string, expected string) (*auth.GitHubOIDCClaims, error) { + tokenAudience := "https://attacker-registry.example" //nolint:gosec // G101 false positive: URL string, not a credential + if expected != tokenAudience { + return nil, fmt.Errorf("invalid audience: expected %s, got [%s]", expected, tokenAudience) + } + return &auth.GitHubOIDCClaims{RepositoryOwner: "octo-org"}, nil + }, + }) + + _, err := handler.ExchangeToken(context.Background(), "captured-token") + require.Error(t, err) + assert.Contains(t, err.Error(), "invalid audience") + }) +} + func TestBuildPermissionsFromOIDC(t *testing.T) { cfg := &config.Config{ - JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + JWTPrivateKey: "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef", + GitHubOIDCAudience: "https://registry.test", } handler := auth.NewGitHubOIDCHandler(cfg) diff --git a/internal/api/handlers/v0/auth/http.go b/internal/api/handlers/v0/auth/http.go index e917f85..5392762 100644 --- a/internal/api/handlers/v0/auth/http.go +++ b/internal/api/handlers/v0/auth/http.go @@ -4,6 +4,7 @@ import ( "context" "fmt" "io" + "net" "net/http" "strings" "time" @@ -34,6 +35,9 @@ type DefaultHTTPKeyFetcher struct { // NewDefaultHTTPKeyFetcher creates a new HTTP key fetcher with timeout func NewDefaultHTTPKeyFetcher() *DefaultHTTPKeyFetcher { + transport := http.DefaultTransport.(*http.Transport).Clone() + transport.DialContext = safeDialContext + return &DefaultHTTPKeyFetcher{ client: &http.Client{ Timeout: 10 * time.Second, @@ -42,10 +46,130 @@ func NewDefaultHTTPKeyFetcher() *DefaultHTTPKeyFetcher { CheckRedirect: func(_ *http.Request, _ []*http.Request) error { return http.ErrUseLastResponse }, + Transport: transport, }, } } +// safeDialContext resolves the target hostname and refuses to dial loopback, +// private (RFC1918, ULA), link-local, or unspecified addresses. Combined with +// IsValidDomain rejecting IP literals, this neutralises SSRF abuse of the +// well-known fetcher: an attacker cannot reach internal HTTPS services +// (Kubernetes API server, internal admin panels, internal DNS-resolved hosts) +// even if they control DNS for an attacker domain. +// +// The hostname is resolved once here; we then dial the resolved IP directly, +// which pins the connection against DNS rebinding (a TOCTOU where the resolver +// returns a public IP to a pre-flight check and an internal IP to the actual +// dial). TLS SNI and the Host header continue to use the original hostname +// since they are set by http.Transport from the request URL, not the dial +// address. +func safeDialContext(ctx context.Context, network, addr string) (net.Conn, error) { + host, port, err := net.SplitHostPort(addr) + if err != nil { + return nil, err + } + + var resolver net.Resolver + ips, err := resolver.LookupIPAddr(ctx, host) + if err != nil { + return nil, err + } + + // Try each non-blocked address in order, falling through on dial failure. + // Without this, a stale public AAAA record that no longer routes (or any + // individually-unreachable IP) breaks auth where the default transport + // would have recovered by trying the next answer. + // + // Each attempt is bounded by perIPDialTimeout so that a single hanging + // address can't consume the whole http.Client budget. This is a + // simpler substitute for Happy Eyeballs (parallel A/AAAA racing) โ€” we + // fail fast and try the next answer instead of racing them. + const perIPDialTimeout = 3 * time.Second + + var lastErr error + allBlocked := true + for _, ip := range ips { + if isBlockedIP(ip.IP) { + continue + } + allBlocked = false + dialCtx, cancel := context.WithTimeout(ctx, perIPDialTimeout) + var d net.Dialer + conn, dialErr := d.DialContext(dialCtx, network, net.JoinHostPort(ip.IP.String(), port)) + cancel() + if dialErr == nil { + return conn, nil + } + lastErr = dialErr + } + if allBlocked { + return nil, fmt.Errorf("dial %s: refusing to connect to private or loopback address", host) + } + return nil, fmt.Errorf("dial %s: all resolved public addresses failed: %w", host, lastErr) +} + +// mustCIDR parses a CIDR literal at init; panics on malformed input so a +// typo surfaces at startup rather than letting a nil *IPNet through to the +// blocklist check (which would silently fail-open). +func mustCIDR(s string) *net.IPNet { + _, n, err := net.ParseCIDR(s) + if err != nil { + panic(fmt.Sprintf("auth: invalid CIDR %q: %v", s, err)) + } + return n +} + +// cgnatRange covers RFC 6598 Carrier-Grade NAT (100.64.0.0/10), which the +// stdlib does not classify via any Is* helper but is reachable on some +// cloud / mobile networks where it shadows internal infrastructure. +var cgnatRange = mustCIDR("100.64.0.0/10") + +// blockedIPv6Prefixes are IPv6 ranges that either embed an arbitrary IPv4 +// address (and therefore tunnel into RFC1918 / cloud-metadata space on +// hosts with the corresponding routing) or are routed into site-local +// internal networks. None of these are caught by Go's per-class Is* +// helpers. +// +// 2002::/16 RFC 3056 6to4 โ€” bits 16-47 are an IPv4 address +// 64:ff9b::/96 RFC 6052 NAT64 well-known โ€” low 32 bits are IPv4 +// 64:ff9b:1::/48 RFC 8215 NAT64 local-use โ€” same IPv4-embedding shape +// fec0::/10 RFC 3879 site-local (deprecated, still routed by some +// stacks) +var blockedIPv6Prefixes = []*net.IPNet{ + mustCIDR("2002::/16"), + mustCIDR("64:ff9b::/96"), + mustCIDR("64:ff9b:1::/48"), + mustCIDR("fec0::/10"), +} + +// isBlockedIP reports whether an IP must not be dialled by the namespace +// verification fetcher. Covers loopback (127/8, ::1), RFC1918 + ULA via +// IsPrivate, link-local (169.254/16, fe80::/10 โ€” includes cloud metadata +// 169.254.169.254), unspecified (0.0.0.0, ::), all multicast (admin-scoped +// 239/8 and ff00::/8 in addition to link-local-multicast), CGNAT, and +// IPv6 prefix families that tunnel to or embed arbitrary IPv4 addresses +// (see blockedIPv6Prefixes). IPv4-mapped IPv6 (::ffff:0:0/96) is handled +// implicitly: the stdlib Is* helpers honour the To4() fast-path, so e.g. +// ::ffff:10.0.0.1 is correctly classified as IsPrivate. +func isBlockedIP(ip net.IP) bool { + if ip == nil { + return true + } + if ip.IsLoopback() || ip.IsPrivate() || + ip.IsLinkLocalUnicast() || ip.IsMulticast() || + ip.IsUnspecified() || + cgnatRange.Contains(ip) { + return true + } + for _, p := range blockedIPv6Prefixes { + if p.Contains(ip) { + return true + } + } + return false +} + // NewDefaultHTTPKeyFetcherWithClient creates a new HTTP key fetcher with a custom HTTP client. // This is primarily useful in tests to inject transports or TLS settings. func NewDefaultHTTPKeyFetcherWithClient(client *http.Client) *DefaultHTTPKeyFetcher { @@ -118,7 +242,7 @@ func RegisterHTTPEndpoint(api huma.API, pathPrefix string, cfg *config.Config) { Path: pathPrefix + "/auth/http", Summary: "Exchange HTTP signature for Registry JWT", Description: "Authenticate using HTTP-hosted public key and signed timestamp", - Tags: []string{"auth"}, + Tags: []string{tagAuth}, }, func(ctx context.Context, input *HTTPTokenExchangeInput) (*v0.Response[auth.TokenResponse], error) { response, err := handler.ExchangeToken(ctx, input.Body.Domain, input.Body.Timestamp, input.Body.SignedTimestamp) if err != nil { diff --git a/internal/api/handlers/v0/auth/http_internal_test.go b/internal/api/handlers/v0/auth/http_internal_test.go new file mode 100644 index 0000000..998c8c8 --- /dev/null +++ b/internal/api/handlers/v0/auth/http_internal_test.go @@ -0,0 +1,80 @@ +package auth + +import ( + "net" + "testing" +) + +func TestIsBlockedIP(t *testing.T) { + tests := []struct { + ip string + blocked bool + }{ + // Blocked โ€” loopback + {"127.0.0.1", true}, + {"::1", true}, + // Blocked โ€” RFC1918 / ULA (IsPrivate) + {"10.0.0.1", true}, + {"172.16.0.1", true}, + {"192.168.1.1", true}, + {"fc00::1", true}, + // Blocked โ€” link-local (includes cloud metadata 169.254.169.254) + {"169.254.169.254", true}, + {"fe80::1", true}, + // Blocked โ€” unspecified + {"0.0.0.0", true}, + {"::", true}, + // Blocked โ€” admin-scoped and broader multicast + {"239.0.0.1", true}, + {"ff00::1", true}, + // Blocked โ€” Carrier-Grade NAT (RFC 6598) + {"100.64.0.1", true}, + {"100.127.255.254", true}, + // Blocked โ€” IPv6 6to4 (RFC 3056 2002::/16); bits 16-47 are an + // arbitrary IPv4 address, so 2002:a9fe:a9fe:: tunnels to + // 169.254.169.254 and 2002:0a00:0001:: tunnels to 10.0.0.1. + {"2002:a9fe:a9fe::", true}, + {"2002:0a00:0001::", true}, + {"2002::1", true}, + // Blocked โ€” IPv6 NAT64 well-known prefix (RFC 6052 64:ff9b::/96); + // low 32 bits embed an IPv4 address. + {"64:ff9b::a9fe:a9fe", true}, + {"64:ff9b::a00:1", true}, + // Blocked โ€” IPv6 NAT64 local-use prefix (RFC 8215 64:ff9b:1::/48). + {"64:ff9b:1::1", true}, + {"64:ff9b:1:abcd::", true}, + // Blocked โ€” IPv6 deprecated site-local (RFC 3879 fec0::/10); + // still routed into internal networks by some stacks. + {"fec0::1", true}, + {"feff::1", true}, + // Blocked โ€” IPv4-mapped IPv6 (::ffff:0:0/96) inherits the + // classification of the wrapped IPv4 via To4() fast-path; covered + // here as an explicit regression guard. + {"::ffff:127.0.0.1", true}, + {"::ffff:10.0.0.1", true}, + {"::ffff:169.254.169.254", true}, + // Allowed โ€” public + {"1.1.1.1", false}, + {"8.8.8.8", false}, + {"2606:4700:4700::1111", false}, + {"2001:4860:4860::8888", false}, + // Allowed โ€” just outside the new IPv6 blocks + {"2001::1", false}, // outside 2002::/16 + {"2003::1", false}, // outside 2002::/16 on the other side + {"64:ff9c::1", false}, // outside 64:ff9b::/96 + // Allowed โ€” outside CGNAT range + {"100.63.255.255", false}, + {"100.128.0.1", false}, + } + for _, tc := range tests { + t.Run(tc.ip, func(t *testing.T) { + ip := net.ParseIP(tc.ip) + if ip == nil { + t.Fatalf("ParseIP(%q) returned nil", tc.ip) + } + if got := isBlockedIP(ip); got != tc.blocked { + t.Errorf("isBlockedIP(%q) = %v, want %v", tc.ip, got, tc.blocked) + } + }) + } +} diff --git a/internal/api/handlers/v0/auth/http_test.go b/internal/api/handlers/v0/auth/http_test.go index d3781ba..d0aa0ed 100644 --- a/internal/api/handlers/v0/auth/http_test.go +++ b/internal/api/handlers/v0/auth/http_test.go @@ -472,17 +472,6 @@ func TestHTTPAuthHandler_Permissions(t *testing.T) { "v1.api.example.com/*", // should be reversed }, }, - { - name: "single part domain", - domain: "localhost", - expectedPatterns: []string{ - "localhost/*", // exact pattern only (no reversal needed) - }, - unexpectedPatterns: []string{ - "localhost.*", // HTTP should not grant subdomain permissions - "*.localhost", // wrong wildcard position - }, - }, { name: "hyphenated domain", domain: "my-app.example-site.com", diff --git a/internal/api/handlers/v0/auth/main.go b/internal/api/handlers/v0/auth/main.go index 26a566b..62d9883 100644 --- a/internal/api/handlers/v0/auth/main.go +++ b/internal/api/handlers/v0/auth/main.go @@ -5,6 +5,9 @@ import ( "github.com/modelcontextprotocol/registry/internal/config" ) +// tagAuth is the OpenAPI tag grouping all token exchange operations. +const tagAuth = "auth" + // RegisterAuthEndpoints registers all authentication endpoints with a custom path prefix func RegisterAuthEndpoints(api huma.API, pathPrefix string, cfg *config.Config) { // Register GitHub access token authentication endpoint diff --git a/internal/api/handlers/v0/auth/none.go b/internal/api/handlers/v0/auth/none.go index 9f373c1..2549208 100644 --- a/internal/api/handlers/v0/auth/none.go +++ b/internal/api/handlers/v0/auth/none.go @@ -43,7 +43,7 @@ func RegisterNoneEndpoint(api huma.API, pathPrefix string, cfg *config.Config) { Path: pathPrefix + "/auth/none", Summary: "Get anonymous Registry JWT (Development/Testing Only)", Description: "Get a short-lived Registry JWT token for publishing and editing servers in the io.modelcontextprotocol.anonymous/* namespace. This endpoint is intended for local development and automated testing only.", - Tags: []string{"auth"}, + Tags: []string{tagAuth}, }, func(ctx context.Context, _ *struct{}) (*v0.Response[auth.TokenResponse], error) { response, err := handler.GetAnonymousToken(ctx) if err != nil { diff --git a/internal/api/handlers/v0/auth/oidc.go b/internal/api/handlers/v0/auth/oidc.go index 0cef699..1b63daf 100644 --- a/internal/api/handlers/v0/auth/oidc.go +++ b/internal/api/handlers/v0/auth/oidc.go @@ -159,7 +159,7 @@ func RegisterOIDCEndpoints(api huma.API, pathPrefix string, cfg *config.Config) Path: pathPrefix + "/auth/oidc", Summary: "Exchange OIDC ID token for Registry JWT", Description: "Exchange an OIDC ID token from any configured provider for a short-lived Registry JWT token", - Tags: []string{"auth"}, + Tags: []string{tagAuth}, }, func(ctx context.Context, input *OIDCTokenExchangeInput) (*v0.Response[auth.TokenResponse], error) { response, err := handler.ExchangeToken(ctx, input.Body.OIDCToken) if err != nil { @@ -224,7 +224,7 @@ func (h *OIDCHandler) validateExtraClaims(claims *OIDCClaims) error { return fmt.Errorf("claim validation failed: required claim %s not found", key) } - if actualValue != expectedValue { + if !claimMatches(actualValue, expectedValue) { return fmt.Errorf("claim validation failed: %s expected %v, got %v", key, expectedValue, actualValue) } } @@ -233,6 +233,38 @@ func (h *OIDCHandler) validateExtraClaims(claims *OIDCClaims) error { return nil } +// claimMatches reports whether a claim value satisfies the expected configuration. +// Both sides may be a scalar or a slice; for slice-typed claims (groups, roles, scp, +// aud, etc.) any single overlap is treated as a match, mirroring how OIDC consumers +// normally interpret list claims. +func claimMatches(actual, expected any) bool { + actualList := toAnySlice(actual) + expectedList := toAnySlice(expected) + for _, e := range expectedList { + for _, a := range actualList { + if a == e { + return true + } + } + } + return false +} + +func toAnySlice(v any) []any { + switch s := v.(type) { + case []any: + return s + case []string: + out := make([]any, len(s)) + for i, x := range s { + out[i] = x + } + return out + default: + return []any{v} + } +} + // buildPermissions builds permissions based on OIDC claims and configuration func (h *OIDCHandler) buildPermissions(_ *OIDCClaims) []auth.Permission { var permissions []auth.Permission diff --git a/internal/api/handlers/v0/auth/oidc_internal_test.go b/internal/api/handlers/v0/auth/oidc_internal_test.go new file mode 100644 index 0000000..cc3e472 --- /dev/null +++ b/internal/api/handlers/v0/auth/oidc_internal_test.go @@ -0,0 +1,41 @@ +package auth + +import "testing" + +func TestClaimMatches(t *testing.T) { + tests := []struct { + name string + actual any + expected any + want bool + }{ + {"scalar/scalar match", "x", "x", true}, + {"scalar/scalar mismatch", "x", "y", false}, + + {"scalar actual in array expected", "x", []any{"x", "y"}, true}, + {"scalar actual not in array expected", "z", []any{"x", "y"}, false}, + + {"array actual contains scalar expected", []any{"x", "y"}, "x", true}, + {"array actual missing scalar expected", []any{"y", "z"}, "x", false}, + + // Pre-#1238 array/array comparison panicked with "comparing uncomparable type []interface {}". + {"array/array overlap", []any{"a", "b"}, []any{"b", "c"}, true}, + {"array/array disjoint", []any{"a", "b"}, []any{"c", "d"}, false}, + + // Exercises the []string branch of toAnySlice (concrete typed slice, not []any). + {"[]string actual matches scalar", []string{"p", "q"}, "p", true}, + {"scalar matches []string expected", "p", []string{"p", "q"}, true}, + + {"non-string scalar match", 42, 42, true}, + {"bool scalar match", true, true, true}, + {"empty actual array", []any{}, "x", false}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + if got := claimMatches(tt.actual, tt.expected); got != tt.want { + t.Errorf("claimMatches(%v, %v) = %v, want %v", tt.actual, tt.expected, got, tt.want) + } + }) + } +} diff --git a/internal/api/handlers/v0/edit.go b/internal/api/handlers/v0/edit.go index 2862350..e552bbe 100644 --- a/internal/api/handlers/v0/edit.go +++ b/internal/api/handlers/v0/edit.go @@ -3,6 +3,7 @@ package v0 import ( "context" "errors" + "log" "net/http" "net/url" "strings" @@ -36,9 +37,9 @@ func RegisterEditEndpoints(api huma.API, pathPrefix string, registry service.Reg Path: pathPrefix + "/servers/{serverName}/versions/{version}", Summary: "Edit MCP server", Description: "Update the configuration of a specific version of an existing MCP server. Requires edit permission for the server. Use PATCH /servers/{serverName}/versions/{version}/status to update status metadata.", - Tags: []string{"servers"}, + Tags: []string{tagServers}, Security: []map[string][]string{ - {"bearer": {}}, + {securitySchemeBearer: {}}, }, }, func(ctx context.Context, input *EditServerInput) (*Response[apiv0.ServerResponse], error) { // Extract bearer token @@ -74,7 +75,8 @@ func RegisterEditEndpoints(api huma.API, pathPrefix string, registry service.Reg if errors.Is(err, database.ErrNotFound) { return nil, huma.Error404NotFound("Server not found") } - return nil, huma.Error500InternalServerError("Failed to get current server", err) + log.Printf("edit: get current server (%q/%q) failed: %v", serverName, version, err) + return nil, huma.Error500InternalServerError("Failed to get current server") } // Verify edit permissions for this server using the existing server name diff --git a/internal/api/handlers/v0/list_errors.go b/internal/api/handlers/v0/list_errors.go new file mode 100644 index 0000000..b83f04e --- /dev/null +++ b/internal/api/handlers/v0/list_errors.go @@ -0,0 +1,24 @@ +package v0 + +import ( + "context" + "errors" + "log" + + "github.com/danielgtaylor/huma/v2" +) + +// ListServersError maps ListServers failures; client disconnects must not log as 500s. +func ListServersError(ctx context.Context, err error) error { + if err == nil { + return nil + } + if errors.Is(err, context.Canceled) || errors.Is(ctx.Err(), context.Canceled) { + return huma.NewError(499, "Client closed request", err) + } + log.Printf("list servers failed: %v", err) + // Do not pass err here: huma serializes extra error args into the response + // body, which would leak internal (e.g. pgx) error detail to clients. Log it + // server-side only, like the sibling handlers in servers.go. + return huma.Error500InternalServerError("Failed to get registry list") +} diff --git a/internal/api/handlers/v0/list_errors_test.go b/internal/api/handlers/v0/list_errors_test.go new file mode 100644 index 0000000..7c50d38 --- /dev/null +++ b/internal/api/handlers/v0/list_errors_test.go @@ -0,0 +1,45 @@ +package v0_test + +import ( + "context" + "encoding/json" + "errors" + "testing" + + "github.com/danielgtaylor/huma/v2" + v0 "github.com/modelcontextprotocol/registry/internal/api/handlers/v0" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" +) + +func TestListServersError_clientCanceled(t *testing.T) { + ctx, cancel := context.WithCancel(context.Background()) + cancel() + + err := v0.ListServersError(ctx, errors.New("error iterating rows: context canceled")) + require.Error(t, err) + var se huma.StatusError + require.True(t, errors.As(err, &se)) + assert.Equal(t, 499, se.GetStatus()) +} + +func TestListServersError_realFailure(t *testing.T) { + err := v0.ListServersError(context.Background(), errors.New("database unavailable")) + require.Error(t, err) + var se huma.StatusError + require.True(t, errors.As(err, &se)) + assert.Equal(t, 500, se.GetStatus()) +} + +// The 500 response body must not echo the internal error back to the client, +// since it can carry DB/driver detail (CWE-209). +func TestListServersError_realFailureDoesNotLeakDetail(t *testing.T) { + const internal = "database unavailable: dsn=postgres://user:pw@internal-host/db" + err := v0.ListServersError(context.Background(), errors.New(internal)) + require.Error(t, err) + + body, marshalErr := json.Marshal(err) + require.NoError(t, marshalErr) + assert.NotContains(t, string(body), "database unavailable") + assert.NotContains(t, string(body), "internal-host") +} diff --git a/internal/api/handlers/v0/openapi.go b/internal/api/handlers/v0/openapi.go new file mode 100644 index 0000000..2dee9fd --- /dev/null +++ b/internal/api/handlers/v0/openapi.go @@ -0,0 +1,12 @@ +package v0 + +// Shared OpenAPI operation metadata, kept in one place so the generated spec +// groups operations consistently. +const ( + // tagServers groups the server CRUD and status operations. + tagServers = "servers" + + // securitySchemeBearer is the name of the Registry JWT bearer security + // scheme declared in the OpenAPI spec. + securitySchemeBearer = "bearer" +) diff --git a/internal/api/handlers/v0/publish.go b/internal/api/handlers/v0/publish.go index 5bd371e..bc01591 100644 --- a/internal/api/handlers/v0/publish.go +++ b/internal/api/handlers/v0/publish.go @@ -32,7 +32,7 @@ func RegisterPublishEndpoint(api huma.API, pathPrefix string, registry service.R Description: "Publish a new MCP server to the registry or update an existing one", Tags: []string{"publish"}, Security: []map[string][]string{ - {"bearer": {}}, + {securitySchemeBearer: {}}, }, }, func(ctx context.Context, input *PublishServerInput) (*Response[apiv0.ServerResponse], error) { // Extract bearer token diff --git a/internal/api/handlers/v0/publish_test.go b/internal/api/handlers/v0/publish_test.go index 94502be..6b5c68c 100644 --- a/internal/api/handlers/v0/publish_test.go +++ b/internal/api/handlers/v0/publish_test.go @@ -168,7 +168,7 @@ func TestPublishEndpoint(t *testing.T) { expectedError: "You do not have permission to publish this server", }, { - name: "registry service error", + name: "duplicate version includes submitted server identity", requestBody: apiv0.ServerJSON{ Schema: model.CurrentSchemaURL, Name: "example/test-server", @@ -202,7 +202,7 @@ func TestPublishEndpoint(t *testing.T) { _, _ = registry.CreateServer(context.Background(), &existingServer) }, expectedStatus: http.StatusBadRequest, - expectedError: "invalid version: cannot publish duplicate version", + expectedError: "invalid version: cannot publish duplicate version: example/test-server@1.0.0 already exists", }, { name: "package validation success - MCPB package", diff --git a/internal/api/handlers/v0/servers.go b/internal/api/handlers/v0/servers.go index d187fc0..7b14452 100644 --- a/internal/api/handlers/v0/servers.go +++ b/internal/api/handlers/v0/servers.go @@ -3,6 +3,7 @@ package v0 import ( "context" "errors" + "log" "net/http" "net/url" "reflect" @@ -89,7 +90,7 @@ func RegisterServersEndpoints(api huma.API, pathPrefix string, registry service. Path: pathPrefix + "/servers", Summary: "List MCP servers", Description: "Get a paginated list of MCP servers from the registry", - Tags: []string{"servers"}, + Tags: []string{tagServers}, }, func(ctx context.Context, input *ListServersInput) (*Response[apiv0.ServerListResponse], error) { // Build filter from input parameters filter := &database.ServerFilter{} @@ -131,7 +132,7 @@ func RegisterServersEndpoints(api huma.API, pathPrefix string, registry service. // Get paginated results with filtering servers, nextCursor, err := registry.ListServers(ctx, filter, input.Cursor, input.Limit) if err != nil { - return nil, huma.Error500InternalServerError("Failed to get registry list", err) + return nil, ListServersError(ctx, err) } // Convert []*ServerResponse to []ServerResponse @@ -158,7 +159,7 @@ func RegisterServersEndpoints(api huma.API, pathPrefix string, registry service. Path: pathPrefix + "/servers/{serverName}/versions/{version}", Summary: "Get specific MCP server version", Description: "Get detailed information about a specific version of an MCP server. Use the special version 'latest' to get the latest version.", - Tags: []string{"servers"}, + Tags: []string{tagServers}, }, func(ctx context.Context, input *ServerVersionDetailInput) (*Response[apiv0.ServerResponse], error) { // URL-decode the server name serverName, err := url.PathUnescape(input.ServerName) @@ -184,7 +185,8 @@ func RegisterServersEndpoints(api huma.API, pathPrefix string, registry service. if err.Error() == errRecordNotFound || errors.Is(err, database.ErrNotFound) { return nil, huma.Error404NotFound("Server not found") } - return nil, huma.Error500InternalServerError("Failed to get server details", err) + log.Printf("get server details (%q/%q) failed: %v", serverName, version, err) + return nil, huma.Error500InternalServerError("Failed to get server details") } return &Response[apiv0.ServerResponse]{ @@ -199,7 +201,7 @@ func RegisterServersEndpoints(api huma.API, pathPrefix string, registry service. Path: pathPrefix + "/servers/{serverName}/versions", Summary: "Get all versions of an MCP server", Description: "Get all available versions for a specific MCP server", - Tags: []string{"servers"}, + Tags: []string{tagServers}, }, func(ctx context.Context, input *ServerVersionsInput) (*Response[apiv0.ServerListResponse], error) { // URL-decode the server name serverName, err := url.PathUnescape(input.ServerName) @@ -213,7 +215,8 @@ func RegisterServersEndpoints(api huma.API, pathPrefix string, registry service. if err.Error() == errRecordNotFound || errors.Is(err, database.ErrNotFound) { return nil, huma.Error404NotFound("Server not found") } - return nil, huma.Error500InternalServerError("Failed to get server versions", err) + log.Printf("get server versions (%q) failed: %v", serverName, err) + return nil, huma.Error500InternalServerError("Failed to get server versions") } // Convert []*ServerResponse to []ServerResponse diff --git a/internal/api/handlers/v0/status.go b/internal/api/handlers/v0/status.go index 627e884..f3cca85 100644 --- a/internal/api/handlers/v0/status.go +++ b/internal/api/handlers/v0/status.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "log" "net/http" "net/url" "strings" @@ -82,9 +83,9 @@ func RegisterStatusEndpoints(api huma.API, pathPrefix string, registry service.R Path: pathPrefix + "/servers/{serverName}/versions/{version}/status", Summary: "Update MCP server status", Description: "Update the status metadata of a specific version of an MCP server. Requires publish or edit permission for the server. This endpoint allows changing status and status message without requiring the full server configuration.", - Tags: []string{"servers"}, + Tags: []string{tagServers}, Security: []map[string][]string{ - {"bearer": {}}, + {securitySchemeBearer: {}}, }, }, func(ctx context.Context, input *UpdateServerStatusInput) (*Response[apiv0.ServerResponse], error) { // Extract bearer token @@ -122,7 +123,8 @@ func RegisterStatusEndpoints(api huma.API, pathPrefix string, registry service.R if errors.Is(err, database.ErrNotFound) { return nil, huma.Error404NotFound("Server version not found") } - return nil, huma.Error500InternalServerError("Failed to get server", err) + log.Printf("status: get server (%q/%q) failed: %v", serverName, version, err) + return nil, huma.Error500InternalServerError("Failed to get server") } // Verify publish or edit permissions for this server @@ -196,9 +198,9 @@ func RegisterAllVersionsStatusEndpoints(api huma.API, pathPrefix string, registr Path: pathPrefix + "/servers/{serverName}/status", Summary: "Update status for all versions of an MCP server", Description: "Update the status metadata of all versions of an MCP server in a single transaction. Requires publish or edit permission for the server. Either all versions are updated or none on failure.", - Tags: []string{"servers"}, + Tags: []string{tagServers}, Security: []map[string][]string{ - {"bearer": {}}, + {securitySchemeBearer: {}}, }, }, func(ctx context.Context, input *UpdateAllVersionsStatusInput) (*Response[UpdateAllVersionsStatusResponse], error) { // Extract bearer token @@ -228,7 +230,8 @@ func RegisterAllVersionsStatusEndpoints(api huma.API, pathPrefix string, registr if errors.Is(err, database.ErrNotFound) { return nil, huma.Error404NotFound("Server not found") } - return nil, huma.Error500InternalServerError("Failed to get server", err) + log.Printf("status: get server (%q) failed: %v", serverName, err) + return nil, huma.Error500InternalServerError("Failed to get server") } // Verify publish or edit permissions for this server @@ -243,7 +246,8 @@ func RegisterAllVersionsStatusEndpoints(api huma.API, pathPrefix string, registr // Fetch all versions to validate the bulk status transition allVersions, err := registry.GetAllVersionsByServerName(ctx, serverName, true) if err != nil { - return nil, huma.Error500InternalServerError("Failed to get server versions", err) + log.Printf("status: get all versions (%q) failed: %v", serverName, err) + return nil, huma.Error500InternalServerError("Failed to get server versions") } // Validate bulk status transition - reject if no changes would occur diff --git a/internal/api/handlers/v0/ui_index.html b/internal/api/handlers/v0/ui_index.html index 38bac7f..dc437ff 100644 --- a/internal/api/handlers/v0/ui_index.html +++ b/internal/api/handlers/v0/ui_index.html @@ -423,13 +423,13 @@ ${server.repository?.url ? ` ` : ''} ${server.websiteUrl ? ` ` : ''}
@@ -491,12 +491,26 @@ }); // Utility functions + // Safe for element-text contexts only: encodes `&`, `<`, `>`. Does NOT + // encode `"` or `'`, so it is unsafe inside attribute values โ€” use + // escapeAttr there. function escapeHtml(text) { const div = document.createElement('div'); div.textContent = text; return div.innerHTML; } + // Safe for HTML attribute values per OWASP attribute-encoding rule. + function escapeAttr(text) { + if (text == null) return ''; + return String(text) + .replace(/&/g, '&') + .replace(//g, '>') + .replace(/"/g, '"') + .replace(/'/g, '''); + } + function formatDate(dateStr) { if (!dateStr) return '-'; const date = new Date(dateStr); diff --git a/internal/api/router/router.go b/internal/api/router/router.go index d951e60..7d64258 100644 --- a/internal/api/router/router.go +++ b/internal/api/router/router.go @@ -2,7 +2,9 @@ package router import ( + "context" "encoding/json" + "errors" "fmt" "net/http" "strings" @@ -19,6 +21,12 @@ import ( "github.com/modelcontextprotocol/registry/internal/telemetry" ) +// statusClientClosed mirrors NGINX's non-standard 499 โ€” used for requests +// where the client disconnected before we finished. Distinguishing these from +// real server errors keeps the availability metric meaningful under bursts of +// scraper traffic that time out and reconnect. +const statusClientClosed = 499 + // Middleware configuration options type middlewareConfig struct { skipPaths map[string]bool @@ -67,6 +75,22 @@ func MetricTelemetryMiddleware(metrics *telemetry.Metrics, options ...Middleware duration := time.Since(start).Seconds() statusCode := ctx.Status() + // If the client disconnected before the handler finished, the handler + // likely converted the resulting context.Canceled into a huma 5xx and + // tried to write a response to a closed socket. NGINX records that + // case as a 499 (client closed). Without this remap we count it as a + // server error: a single ServiceNow-style burst that times out a + // few thousand list-servers requests inflates http_errors_total even + // though no client ever saw a 5xx, and the availability alert fires + // on what is effectively just slow responses. + // + // Only context.Canceled is remapped โ€” context.DeadlineExceeded would + // indicate a server-side timeout we set ourselves and should still + // count as a server error if/when we add per-request deadlines. + if reqErr := ctx.Context().Err(); reqErr != nil && errors.Is(reqErr, context.Canceled) { + statusCode = statusClientClosed + } + // Combine common and custom attributes attrs := []attribute.KeyValue{ attribute.String("method", method), @@ -77,7 +101,9 @@ func MetricTelemetryMiddleware(metrics *telemetry.Metrics, options ...Middleware // Record metrics metrics.Requests.Add(ctx.Context(), 1, metric.WithAttributes(attrs...)) - if statusCode >= 400 { + // Skip the error counter for client-closed requests so the availability + // metric reflects server-visible errors only. + if statusCode >= 400 && statusCode != statusClientClosed { metrics.ErrorCount.Add(ctx.Context(), 1, metric.WithAttributes(attrs...)) } @@ -97,6 +123,7 @@ func WithSkipPaths(paths ...string) MiddlewareOption { // handle404 returns a helpful 404 error with suggestions for common mistakes func handle404(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "application/problem+json") + w.Header().Set("X-Content-Type-Options", "nosniff") w.WriteHeader(http.StatusNotFound) path := r.URL.Path @@ -187,8 +214,28 @@ func NewHumaAPI(cfg *config.Config, registry service.RegistryService, mux *http. // Add UI and 404 handler for all other routes mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { if r.URL.Path == "/" { - // Serve UI at root + // Serve UI at root. The page renders publisher-controlled content + // (server names, descriptions, repository URLs) โ€” server-side + // validation plus a JS escape function are the primary XSS + // defences; these headers are defence-in-depth in case any of + // those slip. w.Header().Set("Content-Type", "text/html; charset=utf-8") + w.Header().Set("X-Content-Type-Options", "nosniff") + w.Header().Set("X-Frame-Options", "DENY") + // connect-src is unrestricted because the UI exposes a base-URL + // selector (prod / staging / custom) that issues cross-origin + // XHRs to whichever target the operator picks. Constraining + // connect-src would silently break that affordance. The other + // directives still meaningfully limit the page's attack surface. + w.Header().Set("Content-Security-Policy", + "default-src 'self'; "+ + "script-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com; "+ + "style-src 'self' 'unsafe-inline' https://cdn.tailwindcss.com; "+ + "img-src 'self' data:; "+ + "connect-src *; "+ + "frame-ancestors 'none'; "+ + "base-uri 'self'; "+ + "form-action 'self'") _, err := w.Write([]byte(v0.GetUIHTML())) if err != nil { http.Error(w, "Failed to write response", http.StatusInternalServerError) diff --git a/internal/api/router/router_test.go b/internal/api/router/router_test.go new file mode 100644 index 0000000..f61b1de --- /dev/null +++ b/internal/api/router/router_test.go @@ -0,0 +1,119 @@ +package router_test + +import ( + "context" + "errors" + "net/http" + "net/http/httptest" + "strings" + "testing" + + "github.com/danielgtaylor/huma/v2" + "github.com/danielgtaylor/huma/v2/adapters/humago" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" + + "github.com/modelcontextprotocol/registry/internal/api/router" + "github.com/modelcontextprotocol/registry/internal/telemetry" +) + +// TestMetricMiddleware_ClientCancelledNotCountedAsError verifies that a request +// the client gave up on (request-context Canceled) is recorded as 499 in +// http_requests_total and is NOT incremented in http_errors_total โ€” even when +// the handler returned huma.Error500InternalServerError because its DB call +// surfaced context.Canceled. +// +// Regression test for the case where a ServiceNow-style scraper burst +// generated thousands of internal 500s for cancelled requests, tripping the +// "Availability dropped below 95%" alert despite zero 5xx reaching clients. +func TestMetricMiddleware_ClientCancelledNotCountedAsError(t *testing.T) { + shutdown, metrics, err := telemetry.InitMetrics("test") + require.NoError(t, err) + defer func() { _ = shutdown(context.Background()) }() + + mux := http.NewServeMux() + api := humago.New(mux, huma.DefaultConfig("Test API", "1.0.0")) + api.UseMiddleware(router.MetricTelemetryMiddleware(metrics)) + + // Handler that simulates: DB returns context.Canceled because the client + // disconnected, handler converts to huma 500. + huma.Register(api, huma.Operation{ + OperationID: "cancelled-list", + Method: http.MethodGet, + Path: "/v0/servers", + }, func(_ context.Context, _ *struct{}) (*struct{}, error) { + return nil, huma.Error500InternalServerError("Failed to get registry list", + errors.New("error iterating rows: context canceled")) + }) + + mux.Handle("/metrics", metrics.PrometheusHandler()) + + cancelledCtx, cancel := context.WithCancel(context.Background()) + cancel() + + req := httptest.NewRequest(http.MethodGet, "/v0/servers", nil).WithContext(cancelledCtx) + rec := httptest.NewRecorder() + mux.ServeHTTP(rec, req) + + scrapeReq := httptest.NewRequest(http.MethodGet, "/metrics", nil) + scrapeRec := httptest.NewRecorder() + mux.ServeHTTP(scrapeRec, scrapeReq) + assert.Equal(t, http.StatusOK, scrapeRec.Code) + + body := scrapeRec.Body.String() + + // The request is recorded โ€” but as 499, not 500. + assert.True(t, + containsMetric(body, `mcp_registry_http_requests_total`, `status_code="499"`, `path="/v0/servers"`), + "expected requests_total to record status_code=499 for the cancelled request; got:\n%s", + filterMetricLines(body, "mcp_registry_http_requests_total"), + ) + assert.False(t, + containsMetric(body, `mcp_registry_http_requests_total`, `status_code="500"`, `path="/v0/servers"`), + "did not expect requests_total to record status_code=500 for a client-cancelled request; got:\n%s", + filterMetricLines(body, "mcp_registry_http_requests_total"), + ) + + // The error counter is NOT bumped for 499s โ€” that is the point of this fix. + assert.False(t, + containsMetric(body, `mcp_registry_http_errors_total`, `status_code="499"`), + "errors_total must not be incremented for client-cancelled requests; got:\n%s", + filterMetricLines(body, "mcp_registry_http_errors_total"), + ) + assert.False(t, + containsMetric(body, `mcp_registry_http_errors_total`, `status_code="500"`, `path="/v0/servers"`), + "errors_total must not record a 500 for a request the client already gave up on; got:\n%s", + filterMetricLines(body, "mcp_registry_http_errors_total"), + ) +} + +// containsMetric returns true iff some line in body starts with `metric{...}` +// and that label set contains every requested label fragment. +func containsMetric(body, metric string, labels ...string) bool { + for _, line := range strings.Split(body, "\n") { + if !strings.HasPrefix(line, metric+"{") { + continue + } + ok := true + for _, l := range labels { + if !strings.Contains(line, l) { + ok = false + break + } + } + if ok { + return true + } + } + return false +} + +func filterMetricLines(body, metric string) string { + var lines []string + for _, line := range strings.Split(body, "\n") { + if strings.HasPrefix(line, metric) { + lines = append(lines, line) + } + } + return strings.Join(lines, "\n") +} diff --git a/internal/api/server.go b/internal/api/server.go index e795a1e..c8ce97c 100644 --- a/internal/api/server.go +++ b/internal/api/server.go @@ -5,6 +5,8 @@ import ( "encoding/json" "log" "net/http" + "net/url" + "path" "strings" "time" @@ -71,9 +73,18 @@ func TrailingSlashMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { // Only redirect if the path is not "/" and ends with a "/" if r.URL.Path != "/" && strings.HasSuffix(r.URL.Path, "/") { - // Create a copy of the URL and remove the trailing slash - newURL := *r.URL - newURL.Path = strings.TrimSuffix(r.URL.Path, "/") + // Build the target from the path and query alone, dropping any + // scheme/host the client may have supplied in an absolute-form + // request URI ("GET http://evil.com/foo/ HTTP/1.1"), which would + // otherwise be echoed back as an off-site redirect. + // + // path.Clean both removes the trailing slash and collapses any + // leading "//" to "/", which prevents an open-redirect via a + // protocol-relative path like "//evil.com/" (GHSA-v8vw-gw5j-w7m6). + newURL := url.URL{ + Path: path.Clean(r.URL.Path), + RawQuery: r.URL.RawQuery, + } // Use 308 Permanent Redirect to preserve the request method http.Redirect(w, r, newURL.String(), http.StatusPermanentRedirect) @@ -106,6 +117,7 @@ func NewServer(cfg *config.Config, registryService service.RegistryService, metr http.MethodGet, http.MethodPost, http.MethodPut, + http.MethodPatch, http.MethodDelete, http.MethodOptions, }, @@ -127,12 +139,29 @@ func NewServer(cfg *config.Config, registryService service.RegistryService, metr Addr: cfg.ServerAddress, Handler: handler, ReadHeaderTimeout: 10 * time.Second, + ReadTimeout: 30 * time.Second, + // WriteTimeout intentionally not set: the publish path runs + // outbound package validators sequentially (npm/pypi/nuget up to + // 10s each, OCI up to 30s), so any tight cap could cut off a + // legitimate multi-package publish mid-response โ€” surfacing as a + // truncated read to the publisher even when the DB commit + // succeeded. Slow-response-read DoS is bounded upstream by + // NGINX ingress timeouts and the per-IP rate limit. Revisit once + // validators are parallelised or per-request package counts are + // bounded. + IdleTimeout: 120 * time.Second, }, } return server } +// Handler returns the fully wrapped HTTP handler (middleware stack plus routes). +// Exposed so tests can exercise the middleware, e.g. CORS, without binding a port. +func (s *Server) Handler() http.Handler { + return s.server.Handler +} + // Start begins listening for incoming HTTP requests func (s *Server) Start() error { log.Printf("HTTP server starting on %s", s.config.ServerAddress) diff --git a/internal/api/server_test.go b/internal/api/server_test.go index dc313b0..9094c36 100644 --- a/internal/api/server_test.go +++ b/internal/api/server_test.go @@ -232,6 +232,22 @@ func TestTrailingSlashMiddleware(t *testing.T) { expectedLocation: "/v0/servers?limit=10", expectRedirect: true, }, + { + // Regression test for GHSA-v8vw-gw5j-w7m6: a protocol-relative + // path like "//evil.com/" must not redirect off-host. + name: "protocol-relative path should not redirect off-host", + path: "//evil.com/", + expectedStatus: http.StatusPermanentRedirect, + expectedLocation: "/evil.com", + expectRedirect: true, + }, + { + name: "path with multiple leading slashes should be collapsed", + path: "///evil.com/foo/", + expectedStatus: http.StatusPermanentRedirect, + expectedLocation: "/evil.com/foo", + expectRedirect: true, + }, } for _, tt := range tests { diff --git a/internal/auth/jwt.go b/internal/auth/jwt.go index b1935e5..88c8f76 100644 --- a/internal/auth/jwt.go +++ b/internal/auth/jwt.go @@ -81,10 +81,17 @@ func (j *JWTManager) GenerateTokenResponse(_ context.Context, claims JWTClaims) } } - // Check permissions against denylist, provided they are not an admin + // Check permissions against denylist, provided they are not an admin. + // Probe two synthetic resources per blocked namespace so that both the + // slash-suffix patterns (e.g. com.evil/*) and the dot-wildcard patterns + // (e.g. com.evil.mailer.* โ€” granted to a subdomain claimant) are + // detected. Probing only "/test" misses the dot-wildcard form + // because the prefix match against "com.evil.mailer." does not start + // with "com.evil/test". if !hasGlobalPermissions { for _, blockedNamespace := range BlockedNamespaces { - if j.HasPermission(blockedNamespace+"/test", PermissionActionPublish, claims.Permissions) { + if j.HasPermission(blockedNamespace+"/test", PermissionActionPublish, claims.Permissions) || + j.HasPermission(blockedNamespace+".test/x", PermissionActionPublish, claims.Permissions) { return nil, fmt.Errorf("your namespace is blocked. raise an issue at https://github.com/modelcontextprotocol/registry/ if you think this is a mistake") } } diff --git a/internal/config/config.go b/internal/config/config.go index 60e9a06..a15a67a 100644 --- a/internal/config/config.go +++ b/internal/config/config.go @@ -17,6 +17,8 @@ type Config struct { EnableAnonymousAuth bool `env:"ENABLE_ANONYMOUS_AUTH" envDefault:"false"` EnableRegistryValidation bool `env:"ENABLE_REGISTRY_VALIDATION" envDefault:"true"` + GitHubOIDCAudience string `env:"GITHUB_OIDC_AUDIENCE" envDefault:""` + // OIDC Configuration OIDCEnabled bool `env:"OIDC_ENABLED" envDefault:"false"` OIDCIssuer string `env:"OIDC_ISSUER" envDefault:""` diff --git a/internal/database/database.go b/internal/database/database.go index c9acf07..b4a797f 100644 --- a/internal/database/database.go +++ b/internal/database/database.go @@ -57,6 +57,10 @@ type Database interface { CheckVersionExists(ctx context.Context, tx pgx.Tx, serverName, version string) (bool, error) // UnmarkAsLatest marks the current latest version of a server as no longer latest UnmarkAsLatest(ctx context.Context, tx pgx.Tx, serverName string) error + // SetLatestVersion sets is_latest=true on the given version and false on all other + // versions of the same server. Passing an empty version clears is_latest for all rows. + // Callers must hold the per-server publish lock to avoid races. + SetLatestVersion(ctx context.Context, tx pgx.Tx, serverName, version string) error // AcquirePublishLock acquires an exclusive advisory lock for publishing a server // This prevents race conditions when multiple versions are published concurrently AcquirePublishLock(ctx context.Context, tx pgx.Tx, serverName string) error diff --git a/internal/database/migrations/014_heal_is_latest.sql b/internal/database/migrations/014_heal_is_latest.sql new file mode 100644 index 0000000..30e860c --- /dev/null +++ b/internal/database/migrations/014_heal_is_latest.sql @@ -0,0 +1,51 @@ +-- Heal servers whose is_latest flag is on a deleted version (or missing entirely) +-- by promoting the highest-semver non-deleted version. Falls back to published_at +-- for non-semver versions and as a tiebreaker for prereleases. +-- See https://github.com/modelcontextprotocol/registry/issues/1081. +-- +-- The migration framework wraps each migration in its own transaction, so no explicit +-- BEGIN/COMMIT here. + +-- Pre-compute the version to promote per affected server. A temp table is used +-- (rather than CTEs) because the two UPDATEs that follow run as separate statements: +-- the unique partial index idx_unique_latest_per_server is non-deferrable and Postgres +-- checks it row-by-row inside a single UPDATE, so the clear and the set must be split. +CREATE TEMP TABLE _heal_picks ON COMMIT DROP AS +WITH broken AS ( + -- Servers where no non-deleted version is flagged is_latest, but at least one + -- non-deleted version exists. Catches "is_latest is on a deleted row" and the + -- defensive case where no row has is_latest at all. + SELECT server_name + FROM servers + GROUP BY server_name + HAVING COUNT(*) FILTER (WHERE is_latest AND status <> 'deleted') = 0 + AND COUNT(*) FILTER (WHERE status <> 'deleted') > 0 +), +parsed AS ( + SELECT s.server_name, s.version, s.published_at, + (regexp_match(s.version, '^(\d+)\.(\d+)\.(\d+)'))[1]::int AS major, + (regexp_match(s.version, '^(\d+)\.(\d+)\.(\d+)'))[2]::int AS minor, + (regexp_match(s.version, '^(\d+)\.(\d+)\.(\d+)'))[3]::int AS patch + FROM servers s + JOIN broken b USING (server_name) + WHERE s.status <> 'deleted' +) +SELECT DISTINCT ON (server_name) server_name, version +FROM parsed +ORDER BY server_name, + major DESC NULLS LAST, + minor DESC NULLS LAST, + patch DESC NULLS LAST, + published_at DESC; + +-- Clear stale is_latest=true on rows of affected servers (typically the deleted row). +UPDATE servers s +SET is_latest = false +WHERE s.server_name IN (SELECT server_name FROM _heal_picks) + AND s.is_latest; + +-- Promote the chosen version. +UPDATE servers s +SET is_latest = true +FROM _heal_picks p +WHERE s.server_name = p.server_name AND s.version = p.version; diff --git a/internal/database/postgres.go b/internal/database/postgres.go index a86e44b..b0b2d98 100644 --- a/internal/database/postgres.go +++ b/internal/database/postgres.go @@ -45,9 +45,13 @@ func NewPostgreSQL(ctx context.Context, connectionURI string) (*PostgreSQL, erro return nil, fmt.Errorf("failed to parse PostgreSQL config: %w", err) } - // Configure pool for stability-focused defaults - config.MaxConns = 30 // Handle good concurrent load - config.MinConns = 5 // Keep connections warm for fast response + // Configure pool for stability-focused defaults. + // MaxConns was 30 per pod (60 total across 2 replicas) which saturated under + // the 2026-04-28 scraper bursts (15 req/s on /v0/servers caused queue blowup + // even though individual queries were fast). 60 per pod gives 120 total, + // leaving 80 of PG max_connections=200 for autovacuum/admin/headroom. + config.MaxConns = 60 // Handle scraper-burst concurrent load + config.MinConns = 10 // Keep connections warm for fast response config.MaxConnIdleTime = 30 * time.Minute // Keep connections available for bursts config.MaxConnLifetime = 2 * time.Hour // Refresh connections regularly for stability @@ -96,7 +100,15 @@ func buildFilterConditions(filter *ServerFilter, argIndex int) ([]string, []any, argIndex++ } if filter.RemoteURL != nil { - conditions = append(conditions, fmt.Sprintf("EXISTS (SELECT 1 FROM jsonb_array_elements(value->'remotes') AS remote WHERE remote->>'url' = $%d)", argIndex)) + // Use a JSONB containment predicate so the planner can use the GIN index + // idx_servers_json_remotes on (value -> 'remotes'). The previously-used + // EXISTS / jsonb_array_elements / ->> form is logically equivalent but + // the planner can't translate the per-row array unfolding into a GIN + // search โ€” it falls back to scanning every row. validateNoDuplicateRemoteURLs + // in the publish path ran this filter and was measured at ~10s on prod's + // 21K-row table on 2026-04-28; the containment form is GIN-indexable and + // completes in low single-digit ms. + conditions = append(conditions, fmt.Sprintf("value -> 'remotes' @> jsonb_build_array(jsonb_build_object('url', $%d::text))", argIndex)) args = append(args, *filter.RemoteURL) argIndex++ } @@ -106,8 +118,13 @@ func buildFilterConditions(filter *ServerFilter, argIndex int) ([]string, []any, argIndex++ } if filter.SubstringName != nil { - conditions = append(conditions, fmt.Sprintf("server_name ILIKE $%d", argIndex)) - args = append(args, "%"+*filter.SubstringName+"%") + // Escape LIKE metacharacters so that user input cannot expand into + // wildcard matches (e.g. `?search=_` matching every single-char name, + // `?search=%` matching everything). Order matters: backslashes must be + // escaped first so subsequent escape backslashes are not double-escaped. + escaped := strings.NewReplacer(`\`, `\\`, `%`, `\%`, `_`, `\_`).Replace(*filter.SubstringName) + conditions = append(conditions, fmt.Sprintf("server_name ILIKE $%d ESCAPE '\\'", argIndex)) + args = append(args, "%"+escaped+"%") argIndex++ } if filter.Version != nil { @@ -127,7 +144,16 @@ func buildFilterConditions(filter *ServerFilter, argIndex int) ([]string, []any, return conditions, args, argIndex } -// addCursorCondition adds pagination cursor condition to WHERE clause +// addCursorCondition adds pagination cursor condition to WHERE clause. +// +// The compound cursor uses a row-constructor comparison so PostgreSQL can seek +// directly into the (server_name, version) B-tree index. The OR-decomposed form +// `server_name > X OR (server_name = X AND version > Y)` is logically equivalent +// but PostgreSQL's planner cannot use it for an index seek โ€” it scans the index +// from the start and filters everything before the cursor, making cost grow +// linearly with cursor depth (a 20K-row table at a deep cursor took ~760ms in +// prod). The row-constructor form `(server_name, version) > (X, Y)` is special- +// cased and stays constant-time regardless of cursor depth. func addCursorCondition(cursor string, argIndex int) (string, []any, int) { if cursor == "" { return "", nil, argIndex @@ -138,9 +164,8 @@ func addCursorCondition(cursor string, argIndex int) (string, []any, int) { if len(parts) == 2 { cursorServerName := parts[0] cursorVersion := parts[1] - // Use compound condition: (server_name > cursor_name) OR (server_name = cursor_name AND version > cursor_version) - condition := fmt.Sprintf("(server_name > $%d OR (server_name = $%d AND version > $%d))", argIndex, argIndex+1, argIndex+2) - return condition, []any{cursorServerName, cursorServerName, cursorVersion}, argIndex + 3 + condition := fmt.Sprintf("(server_name, version) > ($%d, $%d)", argIndex, argIndex+1) + return condition, []any{cursorServerName, cursorVersion}, argIndex + 2 } // Fallback for malformed cursor - treat as server name only for backwards compatibility @@ -173,7 +198,6 @@ func (db *PostgreSQL) ListServers( whereConditions = append(whereConditions, cursorCondition) args = append(args, cursorArgs...) } - _ = argIndex // Silence unused variable warning // Build the WHERE clause whereClause := "" @@ -877,6 +901,40 @@ func (db *PostgreSQL) UnmarkAsLatest(ctx context.Context, tx pgx.Tx, serverName return nil } +// SetLatestVersion sets is_latest=true on the given version and false on all other versions +// of the same server. Passing an empty version clears is_latest for all rows. +// +// The clear and set are issued as separate statements because the unique partial index +// idx_unique_latest_per_server is non-deferrable and Postgres checks it row-by-row within +// a single UPDATE, which would trip when flipping one row's flag off and another's on. +func (db *PostgreSQL) SetLatestVersion(ctx context.Context, tx pgx.Tx, serverName, version string) error { + if ctx.Err() != nil { + return ctx.Err() + } + + executor := db.getExecutor(tx) + + if _, err := executor.Exec(ctx, + `UPDATE servers SET is_latest = false WHERE server_name = $1 AND is_latest = true AND version <> $2`, + serverName, version, + ); err != nil { + return fmt.Errorf("failed to clear previous latest version: %w", err) + } + + if version == "" { + return nil + } + + if _, err := executor.Exec(ctx, + `UPDATE servers SET is_latest = true WHERE server_name = $1 AND version = $2 AND is_latest = false`, + serverName, version, + ); err != nil { + return fmt.Errorf("failed to set latest version: %w", err) + } + + return nil +} + // Close closes the database connection func (db *PostgreSQL) Close() error { db.pool.Close() diff --git a/internal/database/postgres_test.go b/internal/database/postgres_test.go index 9b6a5da..6784ae5 100644 --- a/internal/database/postgres_test.go +++ b/internal/database/postgres_test.go @@ -3,6 +3,7 @@ package database_test import ( "context" "fmt" + "os" "testing" "time" @@ -1149,6 +1150,104 @@ func TestPostgreSQL_PerformanceScenarios(t *testing.T) { // Should have retrieved all servers including the ones we just created assert.GreaterOrEqual(t, len(allResults), serverCount) }) + + t.Run("compound cursor across versions of same server", func(t *testing.T) { + // Insert multiple versions of two servers so cursor pagination has to + // correctly seek across the (server_name, version) boundary. This is the + // case that the row-constructor cursor predicate `(server_name, version) > ($1, $2)` + // has to handle โ€” the OR-decomposed form had the same semantics but a + // linear-scan plan; this test pins the semantic behaviour so a future + // rewrite can't silently break it. + serverA := "com.example/cursor-test-a" + serverB := "com.example/cursor-test-b" + versionsA := []string{"1.0.0", "2.0.0", "3.0.0"} + versionsB := []string{"1.0.0", "2.0.0"} + + // First mark the latest version of each as latest=true; older ones false + // so the pkey + uniqueness constraints are satisfied. + mkServer := func(name, version string, isLatest bool) { + _, err := db.CreateServer(ctx, nil, &apiv0.ServerJSON{ + Name: name, Description: "compound cursor test", Version: version, + }, &apiv0.RegistryExtensions{ + Status: model.StatusActive, + StatusChangedAt: timeNow, PublishedAt: timeNow, UpdatedAt: timeNow, + IsLatest: isLatest, + }) + require.NoError(t, err) + } + for i, v := range versionsA { + mkServer(serverA, v, i == len(versionsA)-1) + } + for i, v := range versionsB { + mkServer(serverB, v, i == len(versionsB)-1) + } + + // Filter to just the two servers we just created so unrelated rows in the + // shared test DB don't bleed in. + filterTo := func(rs []*apiv0.ServerResponse) []*apiv0.ServerResponse { + out := make([]*apiv0.ServerResponse, 0, len(rs)) + for _, r := range rs { + if r.Server.Name == serverA || r.Server.Name == serverB { + out = append(out, r) + } + } + return out + } + + // Cursor at (serverA, "1.0.0") must skip 1.0.0 and return 2.0.0, 3.0.0, + // then both versions of serverB. Specifically tests the compound predicate: + // without it, the OR form would still skip 1.0.0 correctly but the version + // boundary of (serverA, "3.0.0") โ†’ (serverB, "1.0.0") is what depends on + // the second-column comparison. + results, _, err := db.ListServers(ctx, nil, nil, serverA+":1.0.0", 100) + require.NoError(t, err) + got := filterTo(results) + require.Len(t, got, 4, "expected 4 rows after cursor at A:1.0.0") + assert.Equal(t, serverA, got[0].Server.Name) + assert.Equal(t, "2.0.0", got[0].Server.Version) + assert.Equal(t, serverA, got[1].Server.Name) + assert.Equal(t, "3.0.0", got[1].Server.Version) + assert.Equal(t, serverB, got[2].Server.Name) + assert.Equal(t, "1.0.0", got[2].Server.Version) + assert.Equal(t, serverB, got[3].Server.Name) + assert.Equal(t, "2.0.0", got[3].Server.Version) + + // Cursor at the *last* version of serverA must cross the server boundary + // and return serverB rows only. + results, _, err = db.ListServers(ctx, nil, nil, serverA+":3.0.0", 100) + require.NoError(t, err) + got = filterTo(results) + require.Len(t, got, 2, "expected 2 rows after cursor at A:3.0.0") + assert.Equal(t, serverB, got[0].Server.Name) + assert.Equal(t, "1.0.0", got[0].Server.Version) + assert.Equal(t, serverB, got[1].Server.Name) + assert.Equal(t, "2.0.0", got[1].Server.Version) + + // Page-by-page traversal with size=2 must produce the same global ordering + // (A 1.0.0, A 2.0.0, A 3.0.0, B 1.0.0, B 2.0.0). + var paged []*apiv0.ServerResponse + cursor := "" + for { + rs, next, err := db.ListServers(ctx, nil, + &database.ServerFilter{SubstringName: stringPtr("cursor-test-")}, + cursor, 2) + require.NoError(t, err) + paged = append(paged, rs...) + if next == "" || len(rs) < 2 { + break + } + cursor = next + } + require.Len(t, paged, 5) + want := []struct{ name, version string }{ + {serverA, "1.0.0"}, {serverA, "2.0.0"}, {serverA, "3.0.0"}, + {serverB, "1.0.0"}, {serverB, "2.0.0"}, + } + for i, w := range want { + assert.Equal(t, w.name, paged[i].Server.Name, "row %d name", i) + assert.Equal(t, w.version, paged[i].Server.Version, "row %d version", i) + } + }) } func TestPostgreSQL_NewStatusFields(t *testing.T) { @@ -1734,6 +1833,152 @@ func TestPostgreSQL_IncludeDeletedFilter(t *testing.T) { }) } +// TestMigration014_HealIsLatest exercises migrations/014_heal_is_latest.sql against +// synthetic broken states by re-running its SQL after seeding rows directly. The migration +// itself ran via the template DB; since it's idempotent (only matches servers with no +// non-deleted is_latest row), re-running it here only acts on the rows we just broke. +func TestMigration014_HealIsLatest(t *testing.T) { + db := database.NewTestDB(t) + ctx := context.Background() + + migrationSQL, err := os.ReadFile("migrations/014_heal_is_latest.sql") + require.NoError(t, err) + + createVersion := func(t *testing.T, name, version string, publishedAt time.Time, status model.Status, isLatest bool) { + t.Helper() + serverJSON := &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: name, + Description: "test", + Version: version, + } + officialMeta := &apiv0.RegistryExtensions{ + Status: status, + StatusChangedAt: publishedAt, + PublishedAt: publishedAt, + UpdatedAt: publishedAt, + IsLatest: isLatest, + } + _, err := db.CreateServer(ctx, nil, serverJSON, officialMeta) + require.NoError(t, err) + } + + runHeal := func(t *testing.T) { + t.Helper() + err := db.InTransaction(ctx, func(ctx context.Context, tx pgx.Tx) error { + _, err := tx.Exec(ctx, string(migrationSQL)) + return err + }) + require.NoError(t, err) + } + + versionState := func(t *testing.T, name, version string) (model.Status, bool) { + t.Helper() + v, err := db.GetServerByNameAndVersion(ctx, nil, name, version, true) + require.NoError(t, err) + return v.Meta.Official.Status, v.Meta.Official.IsLatest + } + + t.Run("kubernetes-mcp-server scenario picks highest semver", func(t *testing.T) { + name := "io.test/k8s-scenario" + base := time.Now().Add(-10 * time.Hour) + // 1.0.0 published first, then 0.0.50, 0.0.51, 0.0.59, 0.0.60, 0.0.61. + // 1.0.0 was the original latest and got soft-deleted, leaving is_latest stranded. + createVersion(t, name, "1.0.0", base, model.StatusDeleted, true) + createVersion(t, name, "0.0.50", base.Add(1*time.Hour), model.StatusActive, false) + createVersion(t, name, "0.0.51", base.Add(2*time.Hour), model.StatusActive, false) + createVersion(t, name, "0.0.59", base.Add(3*time.Hour), model.StatusActive, false) + createVersion(t, name, "0.0.60", base.Add(4*time.Hour), model.StatusActive, false) + createVersion(t, name, "0.0.61", base.Add(5*time.Hour), model.StatusActive, false) + + runHeal(t) + + _, isLatest := versionState(t, name, "1.0.0") + assert.False(t, isLatest, "deleted 1.0.0 should no longer be latest") + _, isLatest = versionState(t, name, "0.0.61") + assert.True(t, isLatest, "highest active version should become latest") + for _, v := range []string{"0.0.50", "0.0.51", "0.0.59", "0.0.60"} { + _, isLatest := versionState(t, name, v) + assert.False(t, isLatest, "version %s should not be latest", v) + } + }) + + t.Run("backport scenario picks highest semver not most recent", func(t *testing.T) { + // Published 2.0.0 (deleted), then 1.0.1 hotfix, then 1.0.0 (older patch backported later). + // Most-recent-published would pick 1.0.0; semver-aware picks 1.0.1. + name := "io.test/backport-scenario" + base := time.Now().Add(-10 * time.Hour) + createVersion(t, name, "2.0.0", base, model.StatusDeleted, true) + createVersion(t, name, "1.0.1", base.Add(1*time.Hour), model.StatusActive, false) + createVersion(t, name, "1.0.0", base.Add(2*time.Hour), model.StatusActive, false) + + runHeal(t) + + _, isLatest := versionState(t, name, "1.0.1") + assert.True(t, isLatest, "1.0.1 should win on semver despite 1.0.0 being published more recently") + _, isLatest = versionState(t, name, "1.0.0") + assert.False(t, isLatest) + }) + + t.Run("no is_latest row at all gets healed", func(t *testing.T) { + // Defensive case: nothing flagged latest, but active versions exist. + name := "io.test/no-latest-flag" + base := time.Now().Add(-10 * time.Hour) + createVersion(t, name, "1.0.0", base, model.StatusActive, false) + createVersion(t, name, "1.1.0", base.Add(1*time.Hour), model.StatusActive, false) + + runHeal(t) + + _, isLatest := versionState(t, name, "1.1.0") + assert.True(t, isLatest) + _, isLatest = versionState(t, name, "1.0.0") + assert.False(t, isLatest) + }) + + t.Run("all-deleted server is left untouched", func(t *testing.T) { + // No non-deleted version โ†’ nothing to promote, leave existing flags alone so the + // server remains addressable via includeDeleted=true admin lookups. + name := "io.test/all-deleted" + base := time.Now().Add(-10 * time.Hour) + createVersion(t, name, "1.0.0", base, model.StatusDeleted, true) + createVersion(t, name, "2.0.0", base.Add(1*time.Hour), model.StatusDeleted, false) + + runHeal(t) + + _, isLatest := versionState(t, name, "1.0.0") + assert.True(t, isLatest, "all-deleted server should keep its existing latest flag") + _, isLatest = versionState(t, name, "2.0.0") + assert.False(t, isLatest) + }) + + t.Run("healthy server is left untouched", func(t *testing.T) { + name := "io.test/healthy" + base := time.Now().Add(-10 * time.Hour) + createVersion(t, name, "1.0.0", base, model.StatusActive, false) + createVersion(t, name, "2.0.0", base.Add(1*time.Hour), model.StatusActive, true) + + runHeal(t) + + _, isLatest := versionState(t, name, "2.0.0") + assert.True(t, isLatest) + _, isLatest = versionState(t, name, "1.0.0") + assert.False(t, isLatest) + }) + + t.Run("non-semver versions fall back to published_at", func(t *testing.T) { + name := "io.test/non-semver" + base := time.Now().Add(-10 * time.Hour) + createVersion(t, name, "rolling", base, model.StatusDeleted, true) + createVersion(t, name, "build-100", base.Add(1*time.Hour), model.StatusActive, false) + createVersion(t, name, "build-200", base.Add(2*time.Hour), model.StatusActive, false) + + runHeal(t) + + _, isLatest := versionState(t, name, "build-200") + assert.True(t, isLatest, "without semver, most recently published wins") + }) +} + // Helper functions for creating pointers to basic types func stringPtr(s string) *string { return &s diff --git a/internal/importer/importer_test.go b/internal/importer/importer_test.go index db0cc2a..ed5ed05 100644 --- a/internal/importer/importer_test.go +++ b/internal/importer/importer_test.go @@ -20,8 +20,7 @@ import ( ) func TestImportService_LocalFile(t *testing.T) { - // Create a temporary seed file - tempFile := filepath.Join(os.TempDir(), "test_import_seed.json") + tempFile := filepath.Join(t.TempDir(), "test_import_seed.json") seedData := []*apiv0.ServerJSON{ { Schema: model.CurrentSchemaURL, @@ -41,7 +40,6 @@ func TestImportService_LocalFile(t *testing.T) { err = os.WriteFile(tempFile, jsonData, 0600) require.NoError(t, err) - defer os.Remove(tempFile) // Create registry service testDB := database.NewTestDB(t) @@ -187,6 +185,14 @@ func TestImportService_ErrorHandling(t *testing.T) { registryService := service.NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false}) importerService := importer.NewService(registryService) + errorDir := t.TempDir() + missingFile := filepath.Join(errorDir, "non-existent-file.json") + invalidFile := filepath.Join(errorDir, "invalid.json") + + invalidJSON := []byte("{invalid json}") + err := os.WriteFile(invalidFile, invalidJSON, 0600) + require.NoError(t, err) + tests := []struct { name string path string @@ -195,13 +201,13 @@ func TestImportService_ErrorHandling(t *testing.T) { }{ { name: "non-existent local file", - path: "/tmp/non-existent-file.json", + path: missingFile, expectError: true, errorMsg: "failed to read seed data", }, { name: "invalid JSON file", - path: "/tmp/invalid.json", + path: invalidFile, expectError: true, errorMsg: "failed to read seed data", }, @@ -213,22 +219,6 @@ func TestImportService_ErrorHandling(t *testing.T) { }, } - // Create invalid JSON file for testing - invalidJSON := []byte("{invalid json}") - tempFile, err := os.CreateTemp("", "invalid-*.json") - require.NoError(t, err) - defer os.Remove(tempFile.Name()) - err = os.WriteFile(tempFile.Name(), invalidJSON, 0600) - require.NoError(t, err) - - // Update test case to use temp file - for i := range tests { - if tests[i].path == "/tmp/invalid.json" { - tests[i].path = tempFile.Name() - break - } - } - for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { err := importerService.ImportFromPath(context.Background(), tt.path) diff --git a/internal/service/registry_service.go b/internal/service/registry_service.go index 05c4f16..4bf6e19 100644 --- a/internal/service/registry_service.go +++ b/internal/service/registry_service.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "log/slog" "time" "github.com/jackc/pgx/v5" @@ -17,6 +18,18 @@ import ( const maxServerVersionsPerServer = 10000 +// Publish phase names emitted on the structured "publish complete"/"publish failed" +// log from createServerInTransaction. Constants because version_checks is reported +// from multiple branches. +const ( + phaseValidate = "validate" + phaseAcquireLock = "acquire_lock" + phaseValidateRemoteURLs = "validate_remote_urls" + phaseVersionChecks = "version_checks" + phaseUnmarkLatest = "unmark_latest" + phaseDBCreate = "db_create" +) + // registryServiceImpl implements the RegistryService interface using our Database type registryServiceImpl struct { db database.Database @@ -85,47 +98,106 @@ func (s *registryServiceImpl) CreateServer(ctx context.Context, req *apiv0.Serve }) } -// createServerInTransaction contains the actual CreateServer logic within a transaction -func (s *registryServiceImpl) createServerInTransaction(ctx context.Context, tx pgx.Tx, req *apiv0.ServerJSON) (*apiv0.ServerResponse, error) { - // Validate the request - if err := validators.ValidatePublishRequest(ctx, *req, s.cfg); err != nil { +// createServerInTransaction contains the actual CreateServer logic within a transaction. +// +// Phases are individually timed and emitted as a single structured log event per call. +// During the 2026-04-27 incident the validate-only timing (the previous shape) hid +// pool-exhaustion stalls in acquire_lock / version_checks / db_create โ€” we saw 50s+ +// total publish times even though validate_ms was a few hundred ms. With every phase +// reported the next slow publish tells us which step to blame. +func (s *registryServiceImpl) createServerInTransaction(ctx context.Context, tx pgx.Tx, req *apiv0.ServerJSON) (resp *apiv0.ServerResponse, err error) { + start := time.Now() + serverJSON := *req + var ( + validateMs, lockMs, remotesMs, versionChecksMs, unmarkMs, createMs int64 + failedPhase string + ) + + defer func() { + attrs := []any{ + "server_name", serverJSON.Name, + "version", serverJSON.Version, + "total_ms", time.Since(start).Milliseconds(), + "validate_ms", validateMs, + "lock_ms", lockMs, + "remotes_ms", remotesMs, + "version_checks_ms", versionChecksMs, + "unmark_ms", unmarkMs, + "create_ms", createMs, + } + if err != nil { + attrs = append(attrs, "failed_phase", failedPhase, "error", err.Error()) + slog.WarnContext(ctx, "publish failed", attrs...) + } else { + slog.InfoContext(ctx, "publish complete", attrs...) + } + }() + + // runPhase times fn into *ms and, on error, stashes the phase name + error + // onto the closed-over failedPhase / err. Returns true on success so callers + // can `if !runPhase(...) { return nil, err }`. + runPhase := func(name string, ms *int64, fn func() error) bool { + t := time.Now() + e := fn() + *ms = time.Since(t).Milliseconds() + if e != nil { + failedPhase = name + err = e + return false + } + return true + } + + // Validate the request โ€” registry-ownership checks fan out to npm/PyPI/OCI with + // 10s per-host timeouts. Was historically the most likely slow phase; now any + // phase can be the slow one when the connection pool is starved. + if !runPhase(phaseValidate, &validateMs, func() error { + return validators.ValidatePublishRequest(ctx, serverJSON, s.cfg) + }) { return nil, err } publishTime := time.Now() - serverJSON := *req // Acquire advisory lock to prevent concurrent publishes of the same server - if err := s.db.AcquirePublishLock(ctx, tx, serverJSON.Name); err != nil { + if !runPhase(phaseAcquireLock, &lockMs, func() error { + return s.db.AcquirePublishLock(ctx, tx, serverJSON.Name) + }) { return nil, err } // Check for duplicate remote URLs - if err := s.validateNoDuplicateRemoteURLs(ctx, tx, serverJSON); err != nil { + if !runPhase(phaseValidateRemoteURLs, &remotesMs, func() error { + return s.validateNoDuplicateRemoteURLs(ctx, tx, serverJSON) + }) { return nil, err } - // Check we haven't exceeded the maximum versions allowed for a server - versionCount, err := s.db.CountServerVersions(ctx, tx, serverJSON.Name) - if err != nil && !errors.Is(err, database.ErrNotFound) { - return nil, err - } - if versionCount >= maxServerVersionsPerServer { - return nil, database.ErrMaxServersReached - } - - // Check this isn't a duplicate version - versionExists, err := s.db.CheckVersionExists(ctx, tx, serverJSON.Name, serverJSON.Version) - if err != nil { - return nil, err - } - if versionExists { - return nil, database.ErrInvalidVersion - } - - // Get current latest version to determine if new version should be latest - currentLatest, err := s.db.GetCurrentLatestVersion(ctx, tx, serverJSON.Name) - if err != nil && !errors.Is(err, database.ErrNotFound) { + // Version checks: count, exists, current-latest (small DB lookups, but on a + // starved pool any of them stalls until a connection is free). Bundled under + // one phase since they share a logical step. + var currentLatest *apiv0.ServerResponse + if !runPhase(phaseVersionChecks, &versionChecksMs, func() error { + versionCount, e := s.db.CountServerVersions(ctx, tx, serverJSON.Name) + if e != nil && !errors.Is(e, database.ErrNotFound) { + return e + } + if versionCount >= maxServerVersionsPerServer { + return database.ErrMaxServersReached + } + versionExists, e := s.db.CheckVersionExists(ctx, tx, serverJSON.Name, serverJSON.Version) + if e != nil { + return e + } + if versionExists { + return fmt.Errorf("%w: %s@%s already exists", database.ErrInvalidVersion, serverJSON.Name, serverJSON.Version) + } + currentLatest, e = s.db.GetCurrentLatestVersion(ctx, tx, serverJSON.Name) + if e != nil && !errors.Is(e, database.ErrNotFound) { + return e + } + return nil + }) { return nil, err } @@ -146,7 +218,9 @@ func (s *registryServiceImpl) createServerInTransaction(ctx context.Context, tx // Unmark old latest version if needed if isNewLatest && currentLatest != nil { - if err := s.db.UnmarkAsLatest(ctx, tx, serverJSON.Name); err != nil { + if !runPhase(phaseUnmarkLatest, &unmarkMs, func() error { + return s.db.UnmarkAsLatest(ctx, tx, serverJSON.Name) + }) { return nil, err } } @@ -161,7 +235,67 @@ func (s *registryServiceImpl) createServerInTransaction(ctx context.Context, tx } // Insert new server version - return s.db.CreateServer(ctx, tx, &serverJSON, officialMeta) + if !runPhase(phaseDBCreate, &createMs, func() error { + var e error + resp, e = s.db.CreateServer(ctx, tx, &serverJSON, officialMeta) + return e + }) { + return nil, err + } + return resp, nil +} + +// recalculateLatest picks the highest non-deleted version of the given server and flags it +// as latest, clearing is_latest on every other row. If every version is deleted, the highest +// deleted version keeps the flag so admin lookups (GetServerByName with includeDeleted=true) +// still find the server. Caller must hold the per-server publish lock. +func (s *registryServiceImpl) recalculateLatest(ctx context.Context, tx pgx.Tx, serverName string) error { + versions, err := s.db.GetAllVersionsByServerName(ctx, tx, serverName, true) + if err != nil { + if errors.Is(err, database.ErrNotFound) { + return s.db.SetLatestVersion(ctx, tx, serverName, "") + } + return fmt.Errorf("failed to load versions for latest recalculation: %w", err) + } + + winner := pickLatestVersion(versions, false) + if winner == nil { + // No non-deleted versions โ€” fall back to highest deleted so the server is still + // addressable via includeDeleted=true lookups. + winner = pickLatestVersion(versions, true) + } + + winnerVersion := "" + if winner != nil { + winnerVersion = winner.Server.Version + } + return s.db.SetLatestVersion(ctx, tx, serverName, winnerVersion) +} + +// pickLatestVersion returns the highest version from the given slice. If allowDeleted is +// false, deleted versions are skipped. +func pickLatestVersion(versions []*apiv0.ServerResponse, allowDeleted bool) *apiv0.ServerResponse { + var winner *apiv0.ServerResponse + for _, v := range versions { + if !allowDeleted && v.Meta.Official != nil && v.Meta.Official.Status == model.StatusDeleted { + continue + } + if winner == nil { + winner = v + continue + } + var winnerPublishedAt, candidatePublishedAt time.Time + if winner.Meta.Official != nil { + winnerPublishedAt = winner.Meta.Official.PublishedAt + } + if v.Meta.Official != nil { + candidatePublishedAt = v.Meta.Official.PublishedAt + } + if CompareVersions(v.Server.Version, winner.Server.Version, candidatePublishedAt, winnerPublishedAt) > 0 { + winner = v + } + } + return winner } // validateNoDuplicateRemoteURLs checks that no other server is using the same remote URLs @@ -237,11 +371,14 @@ func (s *registryServiceImpl) updateServerInTransaction(ctx context.Context, tx // Handle status change if provided if statusChange != nil { - updatedWithStatus, err := s.db.SetServerStatus(ctx, tx, serverName, version, statusChange.NewStatus, statusChange.StatusMessage) - if err != nil { + if _, err := s.db.SetServerStatus(ctx, tx, serverName, version, statusChange.NewStatus, statusChange.StatusMessage); err != nil { return nil, err } - return updatedWithStatus, nil + if err := s.recalculateLatest(ctx, tx, serverName); err != nil { + return nil, err + } + // Re-read to pick up the possibly updated is_latest flag. + return s.db.GetServerByNameAndVersion(ctx, tx, serverName, version, true) } return updatedServerResponse, nil @@ -279,7 +416,14 @@ func (s *registryServiceImpl) updateServerStatusInTransaction(ctx context.Contex } // Update only the status metadata - return s.db.SetServerStatus(ctx, tx, serverName, version, statusChange.NewStatus, statusChange.StatusMessage) + if _, err := s.db.SetServerStatus(ctx, tx, serverName, version, statusChange.NewStatus, statusChange.StatusMessage); err != nil { + return nil, err + } + if err := s.recalculateLatest(ctx, tx, serverName); err != nil { + return nil, err + } + // Re-read to pick up the possibly updated is_latest flag. + return s.db.GetServerByNameAndVersion(ctx, tx, serverName, version, true) } // UpdateAllVersionsStatus updates the status metadata of all versions of a server in a single transaction @@ -319,5 +463,12 @@ func (s *registryServiceImpl) updateAllVersionsStatusInTransaction(ctx context.C } // Update all versions' status in a single database call - return s.db.SetAllVersionsStatus(ctx, tx, serverName, statusChange.NewStatus, statusChange.StatusMessage) + if _, err := s.db.SetAllVersionsStatus(ctx, tx, serverName, statusChange.NewStatus, statusChange.StatusMessage); err != nil { + return nil, err + } + if err := s.recalculateLatest(ctx, tx, serverName); err != nil { + return nil, err + } + // Re-read to pick up the possibly updated is_latest flags. + return s.db.GetAllVersionsByServerName(ctx, tx, serverName, true) } diff --git a/internal/service/registry_service_test.go b/internal/service/registry_service_test.go index 63b6521..05ec847 100644 --- a/internal/service/registry_service_test.go +++ b/internal/service/registry_service_test.go @@ -982,6 +982,160 @@ func TestUpdateServerStatus_NoConflictWhenRestoringWithUniqueURLs(t *testing.T) assert.Equal(t, model.StatusActive, result.Meta.Official.Status) } +func TestRecalculateLatest_PromotesNextHighestWhenLatestSoftDeleted(t *testing.T) { + ctx := context.Background() + testDB := database.NewTestDB(t) + service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false}) + + serverName := "com.example/delete-latest-server" + + // Publish 1.0.0, then 0.0.59. 1.0.0 is latest. + _, err := service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v1", Version: "1.0.0", + }) + require.NoError(t, err) + _, err = service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v0.0.59", Version: "0.0.59", + }) + require.NoError(t, err) + + // Soft-delete 1.0.0. + _, err = service.UpdateServerStatus(ctx, serverName, "1.0.0", &StatusChangeRequest{ + NewStatus: model.StatusDeleted, + }) + require.NoError(t, err) + + // 0.0.59 should now be latest. + latest, err := service.GetServerByName(ctx, serverName, false) + require.NoError(t, err) + assert.Equal(t, "0.0.59", latest.Server.Version) + assert.True(t, latest.Meta.Official.IsLatest) +} + +func TestRecalculateLatest_ReproFromIssue1081(t *testing.T) { + ctx := context.Background() + testDB := database.NewTestDB(t) + service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false}) + + serverName := "com.example/issue-1081-repro" + + // 1. Publish 1.0.0. + _, err := service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v1", Version: "1.0.0", + }) + require.NoError(t, err) + + // 2. Publish 0.0.59 โ€” expected not latest at this point. + _, err = service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v0.0.59", Version: "0.0.59", + }) + require.NoError(t, err) + + // 3. Delete 1.0.0. + _, err = service.UpdateServerStatus(ctx, serverName, "1.0.0", &StatusChangeRequest{ + NewStatus: model.StatusDeleted, + }) + require.NoError(t, err) + + // 4. /versions/latest must not 404. + latest, err := service.GetServerByName(ctx, serverName, false) + require.NoError(t, err) + assert.Equal(t, "0.0.59", latest.Server.Version) + + // 5. Publish 0.0.60 โ€” should become latest because compare now excludes deleted 1.0.0. + _, err = service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v0.0.60", Version: "0.0.60", + }) + require.NoError(t, err) + + latest, err = service.GetServerByName(ctx, serverName, false) + require.NoError(t, err) + assert.Equal(t, "0.0.60", latest.Server.Version) + assert.True(t, latest.Meta.Official.IsLatest) + + // Only one row should be flagged latest. + all, err := service.GetAllVersionsByServerName(ctx, serverName, true) + require.NoError(t, err) + latestCount := 0 + for _, v := range all { + if v.Meta.Official.IsLatest { + latestCount++ + } + } + assert.Equal(t, 1, latestCount) +} + +func TestRecalculateLatest_AllDeletedKeepsHighestAsLatest(t *testing.T) { + ctx := context.Background() + testDB := database.NewTestDB(t) + service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false}) + + serverName := "com.example/all-deleted-server" + + _, err := service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v1", Version: "1.0.0", + }) + require.NoError(t, err) + _, err = service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v2", Version: "2.0.0", + }) + require.NoError(t, err) + + // Delete all versions in one call. + _, err = service.UpdateAllVersionsStatus(ctx, serverName, &StatusChangeRequest{ + NewStatus: model.StatusDeleted, + }) + require.NoError(t, err) + + // Public lookup (includeDeleted=false) must now 404. + _, err = service.GetServerByName(ctx, serverName, false) + require.ErrorIs(t, err, database.ErrNotFound) + + // Admin lookup (includeDeleted=true) must still find the server: the highest deleted + // version keeps is_latest=true so the server remains addressable for restore flows. + latest, err := service.GetServerByName(ctx, serverName, true) + require.NoError(t, err) + assert.Equal(t, "2.0.0", latest.Server.Version) + assert.True(t, latest.Meta.Official.IsLatest) +} + +func TestRecalculateLatest_RestoringHigherVersionPromotesIt(t *testing.T) { + ctx := context.Background() + testDB := database.NewTestDB(t) + service := NewRegistryService(testDB, &config.Config{EnableRegistryValidation: false}) + + serverName := "com.example/restore-server" + + // Publish 2.0.0 and 1.0.0 โ€” 2.0.0 is latest. + _, err := service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v2", Version: "2.0.0", + }) + require.NoError(t, err) + _, err = service.CreateServer(ctx, &apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, Name: serverName, Description: "v1", Version: "1.0.0", + }) + require.NoError(t, err) + + // Delete 2.0.0 โ€” 1.0.0 gets promoted. + _, err = service.UpdateServerStatus(ctx, serverName, "2.0.0", &StatusChangeRequest{ + NewStatus: model.StatusDeleted, + }) + require.NoError(t, err) + latest, err := service.GetServerByName(ctx, serverName, false) + require.NoError(t, err) + require.Equal(t, "1.0.0", latest.Server.Version) + + // Restore 2.0.0 โ€” it should reclaim latest. + _, err = service.UpdateServerStatus(ctx, serverName, "2.0.0", &StatusChangeRequest{ + NewStatus: model.StatusActive, + }) + require.NoError(t, err) + latest, err = service.GetServerByName(ctx, serverName, false) + require.NoError(t, err) + assert.Equal(t, "2.0.0", latest.Server.Version) + assert.True(t, latest.Meta.Official.IsLatest) +} + // Helper functions func stringPtr(s string) *string { return &s diff --git a/internal/validators/package.go b/internal/validators/package.go index 7104f73..b458244 100644 --- a/internal/validators/package.go +++ b/internal/validators/package.go @@ -23,6 +23,8 @@ func ValidatePackage(ctx context.Context, pkg model.Package, serverName string) return registries.ValidateOCI(ctx, pkg, serverName) case model.RegistryTypeMCPB: return registries.ValidateMCPB(ctx, pkg, serverName) + case model.RegistryTypeCargo: + return registries.ValidateCargo(ctx, pkg, serverName) default: return fmt.Errorf("unsupported registry type: %s", pkg.RegistryType) } diff --git a/internal/validators/registries/cargo.go b/internal/validators/registries/cargo.go new file mode 100644 index 0000000..5aa72b1 --- /dev/null +++ b/internal/validators/registries/cargo.go @@ -0,0 +1,341 @@ +package registries + +import ( + "context" + "encoding/json" + "errors" + "fmt" + "io" + "net/http" + "net/url" + "time" + + "github.com/modelcontextprotocol/registry/pkg/model" +) + +var ( + ErrMissingIdentifierForCargo = errors.New("package identifier is required for Cargo packages") + ErrMissingVersionForCargo = errors.New("package version is required for Cargo packages") +) + +// cargoUserAgent identifies the validator to crates.io. crates.io's crawler +// policy expects a non-generic User-Agent with a contact URL; a bare UA may be +// rate-limited or blocked. (Distinct from the package-level userAgent constant +// used by the NuGet validator, which has no contact URL.) +const cargoUserAgent = "MCP-Registry-Validator/1.0 (https://registry.modelcontextprotocol.io)" + +// cargoStaticHost is the CDN host crates.io serves rendered READMEs from. +const cargoStaticHost = "static.crates.io" + +// maxCargoReadmeBytes caps how much of a rendered README we buffer, so a hostile +// or oversized response cannot exhaust validator memory. +const maxCargoReadmeBytes = 5 << 20 // 5 MiB + +// CargoReadmeMetaResponse is the structure returned by the crates.io readme metadata endpoint. +// +// With `Accept: application/json`, crates.io's /api/v1/crates/{name}/{version}/readme +// endpoint returns 200 OK with a JSON body containing a `url` field that points to the +// rendered README on the static CDN. (Without the Accept header, or via HEAD, the same +// endpoint emits a 302 redirect to the CDN URL โ€” the validator uses the JSON path so +// that crates.io controls where the README lives.) Validators must follow the pointer +// to retrieve the actual README content. +type CargoReadmeMetaResponse struct { + URL string `json:"url"` +} + +// ValidateCargo validates that a Cargo (crates.io) package contains the correct MCP server name. +// +// Verification mechanism: the `mcp-name: ` token is searched for in the package's +// rendered README. This mirrors the PyPI validator's README-token approach (see ValidatePyPI), +// requiring no Cargo.toml parsing on the registry side. Crate authors add a single line +// `mcp-name: io.github.OWNER/REPO` to their README before publishing. +// +// Two-call retrieval pattern: +// 1. GET https://crates.io/api/v1/crates/{name}/{version}/readme +// โ†’ 200 OK with JSON: {"url": "https://static.crates.io/readmes/.../...html"} +// 2. GET +// โ†’ 200 OK with rendered README HTML, or 403 if the crate/version is missing +// +// The two-call pattern stays on the documented crates.io API surface rather than relying +// on the CDN URL layout being stable. +func ValidateCargo(ctx context.Context, pkg model.Package, serverName string) error { + // Set default registry base URL if empty + if pkg.RegistryBaseURL == "" { + pkg.RegistryBaseURL = model.RegistryURLCrates + } + + if pkg.Identifier == "" { + return ErrMissingIdentifierForCargo + } + + if pkg.Version == "" { + return ErrMissingVersionForCargo + } + + // Validate that MCPB-specific fields are not present + if pkg.FileSHA256 != "" { + return fmt.Errorf("cargo packages must not have 'fileSha256' field - this is only for MCPB packages") + } + + // Validate that the registry base URL matches crates.io exactly + if pkg.RegistryBaseURL != model.RegistryURLCrates { + return fmt.Errorf("registry type and base URL do not match: '%s' is not valid for registry type '%s'. Expected: %s", + pkg.RegistryBaseURL, model.RegistryTypeCargo, model.RegistryURLCrates) + } + + return validateCargoREADME(ctx, pkg, serverName) +} + +// cargoAllowedHosts returns the set of hosts the validator is permitted to talk +// to for a given base URL. For the real crates.io base this is crates.io (the API) +// plus static.crates.io (the rendered-README CDN). For any other base โ€” only the +// httptest-driven tests, since the public ValidateCargo pins the base to +// crates.io โ€” it is the base host itself, so mock servers keep working. +// +// This is the allowlist enforced both on the README pointer (step 2 URL) and on +// every redirect hop, so a metadata response or redirect cannot steer the +// validator at an internal or attacker-chosen host (SSRF). +func cargoAllowedHosts(baseURL string) map[string]struct{} { + hosts := map[string]struct{}{} + if u, err := url.Parse(baseURL); err == nil && u.Hostname() != "" { + hosts[u.Hostname()] = struct{}{} + } + if baseURL == model.RegistryURLCrates { + hosts[cargoStaticHost] = struct{}{} + } + return hosts +} + +// cargoURLAllowed reports whether u is a URL the validator may fetch for the +// given base. The host must be in allowedHosts; additionally, for the real +// crates.io base, the scheme must be https and the port must be the default โ€” +// so a metadata response or redirect cannot downgrade to http or steer the +// validator at a non-standard port on an otherwise-trusted host. For test bases +// (httptest servers) only the host is checked, so mocks keep working. +func cargoURLAllowed(u *url.URL, baseURL string, allowedHosts map[string]struct{}) bool { + if _, ok := allowedHosts[u.Hostname()]; !ok { + return false + } + if baseURL == model.RegistryURLCrates { + if u.Scheme != "https" { + return false + } + if p := u.Port(); p != "" && p != "443" { + return false + } + } + return true +} + +// newCargoHTTPClient builds the client used for all crates.io calls. The +// CheckRedirect policy pins every redirect hop via cargoURLAllowed, so even +// though the initial URL is checked, an upstream 3xx cannot redirect the +// validator to an unexpected host, scheme, or port. +func newCargoHTTPClient(baseURL string, allowedHosts map[string]struct{}) *http.Client { + return &http.Client{ + Timeout: 10 * time.Second, + CheckRedirect: func(req *http.Request, via []*http.Request) error { + if !cargoURLAllowed(req.URL, baseURL, allowedHosts) { + return fmt.Errorf("refusing redirect to unexpected URL %q", req.URL.Redacted()) + } + if len(via) >= 10 { + return errors.New("stopped after 10 redirects") + } + return nil + }, + } +} + +// cargoVersionState is the outcome of probing the crate-version metadata +// endpoint, used to disambiguate a 403 from the README CDN. +type cargoVersionState int + +const ( + // cargoVersionUnknown: the probe returned an unexpected status we can't classify. + cargoVersionUnknown cargoVersionState = iota + // cargoVersionExists: the crate version exists (200). + cargoVersionExists + // cargoVersionMissing: the crate version does not exist (404). + cargoVersionMissing + // cargoVersionTransient: the probe failed for a retryable reason (network + // error, 429, or 5xx) โ€” existence is undetermined and the caller should not + // report "not found". + cargoVersionTransient +) + +// probeCargoVersion checks whether a specific crate version exists on crates.io. +// static.crates.io (S3) returns 403 both for a genuinely-missing crate/version +// AND for a crate that exists but has no rendered README, so a 403 from the CDN +// alone cannot tell a publisher which it is; this probe disambiguates, while +// distinguishing a transient failure from a definitive missing/exists answer. +func probeCargoVersion(ctx context.Context, client *http.Client, baseURL, identifier, version string) cargoVersionState { + versionURL := fmt.Sprintf("%s/api/v1/crates/%s/%s", + baseURL, url.PathEscape(identifier), url.PathEscape(version)) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, versionURL, nil) + if err != nil { + return cargoVersionUnknown + } + req.Header.Set("User-Agent", cargoUserAgent) + req.Header.Set("Accept", "application/json") + + resp, err := client.Do(req) + if err != nil { + return cargoVersionTransient + } + defer resp.Body.Close() + + switch { + case resp.StatusCode == http.StatusOK: + return cargoVersionExists + case resp.StatusCode == http.StatusNotFound: + return cargoVersionMissing + case resp.StatusCode == http.StatusTooManyRequests, resp.StatusCode >= 500 && resp.StatusCode < 600: + return cargoVersionTransient + default: + return cargoVersionUnknown + } +} + +// cargoMetadataStatusError maps a non-200 status from the metadata endpoint to a +// caller-actionable error, distinguishing transient upstream conditions (429, +// 5xx) from a genuine fetch failure. +func cargoMetadataStatusError(identifier string, status int) error { + switch { + case status == http.StatusTooManyRequests: + return fmt.Errorf("crates.io rate-limited the metadata request for cargo package '%s' (status: 429) โ€” likely transient, retry later", identifier) + case status >= 500 && status < 600: + return fmt.Errorf("crates.io upstream error fetching metadata for cargo package '%s' (status: %d) โ€” likely transient, retry later", identifier, status) + default: + return fmt.Errorf("cargo package '%s' metadata fetch failed (status: %d)", identifier, status) + } +} + +// cargoReadmeStatusError maps a non-200 status from the README CDN to a +// caller-actionable error. 429/5xx are transient; 403 is disambiguated (see +// cargoReadme403Error) because static.crates.io returns it both for a missing +// crate/version and for a crate that has no rendered README. +func cargoReadmeStatusError(ctx context.Context, client *http.Client, pkg model.Package, serverName string, status int) error { + switch { + case status == http.StatusTooManyRequests: + return fmt.Errorf("crates.io rate-limited the README fetch for cargo package '%s' version '%s' (status: 429) โ€” likely transient, retry later", pkg.Identifier, pkg.Version) + case status >= 500 && status < 600: + return fmt.Errorf("crates.io upstream error fetching README for cargo package '%s' version '%s' (status: %d) โ€” likely transient, retry later", pkg.Identifier, pkg.Version, status) + case status == http.StatusForbidden: + return cargoReadme403Error(ctx, client, pkg, serverName) + default: + return fmt.Errorf("cargo package '%s' version '%s' README fetch failed (status: %d)", pkg.Identifier, pkg.Version, status) + } +} + +// cargoReadme403Error disambiguates a 403 from static.crates.io (S3's default +// for a missing key): a genuinely-missing crate/version versus a crate that +// exists but has no rendered README. It probes the crate-version metadata +// endpoint so the publisher gets an actionable message rather than a blanket +// "not found". +func cargoReadme403Error(ctx context.Context, client *http.Client, pkg model.Package, serverName string) error { + switch probeCargoVersion(ctx, client, pkg.RegistryBaseURL, pkg.Identifier, pkg.Version) { + case cargoVersionExists: + // The crate/version exists but the README CDN returned 403. The likely + // cause is a missing README, but a 403 is not definitive proof (e.g. a + // transient CDN/WAF block), so don't flatly assert "no README". + return fmt.Errorf("cargo package '%s' version '%s' exists on crates.io, but its rendered README could not be retrieved (status: 403). If it has no README, add one containing 'mcp-name: %s' and publish a new version", pkg.Identifier, pkg.Version, serverName) + case cargoVersionMissing: + return fmt.Errorf("cargo package '%s' version '%s' not found on crates.io", pkg.Identifier, pkg.Version) + case cargoVersionTransient: + return fmt.Errorf("crates.io could not confirm cargo package '%s' version '%s' (README status: 403, version check inconclusive) โ€” likely transient, retry later", pkg.Identifier, pkg.Version) + case cargoVersionUnknown: + // Probe returned an unclassifiable status โ€” fall through to the + // best-effort message below. + } + return fmt.Errorf("cargo package '%s' version '%s' not found on crates.io (status: 403)", pkg.Identifier, pkg.Version) +} + +// validateCargoREADME performs the two-call README fetch and the mcp-name token +// check. It is split out from ValidateCargo so that httptest-based tests can +// drive the HTTP pipeline against a mock server (exposed via export_test.go), +// bypassing the exact-baseURL guard that ValidateCargo enforces for callers. +func validateCargoREADME(ctx context.Context, pkg model.Package, serverName string) error { + allowedHosts := cargoAllowedHosts(pkg.RegistryBaseURL) + client := newCargoHTTPClient(pkg.RegistryBaseURL, allowedHosts) + + // Step 1: fetch the README pointer from the documented API endpoint. + metaURL := fmt.Sprintf("%s/api/v1/crates/%s/%s/readme", + pkg.RegistryBaseURL, + url.PathEscape(pkg.Identifier), + url.PathEscape(pkg.Version)) + + metaReq, err := http.NewRequestWithContext(ctx, http.MethodGet, metaURL, nil) + if err != nil { + return fmt.Errorf("failed to create crates.io metadata request: %w", err) + } + metaReq.Header.Set("User-Agent", cargoUserAgent) + metaReq.Header.Set("Accept", "application/json") + + metaResp, err := client.Do(metaReq) + if err != nil { + return fmt.Errorf("failed to fetch package metadata from crates.io: %w", err) + } + defer metaResp.Body.Close() + + if metaResp.StatusCode != http.StatusOK { + return cargoMetadataStatusError(pkg.Identifier, metaResp.StatusCode) + } + + var meta CargoReadmeMetaResponse + if err := json.NewDecoder(metaResp.Body).Decode(&meta); err != nil { + return fmt.Errorf("failed to parse crates.io readme metadata: %w", err) + } + if meta.URL == "" { + return fmt.Errorf("cargo package '%s' metadata response missing 'url' field", pkg.Identifier) + } + + // Pin the README pointer to an allowed host/scheme/port before fetching it, so + // a metadata response cannot steer the validator at an internal or + // attacker-chosen URL. + readmeParsed, err := url.Parse(meta.URL) + if err != nil || readmeParsed.Hostname() == "" { + return fmt.Errorf("cargo package '%s': crates.io returned an unparseable README URL", pkg.Identifier) + } + if !cargoURLAllowed(readmeParsed, pkg.RegistryBaseURL, allowedHosts) { + return fmt.Errorf("cargo package '%s': crates.io returned a README URL on an unexpected host/scheme %q โ€” refusing to fetch", pkg.Identifier, readmeParsed.Redacted()) + } + + // Step 2: fetch the rendered README from the (now host-validated) URL. + readmeReq, err := http.NewRequestWithContext(ctx, http.MethodGet, meta.URL, nil) + if err != nil { + return fmt.Errorf("failed to create crates.io readme request: %w", err) + } + readmeReq.Header.Set("User-Agent", cargoUserAgent) + readmeReq.Header.Set("Accept", "text/html") + + readmeResp, err := client.Do(readmeReq) + if err != nil { + return fmt.Errorf("failed to fetch rendered README from crates.io: %w", err) + } + defer readmeResp.Body.Close() + + if readmeResp.StatusCode != http.StatusOK { + return cargoReadmeStatusError(ctx, client, pkg, serverName, readmeResp.StatusCode) + } + + body, err := io.ReadAll(io.LimitReader(readmeResp.Body, maxCargoReadmeBytes)) + if err != nil { + return fmt.Errorf("failed to read rendered README: %w", err) + } + + // Search for the mcp-name: ownership token. The token contains no + // characters that get HTML-escaped during README rendering (no <, >, &, ", '), + // so matching against the rendered HTML is reliable; containsMCPNameToken + // additionally requires a trailing boundary to avoid prefix confusion. + if containsMCPNameToken(string(body), serverName) { + return nil + } + + // If the token IS present but glued to a trailing character, explain that + // rather than telling the publisher to add a token they can already see. + if trailing, glued := mcpNameTokenGluedTrailing(string(body), serverName); glued { + return fmt.Errorf("cargo package '%s' ownership validation failed: found 'mcp-name: %s' in the README, but it is immediately followed by %q rather than a boundary. The token must be followed by a space, newline, or an HTML tag โ€” put it on its own line and publish a new version", pkg.Identifier, serverName, trailing) + } + + return fmt.Errorf("cargo package '%s' ownership validation failed. The server name '%s' must appear as 'mcp-name: %s' in the package README", pkg.Identifier, serverName, serverName) +} diff --git a/internal/validators/registries/cargo_internal_test.go b/internal/validators/registries/cargo_internal_test.go new file mode 100644 index 0000000..44273b5 --- /dev/null +++ b/internal/validators/registries/cargo_internal_test.go @@ -0,0 +1,47 @@ +package registries + +import ( + "net/url" + "testing" + + "github.com/modelcontextprotocol/registry/pkg/model" +) + +// TestCargoURLAllowed covers the SSRF allow-check: for the real crates.io base, +// the host must be allow-listed AND the scheme/port must be https/default; for a +// test (httptest) base only the host is checked so mocks keep working. +func TestCargoURLAllowed(t *testing.T) { + prodHosts := cargoAllowedHosts(model.RegistryURLCrates) // {crates.io, static.crates.io} + mockBase := "http://127.0.0.1:54321" + mockHosts := cargoAllowedHosts(mockBase) // {127.0.0.1} + + cases := []struct { + desc string + raw string + baseURL string + hosts map[string]struct{} + want bool + }{ + {"prod: https static.crates.io", "https://static.crates.io/readmes/x/x.html", model.RegistryURLCrates, prodHosts, true}, + {"prod: https crates.io", "https://crates.io/api/v1/crates/x/1.0.0", model.RegistryURLCrates, prodHosts, true}, + {"prod: http downgrade rejected", "http://static.crates.io/x", model.RegistryURLCrates, prodHosts, false}, + {"prod: non-default port rejected", "https://static.crates.io:8443/x", model.RegistryURLCrates, prodHosts, false}, + {"prod: explicit 443 ok", "https://static.crates.io:443/x", model.RegistryURLCrates, prodHosts, true}, + {"prod: foreign host rejected", "https://evil.example/x", model.RegistryURLCrates, prodHosts, false}, + {"prod: userinfo host is evil rejected", "https://static.crates.io@evil.example/x", model.RegistryURLCrates, prodHosts, false}, + {"test base: mock host any scheme/port ok", "http://127.0.0.1:54321/readme-static/x", mockBase, mockHosts, true}, + {"test base: foreign host rejected", "http://127.0.0.2:54321/x", mockBase, mockHosts, false}, + } + + for _, tc := range cases { + t.Run(tc.desc, func(t *testing.T) { + u, err := url.Parse(tc.raw) + if err != nil { + t.Fatalf("parse %q: %v", tc.raw, err) + } + if got := cargoURLAllowed(u, tc.baseURL, tc.hosts); got != tc.want { + t.Fatalf("cargoURLAllowed(%q, base=%q) = %v, want %v", tc.raw, tc.baseURL, got, tc.want) + } + }) + } +} diff --git a/internal/validators/registries/cargo_test.go b/internal/validators/registries/cargo_test.go new file mode 100644 index 0000000..5328f45 --- /dev/null +++ b/internal/validators/registries/cargo_test.go @@ -0,0 +1,538 @@ +package registries_test + +import ( + "context" + "encoding/json" + "fmt" + "net/http" + "net/http/httptest" + "net/url" + "strings" + "sync/atomic" + "testing" + + "github.com/modelcontextprotocol/registry/internal/validators/registries" + "github.com/modelcontextprotocol/registry/pkg/model" + "github.com/stretchr/testify/assert" +) + +func TestValidateCargo_RealPackages(t *testing.T) { + ctx := context.Background() + + tests := []struct { + name string + packageName string + version string + serverName string + expectError bool + errorMessage string + }{ + { + name: "empty package identifier should fail", + packageName: "", + version: "0.1.0", + serverName: "io.github.example/test", + expectError: true, + errorMessage: "package identifier is required for Cargo packages", + }, + { + name: "empty package version should fail", + packageName: "rust-faf-mcp", + version: "", + serverName: "io.github.example/test", + expectError: true, + errorMessage: "package version is required for Cargo packages", + }, + { + name: "non-existent crate should fail", + packageName: generateRandomPackageName(), + version: "0.1.0", + serverName: "io.github.example/test", + expectError: true, + errorMessage: "not found", + }, + { + name: "non-existent version of real crate should fail", + packageName: "serde", + version: "99.99.99-not-real", + serverName: "io.github.example/test", + expectError: true, + errorMessage: "not found", + }, + { + name: "real crate without mcp-name token should fail", + packageName: "serde", // most-downloaded crate; no MCP server claim + version: "1.0.219", + serverName: "io.github.example/test", + expectError: true, + errorMessage: "ownership validation failed", + }, + { + name: "real crate with mismatched mcp-name should fail", + packageName: "tokio", + version: "1.40.0", + serverName: "io.github.example/completely-different-name", + expectError: true, + errorMessage: "ownership validation failed", + }, + { + name: "additional real crate without mcp-name (rand)", + packageName: "rand", + version: "0.9.0", + serverName: "io.github.example/test", + expectError: true, + errorMessage: "ownership validation failed", + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + Identifier: tt.packageName, + Version: tt.version, + } + + err := registries.ValidateCargo(ctx, pkg, tt.serverName) + + if tt.expectError { + assert.Error(t, err) + assert.Contains(t, err.Error(), tt.errorMessage) + } else { + assert.NoError(t, err) + } + }) + } +} + +func TestValidateCargo_RegistryBaseURLMismatch(t *testing.T) { + ctx := context.Background() + + tests := []struct { + name string + baseURL string + }{ + {name: "different host", baseURL: "https://example.com"}, + {name: "trailing slash", baseURL: "https://crates.io/"}, + {name: "http (not https)", baseURL: "http://crates.io"}, + {name: "subdomain", baseURL: "https://www.crates.io"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + RegistryBaseURL: tt.baseURL, + Identifier: "rust-faf-mcp", + Version: "0.2.2", + } + + err := registries.ValidateCargo(ctx, pkg, "io.github.Wolfe-Jam/rust-faf-mcp") + assert.Error(t, err) + assert.Contains(t, err.Error(), "registry type and base URL do not match") + }) + } +} + +func TestValidateCargo_RejectsMCPBOnlyFields(t *testing.T) { + ctx := context.Background() + + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + Identifier: "rust-faf-mcp", + Version: "0.2.2", + FileSHA256: "0000000000000000000000000000000000000000000000000000000000000000", + } + + err := registries.ValidateCargo(ctx, pkg, "io.github.Wolfe-Jam/rust-faf-mcp") + assert.Error(t, err) + assert.Contains(t, err.Error(), "cargo packages must not have 'fileSha256' field") +} + +// Server names follow io.github.OWNER/REPO and may contain dots, slashes, +// hyphens, underscores, and digits. None of these get HTML-escaped during +// README rendering, so a boundary-anchored match against the rendered HTML is +// reliable. This is a hermetic POSITIVE test: each format variation is placed in +// a mock README as the exact mcp-name token and must validate successfully, so +// it actually exercises the match (the earlier version used a token-less live +// crate, where every case failed and the assertion was satisfied trivially). +func TestValidateCargo_ServerNameFormats(t *testing.T) { + ctx := context.Background() + + tests := []struct { + name string + serverName string + }{ + {name: "canonical io.github format", serverName: "io.github.Wolfe-Jam/rust-faf-mcp"}, + {name: "multiple hyphens", serverName: "io.github.example/multi-hyphen-test-name"}, + {name: "underscore", serverName: "io.github.example/snake_case_name"}, + {name: "numeric suffix", serverName: "io.github.example/server-v2"}, + {name: "dotted name segment", serverName: "io.github.example/group.tool"}, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + serverName := tt.serverName + var mock *httptest.Server + mock = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.HasSuffix(r.URL.Path, "/readme") { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{"url": mock.URL + "/static-readme"}) + return + } + // Token on its own line; the trailing newline is the boundary. + fmt.Fprintf(w, "\nmcp-name: %s\n", serverName) + })) + defer mock.Close() + + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + RegistryBaseURL: mock.URL, + Identifier: "fmt-crate", + Version: "0.1.0", + } + + err := registries.ValidateCargoREADME(ctx, pkg, serverName) + assert.NoError(t, err, "server name %q should validate when present as an exact mcp-name token", serverName) + }) + } +} + +// TestValidateCargo_PositivePathMock exercises the success branch: a README +// that contains the exact mcp-name token must return no error. Uses httptest +// to stand in for crates.io, so the test is hermetic โ€” it doesn't depend on +// any live crate publishing a specific mcp-name line or on network reachability. +// Calls the test-only ValidateCargoREADME shim so the mock URL can take the +// place of https://crates.io without tripping the exact-baseURL guard. +func TestValidateCargo_PositivePathMock(t *testing.T) { + ctx := context.Background() + const serverName = "io.github.test/positive-path" + + var mock *httptest.Server + mock = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.HasSuffix(r.URL.Path, "/readme") { + w.Header().Set("Content-Type", "application/json") + // Encode of a static map cannot fail; ignore the error rather than + // calling t.Fatalf from this (server) goroutine, which is not the test + // goroutine and would truncate the response instead of failing cleanly. + _ = json.NewEncoder(w).Encode(map[string]string{"url": mock.URL + "/static-readme"}) + return + } + // Rendered README HTML containing the mcp-name token. + fmt.Fprintf(w, "

some content

mcp-name: %s

", serverName) + })) + defer mock.Close() + + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + RegistryBaseURL: mock.URL, + Identifier: "test-crate", + Version: "0.1.0", + } + + err := registries.ValidateCargoREADME(ctx, pkg, serverName) + assert.NoError(t, err, "validator should accept a README containing the exact mcp-name token") +} + +// TestValidateCargo_LivePositivePath is the live anchor โ€” it validates against +// rust-faf-mcp v0.3.1 on real crates.io, the first crate published with the +// mcp-name token as visible markdown (v0.3.0 used a hidden HTML comment, which +// crates.io strips during README rendering โ€” see package-types.mdx for the +// cargo-specific gotcha). Complements TestValidateCargo_PositivePathMock: +// the mock proves the validator works in principle (hermetic, fast); the live +// anchor proves it works against the real crates.io API + static CDN pipeline. +// +// If this test ever starts failing, check (in order): +// 1. Has rust-faf-mcp v0.3.1 been yanked or replaced? +// 2. Did crates.io change its README rendering pipeline (e.g., start +// stripping markdown lines that look like email-like tokens)? +// 3. Is the test machine network-blocked from crates.io or static.crates.io? +func TestValidateCargo_LivePositivePath(t *testing.T) { + ctx := context.Background() + + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + Identifier: "rust-faf-mcp", + Version: "0.3.1", + } + + err := registries.ValidateCargo(ctx, pkg, "io.github.Wolfe-Jam/rust-faf-mcp") + assert.NoError(t, err, "validator should accept the live rust-faf-mcp v0.3.1 crate (the canonical live anchor for cargo positive-path)") +} + +// TestValidateCargo_TransientUpstreamError exercises the 5xx-as-transient branch: +// a 502/503 from static.crates.io is upstream availability, not "crate missing", +// and the error message must signal a retryable failure rather than imply the +// crate doesn't exist (the previous behavior, flagged in PR #1207 review). +func TestValidateCargo_TransientUpstreamError(t *testing.T) { + ctx := context.Background() + + var mock *httptest.Server + mock = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if strings.HasSuffix(r.URL.Path, "/readme") { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{ + "url": mock.URL + "/static-readme", + }) + return + } + // Simulate static.crates.io 502 โ€” upstream blip, not a missing crate. + http.Error(w, "bad gateway", http.StatusBadGateway) + })) + defer mock.Close() + + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + RegistryBaseURL: mock.URL, + Identifier: "test-crate", + Version: "0.1.0", + } + + err := registries.ValidateCargoREADME(ctx, pkg, "io.github.test/transient") + assert.Error(t, err) + assert.Contains(t, err.Error(), "transient") + assert.NotContains(t, err.Error(), "not found", "transient upstream errors should not be reported as 'not found'") +} + +// TestValidateCargo_RejectsForeignReadmeHost is the SSRF guard: the README +// pointer returned by the metadata endpoint must be on an allowed host. Here the +// (mock) metadata endpoint points the README at an unrelated host; the validator +// must refuse to fetch it rather than follow the pointer anywhere crates.io names. +// The ".invalid" host never resolves, so a regression that dropped the host check +// would fail to connect rather than silently pass โ€” but the assertion targets the +// explicit "unexpected host" refusal, which happens before any fetch. +func TestValidateCargo_RejectsForeignReadmeHost(t *testing.T) { + ctx := context.Background() + + mock := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) { + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{"url": "http://internal.invalid/secret-readme"}) + })) + defer mock.Close() + + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + RegistryBaseURL: mock.URL, + Identifier: "evil-crate", + Version: "0.1.0", + } + + err := registries.ValidateCargoREADME(ctx, pkg, "io.github.test/evil") + assert.Error(t, err) + assert.Contains(t, err.Error(), "unexpected host", "a README URL on a foreign host must be refused (SSRF guard)") +} + +// TestValidateCargoCombinedFixture exercises path-encoding and the full status +// matrix in one httptest fixture โ€” the same pattern praised by @P4ST4S on +// PR #1321 for Go modules. One server dispatches on the crate identifier +// embedded in the URL path; wrong encoding routes to the fallback 500, which +// breaks the appropriate assertion. The explicit path assertion (assert.Equal +// on lastMetaPath) also catches encoding regressions directly. +func TestValidateCargoCombinedFixture(t *testing.T) { + ctx := context.Background() + const serverName = "io.github.test/combined" + + tests := []struct { + name string + crateName string + version string + metaStatus int + readmeStatus int + readmeBody string + versionExists bool // response for the /api/v1/crates/{n}/{v} existence probe (403 disambiguation) + versionProbe int // if non-zero, the existence probe returns this status (overrides versionExists) + wantErr bool + wantContains []string + wantNotContains []string + }{ + { + name: "happy_path_visible_token", + crateName: "combined-happy", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusOK, + readmeBody: fmt.Sprintf("

mcp-name: %s

", serverName), + }, + { + // Defensive branch: crates.io's metadata endpoint returns 200 (with a + // CDN url) even for missing crates, so it does NOT 404 in practice for a + // missing crate โ€” the real missing-crate path is readme_403_missing below. + // This case only covers what we'd report if the API ever did 404. + name: "metadata_404_defensive", + crateName: "combined-meta404", + version: "0.1.0", + metaStatus: http.StatusNotFound, + wantErr: true, + wantContains: []string{"metadata fetch failed", "status: 404"}, + }, + { + // Real missing-crate/version path: CDN 403 + existence probe 404. + name: "readme_403_missing", + crateName: "combined-readme403-missing", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusForbidden, + versionExists: false, + wantErr: true, + wantContains: []string{"not found"}, + wantNotContains: []string{"has no rendered README"}, + }, + { + // Crate/version exists but the README CDN 403s: existence probe 200. + // Must NOT be reported as "not found", and must not flatly assert the + // README is absent (a 403 isn't definitive proof of that). + name: "readme_403_no_readme", + crateName: "combined-readme403-noreadme", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusForbidden, + versionExists: true, + wantErr: true, + wantContains: []string{"exists on crates.io", "could not be retrieved"}, + wantNotContains: []string{"not found"}, + }, + { + // CDN 403 + the existence probe itself is rate-limited (429): existence + // is undetermined, so report transient/retryable, NOT "not found". + name: "readme_403_probe_transient", + crateName: "combined-readme403-probe429", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusForbidden, + versionProbe: http.StatusTooManyRequests, + wantErr: true, + wantContains: []string{"transient"}, + wantNotContains: []string{"not found"}, + }, + { + name: "readme_429_transient", + crateName: "combined-readme429", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusTooManyRequests, + wantErr: true, + wantContains: []string{"transient"}, + wantNotContains: []string{"not found"}, + }, + { + name: "readme_502_transient", + crateName: "combined-readme502", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusBadGateway, + wantErr: true, + wantContains: []string{"transient"}, + wantNotContains: []string{"not found"}, + }, + { + // Prefix confusion: README declares a LONGER name; a claim for the + // shorter serverName must be rejected by the boundary-anchored match. + name: "prefix_confusion_rejected", + crateName: "combined-prefix", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusOK, + readmeBody: fmt.Sprintf("

mcp-name: %s-extended

", serverName), + wantErr: true, + wantContains: []string{"ownership validation failed"}, + }, + { + // Token present but glued to a trailing period โ€” the error must explain + // the boundary cause, not tell the publisher to add a token they can see. + name: "glued_trailing_period_explained", + crateName: "combined-glued", + version: "0.1.0", + metaStatus: http.StatusOK, + readmeStatus: http.StatusOK, + readmeBody: fmt.Sprintf("

mcp-name: %s.

", serverName), + wantErr: true, + wantContains: []string{"immediately followed by", `"."`}, + }, + } + + // lastMetaPath captures the metadata request path seen by the handler so + // each sub-test can assert the exact url.PathEscape-encoded form. + var lastMetaPath atomic.Value + lastMetaPath.Store("") + + var srv *httptest.Server + srv = httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + for i := range tests { + tt := &tests[i] + metaPath := fmt.Sprintf("/api/v1/crates/%s/%s/readme", + url.PathEscape(tt.crateName), url.PathEscape(tt.version)) + versionPath := fmt.Sprintf("/api/v1/crates/%s/%s", + url.PathEscape(tt.crateName), url.PathEscape(tt.version)) + staticPath := "/readme-static/" + url.PathEscape(tt.crateName) + + if r.URL.Path == metaPath { + lastMetaPath.Store(r.URL.Path) + if tt.metaStatus != http.StatusOK { + http.Error(w, "simulated non-200", tt.metaStatus) + return + } + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]string{"url": srv.URL + staticPath}) + return + } + // Existence probe used to disambiguate a README 403. + if r.URL.Path == versionPath { + switch { + case tt.versionProbe != 0: + http.Error(w, "simulated probe status", tt.versionProbe) + case tt.versionExists: + w.Header().Set("Content-Type", "application/json") + _ = json.NewEncoder(w).Encode(map[string]any{"version": map[string]string{"num": tt.version}}) + default: + http.Error(w, "not found", http.StatusNotFound) + } + return + } + if r.URL.Path == staticPath { + if tt.readmeStatus != http.StatusOK { + http.Error(w, "simulated non-200", tt.readmeStatus) + return + } + fmt.Fprint(w, tt.readmeBody) + return + } + } + http.Error(w, "unexpected path: "+r.URL.Path, http.StatusInternalServerError) + })) + defer srv.Close() + + for i := range tests { + tt := tests[i] + lastMetaPath.Store("") + t.Run(tt.name, func(t *testing.T) { + wantMetaPath := fmt.Sprintf("/api/v1/crates/%s/%s/readme", + url.PathEscape(tt.crateName), url.PathEscape(tt.version)) + + pkg := model.Package{ + RegistryType: model.RegistryTypeCargo, + RegistryBaseURL: srv.URL, + Identifier: tt.crateName, + Version: tt.version, + } + + err := registries.ValidateCargoREADME(ctx, pkg, serverName) + + // Assert encode step: the validator must have requested exactly the + // url.PathEscape-encoded path; wrong encoding hits the fallback 500. + assert.Equal(t, wantMetaPath, lastMetaPath.Load().(string), + "meta request path must be exactly the url.PathEscape-encoded form") + + if tt.wantErr { + assert.Error(t, err) + for _, want := range tt.wantContains { + assert.Contains(t, err.Error(), want) + } + for _, notWant := range tt.wantNotContains { + assert.NotContains(t, err.Error(), notWant) + } + } else { + assert.NoError(t, err) + } + }) + } +} diff --git a/internal/validators/registries/export_test.go b/internal/validators/registries/export_test.go new file mode 100644 index 0000000..5a1649e --- /dev/null +++ b/internal/validators/registries/export_test.go @@ -0,0 +1,20 @@ +package registries + +// ValidateCargoREADME exposes the package-private validateCargoREADME to the +// external _test package so httptest-driven tests can exercise the README-fetch +// and mcp-name token-match pipeline against a mock server, bypassing the +// exact-baseURL guard that the public ValidateCargo enforces. +// +// Intended for cargo_test.go's positive-path and transient-error tests only. +var ValidateCargoREADME = validateCargoREADME + +// ValidatePyPIPackage and ValidateNPMPackage expose the package-private +// validatePyPIPackage / validateNPMPackage to the external _test package so +// httptest-driven tests can exercise the metadata fetch and status-disambiguation +// pipeline (missing package vs missing/unpropagated version vs transient upstream) +// against a mock server, bypassing the exact-baseURL guard that the public +// ValidatePyPI / ValidateNPM enforce. +var ( + ValidatePyPIPackage = validatePyPIPackage + ValidateNPMPackage = validateNPMPackage +) diff --git a/internal/validators/registries/mcpb.go b/internal/validators/registries/mcpb.go index d42059b..82ba4d9 100644 --- a/internal/validators/registries/mcpb.go +++ b/internal/validators/registries/mcpb.go @@ -54,8 +54,17 @@ func ValidateMCPB(ctx context.Context, pkg model.Package, _ string) error { return fmt.Errorf("MCPB package URL must contain 'mcp': %s", pkg.Identifier) } - // Verify the file exists and is publicly accessible - client := &http.Client{Timeout: 10 * time.Second} + // Verify the file exists and is publicly accessible. Refuse to follow + // redirects: the URL allowlist (github.com / gitlab.com) only constrains + // the FIRST hop, and a 30x bouncing through CDN/release-asset hosts + // could otherwise be steered toward attacker infrastructure or + // internal-only endpoints reached via DNS quirks. + client := &http.Client{ + Timeout: 10 * time.Second, + CheckRedirect: func(_ *http.Request, _ []*http.Request) error { + return http.ErrUseLastResponse + }, + } req, err := http.NewRequestWithContext(ctx, http.MethodHead, pkg.Identifier, nil) if err != nil { return fmt.Errorf("failed to create request: %w", err) @@ -69,7 +78,15 @@ func ValidateMCPB(ctx context.Context, pkg model.Package, _ string) error { } defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { + // GitHub serves release assets via a 302 to a signed S3 URL; a HEAD that + // returns 200 directly OR a 302 with a Location header is acceptable. + // Any other 3xx without a usable Location is treated as inaccessible. + switch { + case resp.StatusCode == http.StatusOK: + // fine + case resp.StatusCode >= 300 && resp.StatusCode < 400 && resp.Header.Get("Location") != "": + // fine โ€” first-hop allowlist + we don't actually need the body + default: return fmt.Errorf("MCPB package '%s' is not publicly accessible (status: %d)", pkg.Identifier, resp.StatusCode) } diff --git a/internal/validators/registries/mcpname.go b/internal/validators/registries/mcpname.go new file mode 100644 index 0000000..527aefb --- /dev/null +++ b/internal/validators/registries/mcpname.go @@ -0,0 +1,97 @@ +package registries + +import "strings" + +// isServerNameChar reports whether c can appear in an MCP server name. +// +// Server names follow the schema pattern ^[a-zA-Z0-9.-]+/[a-zA-Z0-9._-]+$ +// (reverse-DNS namespace + "/" + name), so the full set of characters that may +// continue a server name is [A-Za-z0-9._/-]. +func isServerNameChar(c byte) bool { + switch { + case c >= 'a' && c <= 'z', c >= 'A' && c <= 'Z', c >= '0' && c <= '9': + return true + case c == '.', c == '-', c == '_', c == '/': + return true + default: + return false + } +} + +// isMCPNameBoundary reports whether the content immediately following a matched +// server name terminates the token, so that the matched name is not merely a +// prefix of a longer declared name. +// +// A boundary is the end of content, any non-server-name character (whitespace, a +// newline, or an HTML tag delimiter such as `<`), or the start of an HTML comment +// close (`-->` / `--!>`). The comment-close case matters because PyPI and NuGet +// publishers commonly hide the token in ``, and authors +// (or minifiers) frequently omit the space before `-->`, producing +// ``. There the byte after NAME is `-`, which is a +// server-name character, so without this case the documented hidden-comment form +// would fail to validate. +func isMCPNameBoundary(rest string) bool { + if rest == "" { + return true + } + if !isServerNameChar(rest[0]) { + return true + } + return strings.HasPrefix(rest, "-->") || strings.HasPrefix(rest, "--!>") +} + +// containsMCPNameToken reports whether the package README/description contains +// the ownership token "mcp-name: " as a complete token โ€” i.e. the +// matched server name is not merely a prefix of a longer declared name. +// +// A bare strings.Contains check is vulnerable to prefix confusion: a README that +// legitimately declares `mcp-name: io.github.acme/widget-pro` would otherwise +// satisfy an ownership claim for the shorter `io.github.acme/widget`, because the +// shorter string is a substring of the longer one. This is contained by namespace +// authorization (a publisher can only claim names within a namespace they own), +// but it still weakens the packageโ†”server-name binding the token is meant to +// prove, so we require a trailing boundary after the server name (see +// isMCPNameBoundary). +// +// Shared by the README-token validators (PyPI, NuGet, Cargo). NPM is unaffected +// because it compares an exact metadata field rather than scanning README text. +func containsMCPNameToken(content, serverName string) bool { + token := "mcp-name: " + serverName + searchFrom := 0 + for { + idx := strings.Index(content[searchFrom:], token) + if idx < 0 { + return false + } + tokenEnd := searchFrom + idx + len(token) + if isMCPNameBoundary(content[tokenEnd:]) { + return true + } + // This occurrence is a prefix of a longer name; keep scanning in case a + // properly-terminated occurrence appears later in the content. + searchFrom = searchFrom + idx + 1 + } +} + +// mcpNameTokenGluedTrailing explains why a visibly-present token failed to match. +// When containsMCPNameToken has already returned false, it reports whether the +// literal "mcp-name: " string is nonetheless present and, if so, the +// character immediately following it โ€” i.e. the trailing character that made the +// occurrence look like a prefix of a longer name rather than a complete token. +// Validators use it to turn an unhelpful "token must appear" message into an +// actionable "found it, but it's glued to %q โ€” put it on its own line" message. +// Returns ("", false) when the literal token is absent (a genuinely missing token). +func mcpNameTokenGluedTrailing(content, serverName string) (trailing string, glued bool) { + token := "mcp-name: " + serverName + idx := strings.Index(content, token) + if idx < 0 { + return "", false + } + end := idx + len(token) + if end >= len(content) { + // A token at end-of-content is a valid boundary, so containsMCPNameToken + // would not have failed; be defensive and treat it as not-glued. + return "", false + } + return string(content[end]), true +} diff --git a/internal/validators/registries/mcpname_internal_test.go b/internal/validators/registries/mcpname_internal_test.go new file mode 100644 index 0000000..cd0bc38 --- /dev/null +++ b/internal/validators/registries/mcpname_internal_test.go @@ -0,0 +1,104 @@ +package registries + +import ( + "strings" + "testing" +) + +// TestContainsMCPNameToken covers the boundary-anchored ownership-token match +// shared by the PyPI, NuGet, and Cargo validators โ€” in particular that a server +// name which is a prefix of a longer declared name does not satisfy the match. +func TestContainsMCPNameToken(t *testing.T) { + const name = "io.github.acme/widget" + + cases := []struct { + desc string + content string + want bool + }{ + {"exact on its own line", "intro text\nmcp-name: io.github.acme/widget\nmore text", true}, + {"exact at end of content", "mcp-name: io.github.acme/widget", true}, + {"followed by HTML tag", "

mcp-name: io.github.acme/widget

", true}, + {"followed by space", "mcp-name: io.github.acme/widget is the name", true}, + {"longer hyphenated name not a match", "mcp-name: io.github.acme/widget-pro\n", false}, + {"longer dotted name not a match", "mcp-name: io.github.acme/widget.core\n", false}, + {"longer slashed name not a match", "mcp-name: io.github.acme/widget/sub\n", false}, + {"absent", "nothing to see here", false}, + {"different name", "mcp-name: io.github.other/thing\n", false}, + {"prefix occurrence before a real one still matches", "mcp-name: io.github.acme/widget-pro then mcp-name: io.github.acme/widget\n", true}, + + // HTML hidden-comment form (documented for PyPI/NuGet). The canonical + // spaced form has always passed; the no-space variants must pass too, + // since the byte after the name is the `-` of the comment close. + {"comment, spaced (canonical)", "", true}, + {"comment, no trailing space", "", true}, + {"comment, no spaces at all", "", true}, + {"legacy comment close --!>", "", true}, + // A genuine longer name with a double hyphen is still NOT a match for the + // shorter claim (it is not an HTML comment close). + {"double-hyphen longer name not a match", "mcp-name: io.github.acme/widget--pro\n", false}, + } + + for _, tc := range cases { + t.Run(tc.desc, func(t *testing.T) { + if got := containsMCPNameToken(tc.content, name); got != tc.want { + t.Fatalf("containsMCPNameToken(%q, %q) = %v, want %v", tc.content, name, got, tc.want) + } + }) + } +} + +// TestMCPNameTokenGluedTrailing covers the diagnostic helper that explains why a +// visibly-present token failed: it reports the trailing character gluing the +// token to a longer name, or ("", false) when the token is genuinely absent. +func TestMCPNameTokenGluedTrailing(t *testing.T) { + const name = "io.github.acme/widget" + cases := []struct { + desc string + content string + wantTrailing string + wantGlued bool + }{ + {"absent", "no token here", "", false}, + {"glued period", "mcp-name: io.github.acme/widget.", ".", true}, + {"glued hyphen (longer name)", "mcp-name: io.github.acme/widget-pro", "-", true}, + {"glued slash", "mcp-name: io.github.acme/widget/x", "/", true}, + {"at end of content (boundary, not glued)", "mcp-name: io.github.acme/widget", "", false}, + } + for _, tc := range cases { + t.Run(tc.desc, func(t *testing.T) { + gotTrailing, gotGlued := mcpNameTokenGluedTrailing(tc.content, name) + if gotGlued != tc.wantGlued || gotTrailing != tc.wantTrailing { + t.Fatalf("mcpNameTokenGluedTrailing(%q) = (%q, %v), want (%q, %v)", + tc.content, gotTrailing, gotGlued, tc.wantTrailing, tc.wantGlued) + } + }) + } +} + +// FuzzContainsMCPNameToken pins the core safety property of the boundary-anchored +// matcher: it is strictly stricter than a bare substring check. A true result +// must imply the literal token is present (strings.Contains). This guards against +// a future edit to isServerNameChar/isMCPNameBoundary accidentally accepting +// something the old behavior rejected โ€” i.e. it can only ever flip passโ†’fail, +// never failโ†’pass. Runs the seed corpus under `go test`; exhaustively under +// `go test -fuzz`. +func FuzzContainsMCPNameToken(f *testing.F) { + seeds := []struct{ content, name string }{ + {"mcp-name: io.github.acme/widget", "io.github.acme/widget"}, + {"mcp-name: io.github.acme/widget-pro", "io.github.acme/widget"}, + {"", "io.github.acme/widget"}, + {"prefix mcp-name: a/b then mcp-name: a/b-c", "a/b"}, + {"", ""}, + {"mcp-name: ", ""}, + {"random text with no token", "io.github.x/y"}, + } + for _, s := range seeds { + f.Add(s.content, s.name) + } + f.Fuzz(func(t *testing.T, content, name string) { + if containsMCPNameToken(content, name) && !strings.Contains(content, "mcp-name: "+name) { + t.Fatalf("matcher accepted but literal token absent: content=%q name=%q", content, name) + } + }) +} diff --git a/internal/validators/registries/npm.go b/internal/validators/registries/npm.go index 7c665a9..a6ed170 100644 --- a/internal/validators/registries/npm.go +++ b/internal/validators/registries/npm.go @@ -52,6 +52,14 @@ func ValidateNPM(ctx context.Context, pkg model.Package, serverName string) erro pkg.RegistryBaseURL, model.RegistryTypeNPM, model.RegistryURLNPM) } + return validateNPMPackage(ctx, pkg, serverName) +} + +// validateNPMPackage performs the version-metadata fetch and the mcpName check. +// It is split out from ValidateNPM so that httptest-based tests can drive the HTTP +// pipeline against a mock server (exposed via export_test.go), bypassing the +// exact-baseURL guard that ValidateNPM enforces for callers. +func validateNPMPackage(ctx context.Context, pkg model.Package, serverName string) error { client := &http.Client{Timeout: 10 * time.Second} requestURL := pkg.RegistryBaseURL + "/" + url.PathEscape(pkg.Identifier) + "/" + url.PathEscape(pkg.Version) @@ -60,7 +68,7 @@ func ValidateNPM(ctx context.Context, pkg model.Package, serverName string) erro return fmt.Errorf("failed to create request: %w", err) } - req.Header.Set("User-Agent", "MCP-Registry-Validator/1.0") + req.Header.Set("User-Agent", userAgent) req.Header.Set("Accept", "application/json") resp, err := client.Do(req) @@ -70,7 +78,7 @@ func ValidateNPM(ctx context.Context, pkg model.Package, serverName string) erro defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return fmt.Errorf("NPM package '%s' not found (status: %d)", pkg.Identifier, resp.StatusCode) + return npmFetchStatusError(ctx, client, pkg, resp.StatusCode) } var npmResp NPMPackageResponse @@ -88,3 +96,90 @@ func ValidateNPM(ctx context.Context, pkg model.Package, serverName string) erro return nil } + +// npmPackageState is the outcome of probing the package-level NPM metadata +// endpoint, used to disambiguate a 404 from the version-specific endpoint. +type npmPackageState int + +const ( + // npmPackageUnknown: the probe returned a status we can't classify. + npmPackageUnknown npmPackageState = iota + // npmPackageExists: the package exists (200) but the requested version does not. + npmPackageExists + // npmPackageMissing: the package itself does not exist (404). + npmPackageMissing + // npmPackageTransient: the probe failed for a retryable reason (network error, + // 429, or 5xx). Existence is undetermined and the caller should not report + // "not found". + npmPackageTransient +) + +// npmFetchStatusError maps a non-200 status from the version-specific metadata +// endpoint to a caller-actionable error. A 404 is delegated to npmVersion404Error +// for disambiguation. 429/5xx are transient, not "not found". +func npmFetchStatusError(ctx context.Context, client *http.Client, pkg model.Package, status int) error { + switch { + case status == http.StatusNotFound: + return npmVersion404Error(ctx, client, pkg) + case status == http.StatusTooManyRequests: + return fmt.Errorf("NPM rate-limited the metadata request for package '%s' (status: 429). Likely transient, retry later", pkg.Identifier) + case status >= 500 && status < 600: + return fmt.Errorf("NPM upstream error fetching metadata for package '%s' (status: %d). Likely transient, retry later", pkg.Identifier, status) + default: + return fmt.Errorf("NPM package '%s' metadata fetch failed (status: %d)", pkg.Identifier, status) + } +} + +// npmVersion404Error disambiguates a 404 from the version-specific endpoint: a +// genuinely-missing package versus a package that exists but whose requested +// version is absent (commonly because a freshly published release has not yet +// propagated). It probes the package-level endpoint so the publisher gets an +// actionable message rather than a blanket "not found". +func npmVersion404Error(ctx context.Context, client *http.Client, pkg model.Package) error { + switch probeNPMPackage(ctx, client, pkg.RegistryBaseURL, pkg.Identifier) { + case npmPackageExists: + return fmt.Errorf("NPM package '%s' exists, but version '%s' was not found (status: 404). A newly published release can take a moment to appear on the registry. Wait and retry, or publish version '%s' before registering it", pkg.Identifier, pkg.Version, pkg.Version) + case npmPackageMissing: + return fmt.Errorf("NPM package '%s' not found (status: 404)", pkg.Identifier) + case npmPackageTransient: + return fmt.Errorf("NPM could not confirm package '%s' version '%s' (version status: 404, package check inconclusive). Likely transient, retry later", pkg.Identifier, pkg.Version) + case npmPackageUnknown: + // Probe returned an unclassifiable status, so fall through to the + // best-effort message below. + } + return fmt.Errorf("NPM package '%s' version '%s' not found (status: 404)", pkg.Identifier, pkg.Version) +} + +// probeNPMPackage checks whether a package exists on the NPM registry regardless +// of version, with a HEAD request to the package-level endpoint (/{name}). Only +// the status code is used, so HEAD avoids downloading the (large) packument. +func probeNPMPackage(ctx context.Context, client *http.Client, baseURL, identifier string) npmPackageState { + // The probe only refines the 404 error message, so it must not extend the + // validator's worst case by another full client timeout. + ctx, cancel := context.WithTimeout(ctx, 3*time.Second) + defer cancel() + + probeURL := baseURL + "/" + url.PathEscape(identifier) + req, err := http.NewRequestWithContext(ctx, http.MethodHead, probeURL, nil) + if err != nil { + return npmPackageUnknown + } + req.Header.Set("User-Agent", userAgent) + + resp, err := client.Do(req) + if err != nil { + return npmPackageTransient + } + defer resp.Body.Close() + + switch { + case resp.StatusCode == http.StatusOK: + return npmPackageExists + case resp.StatusCode == http.StatusNotFound: + return npmPackageMissing + case resp.StatusCode == http.StatusTooManyRequests, resp.StatusCode >= 500 && resp.StatusCode < 600: + return npmPackageTransient + default: + return npmPackageUnknown + } +} diff --git a/internal/validators/registries/npm_test.go b/internal/validators/registries/npm_test.go index f9bf7da..7adb828 100644 --- a/internal/validators/registries/npm_test.go +++ b/internal/validators/registries/npm_test.go @@ -2,13 +2,186 @@ package registries_test import ( "context" + "fmt" + "io" + "net/http" + "net/http/httptest" + "strings" "testing" + "time" "github.com/modelcontextprotocol/registry/internal/validators/registries" "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" ) +// newNPMMock stands in for registry.npmjs.org: it routes the version fetch and +// package probe by path shape and returns the given statuses (versionBody used on 200). +func newNPMMock(versionStatus int, versionBody string, packageStatus int) *httptest.Server { + return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // Route on the escaped path: a scoped name like @scope/pkg is sent as the + // single segment @scope%2Fpkg, and decoding it would wrongly split it in two. + parts := strings.Split(strings.Trim(r.URL.EscapedPath(), "/"), "/") + // Pin the method per endpoint (GET fetch, HEAD probe) so a method + // regression in the validator surfaces as a 405 instead of passing. + switch len(parts) { + case 2: // /{name}/{version} + if r.Method != http.MethodGet { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + if versionStatus != http.StatusOK { + w.WriteHeader(versionStatus) + return + } + w.Header().Set("Content-Type", "application/json") + _, _ = io.WriteString(w, versionBody) + case 1: // /{name} (package-existence probe) + if r.Method != http.MethodHead { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + w.WriteHeader(packageStatus) + default: + w.WriteHeader(http.StatusInternalServerError) + } + })) +} + +// TestValidateNPM_VersionNotYetVisible is the #553 regression for npm: version 404s +// while the package exists, so the error must report a missing version, not a missing package. +func TestValidateNPM_VersionNotYetVisible(t *testing.T) { + ctx := context.Background() + mock := newNPMMock(http.StatusNotFound, "", http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "9.9.9"} + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "exists, but version '9.9.9'", "package-exists/version-missing must be distinguished from package-missing") +} + +// TestValidateNPM_PackageMissing: both endpoints 404, so "not found" is correct. +func TestValidateNPM_PackageMissing(t *testing.T) { + ctx := context.Background() + mock := newNPMMock(http.StatusNotFound, "", http.StatusNotFound) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "not found") + assert.NotContains(t, err.Error(), "exists, but version", "a genuinely missing package must not claim the version exists") +} + +// TestValidateNPM_TransientUpstream: a 5xx on the version fetch must be retryable, +// not "not found". +func TestValidateNPM_TransientUpstream(t *testing.T) { + ctx := context.Background() + mock := newNPMMock(http.StatusBadGateway, "", http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "transient") + assert.NotContains(t, err.Error(), "not found", "transient upstream errors must not be reported as 'not found'") +} + +// TestValidateNPM_VersionNotFoundProbeInconclusive: version 404 plus a transient +// probe (503) leaves existence undetermined, so the validator must not say "not found". +func TestValidateNPM_VersionNotFoundProbeInconclusive(t *testing.T) { + ctx := context.Background() + mock := newNPMMock(http.StatusNotFound, "", http.StatusServiceUnavailable) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "transient") + assert.NotContains(t, err.Error(), "not found", "an inconclusive probe must not assert the package is missing") +} + +// TestValidateNPM_ProbeDeadlineBounded: a hung probe must be cut off by the +// probe's own short deadline instead of riding out the client's full 10s +// timeout, and the cutoff must read as inconclusive rather than "not found". +func TestValidateNPM_ProbeDeadlineBounded(t *testing.T) { + ctx := context.Background() + mock := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + parts := strings.Split(strings.Trim(r.URL.EscapedPath(), "/"), "/") + if len(parts) == 2 { // version fetch + w.WriteHeader(http.StatusNotFound) + return + } + // Package probe: hang until the client gives up. + <-r.Context().Done() + })) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + start := time.Now() + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + elapsed := time.Since(start) + assert.Error(t, err) + assert.Contains(t, err.Error(), "transient", "a probe cut off by its deadline is inconclusive, not 'not found'") + assert.Less(t, elapsed, 8*time.Second, "a hung probe must be bounded by the probe deadline, not the client timeout") +} + +// TestValidateNPM_ScopedVersionNotYetVisible covers scoped names (@scope/name), the +// escaped-single-segment case, through the version fetch and the HEAD probe. +func TestValidateNPM_ScopedVersionNotYetVisible(t *testing.T) { + ctx := context.Background() + mock := newNPMMock(http.StatusNotFound, "", http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "@scope/demo", Version: "9.9.9"} + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "exists, but version '9.9.9'", "scoped names must route correctly through both endpoints") +} + +// TestValidateNPM_VersionEndpointRateLimited: a 429 on the version fetch is reported +// as rate-limited/transient. +func TestValidateNPM_VersionEndpointRateLimited(t *testing.T) { + ctx := context.Background() + mock := newNPMMock(http.StatusTooManyRequests, "", http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "rate-limited") + assert.NotContains(t, err.Error(), "not found") +} + +// TestValidateNPM_VersionNotFoundProbeUnclassified: the version 404s and the probe +// returns an unclassifiable status, so the validator falls back to a plain +// version-not-found message. +func TestValidateNPM_VersionNotFoundProbeUnclassified(t *testing.T) { + ctx := context.Background() + mock := newNPMMock(http.StatusNotFound, "", http.StatusTeapot) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidateNPMPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "version '1.0.0' not found") + assert.NotContains(t, err.Error(), "exists, but version") +} + +// TestValidateNPM_PositivePathMock: a version response with the matching mcpName validates. +func TestValidateNPM_PositivePathMock(t *testing.T) { + ctx := context.Background() + const serverName = "io.github.test/demo" + body := fmt.Sprintf(`{"mcpName":%q}`, serverName) + mock := newNPMMock(http.StatusOK, body, http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypeNPM, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidateNPMPackage(ctx, pkg, serverName) + assert.NoError(t, err, "a version response with the matching mcpName should validate") +} + func TestValidateNPM_RealPackages(t *testing.T) { ctx := context.Background() @@ -126,6 +299,12 @@ func TestValidateNPM_RealPackages(t *testing.T) { err := registries.ValidateNPM(ctx, pkg, tt.serverName) + // A live 429/5xx from the registry is inconclusive, not a failure + // of the case under test. + if err != nil && strings.Contains(err.Error(), "retry later") { + t.Skipf("transient registry response: %v", err) + } + if tt.expectError { assert.Error(t, err) assert.Contains(t, err.Error(), tt.errorMessage) diff --git a/internal/validators/registries/nuget.go b/internal/validators/registries/nuget.go index c3b95a0..c229ba0 100644 --- a/internal/validators/registries/nuget.go +++ b/internal/validators/registries/nuget.go @@ -7,6 +7,7 @@ import ( "fmt" "io" "net/http" + "net/url" "strings" "sync" "time" @@ -50,6 +51,9 @@ type ReadmeState int const ( ValidReadme ReadmeState = iota InvalidReadme + // GluedReadme: the literal token is present but glued to a trailing character + // (so the boundary-anchored match rejected it as a prefix of a longer name). + GluedReadme NoReadme ) @@ -98,6 +102,8 @@ func ValidateNuGet(ctx context.Context, pkg model.Package, serverName string) er return nil case InvalidReadme: return fmt.Errorf("NuGet package '%s' ownership validation for version %s failed. The server name '%s' must appear as 'mcp-name: %s' in the package README. Add it to your README and publish a new package version", pkg.Identifier, pkg.Version, serverName, serverName) + case GluedReadme: + return fmt.Errorf("NuGet package '%s' ownership validation for version %s failed: found 'mcp-name: %s' in the README, but it is immediately followed by another character rather than a boundary. The token must be followed by a space, newline, an HTML tag, or a comment close ('-->') โ€” put it on its own line and publish a new package version", pkg.Identifier, pkg.Version, serverName) case NoReadme: // Continue to check if package exists default: @@ -209,9 +215,11 @@ func validateReadme(ctx context.Context, serverName, lowerID, lowerVersion strin return NoReadme, fmt.Errorf("failed to get README URL template: %w", err) } - // Replace placeholders in the template - readmeURL := strings.ReplaceAll(readmeURLTemplate, "{lower_id}", lowerID) - readmeURL = strings.ReplaceAll(readmeURL, "{lower_version}", lowerVersion) + // Replace placeholders in the template. PathEscape both the id and version + // so a publisher cannot smuggle "/" / ".." through the template into a + // fetch against an unrelated package's README. + readmeURL := strings.ReplaceAll(readmeURLTemplate, "{lower_id}", url.PathEscape(lowerID)) + readmeURL = strings.ReplaceAll(readmeURL, "{lower_version}", url.PathEscape(lowerVersion)) req, err := http.NewRequestWithContext(ctx, http.MethodGet, readmeURL, nil) if err != nil { return NoReadme, fmt.Errorf("failed to create NuGet README request: %w", err) @@ -234,10 +242,13 @@ func validateReadme(ctx context.Context, serverName, lowerID, lowerVersion strin readmeContent := string(readmeBytes) - // Check for mcp-name: format (more specific) - mcpNamePattern := "mcp-name: " + serverName - if strings.Contains(readmeContent, mcpNamePattern) { - return ValidReadme, nil // Found as mcp-name: format + // Check for the mcp-name: ownership token (boundary-anchored + // to avoid prefix confusion โ€” see containsMCPNameToken). + if containsMCPNameToken(readmeContent, serverName) { + return ValidReadme, nil + } + if _, glued := mcpNameTokenGluedTrailing(readmeContent, serverName); glued { + return GluedReadme, nil } return InvalidReadme, nil @@ -266,8 +277,10 @@ func validatePackageExists(ctx context.Context, lowerID, lowerVersion string, cl return PackageIDNotFound, fmt.Errorf("failed to get Package Base URL: %w", err) } - // Fetch the package content index to check if package ID and version exist - indexURL := fmt.Sprintf("%s/%s/index.json", strings.TrimRight(packageBaseURL, "/"), lowerID) + // Fetch the package content index to check if package ID and version exist. + // PathEscape so an identifier that smuggles "/" or ".." cannot redirect + // the metadata fetch to a different package than the one being claimed. + indexURL := fmt.Sprintf("%s/%s/index.json", strings.TrimRight(packageBaseURL, "/"), url.PathEscape(lowerID)) req, err := http.NewRequestWithContext(ctx, http.MethodGet, indexURL, nil) if err != nil { diff --git a/internal/validators/registries/oci.go b/internal/validators/registries/oci.go index 6932d7f..f303267 100644 --- a/internal/validators/registries/oci.go +++ b/internal/validators/registries/oci.go @@ -4,7 +4,6 @@ import ( "context" "errors" "fmt" - "log" "net/http" "strings" "time" @@ -33,6 +32,8 @@ var allowedOCIRegistries = map[string]bool{ "index.docker.io": true, // Docker Hub index // GitHub Container Registry "ghcr.io": true, + // Red Hat Quay + "quay.io": true, // Microsoft Container Registry "mcr.microsoft.com": true, // Google Artifact Registry (*.pkg.dev pattern handled in isAllowedRegistry) @@ -49,6 +50,7 @@ var allowedOCIRegistries = map[string]bool{ // Supported registries: // - Docker Hub (docker.io) // - GitHub Container Registry (ghcr.io) +// - Quay.io (quay.io) // - Google Artifact Registry (*.pkg.dev) // - Microsoft Container Registry (mcr.microsoft.com) func ValidateOCI(ctx context.Context, pkg model.Package, serverName string) error { @@ -103,10 +105,13 @@ func ValidateOCI(ctx context.Context, pkg model.Package, serverName string) erro if errors.As(err, &transportErr) { switch transportErr.StatusCode { case http.StatusTooManyRequests: - // Rate limited - skip validation to avoid blocking publishers - // This is intentional: we prioritize UX over strict validation during high traffic - log.Printf("Skipping OCI validation for %s due to rate limiting", pkg.Identifier) - return nil + // Fail closed: a 429 means we could not verify the + // `io.modelcontextprotocol.server.name` label on the image, which is + // the only ownership proof we apply to OCI packages. Returning nil + // here would let a publisher bind their server record to an arbitrary + // public image they do not control, which is the bug this branch + // used to have. Surface the rate-limit as a retryable error instead. + return fmt.Errorf("OCI registry is currently rate-limiting validations for '%s'; please retry shortly", pkg.Identifier) case http.StatusNotFound: return fmt.Errorf("OCI image '%s' does not exist in the registry", pkg.Identifier) case http.StatusUnauthorized, http.StatusForbidden: diff --git a/internal/validators/registries/oci_test.go b/internal/validators/registries/oci_test.go index 634e2e5..fddf446 100644 --- a/internal/validators/registries/oci_test.go +++ b/internal/validators/registries/oci_test.go @@ -66,6 +66,13 @@ func TestValidateOCI_RegistryAllowlist(t *testing.T) { errorMsg: "missing required annotation", mustNotContainMsg: "unsupported OCI registry", }, + { + name: "Quay.io should be allowed", + identifier: "quay.io/prometheus/node-exporter:v1.7.0", + expectError: true, + errorMsg: "missing required annotation", + mustNotContainMsg: "unsupported OCI registry", + }, // Removed ACR test with non-existent host - ACR support is tested elsewhere // Disallowed registries @@ -75,12 +82,6 @@ func TestValidateOCI_RegistryAllowlist(t *testing.T) { expectError: true, errorMsg: "unsupported OCI registry", }, - { - name: "Quay.io should be rejected", - identifier: "quay.io/test/image:latest", - expectError: true, - errorMsg: "unsupported OCI registry", - }, { name: "ECR Public should be rejected", identifier: "public.ecr.aws/test/image:latest", @@ -134,8 +135,9 @@ func TestValidateOCI_RegistryAllowlist(t *testing.T) { } func TestValidateOCI_RegistryPatterns(t *testing.T) { - // This test verifies registry pattern matching (wildcards like *.azurecr.io and *.pkg.dev) - // without relying on external images that may not exist + // Verifies allowlist behavior: wildcard hosts (*.azurecr.io, *.pkg.dev) and fixed hosts + // like quay.io. shouldFail=false means the error must not be "unsupported OCI registry" + // (validation may still error later, for example missing annotation or image not found). tests := []struct { name string identifier string @@ -156,6 +158,12 @@ func TestValidateOCI_RegistryPatterns(t *testing.T) { identifier: "us-west1-docker.pkg.dev/project/repo/image:tag", shouldFail: false, }, + { + name: "Quay.io host should be allowed", + identifier: "quay.io/nonexistent/mcp-registry-fake-repo:v1", + // Past allowlist; fake repo typically yields "does not exist", not unsupported registry + shouldFail: false, + }, { name: "GCR should be rejected at registry check", identifier: "gcr.io/project/image:latest", diff --git a/internal/validators/registries/pypi.go b/internal/validators/registries/pypi.go index 62ce22e..339ed91 100644 --- a/internal/validators/registries/pypi.go +++ b/internal/validators/registries/pypi.go @@ -6,7 +6,7 @@ import ( "errors" "fmt" "net/http" - "strings" + "net/url" "time" "github.com/modelcontextprotocol/registry/pkg/model" @@ -50,15 +50,28 @@ func ValidatePyPI(ctx context.Context, pkg model.Package, serverName string) err pkg.RegistryBaseURL, model.RegistryTypePyPI, model.RegistryURLPyPI) } + return validatePyPIPackage(ctx, pkg, serverName) +} + +// validatePyPIPackage performs the version-metadata fetch and the mcp-name token +// check. It is split out from ValidatePyPI so that httptest-based tests can drive +// the HTTP pipeline against a mock server (exposed via export_test.go), bypassing +// the exact-baseURL guard that ValidatePyPI enforces for callers. +func validatePyPIPackage(ctx context.Context, pkg model.Package, serverName string) error { client := &http.Client{Timeout: 10 * time.Second} - url := fmt.Sprintf("%s/pypi/%s/%s/json", pkg.RegistryBaseURL, pkg.Identifier, pkg.Version) - req, err := http.NewRequestWithContext(ctx, http.MethodGet, url, nil) + // PathEscape so an identifier that smuggles "/" or ".." cannot redirect + // the metadata fetch to a different package than the one being claimed. + fetchURL := fmt.Sprintf("%s/pypi/%s/%s/json", + pkg.RegistryBaseURL, + url.PathEscape(pkg.Identifier), + url.PathEscape(pkg.Version)) + req, err := http.NewRequestWithContext(ctx, http.MethodGet, fetchURL, nil) if err != nil { return fmt.Errorf("failed to create request: %w", err) } - req.Header.Set("User-Agent", "MCP-Registry-Validator/1.0") + req.Header.Set("User-Agent", userAgent) req.Header.Set("Accept", "application/json") resp, err := client.Do(req) @@ -68,7 +81,7 @@ func ValidatePyPI(ctx context.Context, pkg model.Package, serverName string) err defer resp.Body.Close() if resp.StatusCode != http.StatusOK { - return fmt.Errorf("PyPI package '%s' not found (status: %d)", pkg.Identifier, resp.StatusCode) + return pypiFetchStatusError(ctx, client, pkg, resp.StatusCode) } var pypiResp PyPIPackageResponse @@ -79,11 +92,104 @@ func ValidatePyPI(ctx context.Context, pkg model.Package, serverName string) err // Check description (README) content description := pypiResp.Info.Description - // Check for mcp-name: format (more specific) - mcpNamePattern := "mcp-name: " + serverName - if strings.Contains(description, mcpNamePattern) { - return nil // Found as mcp-name: format + // Check for the mcp-name: ownership token (boundary-anchored to + // avoid prefix confusion โ€” see containsMCPNameToken). + if containsMCPNameToken(description, serverName) { + return nil + } + + // If the token IS present but glued to a trailing character, say so โ€” otherwise + // the publisher sees "must appear as mcp-name: X" while looking at exactly that. + if trailing, glued := mcpNameTokenGluedTrailing(description, serverName); glued { + return fmt.Errorf("PyPI package '%s' ownership validation failed: found 'mcp-name: %s' in the README, but it is immediately followed by %q rather than a boundary. The token must be followed by a space, newline, an HTML tag, or a comment close ('-->') โ€” put it on its own line and republish", pkg.Identifier, serverName, trailing) } return fmt.Errorf("PyPI package '%s' ownership validation failed. The server name '%s' must appear as 'mcp-name: %s' in the package README", pkg.Identifier, serverName, serverName) } + +// pypiPackageState is the outcome of probing the package-level PyPI metadata +// endpoint, used to disambiguate a 404 from the version-specific endpoint. +type pypiPackageState int + +const ( + // pypiPackageUnknown: the probe returned a status we can't classify. + pypiPackageUnknown pypiPackageState = iota + // pypiPackageExists: the package exists (200) but the requested version does not. + pypiPackageExists + // pypiPackageMissing: the package itself does not exist (404). + pypiPackageMissing + // pypiPackageTransient: the probe failed for a retryable reason (network error, + // 429, or 5xx). Existence is undetermined and the caller should not report + // "not found". + pypiPackageTransient +) + +// pypiFetchStatusError maps a non-200 status from the version-specific metadata +// endpoint to a caller-actionable error. A 404 is delegated to pypiVersion404Error +// for disambiguation. 429/5xx are transient, not "not found". +func pypiFetchStatusError(ctx context.Context, client *http.Client, pkg model.Package, status int) error { + switch { + case status == http.StatusNotFound: + return pypiVersion404Error(ctx, client, pkg) + case status == http.StatusTooManyRequests: + return fmt.Errorf("PyPI rate-limited the metadata request for package '%s' (status: 429). Likely transient, retry later", pkg.Identifier) + case status >= 500 && status < 600: + return fmt.Errorf("PyPI upstream error fetching metadata for package '%s' (status: %d). Likely transient, retry later", pkg.Identifier, status) + default: + return fmt.Errorf("PyPI package '%s' metadata fetch failed (status: %d)", pkg.Identifier, status) + } +} + +// pypiVersion404Error disambiguates a 404 from the version-specific endpoint: a +// genuinely-missing package versus a package that exists but whose requested +// version is absent (commonly because a freshly published release has not yet +// propagated). It probes the package-level endpoint so the publisher gets an +// actionable message rather than a blanket "not found". +func pypiVersion404Error(ctx context.Context, client *http.Client, pkg model.Package) error { + switch probePyPIPackage(ctx, client, pkg.RegistryBaseURL, pkg.Identifier) { + case pypiPackageExists: + return fmt.Errorf("PyPI package '%s' exists, but version '%s' was not found (status: 404). A newly published release can take a moment to appear on PyPI. Wait and retry, or publish version '%s' before registering it", pkg.Identifier, pkg.Version, pkg.Version) + case pypiPackageMissing: + return fmt.Errorf("PyPI package '%s' not found (status: 404)", pkg.Identifier) + case pypiPackageTransient: + return fmt.Errorf("PyPI could not confirm package '%s' version '%s' (version status: 404, package check inconclusive). Likely transient, retry later", pkg.Identifier, pkg.Version) + case pypiPackageUnknown: + // Probe returned an unclassifiable status, so fall through to the + // best-effort message below. + } + return fmt.Errorf("PyPI package '%s' version '%s' not found (status: 404)", pkg.Identifier, pkg.Version) +} + +// probePyPIPackage checks whether a package exists on PyPI regardless of version, +// with a HEAD request to the package-level endpoint (/pypi/{name}/json). Only the +// status code is used, so HEAD avoids downloading the (large) all-versions body. +func probePyPIPackage(ctx context.Context, client *http.Client, baseURL, identifier string) pypiPackageState { + // The probe only refines the 404 error message, so it must not extend the + // validator's worst case by another full client timeout. + ctx, cancel := context.WithTimeout(ctx, 3*time.Second) + defer cancel() + + probeURL := fmt.Sprintf("%s/pypi/%s/json", baseURL, url.PathEscape(identifier)) + req, err := http.NewRequestWithContext(ctx, http.MethodHead, probeURL, nil) + if err != nil { + return pypiPackageUnknown + } + req.Header.Set("User-Agent", userAgent) + + resp, err := client.Do(req) + if err != nil { + return pypiPackageTransient + } + defer resp.Body.Close() + + switch { + case resp.StatusCode == http.StatusOK: + return pypiPackageExists + case resp.StatusCode == http.StatusNotFound: + return pypiPackageMissing + case resp.StatusCode == http.StatusTooManyRequests, resp.StatusCode >= 500 && resp.StatusCode < 600: + return pypiPackageTransient + default: + return pypiPackageUnknown + } +} diff --git a/internal/validators/registries/pypi_test.go b/internal/validators/registries/pypi_test.go index aadb05f..e240082 100644 --- a/internal/validators/registries/pypi_test.go +++ b/internal/validators/registries/pypi_test.go @@ -2,13 +2,174 @@ package registries_test import ( "context" + "fmt" + "io" + "net/http" + "net/http/httptest" + "strings" "testing" + "time" "github.com/modelcontextprotocol/registry/internal/validators/registries" "github.com/modelcontextprotocol/registry/pkg/model" "github.com/stretchr/testify/assert" ) +// newPyPIMock stands in for pypi.org: it routes the version fetch and package +// probe by path shape and returns the given statuses (versionBody is used on 200). +func newPyPIMock(versionStatus int, versionBody string, packageStatus int) *httptest.Server { + return httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + // Route on the escaped path so an identifier containing an encoded + // separator is not silently re-split into extra segments. + parts := strings.Split(strings.Trim(r.URL.EscapedPath(), "/"), "/") + // Pin the method per endpoint (GET fetch, HEAD probe) so a method + // regression in the validator surfaces as a 405 instead of passing. + switch len(parts) { + case 4: // /pypi/{name}/{version}/json + if r.Method != http.MethodGet { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + if versionStatus != http.StatusOK { + w.WriteHeader(versionStatus) + return + } + w.Header().Set("Content-Type", "application/json") + _, _ = io.WriteString(w, versionBody) + case 3: // /pypi/{name}/json (package-existence probe) + if r.Method != http.MethodHead { + w.WriteHeader(http.StatusMethodNotAllowed) + return + } + w.WriteHeader(packageStatus) + default: + w.WriteHeader(http.StatusInternalServerError) + } + })) +} + +// TestValidatePyPI_VersionNotYetVisible is the #553 regression: version 404s while +// the package exists, so the error must report a missing version, not a missing package. +func TestValidatePyPI_VersionNotYetVisible(t *testing.T) { + ctx := context.Background() + mock := newPyPIMock(http.StatusNotFound, "", http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "9.9.9"} + err := registries.ValidatePyPIPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "exists, but version '9.9.9'", "package-exists/version-missing must be distinguished from package-missing") +} + +// TestValidatePyPI_PackageMissing: both the version and the package endpoints 404, +// so the package genuinely does not exist and "not found" is correct. +func TestValidatePyPI_PackageMissing(t *testing.T) { + ctx := context.Background() + mock := newPyPIMock(http.StatusNotFound, "", http.StatusNotFound) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidatePyPIPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "not found") + assert.NotContains(t, err.Error(), "exists, but version", "a genuinely missing package must not claim the version exists") +} + +// TestValidatePyPI_TransientUpstream: a 5xx on the version fetch is upstream +// availability, not "package missing", and must be reported as retryable. +func TestValidatePyPI_TransientUpstream(t *testing.T) { + ctx := context.Background() + mock := newPyPIMock(http.StatusServiceUnavailable, "", http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidatePyPIPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "transient") + assert.NotContains(t, err.Error(), "not found", "transient upstream errors must not be reported as 'not found'") +} + +// TestValidatePyPI_VersionNotFoundProbeInconclusive: version 404 plus a transient +// probe (429) leaves existence undetermined, so the validator must not say "not found". +func TestValidatePyPI_VersionNotFoundProbeInconclusive(t *testing.T) { + ctx := context.Background() + mock := newPyPIMock(http.StatusNotFound, "", http.StatusTooManyRequests) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidatePyPIPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "transient") + assert.NotContains(t, err.Error(), "not found", "an inconclusive probe must not assert the package is missing") +} + +// TestValidatePyPI_ProbeDeadlineBounded: a hung probe must be cut off by the +// probe's own short deadline instead of riding out the client's full 10s +// timeout, and the cutoff must read as inconclusive rather than "not found". +func TestValidatePyPI_ProbeDeadlineBounded(t *testing.T) { + ctx := context.Background() + mock := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + parts := strings.Split(strings.Trim(r.URL.EscapedPath(), "/"), "/") + if len(parts) == 4 { // version fetch + w.WriteHeader(http.StatusNotFound) + return + } + // Package probe: hang until the client gives up. + <-r.Context().Done() + })) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + start := time.Now() + err := registries.ValidatePyPIPackage(ctx, pkg, "io.github.test/demo") + elapsed := time.Since(start) + assert.Error(t, err) + assert.Contains(t, err.Error(), "transient", "a probe cut off by its deadline is inconclusive, not 'not found'") + assert.Less(t, elapsed, 8*time.Second, "a hung probe must be bounded by the probe deadline, not the client timeout") +} + +// TestValidatePyPI_VersionEndpointRateLimited: a 429 on the version fetch is reported +// as rate-limited/transient. +func TestValidatePyPI_VersionEndpointRateLimited(t *testing.T) { + ctx := context.Background() + mock := newPyPIMock(http.StatusTooManyRequests, "", http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidatePyPIPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "rate-limited") + assert.NotContains(t, err.Error(), "not found") +} + +// TestValidatePyPI_VersionNotFoundProbeUnclassified: the version 404s and the probe +// returns an unclassifiable status, so the validator falls back to a plain +// version-not-found message without claiming the package is present or absent. +func TestValidatePyPI_VersionNotFoundProbeUnclassified(t *testing.T) { + ctx := context.Background() + mock := newPyPIMock(http.StatusNotFound, "", http.StatusTeapot) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidatePyPIPackage(ctx, pkg, "io.github.test/demo") + assert.Error(t, err) + assert.Contains(t, err.Error(), "version '1.0.0' not found") + assert.NotContains(t, err.Error(), "exists, but version") +} + +// TestValidatePyPI_PositivePathMock: a version README carrying the exact mcp-name token validates. +func TestValidatePyPI_PositivePathMock(t *testing.T) { + ctx := context.Background() + const serverName = "io.github.test/demo" + body := fmt.Sprintf(`{"info":{"description":"# Demo\n\nmcp-name: %s\n"}}`, serverName) + mock := newPyPIMock(http.StatusOK, body, http.StatusOK) + defer mock.Close() + + pkg := model.Package{RegistryType: model.RegistryTypePyPI, RegistryBaseURL: mock.URL, Identifier: "demo-pkg", Version: "1.0.0"} + err := registries.ValidatePyPIPackage(ctx, pkg, serverName) + assert.NoError(t, err, "a version README containing the exact mcp-name token should validate") +} + func TestValidatePyPI_RealPackages(t *testing.T) { ctx := context.Background() @@ -79,6 +240,12 @@ func TestValidatePyPI_RealPackages(t *testing.T) { err := registries.ValidatePyPI(ctx, pkg, tt.serverName) + // A live 429/5xx from the registry is inconclusive, not a failure + // of the case under test. + if err != nil && strings.Contains(err.Error(), "retry later") { + t.Skipf("transient registry response: %v", err) + } + if tt.expectError { assert.Error(t, err) assert.Contains(t, err.Error(), tt.errorMessage) diff --git a/internal/validators/schemas/2025-12-11.json b/internal/validators/schemas/2025-12-11.json index 9f6469b..718aaca 100644 --- a/internal/validators/schemas/2025-12-11.json +++ b/internal/validators/schemas/2025-12-11.json @@ -239,6 +239,7 @@ "examples": [ "https://registry.npmjs.org", "https://pypi.org", + "https://crates.io", "https://docker.io", "https://api.nuget.org/v3/index.json", "https://github.com", @@ -252,6 +253,7 @@ "examples": [ "npm", "pypi", + "cargo", "oci", "nuget", "mcpb" @@ -283,6 +285,7 @@ "description": "Package version. Must be a specific version. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '\u003e=1.2.3', '1.x', '1.*').", "example": "1.0.2", "minLength": 1, + "maxLength": 255, "not": { "const": "latest" }, diff --git a/internal/validators/utils.go b/internal/validators/utils.go index 035132d..2e1aea7 100644 --- a/internal/validators/utils.go +++ b/internal/validators/utils.go @@ -6,6 +6,11 @@ import ( "strings" ) +const ( + schemeHTTP = "http" + schemeHTTPS = "https" +) + var ( // Regular expressions for validating repository URLs // These regex patterns ensure the URL is in the format of a valid GitHub or GitLab repository @@ -52,8 +57,8 @@ func replaceTemplateVariables(rawURL string) string { "{host}": "example.com", "{port}": "8080", "{path}": "api", - "{protocol}": "http", - "{scheme}": "http", + "{protocol}": schemeHTTP, + "{scheme}": schemeHTTP, } result := rawURL @@ -86,7 +91,7 @@ func IsValidURL(rawURL string) bool { } // Check if scheme is present (http or https) - if u.Scheme != "http" && u.Scheme != "https" { + if u.Scheme != schemeHTTP && u.Scheme != schemeHTTPS { return false } @@ -153,7 +158,7 @@ func IsValidRemoteURL(rawURL string) bool { return false } - if u.Scheme != "https" { + if u.Scheme != schemeHTTPS { return false } diff --git a/internal/validators/validators.go b/internal/validators/validators.go index 4da756d..114ed3c 100644 --- a/internal/validators/validators.go +++ b/internal/validators/validators.go @@ -195,6 +195,20 @@ func validateWebsiteURL(ctx *ValidationContext, websiteURL string) *ValidationRe result.AddIssue(issue) } + // Reject characters that aren't valid in a URI per RFC 3986 and that have + // caused rendering issues when websiteUrl flows into the catalogue UI's + // href attributes. Publishers should percent-encode these in the source URL. + if i := strings.IndexAny(websiteURL, "\"'<> \t\n\r"); i >= 0 { + issue := NewValidationIssue( + ValidationIssueTypeSemantic, + ctx.String(), + fmt.Sprintf("websiteUrl contains an invalid character %q at position %d: %s", websiteURL[i], i, websiteURL), + ValidationIssueSeverityError, + "website-url-invalid-characters", + ) + result.AddIssue(issue) + } + return result } diff --git a/internal/validators/validators_test.go b/internal/validators/validators_test.go index d4ff5c1..c3e5585 100644 --- a/internal/validators/validators_test.go +++ b/internal/validators/validators_test.go @@ -13,6 +13,8 @@ import ( "github.com/modelcontextprotocol/registry/pkg/model" ) +const websiteURLInvalidCharErrSubstr = "websiteUrl contains an invalid character" + func TestValidate(t *testing.T) { tests := []struct { name string @@ -486,6 +488,98 @@ func TestValidate(t *testing.T) { }, expectedError: "invalid websiteUrl:", }, + { + name: "server with websiteUrl containing double quote", + serverDetail: apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "com.example/test-server", + Description: "A test server", + Repository: &model.Repository{ + URL: "https://github.com/owner/repo", + Source: "github", + }, + Version: "1.0.0", + WebsiteURL: `https://example.com/"oops`, + }, + expectedError: websiteURLInvalidCharErrSubstr, + }, + { + name: "server with websiteUrl containing single quote", + serverDetail: apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "com.example/test-server", + Description: "A test server", + Repository: &model.Repository{ + URL: "https://github.com/owner/repo", + Source: "github", + }, + Version: "1.0.0", + WebsiteURL: "https://example.com/it's", + }, + expectedError: websiteURLInvalidCharErrSubstr, + }, + { + name: "server with websiteUrl containing angle brackets", + serverDetail: apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "com.example/test-server", + Description: "A test server", + Repository: &model.Repository{ + URL: "https://github.com/owner/repo", + Source: "github", + }, + Version: "1.0.0", + WebsiteURL: "https://example.com/", + }, + expectedError: websiteURLInvalidCharErrSubstr, + }, + { + name: "server with websiteUrl containing space", + serverDetail: apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "com.example/test-server", + Description: "A test server", + Repository: &model.Repository{ + URL: "https://github.com/owner/repo", + Source: "github", + }, + Version: "1.0.0", + WebsiteURL: "https://example.com/has space", + }, + expectedError: websiteURLInvalidCharErrSubstr, + }, + { + name: "server with websiteUrl containing newline", + serverDetail: apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "com.example/test-server", + Description: "A test server", + Repository: &model.Repository{ + URL: "https://github.com/owner/repo", + Source: "github", + }, + Version: "1.0.0", + WebsiteURL: "https://example.com/has\nnewline", + }, + // url.Parse rejects ASCII control chars before our character-set + // check runs; either path produces a validation error. + expectedError: "invalid websiteUrl:", + }, + { + name: "server with websiteUrl with percent-encoded special chars is accepted", + serverDetail: apiv0.ServerJSON{ + Schema: model.CurrentSchemaURL, + Name: "com.example/test-server", + Description: "A test server", + Repository: &model.Repository{ + URL: "https://github.com/owner/repo", + Source: "github", + }, + Version: "1.0.0", + WebsiteURL: "https://example.com/path/?q=hello%20world&r=a%22b", + }, + expectedError: "", + }, { name: "server with websiteUrl that matches namespace domain", serverDetail: apiv0.ServerJSON{ diff --git a/pkg/api/v0/types.go b/pkg/api/v0/types.go index de78a91..67fe094 100644 --- a/pkg/api/v0/types.go +++ b/pkg/api/v0/types.go @@ -39,7 +39,7 @@ type ServerJSON struct { Description string `json:"description" minLength:"1" maxLength:"100" doc:"Clear human-readable explanation of server functionality." example:"MCP server providing weather data and forecasts via OpenWeatherMap API"` Title string `json:"title,omitempty" minLength:"1" maxLength:"100" doc:"Optional human-readable title or display name for the MCP server." example:"Weather API"` Repository *model.Repository `json:"repository,omitempty" doc:"Optional repository metadata for the MCP server source code."` - Version string `json:"version" doc:"Version string for this server. SHOULD follow semantic versioning." example:"1.0.2"` + Version string `json:"version" minLength:"1" maxLength:"255" doc:"Version string for this server. SHOULD follow semantic versioning." example:"1.0.2"` WebsiteURL string `json:"websiteUrl,omitempty" format:"uri" doc:"Optional URL to the server's homepage, documentation, or project website." example:"https://modelcontextprotocol.io/examples"` Icons []model.Icon `json:"icons,omitempty" doc:"Optional set of sized icons that the client can display in a user interface."` Packages []model.Package `json:"packages,omitempty" doc:"Array of package configurations"` diff --git a/pkg/model/constants.go b/pkg/model/constants.go index e817f2a..98a3ba1 100644 --- a/pkg/model/constants.go +++ b/pkg/model/constants.go @@ -7,15 +7,18 @@ const ( RegistryTypeOCI = "oci" RegistryTypeNuGet = "nuget" RegistryTypeMCPB = "mcpb" + RegistryTypeCargo = "cargo" ) // Registry Base URLs - supported package registry base URLs const ( - RegistryURLNPM = "https://registry.npmjs.org" - RegistryURLPyPI = "https://pypi.org" - RegistryURLNuGet = "https://api.nuget.org/v3/index.json" + RegistryURLCrates = "https://crates.io" RegistryURLGitHub = "https://github.com" RegistryURLGitLab = "https://gitlab.com" + RegistryURLNPM = "https://registry.npmjs.org" + RegistryURLNuGet = "https://api.nuget.org/v3/index.json" + RegistryURLPyPI = "https://pypi.org" + RegistryURLQuay = "https://quay.io" ) // Transport Types - supported remote transport protocols diff --git a/pkg/model/types.go b/pkg/model/types.go index 03d2841..e9ade02 100644 --- a/pkg/model/types.go +++ b/pkg/model/types.go @@ -22,12 +22,13 @@ type Transport struct { // - NPM: RegistryType, Identifier (package name), Version, RegistryBaseURL (optional) // - PyPI: RegistryType, Identifier (package name), Version, RegistryBaseURL (optional) // - NuGet: RegistryType, Identifier (package ID), Version, RegistryBaseURL (optional) +// - Cargo: RegistryType, Identifier (crate name), Version, RegistryBaseURL (optional) // - OCI: RegistryType, Identifier (full image reference like "ghcr.io/owner/repo:tag") // - MCPB: RegistryType, Identifier (download URL), Version (optional), FileSHA256 (required) type Package struct { - // RegistryType indicates how to download packages (e.g., "npm", "pypi", "oci", "nuget", "mcpb") - RegistryType string `json:"registryType" minLength:"1" doc:"Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'oci', 'nuget', 'mcpb')" example:"npm"` - // RegistryBaseURL is the base URL of the package registry (used by npm, pypi, nuget; not used by oci, mcpb) + // RegistryType indicates how to download packages (e.g., "npm", "pypi", "cargo", "oci", "nuget", "mcpb") + RegistryType string `json:"registryType" minLength:"1" doc:"Registry type indicating how to download packages (e.g., 'npm', 'pypi', 'cargo', 'oci', 'nuget', 'mcpb')" example:"npm"` + // RegistryBaseURL is the base URL of the package registry (used by npm, pypi, nuget, cargo; not used by oci, mcpb) RegistryBaseURL string `json:"registryBaseUrl,omitempty" format:"uri" doc:"Base URL of the package registry" example:"https://registry.npmjs.org"` // Identifier is the package identifier: // - For NPM/PyPI/NuGet: package name or ID @@ -35,7 +36,7 @@ type Package struct { // - For MCPB: direct download URL Identifier string `json:"identifier" minLength:"1" doc:"Package identifier - either a package name (for registries) or URL (for direct downloads)" example:"@modelcontextprotocol/server-brave-search"` // Version is the package version (required for npm, pypi, nuget; optional for mcpb; not used by oci where version is in the identifier) - Version string `json:"version,omitempty" minLength:"1" doc:"Package version. Must be a specific version. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '>=1.2.3', '1.x', '1.*')." example:"1.0.2"` + Version string `json:"version,omitempty" minLength:"1" maxLength:"255" doc:"Package version. Must be a specific version. Version ranges are rejected (e.g., '^1.2.3', '~1.2.3', '>=1.2.3', '1.x', '1.*')." example:"1.0.2"` // FileSHA256 is the SHA-256 hash for integrity verification (required for mcpb, optional for others) FileSHA256 string `json:"fileSha256,omitempty" pattern:"^[a-f0-9]{64}$" doc:"SHA-256 hash of the package file for integrity verification. Required for MCPB packages and optional for other package types. Authors are responsible for generating correct SHA-256 hashes when creating server.json. If present, MCP clients must validate the downloaded file matches the hash before running packages to ensure file integrity." example:"fe333e598595000ae021bd27117db32ec69af6987f507ba7a63c90638ff633ce"` // RunTimeHint suggests the appropriate runtime for the package diff --git a/scripts/mirror_data/README.md b/scripts/mirror_data/README.md index 3237211..2cc3a87 100644 --- a/scripts/mirror_data/README.md +++ b/scripts/mirror_data/README.md @@ -14,7 +14,7 @@ These scripts help you: ## Prerequisites -- Go 1.24.x +- Go โ€” see the [prerequisites in the root README](../../README.md#pre-requisites) for the required version - PostgreSQL (via Docker or local installation) - Required Go packages: ```bash @@ -31,7 +31,7 @@ go run scripts/mirror_data/fetch_production_data.go ``` This will: -- Fetch all servers from https://registry.modelcontextprotocol.io/v0.1/servers +- Fetch all servers from https://registry.modelcontextprotocol.io/v0/servers - Handle pagination automatically - Save data to `scripts/mirror_data/production_servers.json` - Be respectful to the API with rate limiting @@ -71,7 +71,7 @@ This will: 4. Analyze the data and report statistics 5. Show sample servers with NULL status values -To test a different migration, edit `maxMigration` in the script (line 24) +To test a different migration, edit `maxMigration` in `load_production_data.go` ### 4. Test Migrations @@ -80,8 +80,8 @@ After loading the data, you can test migrations against real production data. #### Testing a Single Migration ```bash -# Test migration 008 -cat internal/database/migrations/008_separate_official_metadata.sql | \ +# Test the separate_official_metadata migration +cat internal/database/migrations/009_separate_official_metadata.sql | \ docker exec -i test-postgres psql -U postgres -d registry_test ``` @@ -90,7 +90,7 @@ cat internal/database/migrations/008_separate_official_metadata.sql | \ 1. **Check the error output:** ```bash # Run migration and capture all output -cat internal/database/migrations/008_separate_official_metadata.sql | \ +cat internal/database/migrations/009_separate_official_metadata.sql | \ docker exec -i test-postgres psql -U postgres -d registry_test 2>&1 | \ grep -E "(ERROR|NOTICE|WARNING)" ``` @@ -126,7 +126,7 @@ EOF # Start a transaction to test and rollback docker exec test-postgres psql -U postgres -d registry_test < /dev/null; then @@ -11,19 +13,23 @@ fi OIDC_TOKEN=$(gcloud auth print-identity-token) # Exchange for registry token -RESPONSE=$(curl -s -X POST "${REGISTRY_URL}/v0/auth/oidc" \ +RESPONSE=$(curl -sS -X POST "${REGISTRY_URL}/v0/auth/oidc" \ -H "Content-Type: application/json" \ -d "{\"oidc_token\": \"${OIDC_TOKEN}\"}") # Check if successful -REGISTRY_TOKEN=$(echo "$RESPONSE" | jq -r '.registry_token // empty') +if ! REGISTRY_TOKEN=$(printf '%s\n' "$RESPONSE" | jq -r '.registry_token // empty' 2>/dev/null); then + REGISTRY_TOKEN="" +fi if [ -z "$REGISTRY_TOKEN" ]; then echo "Error: Authentication failed" >&2 - echo "$RESPONSE" | jq '.' >&2 + if ! printf '%s\n' "$RESPONSE" | jq '.' >&2 2>/dev/null; then + printf '%s\n' "$RESPONSE" >&2 + fi exit 1 fi # Output the export command echo "# Successfully authenticated! Now run this to use your token:" >&2 -echo "export REGISTRY_TOKEN='${REGISTRY_TOKEN}'" \ No newline at end of file +echo "export REGISTRY_TOKEN='${REGISTRY_TOKEN}'" diff --git a/tools/admin/takedown.sh b/tools/admin/takedown.sh index d53babf..f9fceed 100755 --- a/tools/admin/takedown.sh +++ b/tools/admin/takedown.sh @@ -1,30 +1,87 @@ #!/bin/bash -# Simple takedown script +# Set the lifecycle status of an MCP server, either for one version or for every version. + +set -euo pipefail REGISTRY_URL="${REGISTRY_URL:-https://registry.modelcontextprotocol.io}" +STATUS="${STATUS:-deleted}" +SERVER_NAME="${SERVER_NAME:-}" +VERSION="${VERSION:-}" +ALL_VERSIONS="${ALL_VERSIONS:-}" +STATUS_MESSAGE="${STATUS_MESSAGE:-}" -if [ -z "$SERVER_NAME" ] || [ -z "$REGISTRY_TOKEN" ]; then - echo "Usage: REGISTRY_TOKEN= SERVER_NAME= [VERSION=] $0" - echo "Example: REGISTRY_TOKEN=token SERVER_NAME=com.example/my-server ./takedown.sh" - echo "Example: REGISTRY_TOKEN=token SERVER_NAME=com.example/my-server VERSION=1.0.0 ./takedown.sh" +usage() { + cat <<'EOF' +Usage: + REGISTRY_TOKEN= SERVER_NAME= VERSION= ./takedown.sh + REGISTRY_TOKEN= SERVER_NAME= ALL_VERSIONS=true ./takedown.sh + +Examples: + REGISTRY_TOKEN=token SERVER_NAME=com.example/my-server VERSION=1.0.0 ./takedown.sh + REGISTRY_TOKEN=token SERVER_NAME=com.example/my-server ALL_VERSIONS=true ./takedown.sh + +Optional environment variables: + STATUS active | deprecated | deleted (default: deleted) + STATUS_MESSAGE reason recorded alongside the status change (max 500 characters) + REGISTRY_URL registry base URL (default: https://registry.modelcontextprotocol.io) +EOF +} + +if [ -z "$SERVER_NAME" ] || [ -z "${REGISTRY_TOKEN:-}" ]; then + usage exit 1 fi -# URL encode the server name (replace / with %2F) -ENCODED_SERVER_NAME=$(echo "$SERVER_NAME" | sed 's|/|%2F|g') - -# Determine the endpoint based on whether VERSION is provided -if [ -n "$VERSION" ]; then - # Mark specific version as deleted - ENDPOINT="${REGISTRY_URL}/v0/servers/${ENCODED_SERVER_NAME}/versions/${VERSION}?status=deleted" - echo "Marking version $VERSION of server $SERVER_NAME as deleted..." -else - # Mark entire server as deleted (latest version) - ENDPOINT="${REGISTRY_URL}/v0/servers/${ENCODED_SERVER_NAME}?status=deleted" - echo "Marking server $SERVER_NAME as deleted..." +# Require an explicit choice, so that a forgotten VERSION cannot silently take +# down every version of a server. +if [ -n "$ALL_VERSIONS" ] && [ "$ALL_VERSIONS" != "true" ]; then + echo "Error: ALL_VERSIONS must be exactly true when set." >&2 + exit 1 +fi +if [ -n "$VERSION" ] && [ -n "$ALL_VERSIONS" ]; then + echo "Error: set either VERSION or ALL_VERSIONS, not both." >&2 + exit 1 +fi +if [ -z "$VERSION" ] && [ -z "$ALL_VERSIONS" ]; then + echo "Error: set VERSION= for a single version, or ALL_VERSIONS=true for every version." >&2 + echo >&2 + usage + exit 1 fi -# Update server status to deleted -curl -X PUT "$ENDPOINT" \ +# URL encode the server name and version (replace / with %2F) +ENCODED_SERVER_NAME="${SERVER_NAME//\//%2F}" + +if [ -n "$VERSION" ]; then + ENCODED_VERSION="${VERSION//\//%2F}" + ENDPOINT="${REGISTRY_URL}/v0/servers/${ENCODED_SERVER_NAME}/versions/${ENCODED_VERSION}/status" + echo "Setting version ${VERSION} of ${SERVER_NAME} to '${STATUS}'..." +else + ENDPOINT="${REGISTRY_URL}/v0/servers/${ENCODED_SERVER_NAME}/status" + echo "Setting ALL versions of ${SERVER_NAME} to '${STATUS}'..." +fi + +if [ -n "$STATUS_MESSAGE" ]; then + BODY=$(jq -n --arg status "$STATUS" --arg message "$STATUS_MESSAGE" \ + '{status: $status, statusMessage: $message}') +else + BODY=$(jq -n --arg status "$STATUS" '{status: $status}') +fi + +RESPONSE_BODY=$(mktemp) +trap 'rm -f "$RESPONSE_BODY"' EXIT + +HTTP_CODE=$(curl -sS -X PATCH "$ENDPOINT" \ -H "Authorization: Bearer ${REGISTRY_TOKEN}" \ - -H "Content-Type: application/json" \ No newline at end of file + -H "Content-Type: application/json" \ + -d "$BODY" \ + -o "$RESPONSE_BODY" \ + -w '%{http_code}') + +cat "$RESPONSE_BODY" +echo + +if [ "$HTTP_CODE" -lt 200 ] || [ "$HTTP_CODE" -ge 300 ]; then + echo "Request failed with HTTP ${HTTP_CODE}" >&2 + exit 1 +fi diff --git a/tools/extract-server-schema/main.go b/tools/extract-server-schema/main.go index a90aa2d..e7e5bd1 100644 --- a/tools/extract-server-schema/main.go +++ b/tools/extract-server-schema/main.go @@ -14,6 +14,9 @@ import ( const ( openAPIPath = "docs/reference/api/openapi.yaml" schemaOutputDir = "docs/reference/server-json/draft" + + // refKey is the JSON Schema reference key. + refKey = "$ref" ) func main() { @@ -99,7 +102,7 @@ func main() { "$schema": "http://json-schema.org/draft-07/schema#", "$id": schemaID, "title": "server.json defining a Model Context Protocol (MCP) server", - "$ref": "#/definitions/ServerDetail", + refKey: "#/definitions/ServerDetail", "definitions": definitions, } @@ -148,7 +151,7 @@ func findReferencedSchemas(obj interface{}, found map[string]bool) { switch v := obj.(type) { case map[string]interface{}: for key, value := range v { - if key == "$ref" { + if key == refKey { if ref, ok := value.(string); ok { // Extract schema name from #/components/schemas/SchemaName if strings.HasPrefix(ref, "#/components/schemas/") { @@ -173,7 +176,7 @@ func replaceComponentRefs(obj interface{}) interface{} { case map[string]interface{}: result := make(map[string]interface{}) for key, value := range v { - if key == "$ref" { + if key == refKey { if ref, ok := value.(string); ok { // Replace the reference path result[key] = strings.ReplaceAll(ref, "#/components/schemas/", "#/definitions/") diff --git a/tools/validate-examples/main.go b/tools/validate-examples/main.go index 54a7e4b..4c48ae6 100644 --- a/tools/validate-examples/main.go +++ b/tools/validate-examples/main.go @@ -33,7 +33,7 @@ func main() { func runValidation() error { // Define what we validate and how - expectedServerJSONCount := 15 + expectedServerJSONCount := 17 targets := []validationTarget{ { path: filepath.Join("docs", "reference", "server-json", "generic-server-json.md"),