From 64d76bf295ce1b1d69f63fe6d8609488eda068d6 Mon Sep 17 00:00:00 2001 From: KQAR <31615748+KQAR@users.noreply.github.com> Date: Tue, 3 Mar 2026 14:29:43 +0800 Subject: [PATCH] fix(mcp): omit nextCursor when no more pages in tools/list Previously, tools/list always returned `"nextCursor": ""` even when all tools fit in a single page. Cursor-agent treats any present nextCursor (including empty string) as "more pages available", causing an infinite pagination loop (~170k requests in 55s) that exhausts the V8 heap and crashes with OOM. Only include nextCursor in the response when there are actually more pages to fetch. Made-with: Cursor --- src/cccc/ports/mcp/main.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/cccc/ports/mcp/main.py b/src/cccc/ports/mcp/main.py index c1736c22..8a179a2b 100644 --- a/src/cccc/ports/mcp/main.py +++ b/src/cccc/ports/mcp/main.py @@ -141,10 +141,10 @@ def handle_request(req: Dict[str, Any]) -> Dict[str, Any]: limit = 100 limit = max(1, min(limit, 200)) page = tools[cursor : cursor + limit] - next_cursor = "" + result_payload: Dict[str, Any] = {"tools": page} if cursor + limit < len(tools): - next_cursor = _encode_cursor(cursor + limit) - return _make_response(req_id, {"tools": page, "nextCursor": next_cursor}) + result_payload["nextCursor"] = _encode_cursor(cursor + limit) + return _make_response(req_id, result_payload) # Optional MCP surfaces (return empty to avoid noisy "Method not found" in some runtimes) if method == "resources/list":