|
| 1 | +#!/bin/bash |
| 2 | + |
| 3 | +# Publish MCP Server to Registry |
| 4 | +# Usage: ./script/publish-mcp-server [--init] [--validate] [--dry-run] |
| 5 | + |
| 6 | +set -e |
| 7 | + |
| 8 | +# Options |
| 9 | +INIT=false |
| 10 | +## Always validate server.json and version |
| 11 | +DRY_RUN=false |
| 12 | + |
| 13 | +for arg in "$@"; do |
| 14 | + case $arg in |
| 15 | + --init) |
| 16 | + INIT=true |
| 17 | + ;; |
| 18 | + # --validate flag removed; validation always runs |
| 19 | + --dry-run) |
| 20 | + DRY_RUN=true |
| 21 | + ;; |
| 22 | + esac |
| 23 | +done |
| 24 | + |
| 25 | +# Step 1: Ensure mcp-publisher is installed |
| 26 | +if ! command -v mcp-publisher &> /dev/null; then |
| 27 | + echo "mcp-publisher not found. Installing with Homebrew..." |
| 28 | + if command -v brew &> /dev/null; then |
| 29 | + brew install mcp-publisher |
| 30 | + else |
| 31 | + echo "Homebrew not found. Please install mcp-publisher manually:" |
| 32 | + echo "curl -L \"https://github.com/modelcontextprotocol/registry/releases/download/v1.0.0/mcp-publisher_1.0.0_$(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/" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | +fi |
| 36 | + |
| 37 | +# Step 2: Initialize server.json if requested |
| 38 | +if [ "$INIT" = true ]; then |
| 39 | + echo "Initializing server.json..." |
| 40 | + mcp-publisher init |
| 41 | +fi |
| 42 | + |
| 43 | +# Step 3: Authenticate (GitHub for io.github.*) |
| 44 | +if ! mcp-publisher whoami &> /dev/null; then |
| 45 | + echo "Authenticating with MCP registry (GitHub)..." |
| 46 | + mcp-publisher login github |
| 47 | +fi |
| 48 | + |
| 49 | +# Step 4: Validate server.json schema |
| 50 | +echo "Validating server.json version against latest release tag..." |
| 51 | +# Get latest release tag |
| 52 | +LATEST_TAG=$(git tag --sort=-version:refname | grep -E '^v[0-9]+\.[0-9]+\.[0-9]+(-.*)?$' | head -n 1) |
| 53 | +if [ -z "$LATEST_TAG" ]; then |
| 54 | + echo "❌ No release tag found. Cannot set version." |
| 55 | + exit 1 |
| 56 | +fi |
| 57 | +TAG_VERSION=$(echo "$LATEST_TAG" | sed 's/^v//') |
| 58 | +# Set server.json version and all package versions to latest tag |
| 59 | +jq ".version = \"$TAG_VERSION\" | .packages[].version = \"$TAG_VERSION\"" server.json > server.json.tmp && mv server.json.tmp server.json |
| 60 | +echo "Set server.json version and all package versions to $TAG_VERSION (from latest release tag $LATEST_TAG)." |
| 61 | +# Show user and confirm |
| 62 | +echo "Please confirm this is the correct version to publish: $TAG_VERSION (latest tag: $LATEST_TAG)" |
| 63 | +read -p "Proceed with this version? (y/n) " -n 1 -r |
| 64 | +echo |
| 65 | +if [[ ! $REPLY =~ ^[Yy]$ ]]; then |
| 66 | + echo "Publish cancelled by user." |
| 67 | + exit 1 |
| 68 | +fi |
| 69 | +echo "✅ Confirmed. Proceeding with publish." |
| 70 | + |
| 71 | +# Step 5: Publish |
| 72 | +if [ "$DRY_RUN" = true ]; then |
| 73 | + echo "DRY RUN: Skipping actual publish." |
| 74 | +else |
| 75 | + echo "Publishing MCP server..." |
| 76 | + mcp-publisher publish |
| 77 | +fi |
| 78 | + |
| 79 | +# Step 6: Verify publication |
| 80 | +SERVER_NAME=$(jq -r .name server.json) |
| 81 | +echo "Verifying server in registry..." |
| 82 | +curl -s "https://registry.modelcontextprotocol.io/v0/servers?search=$SERVER_NAME" | jq |
| 83 | + |
| 84 | +echo "Done." |
0 commit comments