fastmcp/tests/server/tasks
Chris Guidry 34313ea112
Restore task snapshot via a worker-level dependency (#3945)
* Restore task snapshot via a worker-level dependency

`get_access_token()` returned `None` inside background tasks whenever
`FASTMCP_DOCKET_URL` pointed at a `redis+cluster://` URL. The write side
was fine — it went through `docket.redis()`, which is cluster-aware —
but fastmcp kept a parallel sync Redis client just to read the snapshot
back, and `Redis.from_url()` rejects the cluster scheme.

Docket 0.19.1 ships worker-level dependencies that resolve per task in
the same asyncio.Task as user code, so ContextVars propagate cleanly.
That lets us load the snapshot once via `restore_task_snapshot` and
drop the sync Redis path entirely. Sync helpers like
`get_access_token()` and `get_http_request()` now just read a
ContextVar; Docket is the sole Redis consumer.

Closes #3897

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

* Revert TaskKey stub to a plain return

NotImplementedError would fire at module import if anything evaluated
the default; a no-op stub keeps the module usable without the
fastmcp[tasks] extra, which is what we want.

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

---------

Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-17 08:24:42 -04:00
..
__init__.py [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00
conftest.py Expose minimum_check_interval, reduce task pickup latency (#3500) 2026-03-14 16:08:28 -04:00
test_concurrent_dependencies.py Unify background task context forwarding, fix concurrent dependency bugs (#3710) 2026-04-03 10:48:27 -04:00
test_context_background_task.py Restore task snapshot via a worker-level dependency (#3945) 2026-04-17 08:24:42 -04:00
test_custom_subclass_tasks.py fix: resolve Pyright "Module is not callable" on @tool, @resource, @prompt decorators (#3540) 2026-03-17 18:11:42 -04: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 fix: resolve Pyright "Module is not callable" on @tool, @resource, @prompt decorators (#3540) 2026-03-17 18:11:42 -04:00
test_server_tasks_parameter.py fix tests that relied on task=True returning error results (#3954) 2026-04-17 07:48:46 -04:00
test_snapshot_restore.py Restore task snapshot via a worker-level dependency (#3945) 2026-04-17 08:24:42 -04: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 Version-check is_docket_available() to avoid transitive pydocket crash (#3807) 2026-04-09 21:52:21 -04:00
test_task_config.py fix tests that relied on task=True returning error results (#3954) 2026-04-17 07:48:46 -04:00
test_task_dependencies.py Unify background task context forwarding, fix concurrent dependency bugs (#3710) 2026-04-03 10:48:27 -04:00
test_task_elicitation_relay.py Relay task elicitation through standard MCP protocol 2026-02-10 14:58:19 -05:00
test_task_keys.py Scope tasks to authorization context, not session (#3800) 2026-04-13 13:50:43 -04:00
test_task_meta_parameter.py fix: resolve Pyright "Module is not callable" on @tool, @resource, @prompt decorators (#3540) 2026-03-17 18:11:42 -04: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 Expose minimum_check_interval, reduce task pickup latency (#3500) 2026-03-14 16:08:28 -04:00
test_task_mount.py fix tests that relied on task=True returning error results (#3954) 2026-04-17 07:48:46 -04: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 fix tests that relied on task=True returning error results (#3954) 2026-04-17 07:48:46 -04: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: retry when LLM returns text instead of calling final_response (#3850) 2026-04-12 12:52:16 -04:00
test_task_security.py Scope tasks to authorization context, not session (#3800) 2026-04-13 13:50:43 -04:00
test_task_status_notifications.py [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00
test_task_tools.py fix tests that relied on task=True returning error results (#3954) 2026-04-17 07:48:46 -04:00
test_task_ttl.py [2.14] SEP-1686 tasks (#2378) 2025-12-04 20:10:35 -05:00