Skip to main content

fastmcp-tasks

A complete implementation of background tasks for the Model Context Protocol — the io.modelcontextprotocol/tasks extension defined in SEP-2663.

The MCP tasks extension is a Final SEP, but as of this writing it ships in the ecosystem as a schema and a prose specification — no language SDK provides a working runtime for it. fastmcp-tasks is, to our knowledge, the first: a full server-side implementation of the protocol, built on the durable execution engine (docket) that FastMCP has run in production since v3. If you want to actually run MCP background tasks today, this is the implementation.

What background tasks are

Most tool calls are synchronous: the client sends tools/call and holds the request open until the tool returns. That breaks down for work that takes minutes or hours — a long analysis, a batch job, a slow external API. The tasks extension lets a server answer such a call immediately with a durable task handle, then run the work in the background while the client polls for completion on its own schedule.

The model is poll-based and stateless by construction, which is what makes it survive disconnects, server restarts, and load balancers:

  1. A client that supports tasks issues a normal tools/call with a per-request opt-in.
  2. The server decides whether to run it as a task. If it does, it returns a CreateTaskResult carrying a server-generated task id — right away, before the work starts.
  3. The client polls tasks/get until the task reaches a terminal state, then reads the result inlined in the response.
  4. tasks/cancel requests cancellation; tasks/update answers any input the task asks for mid-run.

The server owns the task's durable state, so the client can poll across independent requests — from any process, after a crash, through any replica — with no session affinity required.

Usage

Install it as the tasks extra on FastMCP:

uv pip install "fastmcp[tasks]"

Register the extension on your server and mark the tools that may run as tasks. The extension is where the backend is configured — point it at Redis for a distributed deployment, or leave it on the in-memory default for a single process:

from fastmcp import FastMCP
from fastmcp_tasks import TasksExtension

mcp = FastMCP("Analytics")
mcp.add_extension(TasksExtension(url="redis://localhost:6379/0"))


@mcp.tool(task=True)
async def analyze(dataset: str) -> str:
    # Long-running work. The client gets a task handle immediately and
    # polls for the result; this runs in a background worker.
    ...

task=True is a declaration of intent — this tool may run as a task — while the server, per the spec, decides per call whether to actually task it. Use TaskConfig for finer control:

from fastmcp.utilities.tasks import TaskConfig


@mcp.tool(task=TaskConfig(mode="required"))
async def must_run_async(n: int) -> int:
    # Always runs as a task; a client that has not opted in is told so.
    ...

Registering TasksExtension is required to serve task=True tools — the tool declares intent, the extension provides the engine. A task=True tool on a server with no tasks extension registered fails loudly at startup rather than silently running inline.

Running out-of-process workers

For distributed deployments backed by Redis, run dedicated worker processes alongside your server:

python -m fastmcp_tasks.worker_cli worker server.py

Workers and servers that share a backend URL and queue name share a task queue, so you can scale execution independently of your request-serving frontends.

Configuration

The backend is configured on the extension. Every option also has a FASTMCP_DOCKET_* environment variable, so an env-configured deployment can construct TasksExtension() with no arguments:

Option Env var Default Description
url FASTMCP_DOCKET_URL memory:// Backend URL. memory:// for single-process; redis://host:port/db for distributed workers.
name FASTMCP_DOCKET_NAME fastmcp Queue name. Servers and workers sharing a name and URL share a queue.
concurrency FASTMCP_DOCKET_CONCURRENCY 10 Maximum concurrent tasks per worker.

See the FastMCP task documentation for the full reference.

Status

The tasks extension is an experimental MCP extension, and fastmcp-tasks tracks its draft schema. The protocol's shape is settled — SEP-2663 is Final — but field-level details may still move; this package versions independently so it can follow the schema without waiting on a FastMCP release.

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

fastmcp_tasks-4.0.0.tar.gz (54.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

fastmcp_tasks-4.0.0-py3-none-any.whl (65.4 kB view details)

Uploaded Python 3

File details

Details for the file fastmcp_tasks-4.0.0.tar.gz.

File metadata

  • Download URL: fastmcp_tasks-4.0.0.tar.gz
  • Upload date:
  • Size: 54.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastmcp_tasks-4.0.0.tar.gz
Algorithm Hash digest
SHA256 533ab925ff137ec4c19dc76d50b02db810bb2e12be5622bd5869bb38136b3b1f
MD5 23a04abdc1e6e070b28be832dad2da3b
BLAKE2b-256 46bbef451b4656a6c68b84cc1fc6946591920daf70dbaa48d4adbf64fb2b9a43

See more details on using hashes here.

File details

Details for the file fastmcp_tasks-4.0.0-py3-none-any.whl.

File metadata

  • Download URL: fastmcp_tasks-4.0.0-py3-none-any.whl
  • Upload date:
  • Size: 65.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.12.7 {"installer":{"name":"uv","version":"0.12.7","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for fastmcp_tasks-4.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3020e1d6056626f367563f33c86eeb70d2857cbc6da44fa78e08c042748697a5
MD5 3d1a3cf1e34db98626d71cdb4f7fc745
BLAKE2b-256 6372f9dd67b43c0bd3286dba2c57c9740027c3b34dfe7583fa8b1fa3f1ddb57e

See more details on using hashes here.

Release history Release notifications | RSS feed

4.0.3

2 files

4.0.2

2 files

4.0.1

2 files

This release

4.0.0 This release

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page