Skip to content

feat(pagination): surface truncation explicitly so LLMs notice partial results#51

Merged
ysyneu merged 1 commit intomainfrom
feat/pagination-truncation-hint
May 8, 2026
Merged

feat(pagination): surface truncation explicitly so LLMs notice partial results#51
ysyneu merged 1 commit intomainfrom
feat/pagination-truncation-hint

Conversation

@ysyneu
Copy link
Copy Markdown
Collaborator

@ysyneu ysyneu commented May 8, 2026

Summary

  • List tools (incidents/alerts/changes/...) default to limit=20 but only returned items+total. The LLM frequently skipped the implicit len(items) < total check and presented page 1 as the full picture.
  • This PR stamps truncated:true + a human-readable hint ("Returned 20 of 444 total. To see more: raise limit (max 100), narrow since/until, or add filters") onto the response only when actually truncated, so the LLM cannot miss it. Happy path stays clean.
  • Refreshes the limit parameter description on the three time-window query tools to call out the new fields up front, priming the LLM before the call.

Wired into 10 list-shaped tools: query_incidents, query_alerts, query_changes, query_channels, query_escalation_rules, query_members, query_teams, query_fields, list_status_changes, list_similar_incidents.

Test plan

End-to-end through Safari → runner → mcp-server:

  • Direct curl returns truncated:true + hint (verified total:444 / count:3)
  • Direct curl with full result returns no truncated/hint field
  • Safari LLM prompt "查询最近一周的所有告警" — LLM proactively used limit:100 (from refreshed description), recognized truncation, attempted time-window splitting, and reported "100/444" to the user
  • go test ./..., go vet ./..., gofmt clean

🤖 Generated with Claude Code

…l results

List-shaped tools default to limit=20 and used to return only `items`+`total`.
LLMs frequently skipped the implicit `len < total` check and presented the
first page as the full picture (the most common "the LLM only saw 20 incidents"
report).

Add `truncated:true` + a human-readable `hint` ("Returned 20 of 444 total. To
see more: raise `limit` (max 100), narrow `since`/`until`, or add filters")
when the result is actually truncated. No-op on full results so happy-path
output stays clean.

Also refresh the `limit` parameter description on incidents/alerts/changes to
mention the new fields up front, so the LLM is primed before the call.

Wired into: query_incidents, query_alerts, query_changes, query_channels,
query_escalation_rules, query_members, query_teams, query_fields,
list_status_changes, list_similar_incidents.

Verified end-to-end through Safari → runner → mcp-server: when asked to
"查询最近一周的所有告警", the LLM (a) proactively raised `limit` to 100 from
the new description, (b) read `truncated:true`/`total:444` and split the
window into multiple sub-queries on its own, (c) reported "100/444 分析样本"
to the user instead of silently presenting page 1 as the whole truth.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@ysyneu ysyneu merged commit a70ba6b into main May 8, 2026
13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant