Skip to content

Commit 2a4fac6

Browse files
committed
test(smoke): follow tools/list cursor pagination in inv_tools_list
tools/list is cursor-paginated (MCP_TOOLS_PAGE_SIZE=8): the server returns a page of tools plus result.nextCursor, and a compliant client follows the cursor to retrieve the rest. inv_tools_list only read the first page and expected all 14 tools in one response, so it failed with "got 8, expected 14" even though the server is correct. Follow nextCursor across pages and assert the union. No server change — the pagination behavior was already correct. Signed-off-by: Martin Vogel <martin.vogel.tech@gmail.com>
1 parent 9cb3cab commit 2a4fac6

1 file changed

Lines changed: 37 additions & 17 deletions

File tree

‎scripts/smoke-invariants.sh‎

Lines changed: 37 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -454,28 +454,48 @@ inv_tools_list() {
454454
fail "tools-list" "server not alive"
455455
return
456456
fi
457-
local req='{"jsonrpc":"2.0","id":2,"method":"tools/list","params":{}}'
458-
if ! mcp_send_recv "$req" 15; then
459-
fail "tools-list" "no response within 15s (hang)"
460-
return
461-
fi
462-
if ! printf '%s' "$MCP_RESP" | is_json; then
463-
fail "tools-list" "response not valid JSON"
464-
return
465-
fi
466-
# Extract tool names from result.tools[].name.
467-
local got_names got_count
468-
got_names="$(printf '%s' "$MCP_RESP" | "$PY" -c '
457+
# tools/list is cursor-paginated (MCP spec): the server returns a page of
458+
# tools plus result.nextCursor. Follow the cursor across pages and accumulate
459+
# the advertised tools — exactly what a compliant client does — then assert the
460+
# union covers all expected tools.
461+
local got_names="" cursor="" page=0
462+
while :; do
463+
page=$((page + 1))
464+
if [ "$page" -gt 20 ]; then
465+
fail "tools-list" "pagination did not terminate after 20 pages"
466+
return
467+
fi
468+
local params='{}'
469+
[ -n "$cursor" ] && params="{\"cursor\":\"$cursor\"}"
470+
local req="{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"tools/list\",\"params\":$params}"
471+
if ! mcp_send_recv "$req" 15; then
472+
fail "tools-list" "no response within 15s (page $page, hang)"
473+
return
474+
fi
475+
if ! printf '%s' "$MCP_RESP" | is_json; then
476+
fail "tools-list" "response not valid JSON (page $page)"
477+
return
478+
fi
479+
# Line 1 = space-joined names on this page; line 2 = nextCursor ("" if last).
480+
local parsed
481+
parsed="$(printf '%s' "$MCP_RESP" | "$PY" -c '
469482
import sys,json
470483
try:
471484
d=json.load(sys.stdin)
472485
except Exception:
473-
sys.exit(0)
474-
tools=(d.get("result") or {}).get("tools") or []
475-
print(" ".join(sorted(t.get("name","") for t in tools)))' 2>/dev/null)"
476-
got_count="$(printf '%s' "$got_names" | tr ' ' '\n' | grep -c . )"
486+
print(""); print(""); sys.exit(0)
487+
r=d.get("result") or {}
488+
print(" ".join(t.get("name","") for t in (r.get("tools") or [])))
489+
print(r.get("nextCursor") or "")' 2>/dev/null)"
490+
got_names="$got_names $(printf '%s' "$parsed" | sed -n '1p')"
491+
local next; next="$(printf '%s' "$parsed" | sed -n '2p')"
492+
[ -z "$next" ] && break
493+
cursor="$next"
494+
done
495+
local got_count
496+
got_count="$(printf '%s' "$got_names" | tr ' ' '\n' | grep -c .)"
477497
if [ "${got_count:-0}" -ne "$EXPECTED_TOOL_COUNT" ]; then
478-
fail "tools-list" "got $got_count tools, expected $EXPECTED_TOOL_COUNT; names=[$got_names]"
498+
fail "tools-list" "got $got_count tools across $page page(s), expected $EXPECTED_TOOL_COUNT; names=[$got_names]"
479499
return
480500
fi
481501
local missing=""

0 commit comments

Comments
 (0)