fastmcp/tests/server/providers
Francis Secada 032b9f6382
fix: don't infer an output schema for unconstrained sequences (#4999)
* fix: don't infer an output schema for unconstrained sequences

`Any` is already excluded from output-schema inference because the schema
it produces constrains nothing. A bare `list` or `tuple` is the
sequence-shaped equivalent: it yields `{"result": {"items": {}, "type":
"array"}}`, which permits every value that no schema at all permits.

Inferring it is not free. An output schema forces structured content, and
`replace_type` cannot suppress the MCP content types inside a sequence
that has no item type to match -- which is why `list[ContentBlock]`
already infers nothing but bare `list` does not. So a tool annotated
`-> list` returning `[ImageContent(...), {...}]`, the shape used to pair
a picture with its metadata, puts the base64 image on the wire twice:
once as an image content block, and once again serialised into
`structuredContent`.

Clients break on that in both directions. Some render the JSON blob
instead of the picture; others inject the duplicated base64 into model
context and blow their tool-output token cap. Server authors currently
work around it per-tool with `output_schema=None`, which also discards
the schema for tools that wanted one.

`list`, `tuple`, `list[Any]` and `tuple[Any, ...]` now infer no schema,
matching `Any`. Annotations that say something about their items --
`list[int]`, `tuple[int, str]`, `dict`, `str` -- are untouched.

Two parametrized sweeps asserted the old bare-`list` schema as one case
among many annotations; `list` is dropped from both, and the new
behaviour gets its own tests including a regression test that a returned
image is not duplicated into `structuredContent`.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>

* tools: catch typing.List, Sequence, and Annotated in the unconstrained-sequence guard

fixed-length tuple[Any, ...] variants keep their schema since they still
pin a length. documents the exception in the tools docs.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_0186WjrVNudDm5qaDPw5mntN

---------

Co-authored-by: Claude Opus 5 <noreply@anthropic.com>
Co-authored-by: zzstoatzz <thrast36@gmail.com>
2026-09-04 13:02:02 -05:00
..
local_provider_tools fix: don't infer an output schema for unconstrained sequences (#4999) 2026-09-04 13:02:02 -05:00
openapi Preserve legacy httpx compatibility without importing it (#4766) 2026-08-05 18:09:16 -04:00
proxy Fix proxy forwarding of MCP transport headers (#4853) 2026-08-18 12:36:24 -04:00
__init__.py Refactor MountedProvider into FastMCPProvider + TransformingProvider (#2653) 2025-12-19 11:42:59 -05:00
test_addressing.py Replace ___ with hash-based backend tool routing and per-tool prefab resources (#3824) 2026-04-12 12:52:07 -04:00
test_base_provider.py Move task subsystem to fastmcp-tasks package, disconnect SEP-1686 wire from core 2026-07-21 21:51:45 -04:00
test_fastmcp_provider.py Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
test_local_provider.py Move task subsystem to fastmcp-tasks package, disconnect SEP-1686 wire from core 2026-07-21 21:51:45 -04:00
test_local_provider_prompts.py Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
test_local_provider_resources.py Migrate to MCP Python SDK v2 (#4437) 2026-07-06 17:36:45 -04:00
test_prefab_roundtrip.py Late-bind app tool names so UIs survive composition (#4682) 2026-07-28 10:54:19 -04:00
test_prefab_synthesis.py Replace ___ with hash-based backend tool routing and per-tool prefab resources (#3824) 2026-04-12 12:52:07 -04:00
test_skills_provider.py Remove 3.x-era compatibility shims (#4661) 2026-07-27 14:59:43 -04:00
test_skills_vendor_providers.py Add Skills Provider for exposing agent skills as MCP resources (#2944) 2026-01-19 18:29:16 -05:00
test_transforming_provider.py Refactor transform list methods to pure function pattern (#2942) 2026-01-19 16:21:35 -05:00