fastmcp/tests/server/mount
d 🔹 68e76fea2e
fix: forward custom_route endpoints from mounted servers (#3462)
* fix: forward custom_route endpoints from mounted servers

When a child server with custom HTTP routes (registered via
@server.custom_route()) is mounted onto a parent, the routes were
silently dropped because _get_additional_http_routes() only returned
self._additional_http_routes without recursing into mounted providers.

This caused 404s for endpoints like /readyz health checks that worked
in v2 but broke in v3 (regression).

The fix updates _get_additional_http_routes() to traverse providers,
unwrap _WrappedProvider layers (from namespace transforms), find
FastMCPProvider instances, and recursively collect their server's
custom routes.

Fixes #3457

* fix: narrow type annotation from BaseRoute to Route

All items in _additional_http_routes are Route objects (created via
Route(...) in custom_route()). Using list[Route] instead of
list[BaseRoute] fixes the ty type checker failure where .path is
accessed on BaseRoute which doesn't have that attribute.

Removes unused BaseRoute imports from both server.py and transport.py.

* fix: revert route type to list[BaseRoute] to fix ty errors

The previous commit narrowed _additional_http_routes from list[BaseRoute]
to list[Route], which broke:
- component_manager appending Mount objects (Mount is BaseRoute, not Route)
- tests assigning list[BaseRoute] variables (generics are invariant)

Revert to list[BaseRoute] and use isinstance(r, Route) guards in tests
for type-safe .path access.

* fix: remove unused import and fix import grouping

- Remove unused `Route` import from server.py
- Fix import grouping in test_advanced.py (ruff check)

* Address review: move imports to module root, type Provider, add collision note

* fix: sort imports in transport.py

---------

Co-authored-by: voidborne-d <voidborne-d@users.noreply.github.com>
Co-authored-by: d 🔹 <258577966+voidborne-d@users.noreply.github.com>
Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
2026-03-13 20:37:22 -04:00
..
__init__.py Consolidate test fixtures and refactor large test files (#2941) 2026-01-19 15:18:35 -05:00
test_advanced.py fix: forward custom_route endpoints from mounted servers (#3462) 2026-03-13 20:37:22 -04:00
test_filtering.py Remove deprecated FastMCP() constructor kwargs (#3148) 2026-02-11 11:39:34 -05:00
test_mount.py Consolidate test fixtures and refactor large test files (#2941) 2026-01-19 15:18:35 -05:00
test_prompts.py Consolidate test fixtures and refactor large test files (#2941) 2026-01-19 15:18:35 -05:00
test_proxy.py Consolidate test fixtures and refactor large test files (#2941) 2026-01-19 15:18:35 -05:00
test_resources.py Fix resource templates with query params on mounted servers 2026-03-03 16:43:27 -05:00