What happened?
When ResponseLimitingMiddleware truncates a response from a tool that has an outputSchema (either explicitly set or auto-generated from a return type annotation), the truncated ToolResult has no structured_content. This causes the MCP SDK's output validation to fail with:
Output validation error: outputSchema defined but no structured output returned
Normal-sized responses work fine. The error only occurs when the response exceedsmax_sizeand gets truncated.
I noticed that the original PR (#3072) had a raise_on_structured option that was removed during review as unnecessary complexity. However, the current behavior silently produces an MCP protocol violation for any tool with outputSchema — which includes any tool with a return type annotation. It seems like some form of explicit handling for outputSchema-bearing tools is needed, whether that's raising, preserving structured_content, or something else.
Example Code
import asyncio
from fastmcp import Client, FastMCP
from fastmcp.server.middleware.response_limiting import ResponseLimitingMiddleware
from pydantic import BaseModel
class Answer(BaseModel):
text: str
mcp = FastMCP()
mcp.add_middleware(ResponseLimitingMiddleware(max_size=1_000))
@mcp.tool()
def big_answer() -> Answer:
return Answer(text="x" * 2_000)
async def demo():
async with Client(mcp) as client:
result = await client.call_tool("big_answer")
print(f"OK: {result}")
asyncio.run(demo())
WARNING Tool 'big_answer' response exceeds size limit: 4131 bytes > 1000 bytes, truncating
fastmcp.exceptions.ToolError: Output validation error: outputSchema defined but no structured output returned
Version Information
FastMCP version: 3.1.1
MCP version: 1.26.0
Python version: 3.13.11
Platform: macOS-26.3-arm64-arm-64bit-Mach-O
What happened?
When
ResponseLimitingMiddlewaretruncates a response from a tool that has an outputSchema (either explicitly set or auto-generated from a return type annotation), the truncatedToolResulthas nostructured_content. This causes the MCP SDK's output validation to fail with:Output validation error: outputSchema defined but no structured output returned
Normal-sized responses work fine. The error only occurs when the response exceeds
max_sizeand gets truncated.I noticed that the original PR (#3072) had a
raise_on_structuredoption that was removed during review as unnecessary complexity. However, the current behavior silently produces an MCP protocol violation for any tool withoutputSchema— which includes any tool with a return type annotation. It seems like some form of explicit handling for outputSchema-bearing tools is needed, whether that's raising, preservingstructured_content, or something else.Example Code
Version Information