feat: cap individual tool response sizes#1029
Draft
jmikitova wants to merge 1 commit into
Draft
Conversation
Bound per-call output for the tools that could blow the context budget: - get-dataset-items: clamp effective limit to MAX_DATASET_ITEMS_LIMIT (100) pre-fetch, then a DATASET_ITEMS_MAX_BYTES (50KB) byte cap on the encoded payload, dropping trailing items and paginating via offset. - get-key-value-store-record: cap inlined text/JSON at KV_RECORD_MAX_INLINE_TEXT_BYTES (50KB), truncate + link to the full record. - search-apify-docs: clip per-snippet content to DOCS_SNIPPET_MAX_LENGTH (1000). - call-actor: stop dumping the full input schema on validation/missing-input errors; return the AJV errors + a fetch-actor-details pointer instead. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Several MCP tools returned unbounded output, so a single tool call could blow the AI-chat context budget (e.g.
get-dataset-itemsreaching ~236k tokens). This caps per-call output so no single response is unbounded, and every truncated response tells the model how to get the rest (paginate / fetch full record / fetch full schema).Changes
limittoMAX_DATASET_ITEMS_LIMIT(100) pre-fetch, then aDATASET_ITEMS_MAX_BYTES(50 KB) byte cap on the encoded payload, dropping trailing items and steering tooffsetpagination from the actually-returned count (lossless resume).KV_RECORD_MAX_INLINE_TEXT_BYTES(50 KB) → truncate + link to the full record (mirrors the existing 256 KB binary cap).contenttoDOCS_SNIPPET_MAX_LENGTH(1000), with a pointer tofetch-apify-docsfor the full page.fetch-actor-detailspointer instead.Measured on what the model actually receives: the chat serializes MCP results via
mcpToModelOutput(schemas: "automatic"), which forwards onlycontentand dropsstructuredContent, so the caps measure thecontentpayload.Tests
New/extended unit tests in
tests/unit/for each cap (over-cap input stays bounded, truncation/pointer present, pagination offset resumes from the returned count). Full unit suite green (68 files, 973 pass / 2 skip).Out of scope (follow-up)
The model paginating through an entire dataset (many capped calls) is a separate prompt/behavior lever, not a per-call size fix — worth its own change.
🤖 Generated with Claude Code