From 70490ec09dea34d119c28a3c67bf87379ddb6aa4 Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Fri, 20 Mar 2026 00:35:44 -0400 Subject: [PATCH] mcp: fix summary mode aggregation limit + add pagination hint Summary mode bug: by_label only counted 50 results (the default limit) instead of all symbols. Fix: override effective_limit to 10000 when mode=summary so aggregation covers representative sample. Pagination: when has_more=true, add pagination_hint field: "Use offset:50 and limit:50 for next page (13818 total)" This guides LLMs to use offset/limit for progressive exploration. Verified on RTK codebase (45,388 symbols): - Summary mode: 1,317 bytes with accurate label counts - Default search: pagination_hint present when has_more=true - All 2064 tests pass Signed-off-by: Andrew Hundt --- src/mcp/mcp.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/mcp/mcp.c b/src/mcp/mcp.c index 28d2b1362..5dc34ab75 100644 --- a/src/mcp/mcp.c +++ b/src/mcp/mcp.c @@ -818,12 +818,16 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) { int min_degree = cbm_mcp_get_int_arg(args, "min_degree", -1); int max_degree = cbm_mcp_get_int_arg(args, "max_degree", -1); + /* Summary mode needs all results for accurate aggregation */ + bool is_summary_early = search_mode && strcmp(search_mode, "summary") == 0; + int effective_limit = is_summary_early ? 10000 : limit; + cbm_search_params_t params = { .project = project, .label = label, .name_pattern = name_pattern, .file_pattern = file_pattern, - .limit = limit, + .limit = effective_limit, .offset = offset, .min_degree = min_degree, .max_degree = max_degree, @@ -913,7 +917,15 @@ static char *handle_search_graph(cbm_mcp_server_t *srv, const char *args) { yyjson_mut_arr_add_val(results, item); } yyjson_mut_obj_add_val(doc, root, "results", results); - yyjson_mut_obj_add_bool(doc, root, "has_more", out.total > offset + out.count); + bool more = out.total > offset + out.count; + yyjson_mut_obj_add_bool(doc, root, "has_more", more); + if (more) { + char hint[128]; + snprintf(hint, sizeof(hint), + "Use offset:%d and limit:%d for next page (%d total)", + offset + out.count, limit, (int)out.total); + yyjson_mut_obj_add_strcpy(doc, root, "pagination_hint", hint); + } } char *json = yy_doc_to_str(doc);