Skip to content

Commit 47bfa85

Browse files
authored
Remove the unused timeout parameter from OAuthClientProvider (#3165)
1 parent 3212591 commit 47bfa85

6 files changed

Lines changed: 24 additions & 11 deletions

File tree

docs/client/oauth-clients.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ The first time `Client` sends a request, the server answers `401`. The provider
8383

8484
After that it is quiet. Tokens come out of storage, an expired access token is refreshed with the refresh token, and only when none of that works does it run the flow again.
8585

86-
You wrote none of it. Three keyword arguments remain (`timeout`, `client_metadata_url` and `validate_resource_url`), and this file needs none of them. `client_metadata_url` is the one worth knowing about; it gets its own section below.
86+
You wrote none of it. Two keyword arguments remain (`client_metadata_url` and `validate_resource_url`), and this file needs neither. `client_metadata_url` is the one worth knowing about; it gets its own section below.
8787

8888
### Try it
8989

docs/migration.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2034,6 +2034,24 @@ ClientCredentialsOAuthProvider(..., scopes="read write")
20342034
ClientCredentialsOAuthProvider(..., scope="read write")
20352035
```
20362036

2037+
### `timeout` parameter removed from `OAuthClientProvider`
2038+
2039+
`OAuthClientProvider` no longer accepts a `timeout` argument, and `OAuthContext.timeout` is gone. The value was stored but never read, so it never bounded anything — removing it changes nothing at runtime.
2040+
2041+
**Before (v1):**
2042+
2043+
```python
2044+
provider = OAuthClientProvider(server_url, client_metadata, storage, timeout=120.0)
2045+
```
2046+
2047+
**After (v2):**
2048+
2049+
```python
2050+
provider = OAuthClientProvider(server_url, client_metadata, storage)
2051+
```
2052+
2053+
If you passed `timeout` to bound how long you wait for the user to complete authorization, apply that bound where you actually wait — inside your `redirect_handler`/`callback_handler`, e.g. `with anyio.fail_after(120): ...`.
2054+
20372055
### Client rejects authorization server metadata with a mismatched `issuer`
20382056

20392057
During OAuth discovery, `OAuthClientProvider` now validates that the authorization server

src/mcp/client/auth/extensions/client_credentials.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def __init__(
6363
token_endpoint_auth_method=token_endpoint_auth_method,
6464
scope=scope,
6565
)
66-
super().__init__(server_url, client_metadata, storage, None, None, 300.0)
66+
super().__init__(server_url, client_metadata, storage, None, None)
6767
# Store client_info to be set during _initialize - no dynamic registration needed
6868
self._fixed_client_info = OAuthClientInformationFull(
6969
redirect_uris=None,
@@ -277,7 +277,7 @@ def __init__(
277277
token_endpoint_auth_method="private_key_jwt",
278278
scope=scope,
279279
)
280-
super().__init__(server_url, client_metadata, storage, None, None, 300.0)
280+
super().__init__(server_url, client_metadata, storage, None, None)
281281
self._assertion_provider = assertion_provider
282282
# Store client_info to be set during _initialize - no dynamic registration needed
283283
self._fixed_client_info = OAuthClientInformationFull(

src/mcp/client/auth/oauth2.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,6 @@ class OAuthContext:
103103
storage: TokenStorage
104104
redirect_handler: Callable[[str], Awaitable[None]] | None
105105
callback_handler: Callable[[], Awaitable[AuthorizationCodeResult]] | None
106-
timeout: float = 300.0
107106
client_metadata_url: str | None = None
108107

109108
# Discovered metadata
@@ -233,7 +232,6 @@ def __init__(
233232
storage: TokenStorage,
234233
redirect_handler: Callable[[str], Awaitable[None]] | None = None,
235234
callback_handler: Callable[[], Awaitable[AuthorizationCodeResult]] | None = None,
236-
timeout: float = 300.0,
237235
client_metadata_url: str | None = None,
238236
validate_resource_url: Callable[[str, str | None], Awaitable[None]] | None = None,
239237
):
@@ -245,7 +243,6 @@ def __init__(
245243
storage: Token storage implementation.
246244
redirect_handler: Handler for authorization redirects.
247245
callback_handler: Handler for authorization callbacks.
248-
timeout: Timeout for the OAuth flow.
249246
client_metadata_url: URL-based client ID. When provided and the server
250247
advertises client_id_metadata_document_supported=True, this URL will be
251248
used as the client_id instead of performing dynamic client registration.
@@ -271,7 +268,6 @@ def __init__(
271268
storage=storage,
272269
redirect_handler=redirect_handler,
273270
callback_handler=callback_handler,
274-
timeout=timeout,
275271
client_metadata_url=client_metadata_url,
276272
)
277273
self._validate_resource_url_callback = validate_resource_url

tests/client/test_auth.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ async def test_oauth_provider_initialization(
192192
assert oauth_provider.context.server_url == "https://api.example.com/v1/mcp"
193193
assert oauth_provider.context.client_metadata == client_metadata
194194
assert oauth_provider.context.storage == mock_storage
195-
assert oauth_provider.context.timeout == 300.0
196195
assert oauth_provider.context is not None
197196

198197
def test_context_url_parsing(self, oauth_provider: OAuthClientProvider):

tests/docs_src/test_oauth_clients.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,11 @@ async def test_client_credentials_provider_builds_its_own_metadata() -> None:
8080
assert metadata.scope == "user"
8181

8282

83-
async def test_the_three_remaining_keyword_arguments_have_defaults() -> None:
84-
"""The page names `timeout`, `client_metadata_url` and `validate_resource_url` as the remainder."""
83+
async def test_the_two_remaining_keyword_arguments_have_defaults() -> None:
84+
"""The page names `client_metadata_url` and `validate_resource_url` as the remainder."""
8585
parameters = inspect.signature(OAuthClientProvider.__init__).parameters
8686
supplied = ["server_url", "client_metadata", "storage", "redirect_handler", "callback_handler"]
87-
remainder = ["timeout", "client_metadata_url", "validate_resource_url"]
87+
remainder = ["client_metadata_url", "validate_resource_url"]
8888
assert list(parameters) == ["self", *supplied, *remainder]
8989
assert all(parameters[name].default is not inspect.Parameter.empty for name in remainder)
9090

0 commit comments

Comments
 (0)