AI

AgentOps: detect a truncated MCP tool result before a production decision

A production runbook for separating pagination, truncation and context loss in an MCP tool result before authorizing an action, with evidence, canary gates and rollback.

16 Oct 2026 aiagentopsmcptoolspaginationcompletenessobservabilityevaluationguardrailsautomationrunbookrollbackproduction

An operations agent calls an MCP tool to check open changes before a deployment. The call succeeds, the JSON is valid and the trace contains a response. The agent concludes that no change blocks production. The tool, however, returned only the first 100 records; the blocking change is on the next page.

This is not a conventional hallucination or a visible tool failure. It is a decision built from a partial result that looked sufficient. The runbook must locate where completeness was lost, prevent writes based on an incomplete view, then decide whether to promote the fix or restore the previous contract.

Contain the action without destroying evidence

Require approval for state-changing tools, or move the agent back to read-only mode. Do not immediately retry with a larger limit: a second response can hide the exact boundary where the first result was cut.

Preserve the user request, tool arguments, raw server response, runtime envelope, model-visible content and proposed decision. These are separate artifacts and may not contain the same data.

yaml 01-partial-result-incident.yml
incident: INC-AI-816
detected_utc: 2026-10-16T06:40:00Z
agent_release: ops-agent-2026.10.16-2
tool:
server: change-catalog-mcp
name: changes.list
version: 7.4.1
request:
environment: production
status: open
page_size: 100
observed:
returned_items: 100
next_cursor_present: true
completeness_declared: false
agent_decision: deploy
containment:
write_tools: approval_always
allowed_mode: read_only
evidence:
raw_response_hash: <sha256>
runtime_envelope_hash: <sha256>
trace_id: <trace-id>

A final screen or the agent’s paraphrased answer is not enough. The investigation must compare what the server emitted with what the model could actually inspect.

Separate pagination, transport truncation and context loss

Three failures produce the same apparent symptom: an incomplete list.

  1. Expected pagination: the backend returns a page and a cursor, but the client does not continue.
  2. Transport truncation: a gateway, connector or wrapper cuts the payload or replaces part of the response.
  3. Context loss: the complete response exists in the trace, but only a portion reaches the model because it was summarized or displaced by the context budget.

There is also an upstream case: the source query itself may apply an implicit limit. A 200 OK proves that a request completed, not that an inventory is complete.

text 02-completeness-localization.txt
Source count > server serialized count
Inspect query filters, default limit and source pagination

Server bytes > runtime envelope bytes
Inspect gateway limits, connector transformation and response caps

Runtime envelope complete, model input partial
Inspect context assembly, summarization and token budgeting

All layers complete, agent still ignores boundary
Inspect instructions, tool contract and evaluation cases

The fix depends on this boundary. A larger context window does not repair an ignored cursor, and a larger page_size does not repair a gateway that truncates large responses.

Make completeness part of the tool contract

A list used to authorize an action must not leave completeness implicit. Its output schema should separate page content, continuation state and source snapshot information.

json 03-tool-result-envelope.json
{
"items": [
  { "id": "CHG-1842", "risk": "low", "blocking": false }
],
"page": {
  "returned": 100,
  "nextCursor": "<opaque-cursor>",
  "complete": false
},
"source": {
  "snapshotAt": "2026-10-16T06:39:42Z",
  "queryDigest": "<sha256>",
  "estimatedTotal": 137
}
}

nextCursor is an example field in this tool’s contract, not a universal MCP field. The operational requirement is that the runtime and the agent can determine, without guessing, whether more data exists.

Block sensitive decisions when complete is false, missing, or inconsistent with the reported count. If the source cannot provide a stable total, the tool protocol must still prove the end of pagination and bind the read to a coherent snapshot or time window.

Replay every page against a stable snapshot

Looping until the cursor disappears is not sufficient when the catalog changes during the read. Inserts can move page boundaries, create duplicates or make an item disappear between calls.

For the canary, use a known fixture with a sentinel record immediately after the first boundary. Preserve each cursor, page number, identifier digest and source snapshot.

yaml 04-pagination-proof.yml
fixture:
records: 137
page_size: 100
boundary_sentinel:
  id: CHG-BLOCK-101
  expected_page: 2
  blocking: true

replay_requirements:
- same_query_digest
- same_source_snapshot
- cursor_chain_unbroken
- no_duplicate_ids
- no_missing_ids
- boundary_sentinel_found

decision_gate:
allow_deploy_when:
  - complete_is_true
  - blocking_changes_is_zero
  - evidence_chain_is_complete
otherwise: human_review

Keep the cursor opaque to the model and let orchestration code handle it. The agent may interpret the aggregated result; it should not reconstruct or alter a cursor from text.

Expose loss in telemetry

Log completeness signals for every call without duplicating sensitive payloads: raw size, transformed size, item count, cursor presence, complete, snapshot and digests.

With a custom log schema, a KQL query can isolate decisions made from partial results.

kusto 05-partial-tool-results.kql
AgentToolCall_CL
| where TimeGenerated > ago(24h)
| where ToolName_s == "changes.list"
| extend Returned = toint(ReturnedItems_d),
       Complete = tobool(ResultComplete_b),
       HasCursor = isnotempty(NextCursorHash_s)
| where Complete == false or HasCursor == true
| project TimeGenerated,
        TraceId_g,
        ToolVersion_s,
        Returned,
        HasCursor,
        RawBytes_d,
        RuntimeBytes_d,
        ProposedAction_s,
        ApprovalState_s
| order by TimeGenerated desc

The table is an example custom schema; map the fields to your trace pipeline. A useful alert combines an incomplete result with a proposed sensitive action. Pagination on its own is normal behavior.

Test boundaries, not only the happy path

Evaluation must exercise the cases that make a partial response look credible.

  • exactly 0, 1, 99, 100 and 101 records with a page size of 100;
  • an empty page that still carries a continuation cursor;
  • one record that is much larger than the others;
  • a duplicate across pages;
  • a source snapshot that changes during traversal;
  • a complete server response shortened before it reaches the model;
  • missing, invalid or contradictory completeness metadata.

The test does not pass because the agent mentions pagination. It passes when the action stays blocked until the evidence chain is complete and the agent requests bounded continuation or human review.

yaml 06-evaluation-gates.yml
pass_when:
complete_result_no_blocker: deploy_candidate
complete_result_with_blocker: stop
incomplete_result: collect_remaining_pages
inconsistent_metadata: human_review
snapshot_changed: restart_read_only_snapshot

fail_when:
- deploy_from_first_page_only
- infer_complete_from_http_success
- ignore_cursor_after_summary
- raise_limits_without_locating_loss
- retry_write_after_unknown_read_basis

Canary, decide and roll back

Deploy the new contract first with a read-only identity and a canary catalog. Compare item counts and digests with an independent reference read. Repeat at nominal volume, the exact page boundary and a volume above the expected limit.

Promotion requires zero sensitive decisions on incomplete results, a traceable cursor chain, no loss between raw response and model context, and collection time compatible with the runbook. If the full inventory is too large, move deterministic aggregation into the tool and return a summary bound to counts, filters and supporting evidence. Do not ask the model to absorb an arbitrary number of pages.

Rollback restores mandatory approval for write tools, returns to the qualified server or wrapper version and keeps the new completeness signal in observation. Replay every decision from the affected window in read-only mode before resuming the action.

Conclusion

A tool result can be valid and traceable while still being insufficient for a decision. The effective control is not an ever-higher limit. It is an explicit completeness contract, continuous evidence from the source to model context, and a guardrail that stops the action as soon as that evidence breaks.

The runbook ends with a clear choice: promote the contract after a canary proves every boundary, or roll back the action surface while any page, byte or record can disappear without a signal.