Repository navigation
fix(get_file_contents): keep modern-protocol results under 1 MiB - #3709
severus0044 wants to merge 4 commits into
Conversation
There was a problem hiding this comment.
🟡 Changes recommended
Inline file responses can still exceed the 1 MiB transport limit because the cutoff ignores serialized-output overhead and fails to recognize modern protocol versions supplied only through request metadata.
2 open issues
What changed in this PR
This PR addresses #3603 by lowering get_file_contents’ inline threshold for modern protocols, aiming to accommodate duplicated file content within common 1 MiB transport limits.
Changes:
- Uses a 512 KiB threshold when context identifies protocol
2026-07-28or later, retaining 1 MiB otherwise. - Reuses the existing
ResourceLinkfallback without changing the output schema. - Adds a 600 KiB regression case comparing legacy and modern behavior.
| File | Description |
|---|---|
pkg/github/repositories.go |
Adds a protocol-dependent inline-content threshold. |
pkg/github/repositories_test.go |
Supports fixture contexts and tests protocol-dependent fallback behavior. |
Review effort: Balanced (auto)
| // fits the old limit does not push the whole result past common 1 MiB | ||
| // transport limits. | ||
| inlineContentLimit := maxContentSize | ||
| if info, ok := ghcontext.MCPMethod(ctx); ok && info.ProtocolVersion >= inventory.ProtocolVersionMultiRoundTrip { |
| // transport limits. | ||
| inlineContentLimit := maxContentSize | ||
| if info, ok := ghcontext.MCPMethod(ctx); ok && info.ProtocolVersion >= inventory.ProtocolVersionMultiRoundTrip { | ||
| inlineContentLimit = maxContentSize / 2 |
2f4e96e to
436e5c4
Compare
|
Reopening after re-checking the two Copilot findings against the current head
Both are already in this branch; I also removed two stray blank lines in the import block. |
|
Closing after a real test run: overlaying this branch on the current upstream base (99d6d65) and running |

Summary
get_file_contentsnow budgets for thestructuredContentcopy that protocol2026-07-28mirrors the file body into, so the encoded tool result stays under 1 MiB instead of roughly doubling the file size.Why
Fixes #3603
On protocol
2026-07-28the typed output mirrors the file body instructuredContent, so a 517 KB file produced a 1.1 MB result and clients with a 1 MiB SSE limit rejected it before they could use it. Files between 512 KiB and 1 MiB therefore worked on2025-11-25but failed on the modern protocol.What changed
MCPMethodInfo.ProtocolVersionis2026-07-28or later, so two copies still fit a 1 MiB payload.ResourceLinkresult above that threshold, which keeps thestructuredContentschema unchanged for consumers.ResourceLinkon the modern protocol.MCP impact
The tool schema is unchanged. On protocol
2026-07-28and later, files from 512 KiB to 1 MiB now return aResourceLinkinstead of inline content, which is the documented fallback already used for files at or above 1 MiB.Prompts tested (tool changes only)
Not applicable to a live client run: the size boundary is covered by unit tests against the real handler rather than a model prompt. The regression test exercises
get_file_contentswith a 600 KiB file and both protocol eras.Security / limits
This change only tightens the existing transport-size fallback; no new data is exposed.
Tool renaming
Lint & tests
./script/lint./script/testgo test ./pkg/github -count=1andgo vet ./pkg/githubpass. The regression subtest was verified to fail against the previous threshold logic.Docs
From Codex