Skip to content

Commit 6c16aa6

Browse files
authored
scripts: add conformance test runner (#694)
Add a script to run the official MCP conformance tests against the SDK's conformance server. The script supports saving results to a custom directory (--result_dir) and running against a local checkout of the conformance repo (--conformance_repo). Document the script in CONTRIBUTING.md. For #650
1 parent 7b8f83f commit 6c16aa6

File tree

2 files changed

+139
-0
lines changed

2 files changed

+139
-0
lines changed

CONTRIBUTING.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,34 @@ containing the SDK, run:
2626
go work init ./project ./go-sdk
2727
```
2828

29+
### Conformance tests
30+
31+
The SDK includes a script to run the official MCP conformance tests against the
32+
SDK's conformance server:
33+
34+
```sh
35+
./scripts/conformance.sh
36+
```
37+
38+
By default, results are cleaned up after the script runs. To save results to a
39+
specific directory:
40+
41+
```sh
42+
./scripts/conformance.sh --result_dir ./conformance-results
43+
```
44+
45+
To run against a local checkout of the
46+
[conformance repo](https://github.com/modelcontextprotocol/conformance) instead
47+
of the latest npm release:
48+
49+
```sh
50+
./scripts/conformance.sh --conformance_repo ~/src/conformance
51+
```
52+
53+
Note: you must run `npm install` in the conformance repo first.
54+
55+
Run `./scripts/conformance.sh --help` for more options.
56+
2957
## Filing issues
3058

3159
This project uses the [GitHub issue

scripts/conformance.sh

Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
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

Comments
 (0)