fastmcp/tests/server/tasks
Chris Guidry 547daf7a36
Replace vendored DI with uncalled-for (#3301)
* Replace vendored DI with uncalled-for

FastMCP vendored a minimal DI engine extracted from Docket (~164 lines)
with try/except fallback patterns everywhere. The `uncalled-for` package
is a clean, typed extraction of this same system, and since Docket will
also depend on it (chrisguidry/docket#353), `uncalled_for.Dependency`
becomes the single canonical base class.

This deletes the `_vendor/docket_di/` directory, replaces all the
try/except import patterns with direct `uncalled_for` imports, and
updates the `Dependency.execution` → `current_execution` ContextVar
references to match the Docket branch. The `Progress` class now
delegates to an internal impl and returns `self` from `__aenter__`
(matching Docket's pattern) so that ty's generic resolution works
without `type: ignore` suppressions.

Temporarily points pydocket at the `use-uncalled-for` branch so both
sides can be validated together in CI.

🤖 Generated with Claude Code

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

* Re-export Dependency from fastmcp.dependencies

Internal code like azure.py should import from the fastmcp namespace
rather than reaching into uncalled_for directly.

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

* Import Dependency from fastmcp namespace in tests

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

* Add generic type parameters to Dependency subclasses

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

* Mention uncalled-for in DI docs

The DI engine now comes from uncalled-for, so the docs should credit
it alongside Docket. Also updates the Docket docs link to docket.lol.

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

* Point docket dependency at main

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

* Bump uncalled-for pin to >=0.2.0

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

* Fix uncalled-for imports for 0.2.0 API changes

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

* Support Shared() dependencies without docket

Enters a SharedContext at server lifetime so that Shared() dependencies
from uncalled-for resolve once and are cached across tool/resource/prompt
calls. When running with docket, the Worker already handles this; this
covers the non-docket path and direct call_tool() usage.

Also re-exports Shared from fastmcp.dependencies.

Closes #3251

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

* Bump docket lockfile to latest main

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

* Remove duplicate test classes from rebase conflict resolution

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

* Point docket dependency at pydocket>=0.18.0 release

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

* Pair SharedContext __aenter__ with __aexit__ in Context lifecycle

The old `_ensure_shared_context` on the server called `__aenter__()` on a
lazy `SharedContext` but never `__aexit__()`, leaking the exit stack and
its resources. Moved the SharedContext management into Context's own
enter/exit so it's properly paired: when docket is available the lifespan
handles it, otherwise Context creates and cleans up a per-request one.

Updated Shared() tests to use Client (which runs the lifespan) rather
than calling server methods directly, since cross-request sharing
requires a lifespan.

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

* Hoist SharedContext import to module level

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-02 16:35:15 -05:00
..
__init__.py [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00
test_context_background_task.py fix: propagate origin_request_id to background task workers (#3175) 2026-02-22 11:16:30 -05:00
test_custom_subclass_tasks.py Add component versioning and VersionFilter transform (#2894) 2026-01-16 20:53:18 -05:00
test_notifications.py Move relay logic to elicitation.py, fix related-task metadata key 2026-02-10 16:00:01 -05:00
test_progress_dependency.py Remove enable_docket setting; Docket is now always on 2025-12-05 11:40:04 -05:00
test_resource_task_meta_parameter.py Add task_meta to prompts and centralize fn_key enrichment (#2751) 2025-12-26 15:04:25 -05:00
test_server_tasks_parameter.py Add component versioning and VersionFilter transform (#2894) 2026-01-16 20:53:18 -05:00
test_sync_function_task_disabled.py Decorators return functions instead of component objects (#2856) 2026-01-12 21:58:07 -05:00
test_task_capabilities.py Fix task capabilities location (issue #2870) 2026-01-13 22:26:13 -05:00
test_task_config.py Unify component storage in LocalProvider (#2680) 2025-12-23 19:24:09 -05:00
test_task_dependencies.py Replace vendored DI with uncalled-for (#3301) 2026-03-02 16:35:15 -05:00
test_task_elicitation_relay.py Relay task elicitation through standard MCP protocol 2026-02-10 14:58:19 -05:00
test_task_meta_parameter.py Add loq file size limits and clean up type ignores (#2859) 2026-01-13 07:29:12 -05:00
test_task_metadata.py Move relay logic to elicitation.py, fix related-task metadata key 2026-02-10 16:00:01 -05:00
test_task_methods.py Normalize repo references to PrefectHQ/fastmcp casing (#3218) 2026-02-18 14:51:18 -05:00
test_task_mount.py Add task_meta to prompts and centralize fn_key enrichment (#2751) 2025-12-26 15:04:25 -05:00
test_task_prompts.py Refactor Client class into mixins and add timeout utilities (#2933) 2026-01-19 09:54:47 -05:00
test_task_protocol.py fix: stabilize task notification integration tests 2026-02-08 15:20:22 +01:00
test_task_proxy.py Refactor FastMCPProxy into ProxyProvider (#2669) 2025-12-21 21:30:03 -05:00
test_task_resources.py Refactor Client class into mixins and add timeout utilities (#2933) 2026-01-19 09:54:47 -05:00
test_task_return_types.py fix: propagate origin_request_id to background task workers (#3175) 2026-02-22 11:16:30 -05:00
test_task_security.py [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00
test_task_status_notifications.py [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00
test_task_tools.py Refactor Client class into mixins and add timeout utilities (#2933) 2026-01-19 09:54:47 -05:00
test_task_ttl.py [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00