fastmcp/tests/server/middleware
Asem ahmed 83cd06b35c
Keep is_error when ResponseLimitingMiddleware truncates a result (#5309)
`ResponseLimitingMiddleware` rebuilt an oversized result as a fresh `ToolResult` that kept `meta` but not `is_error`, so truncating a failed tool's output reported the call as a success. The truncated result now carries the original `is_error`, so truncation only changes the size of the result, not whether it succeeded.

```python
mcp.add_middleware(ResponseLimitingMiddleware(max_size=500))

@mcp.tool
def fetch() -> ToolResult:
    return ToolResult(content="upstream failed: " + "x" * 1000, is_error=True)

# before: result.is_error is False once truncated
# after:  result.is_error is True
```

This touches the same `_truncate_to_result` as #5286, so whichever lands second needs a small rebase.

Fixes #5304.

Co-authored-by: asemabdallah <asasem547@gmail.com>
2026-10-04 20:29:26 -04:00
..
__init__.py Add single-component methods 2025-06-18 19:47:19 -04:00
test_caching.py Preserve binary resource contents in response cache (#5181) 2026-09-21 18:04:07 -05:00
test_caching_guards.py Split guard caching tests into their own module 2026-07-26 16:46:21 -04:00
test_dereference.py Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
test_discovery_middleware.py Forward proxy server metadata across protocol eras (#4776) 2026-08-06 19:09:05 -04:00
test_error_handling.py Keep the original cause when ErrorHandlingMiddleware re-raises an error unchanged (#5344) 2026-10-04 20:27:25 -04:00
test_initialization_middleware.py Audit mode="legacy" pins in server tests and top-level stragglers 2026-07-20 16:00:27 -04:00
test_logging.py Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
test_message_visibility.py Forward proxy server metadata across protocol eras (#4776) 2026-08-06 19:09:05 -04:00
test_middleware.py Update tests for the removed sampling and roots server API 2026-07-26 14:38:26 -04:00
test_middleware_nested.py Update tests for the removed sampling and roots server API 2026-07-26 14:38:26 -04:00
test_ping.py Audit mode="legacy" pins in server tests and top-level stragglers 2026-07-20 16:00:27 -04:00
test_rate_limiting.py rate_limiting: deprecate a burst_capacity below 1 (#5296) 2026-09-26 17:38:30 -05:00
test_response_limiting.py Keep is_error when ResponseLimitingMiddleware truncates a result (#5309) 2026-10-04 20:29:26 -04:00
test_timing.py Consolidate test fixtures and refactor large test files (#2941) 2026-01-19 15:18:35 -05:00
test_tool_injection.py Resolve injected tools through the server's tool lookup (#5431) 2026-10-04 10:39:47 -04:00
test_versioned_caching.py Fix response cache partitioning for versioned components (#4948) 2026-08-31 01:23:41 -05:00