@@ -32,34 +32,51 @@ if [ "$READY" != "true" ]; then
3232 exit 1
3333fi
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 ---
4736echo " === 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+
4953SERVER_NAME=$( echo " $INIT " | jq -r ' .result.serverInfo.name // empty' )
5054if [ -z " $SERVER_NAME " ]; then
5155 echo " FAIL: initialize did not return serverInfo.name"
5256 echo " Response: $INIT "
5357 exit 1
5458fi
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 )
5862curl -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 ---
6481echo " === Listing tools ==="
6582TOOLS=$( rpc 2 " tools/list" ' {}' )
0 commit comments