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 <[email protected]>
@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.

@jlowin jlowin added the DON'T MERGE PR is not ready for merging. Used by authors to prevent premature merging. label Nov 2, 2025
@jlowin
Copy link
Owner

jlowin commented Nov 2, 2025

Holding temporarily as we sort out 2.14 roadmap offline; may be fine to include as an experimental feature regardless

@chrisguidry chrisguidry changed the base branch from FMCP-390-docket-di to sep-1686 November 3, 2025 14:20
@chrisguidry chrisguidry merged commit c589836 into sep-1686 Nov 3, 2025
11 checks passed
@chrisguidry chrisguidry deleted the docket-background-tasks branch November 3, 2025 14:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DON'T MERGE PR is not ready for merging. Used by authors to prevent premature merging. feature Major new functionality. Reserved for 2-4 significant PRs per release. Not for issues.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants