#!/usr/bin/env bash # MCP over plain HTTP with curl (Streamable HTTP): initialize, list the tools, call browser_status, end the session. # Agents do this for you; this shows what goes over the wire and checks a token from a terminal. # WEBPILOT_URL=http://localhost:8931 WEBPILOT_TOKEN=cbu_... bash examples/curl/mcp.sh set -euo pipefail : "${WEBPILOT_URL:=http://localhost:8931}" : "${WEBPILOT_TOKEN:?set WEBPILOT_TOKEN to your cbu_ token}" MCP="$WEBPILOT_URL/mcp" H=(-H "Authorization: Bearer $WEBPILOT_TOKEN" -H "content-type: application/json" -H "accept: application/json, text/event-stream") echo "--- initialize (the answer's Mcp-Session-Id header names the session)" SID=$(curl -sS -D - -o /dev/null "${H[@]}" -X POST "$MCP" \ -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-03-26","capabilities":{},"clientInfo":{"name":"curl","version":"0"}}}' \ | tr -d '\r' | awk -F': ' 'tolower($1)=="mcp-session-id"{print $2}') echo "session $SID" S=(-H "mcp-session-id: $SID" -H "mcp-protocol-version: 2025-03-26") curl -sS "${H[@]}" "${S[@]}" -X POST "$MCP" -d '{"jsonrpc":"2.0","method":"notifications/initialized"}' -o /dev/null echo "--- tools/list (names only)" curl -sS "${H[@]}" "${S[@]}" -X POST "$MCP" -d '{"jsonrpc":"2.0","id":2,"method":"tools/list"}' \ | sed -n 's/^data: //p' | grep -o '"name":"browser_[a-z_]*"' | cut -d'"' -f4 | tr '\n' ' '; echo echo "--- tools/call browser_status" curl -sS "${H[@]}" "${S[@]}" -X POST "$MCP" \ -d '{"jsonrpc":"2.0","id":3,"method":"tools/call","params":{"name":"browser_status","arguments":{}}}' | sed -n 's/^data: //p' | head -c 600; echo echo "--- end the session" curl -sS "${H[@]}" "${S[@]}" -X DELETE "$MCP" -o /dev/null -w "HTTP %{http_code}\n"