mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-19 12:04:18 +02:00
* Implement MCP background tasks (SEP-1686) using Docket Adds support for background task execution via the MCP task protocol, powered by Docket for task queue management. - Tools, resources, and prompts can be marked with `task=True` to run async - Progress dependency for tracking task progress - CurrentDocket and CurrentWorker dependencies for advanced use cases - Client API with `.call_tool(..., task=True)` returns task handles - Task status notifications via subscriptions - CLI worker command for distributed task processing Configuration via environment: - FASTMCP_ENABLE_DOCKET=true - FASTMCP_ENABLE_TASKS=true - FASTMCP_DOCKET_URL=redis://... (or memory:// for single-process) 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix tasks example import (TaskStatusResponse → GetTaskResult) The example was using a non-existent TaskStatusResponse type. Updated to use mcp.types.GetTaskResult which is what the on_status_change callback actually receives. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Fix env var name in Docket error messages The error messages referenced FASTMCP_EXPERIMENTAL_ENABLE_DOCKET but the actual setting is FASTMCP_ENABLE_DOCKET. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com> * Remove deprecated code re-added from pre-#2329 branch - Remove ExtendedEnvSettingsSource (FASTMCP_SERVER_ prefix support) - Remove dependencies parameter from FastMCP.__init__ * Replace fakeredis git pin with PyPI release * Remove redundant fakeredis dev dep (pulled via pydocket) --------- Co-authored-by: Claude <noreply@anthropic.com> Co-authored-by: Jeremiah Lowin <153965+jlowin@users.noreply.github.com>
62 lines
1.6 KiB
Markdown
62 lines
1.6 KiB
Markdown
# FastMCP Tasks Example
|
|
|
|
Demonstrates background task execution with Docket, including progress tracking, distributed backends, and CLI worker management.
|
|
|
|
## Setup
|
|
|
|
```bash
|
|
# From the fastmcp root directory
|
|
uv sync
|
|
|
|
# Start Redis
|
|
cd examples/tasks
|
|
docker compose up -d
|
|
|
|
# Load environment (or source .envrc manually)
|
|
direnv allow
|
|
|
|
# Run the server
|
|
fastmcp run server.py
|
|
```
|
|
|
|
For single-process mode without Redis, set `FASTMCP_DOCKET_URL=memory://` (note: CLI workers won't work).
|
|
|
|
## Running the Client
|
|
|
|
```bash
|
|
# Background execution with progress callbacks
|
|
python examples/tasks/client.py --duration 10
|
|
|
|
# Immediate execution (blocks)
|
|
python examples/tasks/client.py immediate --duration 5
|
|
```
|
|
|
|
## Starting Additional Workers
|
|
|
|
With Redis, you can run additional workers to process tasks in parallel:
|
|
|
|
```bash
|
|
fastmcp tasks worker server.py
|
|
|
|
# Configure via environment:
|
|
export FASTMCP_DOCKET_CONCURRENCY=20
|
|
fastmcp tasks worker server.py
|
|
```
|
|
|
|
**Backend options:**
|
|
- `memory://` - Single-process only (default)
|
|
- `redis://` - Distributed, multi-process (Redis or Valkey)
|
|
|
|
## Environment Variables
|
|
|
|
| Variable | Default | Description |
|
|
|----------|---------|-------------|
|
|
| `FASTMCP_ENABLE_DOCKET` | `false` | Enable Docket task system |
|
|
| `FASTMCP_ENABLE_TASKS` | `false` | Enable MCP task protocol (SEP-1686) |
|
|
| `FASTMCP_DOCKET_URL` | `memory://` | Docket backend URL |
|
|
|
|
## Learn More
|
|
|
|
- [FastMCP Tasks Documentation](https://gofastmcp.com/docs/tasks)
|
|
- [Docket Documentation](https://github.com/PrefectHQ/docket)
|
|
- [MCP Task Protocol (SEP-1686)](https://spec.modelcontextprotocol.io/specification/architecture/tasks/)
|