Skip to content

perf+docs: cut list_incidents token usage — pagination hint + Code Mode as default#151

Open
spencerhcheng wants to merge 5 commits into
mainfrom
feat/list-incidents-pagination-hint
Open

perf+docs: cut list_incidents token usage — pagination hint + Code Mode as default#151
spencerhcheng wants to merge 5 commits into
mainfrom
feat/list-incidents-pagination-hint

Conversation

@spencerhcheng

@spencerhcheng spencerhcheng commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Two complementary changes that reduce token usage for the hosted Rootly MCP, consolidated into one PR.

1. Pagination efficiency hint (list_incidents)

MCPCat/Datadog traces show clients walking the full incident history one tiny page at a time (page_size=1) — a single sweep of 281 incidents = 281 tool calls. When list_incidents is called with a below-default page_size against a result set large enough to require many paginated calls, the response now includes an advisory _use_tool hint steering the caller to collect_incidents (bulk fetch in one call), a larger page_size, or filters. Reuses the existing _use_tool convention.

  • Non-breaking: does not change returned data, status, or pagination — purely advisory.
  • Fires only when it would actually save calls: page_size < 25 and has_more and the sweep would exceed 5 paginated calls.
  • tools/incidents.py: _pagination_efficiency_hint helper + wiring; tests cover all boundary conditions and the list_incidents integration.

2. Recommend Code Mode as the default hosted endpoint (README)

Code Mode (/mcp-codemode) exposes a compact set of meta-tools (list_tools, tool_search, get_schema, tags, execute) instead of ~200 individual tools, and lets the model chain call_tool() calls server-side in one execute block — dramatically lower token usage and fewer round-trips. Verified end-to-end including OAuth2 and Claude Desktop's tool-discovery flow.

  • Lead the hosted transport options with Code Mode (recommended) + rationale callout; demote Streamable HTTP / SSE to alternatives.
  • Lead the general remote setup and Claude Code quick-add with /mcp-codemode.
  • Warning (proven in testing): connect Code Mode instead of the classic endpoints, not alongside — with both available, clients call the classic tools directly and skip execute, losing the savings.

Testing

  • Full unit suite passes; ruff + pyright clean.
  • Docs counterpart for the Rootly docs site: rootlyhq/rootly-docs#514.

(Supersedes #152, which is folded in here.)

@spencerhcheng
spencerhcheng force-pushed the feat/list-incidents-pagination-hint branch from 45db5c3 to d94223e Compare June 30, 2026 19:09
@spencerhcheng spencerhcheng changed the title feat: hint toward collect_incidents on inefficient list_incidents pagination perf+docs: cut list_incidents token usage — pagination hint + Code Mode as default Jun 30, 2026
@spencerhcheng
spencerhcheng requested a review from kwent June 30, 2026 20:48
…ination

Some clients walk the full incident history one tiny page at a time
(e.g. page_size=1), turning a bounded fetch into hundreds of tool calls
— a single sweep of 281 incidents at page_size=1 is 281 calls.

When list_incidents is called with a below-default page_size against a
result set large enough to require many paginated calls, the response now
includes an advisory `_use_tool` hint steering callers to collect_incidents
(bulk fetch in one call), a larger page_size, or narrowing filters. This
matches the existing `_use_tool` convention used for the alert-routing
deprecation.

The hint is non-breaking: it does not alter the returned data, status, or
pagination — it is purely advisory, so existing clients are unaffected.

- tools/incidents.py: _pagination_efficiency_hint helper + wiring into
  list_incidents (fires only when page_size < 25, has_more, and the sweep
  would exceed 5 paginated calls).
- tests: direct coverage of the hint's boundary conditions plus
  list_incidents integration (fires at page_size=1, silent at default).
Code Mode (/mcp-codemode) exposes a compact set of meta-tools
(list_tools, tool_search, get_schema, tags, execute) instead of ~200
individual tools, and lets the model chain multiple call_tool() calls
server-side in a single execute block. That means dramatically lower
token usage (a handful of tool schemas re-sent per turn instead of
hundreds) and fewer round-trips for multi-step work — verified working
end-to-end, including OAuth2 (identical challenge to the classic endpoint).

- Lead the hosted transport options with Code Mode (recommended) + a
  rationale callout; demote plain Streamable HTTP / SSE to alternatives.
- Lead the general remote setup and Claude Code quick-add with the
  /mcp-codemode URL; keep the classic one-tool-per-operation endpoints
  documented for clients that can't use the execute sandbox.
@spencerhcheng
spencerhcheng force-pushed the feat/list-incidents-pagination-hint branch from d59622c to 050ae63 Compare July 23, 2026 22:23
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