Repository navigation
fix(server): apply tool_response_limit to structuredContent - #1937
Merged
Merged
Conversation
tool_response_limit truncated only TextContent blocks, so an upstream returning a large structuredContent delivered the full payload to the client. An oversize structured result is now withheld and, unless a text block already carries the same JSON, turned into text blocks before output sanitisation, so it is redacted, scanned, truncated and cached for read_cache like any other block. Results within the limit are unchanged. Output-schema validation still judges the upstream value, Spec 069 response_bytes still measures it, and on the direct surface a tool whose published listing carries an outputSchema keeps its structuredContent. Closes #1932
Dumbris
enabled auto-merge (squash)
November 19, 2026 11:20
Deploying mcpproxy-docs with
|
| Latest commit: |
aab59f9
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://eaeaa18b.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://claude-pass-through-behavior.mcpproxy-docs.pages.dev |
The docs site does not publish docs/configuration.md, so the link from output-schema-validation broke the Docusaurus build. Point it at configuration/config-file.md and describe the structuredContent bound there.
Contributor
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 44514382038 --repo smart-mcp-proxy/mcpproxy-go
|
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
Dumbris
added a commit
that referenced
this pull request
Nov 24, 2026
## Summary Since 0.75.0 (#1937) `tool_response_limit` also bounds `structuredContent`. That is right for agents, but a local script that parses the JSON itself now gets cut answers, and `read_cache` cannot rebuild them (it pages one record array and leaves out sibling fields such as `@odata.nextLink`). This adds the override the issue asks for: `profiles[].tool_response_limit`. - unset: the profile inherits the global limit - `0`: no limit, text blocks and `structuredContent` arrive whole - a positive number: that many characters (may be larger or smaller than the global limit) A script gets its own read-only profile with whole answers; chats keep the default bound. ```json { "name": "script", "servers": ["workiq", "tickets"], "max_tier": "read", "tool_response_limit": 0 } ``` closes #2027 ## What changed - **Config** (`internal/config/profiles.go`): new `ToolResponseLimit *int` (a pointer, so an explicit `0` survives `omitempty`), `EffectiveToolResponseLimit`, and a negative value is refused by the one profile validator (field `tool_response_limit`). It is a delivery setting, not policy: it does not make a profile non-legacy. - **Serving path** (`internal/server/profile_response_limit.go`): the truncator is resolved per call from the effective profile (`truncatorForProfile`), and used by `call_tool_read|write|destructive`, the legacy `call_tool`, the direct tools, `retrieve_tools`, `read_cache` and the TOON encoder. A profile that sets no limit, or a name that no longer exists, keeps the live global truncator. - **Sanitisation is not weakened.** Output sanitisation reads text blocks only, and under the global limit an oversize structured result reached it as text. While sanitisation is set to block, redact or strip, the global limit still decides when a structured result becomes a text block; the profile's limit then delivers that text whole (`structuredWithholdLimit`). With sanitisation in its default mode the result stays in `structuredContent`. - **Admin surfaces**: REST `ProfileView.tool_response_limit`, the profile change diff, the MCP `profiles` tool schema, CLI `profile create|update --tool-response-limit <n|inherit>` / `--clear-tool-response-limit` / `profile try --set tool_response_limit=`, `profile show`. - **Editors**: the Web UI and macOS profile editors gain an Inherit / No limit / Custom control. Without it, saving a profile there would have dropped a limit set elsewhere, because both build the PUT body from their own draft. - **Docs**: `docs/features/profiles.md` "Response limit per profile", config reference, CLI and REST references, swagger, changelog. ## Decisions made without asking - The override may widen as well as narrow. The limit is a context-budget setting, not an access rule, and only an operator can set it. Any caller that can select the profile gets its limit, which the docs say. - `mcpproxy call tool-read` has no profile argument and is unchanged; a script uses `/mcp/p/<profile>` or a credential bound to the profile. ## Testing - New Go tests: config validation and JSON round trip, `handleCallToolVariant` under URL, session and pinned profiles against a real in-process upstream (fails without the change), the sanitisation case, direct-mode limit resolution, REST view and diff, CLI flags. - New vitest spec for the editor control; new XCTest cases for the Swift payload round trip. - Live check with the built binary and a fixture returning 128,357 characters of `structuredContent` (300 records plus `@odata.nextLink`): | Endpoint | Result | |---|---| | `/mcp` (no profile, limit 20000) | structuredContent withheld, text cut at 19,811 | | `/mcp/p/chat` (inherits) | same as above | | `/mcp/p/script` (`tool_response_limit: 0`) | structuredContent whole: 300 records, `@odata.nextLink` present | A live `profile update chat --tool-response-limit 60000` took effect on the next call without a restart. ## Known, not changed here Direct mode reads the global limit from the construction-time config, so a hot-reloaded global `tool_response_limit` does not reach it. That predates this change.
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.
Summary
tool_response_limittruncated only the text blocks incontent, so an upstream that returned a largestructuredContent(the report: a Vikunja MCP server) delivered the full payload to the client. This was a gap rather than a decision. Spec 056 and #1861 only promise that output validation never mutatesstructuredContent; neither addresses the response limit.Now, when the JSON encoding of
structuredContentis longer than the limit:structuredContent, andRawStructuredContentis cleared as well;read_cachehandle.A
structuredContentwithin the limit is forwarded unchanged (Spec 056 SC-002 holds).Kept consistent:
outputValidationView), so strict mode withmissing_structured_content=blockdoes not refuse a large response.response_byteskeeps measuring what the upstream returned (upstreamSizeView): the structured value and its raw bytes are restored and the appended blocks dropped.outputSchemakeeps itsstructuredContent, because MCP clients reject a result without it. The handler decides fromdirectCatalogEntry.OutputSchemaListed, which is set at render time from the registeredmcp.Tool. Deferred listings never publish an outputSchema, so their structured results are bounded too. The direct surface has noread_cache, so its JSON block is cut plainly.No new config option. Withholding by default is what the issue asked for. A pass-through knob can follow if someone needs the old behaviour.
closes #1932
Testing
internal/server/content_forward_structured_test.go: withholding and caching (the banner names the stored key), duplicate text detection, no write into the caller's backing array, no-op cases, redaction of the replacement (proved through the cached copy), validation view with a real validator plus a control,response_bytesparity (including raw bytes), direct render flag in full and deferred modes.go test -race -tags serverover./internal/server/...and./internal/truncate/...with the CI skip regex: pass../scripts/test-api-e2e.sh: 77/77..github/.golangci.yml), bare and--build-tags server: 0 new issues.github-copilot/gpt-6.1-sol, 3 rounds. Round 1 found the replacement bypassing sanitisation/detection and deferred listings being exempted. Round 2 foundresponse_bytesmeasuring the withheld form. Round 3: clean.