π The fast, Pythonic way to build MCP servers and clients.
fix(tasks): send task IDs in routing headers (#5810)
Jason19b5c33ab8428
diff --git a/fastmcp_tasks/fastmcp_tasks/client_models.py b/fastmcp_tasks/fastmcp_tasks/client_models.pyindex 3df5293df..ed0c9e50d 100644--- a/fastmcp_tasks/fastmcp_tasks/client_models.py+++ b/fastmcp_tasks/fastmcp_tasks/client_models.py@@ -110,6 +110,7 @@ class GetTaskRequest(mcp_types.Request[GetTaskRequestParams, Literal["tasks/get"method: Literal["tasks/get"] = "tasks/get"params: GetTaskRequestParams+ name_param = "taskId"class UpdateTaskRequest(@@ -119,6 +120,7 @@ class UpdateTaskRequest(method: Literal["tasks/update"] = "tasks/update"params: UpdateTaskRequestParams+ name_param = "taskId"class CancelTaskRequest(@@ -128,3 +130,4 @@ class CancelTaskRequest(method: Literal["tasks/cancel"] = "tasks/cancel"params: CancelTaskRequestParams+ name_param = "taskId"diff --git a/tests/tasks/client/test_routing_headers.py b/tests/tasks/client/test_routing_headers.pynew file mode 100644index 000000000..6973b0f8b--- /dev/null+++ b/tests/tasks/client/test_routing_headers.py@@ -0,0 +1,48 @@+"""Task-management requests mirror their task ID into the HTTP routing header."""++from typing import Any++import httpx2+import pytest+from fastmcp_tasks.client import _send_cancel, _send_get, _send_update+from mcp.shared.exceptions import MCPError+from mcp.shared.inbound import decode_header_value++from fastmcp import Client, FastMCP+from fastmcp.utilities.tests import asgi_server+from fastmcp_tasks import TasksExtension++[email protected]("method", ["tasks/get", "tasks/update", "tasks/cancel"])[email protected]("task_id", ["task-123", " task-δΈζ "])+async def test_task_management_routing_headers(method: str, task_id: str):+ server = FastMCP("task-routing-headers")+ server.add_extension(TasksExtension())+ requests: list[httpx2.Request] = []++ async def capture(request: httpx2.Request) -> None:+ if request.headers.get("Mcp-Method") == method:+ requests.append(request)++ async with asgi_server(server) as running_server:++ def http_client(**kwargs: Any) -> httpx2.AsyncClient:+ return running_server.http_client(+ **kwargs, event_hooks={"request": [capture]}+ )++ transport = running_server.transport(httpx_client_factory=http_client)+ async with Client(transport, mode="auto") as client:+ # Unknown IDs exercise the real HTTP path without starting a worker job.+ with pytest.raises(MCPError, match="not found"):+ if method == "tasks/get":+ await _send_get(client.session, task_id)+ elif method == "tasks/update":+ await _send_update(client.session, task_id, {})+ else:+ await _send_cancel(client.session, task_id)++ assert len(requests) == 1+ header = requests[0].headers.get("Mcp-Name")+ assert header is not None+ assert decode_header_value(header) == task_id