mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-18 11:39:12 +02:00
Docket provides background task execution and is now always available for all FastMCP servers. Only `enable_tasks` remains to control the SEP-1686 task protocol support. Changes: - Remove `enable_docket` setting and related validation - Docket/Worker lifecycle is always active in server lifespan - CurrentDocket and CurrentWorker dependencies work without config - Add server readiness signaling via `_started` event - Fix test timing issues with proper port probing 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
81 lines
2.8 KiB
Python
81 lines
2.8 KiB
Python
"""
|
|
Tests for SEP-1686 task capabilities declaration.
|
|
|
|
Verifies that the server correctly advertises task support based on settings.
|
|
"""
|
|
|
|
from fastmcp import FastMCP
|
|
from fastmcp.client import Client
|
|
from fastmcp.utilities.tests import temporary_settings
|
|
|
|
|
|
async def test_capabilities_include_tasks_when_enabled():
|
|
"""Server capabilities include tasks when enable_tasks=True."""
|
|
with temporary_settings(enable_tasks=True):
|
|
mcp = FastMCP("capability-test")
|
|
|
|
@mcp.tool()
|
|
async def test_tool() -> str:
|
|
return "test"
|
|
|
|
async with Client(mcp) as client:
|
|
# Get server initialization result which includes capabilities
|
|
init_result = client.initialize_result
|
|
|
|
# Verify tasks capability is present
|
|
assert init_result.capabilities.experimental is not None
|
|
assert "tasks" in init_result.capabilities.experimental
|
|
tasks_cap = init_result.capabilities.experimental["tasks"]
|
|
assert tasks_cap == {
|
|
"tools": True,
|
|
"prompts": True,
|
|
"resources": True,
|
|
}
|
|
|
|
|
|
async def test_capabilities_exclude_tasks_when_disabled():
|
|
"""Server capabilities do NOT include tasks when enable_tasks=False."""
|
|
with temporary_settings(enable_tasks=False):
|
|
mcp = FastMCP("capability-test")
|
|
|
|
@mcp.tool()
|
|
def test_tool() -> str:
|
|
return "test"
|
|
|
|
async with Client(mcp) as client:
|
|
# Get server initialization result
|
|
init_result = client.initialize_result
|
|
|
|
# Verify tasks capability is NOT present
|
|
if init_result.capabilities.experimental:
|
|
assert "tasks" not in init_result.capabilities.experimental
|
|
|
|
|
|
async def test_client_advertises_task_capability_when_enabled():
|
|
"""Client advertises experimental.tasks capability when enable_tasks=True."""
|
|
with temporary_settings(enable_tasks=True):
|
|
mcp = FastMCP("client-cap-test")
|
|
|
|
@mcp.tool()
|
|
async def test_tool() -> str:
|
|
return "test"
|
|
|
|
async with Client(mcp) as client:
|
|
# Client should have connected successfully with task capabilities
|
|
assert client.initialize_result is not None
|
|
|
|
|
|
async def test_client_does_not_advertise_tasks_when_disabled():
|
|
"""Client does NOT use custom session when enable_tasks=False."""
|
|
with temporary_settings(enable_tasks=False):
|
|
mcp = FastMCP("no-tasks-client-test")
|
|
|
|
@mcp.tool()
|
|
def test_tool() -> str:
|
|
return "test"
|
|
|
|
async with Client(mcp) as client:
|
|
# Session should be standard ClientSession, not our custom one
|
|
|
|
# The session should be a standard ClientSession
|
|
assert type(client.session).__name__ == "ClientSession"
|