Skip to content

Commit 0073ab2

Browse files
authored
Add server conformance testing (#1375)
1 parent 2bb7f47 commit 0073ab2

File tree

7 files changed

+1192
-2
lines changed

7 files changed

+1192
-2
lines changed

.github/workflows/conformance.yml

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ on:
66
pull_request:
77
workflow_dispatch:
88

9+
concurrency:
10+
group: conformance-${{ github.ref }}
11+
cancel-in-progress: true
12+
913
permissions:
1014
contents: read
1115

1216
jobs:
1317
client-conformance:
1418
runs-on: ubuntu-latest
15-
continue-on-error: true # Non-blocking initially
19+
continue-on-error: true
1620
steps:
1721
- uses: actions/checkout@v4
1822
- name: Install pnpm
@@ -27,3 +31,21 @@ jobs:
2731
- run: pnpm install
2832
- run: pnpm run build:all
2933
- run: pnpm run test:conformance:client:all
34+
35+
server-conformance:
36+
runs-on: ubuntu-latest
37+
continue-on-error: true
38+
steps:
39+
- uses: actions/checkout@v4
40+
- name: Install pnpm
41+
uses: pnpm/action-setup@v4
42+
with:
43+
run_install: false
44+
- uses: actions/setup-node@v4
45+
with:
46+
node-version: 24
47+
cache: pnpm
48+
cache-dependency-path: pnpm-lock.yaml
49+
- run: pnpm install
50+
- run: pnpm run build:all
51+
- run: pnpm run test:conformance:server

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,3 +133,6 @@ dist/
133133

134134
# IDE
135135
.idea/
136+
137+
# Conformance test results
138+
results/

package.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,11 @@
3232
"test:all": "pnpm -r test",
3333
"test:conformance:client": "conformance client --command 'npx tsx src/conformance/everything-client.ts'",
3434
"test:conformance:client:all": "conformance client --command 'npx tsx src/conformance/everything-client.ts' --suite all",
35-
"test:conformance:client:run": "npx tsx src/conformance/everything-client.ts"
35+
"test:conformance:client:run": "npx tsx src/conformance/everything-client.ts",
36+
"test:conformance:server": "scripts/run-server-conformance.sh",
37+
"test:conformance:server:all": "scripts/run-server-conformance.sh --suite all",
38+
"test:conformance:server:run": "npx tsx src/conformance/everything-server.ts",
39+
"test:conformance:all": "pnpm run test:conformance:client:all && pnpm run test:conformance:server:all"
3640
},
3741
"devDependencies": {
3842
"@cfworker/json-schema": "catalog:runtimeShared",
@@ -41,6 +45,7 @@
4145
"@eslint/js": "catalog:devTools",
4246
"@modelcontextprotocol/client": "workspace:^",
4347
"@modelcontextprotocol/conformance": "0.1.9",
48+
"@modelcontextprotocol/server": "workspace:^",
4449
"@types/content-type": "catalog:devTools",
4550
"@types/cors": "catalog:devTools",
4651
"@types/cross-spawn": "catalog:devTools",
@@ -51,9 +56,11 @@
5156
"@types/supertest": "catalog:devTools",
5257
"@types/ws": "catalog:devTools",
5358
"@typescript/native-preview": "catalog:devTools",
59+
"cors": "catalog:runtimeServerOnly",
5460
"eslint": "catalog:devTools",
5561
"eslint-config-prettier": "catalog:devTools",
5662
"eslint-plugin-n": "catalog:devTools",
63+
"express": "catalog:runtimeServerOnly",
5764
"prettier": "catalog:devTools",
5865
"supertest": "catalog:devTools",
5966
"tsdown": "catalog:devTools",

pnpm-lock.yaml

Lines changed: 9 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/run-server-conformance.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
# Script to run server conformance tests
3+
# Starts the conformance server, runs conformance tests, then stops the server
4+
5+
set -e
6+
7+
PORT="${PORT:-3000}"
8+
SERVER_URL="http://localhost:${PORT}/mcp"
9+
10+
# Navigate to the repo root
11+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
12+
cd "$SCRIPT_DIR/.."
13+
14+
# Start the server in the background
15+
echo "Starting conformance test server on port ${PORT}..."
16+
npx tsx src/conformance/everything-server.ts &
17+
SERVER_PID=$!
18+
19+
# Function to cleanup on exit
20+
cleanup() {
21+
echo "Stopping server (PID: ${SERVER_PID})..."
22+
kill $SERVER_PID 2>/dev/null || true
23+
wait $SERVER_PID 2>/dev/null || true
24+
}
25+
trap cleanup EXIT
26+
27+
# Wait for server to be ready
28+
echo "Waiting for server to be ready..."
29+
MAX_RETRIES=30
30+
RETRY_COUNT=0
31+
while ! curl -s "${SERVER_URL}" > /dev/null 2>&1; do
32+
RETRY_COUNT=$((RETRY_COUNT + 1))
33+
if [ $RETRY_COUNT -ge $MAX_RETRIES ]; then
34+
echo "Server failed to start after ${MAX_RETRIES} attempts"
35+
exit 1
36+
fi
37+
sleep 0.5
38+
done
39+
40+
echo "Server is ready. Running conformance tests..."
41+
42+
# Run conformance tests - pass through all arguments
43+
npx @modelcontextprotocol/conformance server --url "${SERVER_URL}" "$@"
44+
45+
echo "Conformance tests completed."

src/conformance/README.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
# Conformance Tests
2+
3+
This directory contains conformance test implementations for the TypeScript MCP SDK.
4+
5+
## Client Conformance Tests
6+
7+
Tests the SDK's client implementation against a conformance test server.
8+
9+
```bash
10+
# Run all client tests
11+
pnpm run test:conformance:client:all
12+
13+
# Run specific suite
14+
pnpm run test:conformance:client -- --suite auth
15+
16+
# Run single scenario
17+
pnpm run test:conformance:client -- --scenario auth/basic-cimd
18+
```
19+
20+
## Server Conformance Tests
21+
22+
Tests the SDK's server implementation by running a conformance server.
23+
24+
```bash
25+
# Run all active server tests
26+
pnpm run test:conformance:server
27+
28+
# Run all server tests (including pending)
29+
pnpm run test:conformance:server:all
30+
```
31+
32+
## Local Development
33+
34+
### Running Tests Against Local Conformance Repo
35+
36+
Link the local conformance package:
37+
```bash
38+
cd ~/code/mcp/typescript-sdk
39+
pnpm link ~/code/mcp/conformance
40+
```
41+
42+
Then run tests as above.
43+
44+
### Debugging Server Tests
45+
46+
Start the server manually:
47+
```bash
48+
pnpm run test:conformance:server:run
49+
```
50+
51+
In another terminal, run specific tests:
52+
```bash
53+
npx @modelcontextprotocol/conformance server \
54+
--url http://localhost:3000/mcp \
55+
--scenario server-initialize
56+
```
57+
58+
## Files
59+
60+
- `everything-client.ts` - Client that handles all client conformance scenarios
61+
- `everything-server.ts` - Server that implements all server conformance features
62+
- `helpers/` - Shared utilities for conformance tests
63+
64+
Scripts are in `scripts/` at the repo root.

0 commit comments

Comments
 (0)