|
| 1 | +#!/bin/bash |
| 2 | +# Copyright 2025 The Go MCP SDK Authors. All rights reserved. |
| 3 | +# Use of this source code is governed by an MIT-style |
| 4 | +# license that can be found in the LICENSE file. |
| 5 | + |
| 6 | +# Run MCP conformance tests against the Go SDK conformance server. |
| 7 | + |
| 8 | +set -e |
| 9 | + |
| 10 | +PORT="${PORT:-3000}" |
| 11 | +SERVER_PID="" |
| 12 | +RESULT_DIR="" |
| 13 | +WORKDIR="" |
| 14 | +CONFORMANCE_REPO="" |
| 15 | + |
| 16 | +usage() { |
| 17 | + echo "Usage: $0 [options]" |
| 18 | + echo "" |
| 19 | + echo "Run MCP conformance tests against the Go SDK conformance server." |
| 20 | + echo "" |
| 21 | + echo "Options:" |
| 22 | + echo " --result_dir <dir> Save results to the specified directory" |
| 23 | + echo " --conformance_repo <dir> Run conformance tests from a local checkout" |
| 24 | + echo " instead of using the latest npm release" |
| 25 | + echo " --help Show this help message" |
| 26 | +} |
| 27 | + |
| 28 | +# Parse arguments. |
| 29 | +while [[ $# -gt 0 ]]; do |
| 30 | + case $1 in |
| 31 | + --result_dir) |
| 32 | + RESULT_DIR="$2" |
| 33 | + shift 2 |
| 34 | + ;; |
| 35 | + --conformance_repo) |
| 36 | + CONFORMANCE_REPO="$2" |
| 37 | + shift 2 |
| 38 | + ;; |
| 39 | + --help) |
| 40 | + usage |
| 41 | + exit 0 |
| 42 | + ;; |
| 43 | + *) |
| 44 | + echo "Unknown option: $1" |
| 45 | + usage |
| 46 | + exit 1 |
| 47 | + ;; |
| 48 | + esac |
| 49 | +done |
| 50 | + |
| 51 | +cleanup() { |
| 52 | + if [ -n "$SERVER_PID" ]; then |
| 53 | + kill "$SERVER_PID" 2>/dev/null || true |
| 54 | + fi |
| 55 | + # Clean up the work directory unless --result_dir was specified. |
| 56 | + if [ -z "$RESULT_DIR" ] && [ -n "$WORKDIR" ]; then |
| 57 | + rm -rf "$WORKDIR" |
| 58 | + fi |
| 59 | +} |
| 60 | +trap cleanup EXIT |
| 61 | + |
| 62 | +# Set up the work directory. |
| 63 | +if [ -n "$RESULT_DIR" ]; then |
| 64 | + mkdir -p "$RESULT_DIR" |
| 65 | + WORKDIR="$RESULT_DIR" |
| 66 | +else |
| 67 | + WORKDIR=$(mktemp -d) |
| 68 | +fi |
| 69 | + |
| 70 | +# Build the conformance server. |
| 71 | +go build -o "$WORKDIR/conformance-server" ./examples/server/conformance |
| 72 | + |
| 73 | +# Start the server in the background |
| 74 | +echo "Starting conformance server on port $PORT..." |
| 75 | +"$WORKDIR/conformance-server" -http=":$PORT" & |
| 76 | +SERVER_PID=$! |
| 77 | + |
| 78 | +echo "Server pid is $SERVER_PID" |
| 79 | + |
| 80 | +# Wait for server to be ready |
| 81 | +echo "Waiting for server to be ready..." |
| 82 | +for i in {1..30}; do |
| 83 | + if curl -s "http://localhost:$PORT" > /dev/null 2>&1; then |
| 84 | + echo "Server is ready." |
| 85 | + break |
| 86 | + fi |
| 87 | + if [ "$i" -eq 30 ]; then |
| 88 | + echo "Server failed to start within 15 seconds." |
| 89 | + exit 1 |
| 90 | + fi |
| 91 | + sleep 0.5 |
| 92 | +done |
| 93 | + |
| 94 | +# Run conformance tests from the work directory to avoid writing results to the repo. |
| 95 | +echo "Running conformance tests..." |
| 96 | +if [ -n "$CONFORMANCE_REPO" ]; then |
| 97 | + # Run from local checkout using npm run start. |
| 98 | + (cd "$WORKDIR" && \ |
| 99 | + npm --prefix "$CONFORMANCE_REPO" run start -- \ |
| 100 | + server --url "http://localhost:$PORT") |
| 101 | +else |
| 102 | + (cd "$WORKDIR" && \ |
| 103 | + npx @modelcontextprotocol/conformance@latest server --url "http://localhost:$PORT") |
| 104 | +fi |
| 105 | + |
| 106 | +echo "" |
| 107 | +if [ -n "$RESULT_DIR" ]; then |
| 108 | + echo "See $RESULT_DIR for details." |
| 109 | +else |
| 110 | + echo "Run with --result_dir to save results." |
| 111 | +fi |
0 commit comments