Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ dependencies = [
"mcp>=1.24.0,<2.0",
"openapi-pydantic>=0.5.1",
"platformdirs>=4.0.0",
"pydocket>=0.16.3",
"pydocket>=0.16.4",
"rich>=13.9.4",
"cyclopts>=4.0.0",
"authlib>=1.6.5",
Expand Down
12 changes: 8 additions & 4 deletions src/fastmcp/server/tasks/handlers.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,16 @@ async def submit_to_docket(
ttl_seconds = int(ttl_ms / 1000) + TASK_MAPPING_TTL_BUFFER_SECONDS

# Store task metadata in Redis for protocol handlers
redis_key = f"fastmcp:task:{session_id}:{server_task_id}"
created_at_key = f"fastmcp:task:{session_id}:{server_task_id}:created_at"
poll_interval_key = f"fastmcp:task:{session_id}:{server_task_id}:poll_interval"
task_meta_key = docket.key(f"fastmcp:task:{session_id}:{server_task_id}")
created_at_key = docket.key(
f"fastmcp:task:{session_id}:{server_task_id}:created_at"
)
poll_interval_key = docket.key(
f"fastmcp:task:{session_id}:{server_task_id}:poll_interval"
)
poll_interval_ms = int(component.task_config.poll_interval.total_seconds() * 1000)
async with docket.redis() as redis:
await redis.set(redis_key, task_key, ex=ttl_seconds)
await redis.set(task_meta_key, task_key, ex=ttl_seconds)
await redis.set(created_at_key, created_at.isoformat(), ex=ttl_seconds)
await redis.set(poll_interval_key, str(poll_interval_ms), ex=ttl_seconds)

Expand Down
17 changes: 10 additions & 7 deletions src/fastmcp/server/tasks/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,18 @@ async def _lookup_task_execution(
Raises:
McpError: If task not found or execution not found
"""
# Build Redis keys
redis_key = f"fastmcp:task:{session_id}:{client_task_id}"
created_at_key = f"{redis_key}:created_at"
poll_interval_key = f"{redis_key}:poll_interval"
task_meta_key = docket.key(f"fastmcp:task:{session_id}:{client_task_id}")
created_at_key = docket.key(
f"fastmcp:task:{session_id}:{client_task_id}:created_at"
)
poll_interval_key = docket.key(
Comment on lines +63 to +67
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve access to pre-upgrade task metadata keys

Because _lookup_task_execution now builds task_meta_key via docket.key(...), lookups only hit the new {docket_name}:fastmcp:task:... namespace. Tasks submitted before this change stored metadata under the old fastmcp:task:... keys; after a rolling upgrade, tasks/get, tasks/result, and tasks/cancel will return “not found” until those tasks expire. Consider checking the legacy key as a fallback or migrating existing keys on startup to avoid breaking in-flight tasks.

Useful? React with 👍 / 👎.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Yep that's accurate, but I think this is an acceptable risk because most folks would be using the memory:// broker, and also these are fairly transient keys.

f"fastmcp:task:{session_id}:{client_task_id}:poll_interval"
)

# Fetch metadata (single round-trip with mget)
async with docket.redis() as redis:
task_key_bytes, created_at_bytes, poll_interval_bytes = await redis.mget(
redis_key, created_at_key, poll_interval_key
task_meta_key, created_at_key, poll_interval_key
)

# Decode and validate task_key
Expand Down Expand Up @@ -225,9 +228,9 @@ async def tasks_result_handler(server: FastMCP, params: dict[str, Any]) -> Any:
)

# Look up full task key from Redis
redis_key = f"fastmcp:task:{session_id}:{client_task_id}"
task_meta_key = docket.key(f"fastmcp:task:{session_id}:{client_task_id}")
async with docket.redis() as redis:
task_key_bytes = await redis.get(redis_key)
task_key_bytes = await redis.get(task_meta_key)

task_key = None if task_key_bytes is None else task_key_bytes.decode("utf-8")

Expand Down
6 changes: 2 additions & 4 deletions src/fastmcp/server/tasks/subscriptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,7 @@ async def _send_status_notification(
key_parts = parse_task_key(task_key)
session_id = key_parts["session_id"]

# Retrieve createdAt timestamp from Redis
created_at_key = f"fastmcp:task:{session_id}:{task_id}:created_at"
created_at_key = docket.key(f"fastmcp:task:{session_id}:{task_id}:created_at")
async with docket.redis() as redis:
created_at_bytes = await redis.get(created_at_key)

Expand Down Expand Up @@ -183,8 +182,7 @@ async def _send_progress_notification(
key_parts = parse_task_key(task_key)
session_id = key_parts["session_id"]

# Retrieve createdAt timestamp from Redis
created_at_key = f"fastmcp:task:{session_id}:{task_id}:created_at"
created_at_key = docket.key(f"fastmcp:task:{session_id}:{task_id}:created_at")
async with docket.redis() as redis:
created_at_bytes = await redis.get(created_at_key)

Expand Down
8 changes: 4 additions & 4 deletions uv.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading