Skip to content

Commit 8fbfbcd

Browse files
Ajit Pratap Singhclaude
authored andcommitted
fix(mcp): add Mcp-Session-Id header to E2E test script
Streamable HTTP transport requires session ID on all requests after initialization. Capture the header from the initialize response and pass it on all subsequent JSON-RPC calls. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent d80270d commit 8fbfbcd

1 file changed

Lines changed: 32 additions & 15 deletions

File tree

scripts/mcp-e2e-test.sh

Lines changed: 32 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -32,34 +32,51 @@ if [ "$READY" != "true" ]; then
3232
exit 1
3333
fi
3434

35-
# Helper: send a JSON-RPC request and extract the result field.
36-
rpc() {
37-
local id="$1"
38-
local method="$2"
39-
local params="$3"
40-
curl -sf -X POST "$ADDR" \
41-
-H "Content-Type: application/json" \
42-
-H "Accept: application/json" \
43-
-d "{\"jsonrpc\":\"2.0\",\"id\":${id},\"method\":\"${method}\",\"params\":${params}}"
44-
}
45-
46-
# --- Step 1: Initialize session ---
35+
# --- Step 1: Initialize session and capture Mcp-Session-Id ---
4736
echo "=== Initializing MCP session ==="
48-
INIT=$(rpc 1 "initialize" '{"protocolVersion":"2025-11-25","clientInfo":{"name":"e2e-test","version":"0.1"},"capabilities":{}}')
37+
INIT_HEADERS=$(mktemp)
38+
INIT=$(curl -sf -X POST "$ADDR" \
39+
-H "Content-Type: application/json" \
40+
-H "Accept: application/json" \
41+
-D "$INIT_HEADERS" \
42+
-d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","clientInfo":{"name":"e2e-test","version":"0.1"},"capabilities":{}}}')
43+
44+
SESSION_ID=$(grep -i 'Mcp-Session-Id' "$INIT_HEADERS" | tr -d '\r' | awk '{print $2}')
45+
rm -f "$INIT_HEADERS"
46+
47+
if [ -z "$SESSION_ID" ]; then
48+
echo "FAIL: initialize did not return Mcp-Session-Id header"
49+
echo "Response: $INIT"
50+
exit 1
51+
fi
52+
4953
SERVER_NAME=$(echo "$INIT" | jq -r '.result.serverInfo.name // empty')
5054
if [ -z "$SERVER_NAME" ]; then
5155
echo "FAIL: initialize did not return serverInfo.name"
5256
echo "Response: $INIT"
5357
exit 1
5458
fi
55-
echo "PASS: initialized — server=$SERVER_NAME"
59+
echo "PASS: initialized — server=$SERVER_NAME, session=$SESSION_ID"
5660

57-
# Send initialized notification (no id, no response expected)
61+
# Send initialized notification (requires session ID)
5862
curl -sf -X POST "$ADDR" \
5963
-H "Content-Type: application/json" \
64+
-H "Mcp-Session-Id: $SESSION_ID" \
6065
-d '{"jsonrpc":"2.0","method":"notifications/initialized"}' \
6166
-o /dev/null 2>/dev/null || true
6267

68+
# Helper: send a JSON-RPC request with session ID.
69+
rpc() {
70+
local id="$1"
71+
local method="$2"
72+
local params="$3"
73+
curl -sf -X POST "$ADDR" \
74+
-H "Content-Type: application/json" \
75+
-H "Accept: application/json" \
76+
-H "Mcp-Session-Id: $SESSION_ID" \
77+
-d "{\"jsonrpc\":\"2.0\",\"id\":${id},\"method\":\"${method}\",\"params\":${params}}"
78+
}
79+
6380
# --- Step 2: List tools ---
6481
echo "=== Listing tools ==="
6582
TOOLS=$(rpc 2 "tools/list" '{}')

0 commit comments

Comments
 (0)