fastmcp/tests/server
Jeremiah Lowin 19fdac7b02
Refactor provider execution: components own their execution (#2663)
* Add test_custom_subclass_tasks.py

* Refactor provider execution: delegate to middleware via wrapper components

- Remove execution methods (call_tool, read_resource, etc.) from Provider base
- Add FastMCPProvider* wrapper classes that delegate to child server middleware
- Move task routing to Tool._run() using contextvars (_task_metadata, _tool_call_key)
- Add convert_to_tool_result(result, output_schema) utility for Docket results
- Add convert_to_prompt_result() utility for prompt task results
- Pass namespaced key via add_to_docket(name=) for mounted tool lookup

* Standardize add_to_docket() with fn_key/task_key parameters

All components now use explicit fn_key (function lookup) and task_key
(result storage) parameters instead of relying on implicit key handling.
This fixes mounted component task execution where the MCP-visible key
differs from the Docket-registered function name.

* Add middleware chain tests for three-level mount hierarchy

Tests verify middleware runs at parent, child, and grandchild levels
for tools, resources, prompts, and resource templates.

* WIP: Provider refactor - unified submit_to_docket, template _read() in progress

Work in progress on refactoring execution to use component _read()/_run()/_render() methods.
Template background tasks not yet working - needs fix for Docket key lookup.

* Fix conversion functions to take full component for attribute access

Pass Tool/Prompt/Resource/Template to conversion functions instead of
individual attributes, ensuring access to serializer, output_schema,
mime_type, etc. Also fixes mixed-content output schema validation.

* Refactor: unified convert_result() methods and check_background_task helper

- Add convert_result() instance methods to all component types (Tool, Prompt, Resource, ResourceTemplate)
- Extract duplicated task routing logic into check_background_task() helper
- Fix type annotations on FastMCPProviderResource.read() and FastMCPProviderPrompt.render()
- Update protocol.py to use component.convert_result() uniformly

* Update tests to use namespace= instead of deprecated prefix= parameter
2025-12-21 15:03:24 -05:00
..
auth Add smart fallback for missing access token expiry (#2587) 2025-12-09 21:31:17 -05:00
http Fix type errors for ty 0.0.1-alpha.31 upgrade (#2561) 2025-12-05 21:29:14 -05:00
middleware Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
openapi Switch to new OpenAPI parser as default (#2513) 2025-12-01 20:29:18 -05:00
providers Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
proxy Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
sampling SEP-1577: Sampling with tools (#2551) 2025-12-14 13:51:05 -05:00
tasks Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
__init__.py restore 1.x code 2025-04-09 11:54:42 -04:00
test_app_state.py Update docs and test 2025-06-20 13:06:48 -04:00
test_auth_integration.py Update FastMCP for MCP SDK 1.23.1 auth changes 2025-12-03 11:50:08 -05:00
test_context.py SEP-1577: Sampling with tools (#2551) 2025-12-14 13:51:05 -05:00
test_dependencies.py Let FastMCPError propagate from dependencies 2025-12-18 10:59:24 -05:00
test_event_store.py SEP-1699: Add SSE polling support with EventStore (#2564) 2025-12-09 09:55:51 -05:00
test_file_server.py Internal refactor of MCP handlers (#2005) 2025-10-05 08:45:10 -04:00
test_icons.py Implement icon support (#2121) 2025-10-17 17:28:08 -04:00
test_input_validation.py Add Pydantic-compatible input validation (#2073) 2025-10-14 11:49:30 -07:00
test_log_level.py Add log level support for stdio and HTTP transports (#1840) 2025-09-19 13:46:30 -04:00
test_logging.py Remove enable_docket setting; Docket is now always on 2025-12-05 11:40:04 -05:00
test_mount.py Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
test_providers.py Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
test_run_server.py Update tests for prompts 2025-06-04 16:37:41 -04:00
test_server.py Refactor MountedProvider into FastMCPProvider + TransformingProvider (#2653) 2025-12-19 11:42:59 -05:00
test_server_docket.py Fix type errors for ty 0.0.1-alpha.31 upgrade (#2561) 2025-12-05 21:29:14 -05:00
test_server_interactions.py Revert "Revert "Refactor prompt behavior and add meta support (#2600)" (#2608)" (#2610) 2025-12-14 21:52:20 -05:00
test_server_lifespan.py Fix type errors for ty 0.0.1-alpha.31 upgrade (#2561) 2025-12-05 21:29:14 -05:00
test_streamable_http_no_redirect.py Improve redirect handling to address 307's (#1387) 2025-08-08 11:55:30 -04:00
test_tool_annotations.py Add TaskConfig for SEP-1686 execution modes 2025-12-06 21:01:11 -05:00
test_tool_transformation.py Internal refactor of MCP handlers (#2005) 2025-10-05 08:45:10 -04:00