fastmcp/tests
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
..
cli Remove enable_docket setting; Docket is now always on 2025-12-05 11:40:04 -05:00
client Convert mounted servers to MountedProvider (#2635) 2025-12-17 22:21:51 -05:00
contrib Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
deprecated Simplify .key as computed property (#2648) 2025-12-18 14:48:47 -05:00
experimental Unify SamplingHandler and promote OpenAI handler (#2616) 2025-12-14 15:22:43 -05:00
integration_tests Improve rate limit detection for integration tests 2025-12-04 11:52:40 -05:00
prompts Revert "Revert "Refactor prompt behavior and add meta support (#2600)" (#2608)" (#2610) 2025-12-14 21:52:20 -05:00
resources Simplify .key as computed property (#2648) 2025-12-18 14:48:47 -05:00
server Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
tools Refactor provider execution: components own their execution (#2663) 2025-12-21 15:03:24 -05:00
utilities Simplify .key as computed property (#2648) 2025-12-18 14:48:47 -05:00
__init__.py Update type handling for resources 2024-11-29 19:42:46 -05:00
conftest.py Use WindowsSelectorEventLoopPolicy to fix Windows test warnings (#2607) 2025-12-14 08:39:44 -05:00
test_mcp_config.py Bump ty to ==0.0.1a25 (#2350) 2025-11-02 20:02:45 -05:00