Files

30 lines
1.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Runs the packaged fat jar and talks to it with curl: the same three tools, no SDK, no test harness.
# Writes output/10-fat-jar-curl.txt.
set -eu
cd "$(dirname "$0")/.."
PORT=8791
OUT=output/10-fat-jar-curl.txt
META='"_meta":{"io.modelcontextprotocol/protocolVersion":"2026-07-28","io.modelcontextprotocol/clientInfo":{"name":"curl","version":"1"},"io.modelcontextprotocol/clientCapabilities":{}}'
java -jar target/code-search-mcp.jar sample-monorepo "$PORT" > /tmp/code-search-mcp.log 2>&1 &
PID=$!
trap 'kill $PID 2>/dev/null || true' EXIT
for _ in $(seq 1 60); do grep -q 'serving MCP' /tmp/code-search-mcp.log && break; sleep 0.5; done
call() { # $1 tool, $2 arguments json
curl -s -X POST "http://127.0.0.1:$PORT/mcp" \
-H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
-H 'MCP-Protocol-Version: 2026-07-28' -H 'Mcp-Method: tools/call' -H "Mcp-Name: $1" \
-d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/call\",\"params\":{\"name\":\"$1\",\"arguments\":$2,$META}}"
}
{
echo '# java -jar target/code-search-mcp.jar sample-monorepo 8791, then curl'
grep -E 'indexed|serving|HmacRequestStateCodec' /tmp/code-search-mcp.log | sed -E 's#/[^ ]*/sample-monorepo#sample-monorepo#; s#:[0-9]{4,5}/mcp#:<port>/mcp#'
echo
echo '$ curl ... -H "Mcp-Method: tools/call" -H "Mcp-Name: search_code" -d {"query":"cancel an order","k":2}'
call search_code '{"query":"cancel an order","k":2}' | python3 -c 'import sys,json; print(json.load(sys.stdin)["result"]["content"][0]["text"])'
} > "$OUT"
cat "$OUT"