check-mcp-urls.yml 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137
  1. name: Check MCP URLs
  2. # Liveness check for http/sse MCP server URLs declared by plugins vendored
  3. # in this repo. Catches typos in new submissions and upstream endpoints that
  4. # disappear after merge.
  5. #
  6. # Scope: only plugins whose files live in this working tree (marketplace
  7. # entries with a string `source`, e.g. "./plugins/foo"). External entries
  8. # are pinned to an upstream repo at a SHA — reading their .mcp.json would
  9. # mean cloning every upstream on each run, which is slow and flaky. Those
  10. # are out of scope for now.
  11. #
  12. # What counts as "alive": anything that proves the hostname/path resolves to
  13. # a server. 401/403/405/5xx all pass — auth and method errors are expected
  14. # without credentials. Only 404/410 and connection/DNS/TLS failures fail.
  15. on:
  16. pull_request:
  17. paths:
  18. - '.claude-plugin/marketplace.json'
  19. - 'plugins/**'
  20. - 'external_plugins/**'
  21. - '.github/workflows/check-mcp-urls.yml'
  22. schedule:
  23. - cron: '0 6 * * *'
  24. workflow_dispatch:
  25. permissions:
  26. contents: read
  27. jobs:
  28. check:
  29. runs-on: ubuntu-latest
  30. timeout-minutes: 15
  31. steps:
  32. - uses: actions/checkout@v4
  33. - name: Discover and probe MCP server URLs
  34. run: |
  35. set -euo pipefail
  36. MARKETPLACE=".claude-plugin/marketplace.json"
  37. # Each line: "<plugin>\t<server>\t<url>". Marketplace entries with a
  38. # string `source` are local paths; objects describe an external repo
  39. # pinned at a SHA, which we don't have checked out — skip those.
  40. discover() {
  41. jq -r '.plugins[] | select(.source | type == "string") | "\(.name)\t\(.source)"' "$MARKETPLACE" |
  42. while IFS=$'\t' read -r plugin src; do
  43. dir="${src#./}"
  44. [[ -d "$dir" ]] || continue
  45. for cfg in "$dir/.mcp.json" "$dir/mcp.json" "$dir/.claude-plugin/plugin.json"; do
  46. [[ -f "$cfg" ]] || continue
  47. # MCP config comes in two shapes: a bare map of server name ->
  48. # config, or wrapped under a top-level "mcpServers" key (also
  49. # the shape inside plugin.json). Normalize, then keep entries
  50. # with an http/sse type and a string url.
  51. # Skip entries with empty url — those are placeholders awaiting
  52. # user config, not dead endpoints, and would false-fail.
  53. jq -r --arg plugin "$plugin" '
  54. (if (type == "object" and has("mcpServers")) then .mcpServers else . end)
  55. | to_entries[]
  56. | select((.value | type) == "object")
  57. | select(.value.type == "http" or .value.type == "sse")
  58. | select(.value.url | type == "string" and . != "")
  59. | "\($plugin)\t\(.key)\t\(.value.url)"
  60. ' "$cfg" 2>/dev/null || true
  61. done
  62. done | sort -u
  63. }
  64. # Returns 0 on pass, 1 on fail; prints "PASS|FAIL <code> <note>".
  65. probe() {
  66. local url="$1"
  67. local code
  68. # HEAD first — cheap and covers plain web endpoints. -L follows
  69. # redirects so a permanent redirect to a live page still passes.
  70. #
  71. # On a connection-level failure curl writes "000" to -w AND exits
  72. # nonzero. The fallback assignment must happen OUTSIDE the command
  73. # substitution — `... || echo "000"` inside $() would *append* a
  74. # second "000", producing "000000" which falls through the case
  75. # statement and silently passes a dead host.
  76. code="$(curl -sS -o /dev/null -w '%{http_code}' \
  77. --connect-timeout 10 --max-time 10 \
  78. --retry 2 --retry-delay 2 \
  79. -L -I "$url" 2>/dev/null)" || code="000"
  80. # MCP endpoints typically reject HEAD (404/405) but answer POST
  81. # with a JSON-RPC body. Retry as a real MCP client would.
  82. if [[ "$code" == "000" || "$code" == "404" || "$code" == "405" ]]; then
  83. code="$(curl -sS -o /dev/null -w '%{http_code}' \
  84. --connect-timeout 10 --max-time 10 \
  85. --retry 2 --retry-delay 2 \
  86. -L -X POST \
  87. -H 'Content-Type: application/json' \
  88. -H 'Accept: application/json, text/event-stream' \
  89. --data '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"ci","version":"0"}}}' \
  90. "$url" 2>/dev/null)" || code="000"
  91. fi
  92. case "$code" in
  93. 000) echo "FAIL $code unreachable"; return 1 ;;
  94. 404|410) echo "FAIL $code gone"; return 1 ;;
  95. *) echo "PASS $code"; return 0 ;;
  96. esac
  97. }
  98. entries="$(discover)"
  99. if [[ -z "$entries" ]]; then
  100. echo "::notice::No http/sse MCP server URLs found in vendored plugins."
  101. exit 0
  102. fi
  103. failures=0
  104. printf '%-24s %-18s %-52s %s\n' "PLUGIN" "SERVER" "URL" "RESULT"
  105. while IFS=$'\t' read -r plugin server url; do
  106. # Skip URLs with template placeholders — they need user config
  107. # and can't be probed as-is.
  108. if [[ "$url" == *'${'* || "$url" == *'{{'* ]]; then
  109. printf '%-24s %-18s %-52s %s\n' "$plugin" "$server" "$url" "SKIP templated"
  110. continue
  111. fi
  112. result="$(probe "$url")" || true
  113. printf '%-24s %-18s %-52s %s\n' "$plugin" "$server" "$url" "$result"
  114. if [[ "$result" == FAIL* ]]; then
  115. failures=$((failures + 1))
  116. echo "::error::MCP server URL for plugin '$plugin' (server '$server') is unreachable: $url ($result)"
  117. fi
  118. done <<< "$entries"
  119. echo
  120. if (( failures > 0 )); then
  121. echo "::error::$failures MCP server URL(s) failed liveness check."
  122. exit 1
  123. fi
  124. echo "All MCP server URLs reachable."