Skip to content

Conversation

@chrisguidry
Copy link
Collaborator

Brings FastAPI-style background task execution to FastMCP as the next step toward MCP SEP-1686 support.

When FASTMCP_EXPERIMENTAL_ENABLE_DOCKET=true, FastMCP automatically creates a Docket instance with an in-process Worker, enabling tools to schedule background tasks via dependency injection:

from fastmcp.dependencies import CurrentDocket

@mcp.tool()
async def analyze_data(query: str, docket: Docket = CurrentDocket()) -> str:
    await docket.add(long_running_analysis)(query)
    return "Analysis started"

This provides Starlette-like background task capabilities without requiring distributed infrastructure. All tasks run in the same process via memory:// broker. Distributed workers will come in a future phase.

Also adds CurrentContext() and CurrentWorker() dependency functions following Docket's pattern (no Depends() wrapper needed).

New fastmcp.dependencies module centralizes all dependency injection exports to keep the top-level namespace clean.

Related: https://linear.app/prefect/document/fastmcp-sep-1686-tasks-7c4711171324

🤖 Generated with Claude Code

Brings FastAPI-style background task execution to FastMCP as the next step
toward MCP SEP-1686 support. When `FASTMCP_EXPERIMENTAL_ENABLE_DOCKET=true`,
FastMCP automatically creates a Docket instance with an in-process Worker,
enabling tools to schedule background tasks via dependency injection.

```python
from fastmcp.dependencies import CurrentDocket

@mcp.tool()
async def analyze_data(query: str, docket: Docket = CurrentDocket()) -> str:
    # Schedule work to run in background
    await docket.add(long_running_analysis)(query)
    return "Analysis started"
```

This provides Starlette-like background task capabilities without requiring
distributed infrastructure. All tasks run in the same process via memory://
broker. Distributed workers will come in a future phase.

Also adds `CurrentContext()` and `CurrentWorker()` dependency functions
following Docket's pattern (no `Depends()` wrapper needed).

New `fastmcp.dependencies` module centralizes all dependency injection exports
to keep the top-level namespace clean.

Related: https://linear.app/prefect/document/fastmcp-sep-1686-tasks-7c4711171324
Based on: #2318

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 31, 2025

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch docket-background-tasks

Comment @coderabbitai help to get the list of available commands and usage tips.

@chrisguidry chrisguidry requested a review from jlowin October 31, 2025 20:29
@marvin-context-protocol marvin-context-protocol bot added the feature Major new functionality. Reserved for 2-4 significant PRs per release. Not for issues. label Oct 31, 2025
Copy link
Owner

@jlowin jlowin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

feature Major new functionality. Reserved for 2-4 significant PRs per release. Not for issues.

3 participants