fix: ResponseLimitingMiddleware no longer breaks outputSchema tools#3756
fix: ResponseLimitingMiddleware no longer breaks outputSchema tools#3756
Conversation
Per the MCP Apps spec, McpUiToolMeta only defines resourceUri and visibility. CSP belongs on the UIResourceMeta (the renderer resource), where we already set it correctly via _ensure_prefab_renderer. Closes #3735
When truncating, set meta on the ToolResult so it goes through the CallToolResult path, bypassing MCP SDK outputSchema validation that would reject the truncated (text-only) response. Closes #3717
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 071745281f
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| ) | ||
|
|
||
| return self._truncate_to_result(text) | ||
| return self._truncate_to_result(text, meta=result.meta) |
There was a problem hiding this comment.
Drop oversized metadata when returning truncated results
Passing result.meta into _truncate_to_result preserves the original metadata blob even after the response was flagged as over max_size, so the middleware can still return payloads far above the configured limit when _meta is large (for example, a tool returning a large debug object in ToolResult.meta). This regresses the middleware’s core size-limiting guarantee because only content is truncated while the oversized metadata is forwarded unchanged.
Useful? React with 👍 / 👎.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: cc3fefb116
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| return ToolResult( | ||
| content=[TextContent(type="text", text=truncated)], | ||
| meta=meta if meta is not None else {}, | ||
| ) |
There was a problem hiding this comment.
Avoid returning schema-less CallToolResult on truncation
Setting meta unconditionally here forces ToolResult.to_mcp_result() down the CallToolResult path even when truncation removed structured_content. For tools that advertise outputSchema, MCP clients still validate successful responses and reject missing structured content, so Client.call_tool() remains broken for oversized schema tools (now surfacing as a runtime validation failure instead of a normal tool error).
Useful? React with 👍 / 👎.
When
ResponseLimitingMiddlewaretruncates a response from a tool withoutputSchema, the MCP SDK rejects it becausestructured_contentis gone but the schema still expects it. This is intentional — truncated text can't satisfy a structured schema, and passingstructured_contentthrough unmodified would defeat the middleware's size-limiting purpose.The fix ensures truncated results always carry
meta, which makesto_mcp_result()return aCallToolResult. The SDK passesCallToolResultthrough without outputSchema validation, so the truncated text reaches the client cleanly.Closes #3717