π The fast, Pythonic way to build MCP servers and clients.
Reject streaming credential providers in TasksExtension (#6043)
nate nowackcb1105241c76
diff --git a/docs/servers/tasks.mdx b/docs/servers/tasks.mdxindex 53aae92cd..05ab20945 100644--- a/docs/servers/tasks.mdx+++ b/docs/servers/tasks.mdx@@ -231,7 +231,7 @@ async def double(value: int) -> int:return value * 2```-You can also supply a provider that implements `get_credentials_async()`, or a provider from your cloud authentication library. FastMCP does not generate or refresh cloud tokens itself. Docket manages connection authentication, including refresh notifications from streaming providers; see [Docket credential providers](https://docket.lol/en/latest/production/#credential-providers) for details about long-lived connections and provider ownership.+You can also supply a provider that implements `get_credentials_async()`. FastMCP does not generate or refresh cloud tokens itself, and `TasksExtension` rejects streaming providers (such as redis-entraid's) for now, because a token refresh can hand one Redis connection to two commands at once. See [Docket credential providers](https://docket.lol/en/latest/production/#credential-providers) for details about long-lived connections and provider ownership.Configure the provider in your server module. [Additional workers](#workers) load that same module and use its registered extension, so no separate worker flag is needed. Provider objects are runtime configuration, not `FASTMCP_DOCKET_*` environment settings. The default `memory://` backend ignores them.diff --git a/fastmcp_tasks/fastmcp_tasks/extension.py b/fastmcp_tasks/fastmcp_tasks/extension.pyindex 06e0785d5..6c9488e90 100644--- a/fastmcp_tasks/fastmcp_tasks/extension.py+++ b/fastmcp_tasks/fastmcp_tasks/extension.py@@ -88,7 +88,9 @@ class TasksExtension(ServerExtension):Pass a redis-py `credential_provider` for rotating backend credentials,with no credentials in the URL. The provider is runtime configuration,- not an environment setting; Docket manages its connections and refreshes.+ not an environment setting; Docket manages its connections. Streaming+ providers are rejected until Docket re-authenticates in-use connections+ without racing other commands for their sockets."""identifier = TASKS_EXTENSION_ID@@ -105,6 +107,16 @@ class TasksExtension(ServerExtension):reconnection_delay: timedelta | None = None,minimum_check_interval: timedelta | None = None,) -> None:+ if credential_provider is not None:+ from redis.credentials import StreamingCredentialProvider++ if isinstance(credential_provider, StreamingCredentialProvider):+ raise ValueError(+ "Streaming credential providers are not supported yet: a token "+ "refresh can hand one Redis connection to two commands at once "+ "(redis/redis-py#4433). Use a CredentialProvider that returns "+ "current credentials for each new connection."+ )self._credential_provider = credential_provideroverrides: dict[str, Any] = {"url": url,diff --git a/tests/server/test_server_docket.py b/tests/server/test_server_docket.pyindex 923e11069..e0a23ab32 100644--- a/tests/server/test_server_docket.py+++ b/tests/server/test_server_docket.py@@ -7,7 +7,7 @@ import pytestfrom docket import Docketfrom docket.worker import Workerfrom fastmcp_tasks.dependencies import CurrentDocket, CurrentWorker-from redis.credentials import CredentialProvider+from redis.credentials import CredentialProvider, StreamingCredentialProviderfrom fastmcp import FastMCPfrom fastmcp.client import Client@@ -192,6 +192,22 @@ async def test_memory_backend_does_not_request_credentials():assert type(result.data) is int+def test_streaming_credential_providers_are_rejected():+ class RefreshingCredentials(StreamingCredentialProvider):+ def get_credentials(self) -> tuple[str, str]:+ return "tasks", "secret"++ def on_next(self, callback): ...++ def on_error(self, callback): ...++ def is_streaming(self) -> bool:+ return True++ with pytest.raises(ValueError, match="Streaming credential providers"):+ TasksExtension(credential_provider=RefreshingCredentials())++async def test_provider_and_url_credentials_are_rejected():mcp = FastMCP("conflicting-credentials")mcp.add_extension(