Document the timeout a hand-built httpx2 client needs (#3618) · modelcontextprotocol/python-sdk@ebf6e5a · GitHub
Skip to content

Commit ebf6e5a

Browse files
authored
Document the timeout a hand-built httpx2 client needs (#3618)
1 parent c8fcfc8 commit ebf6e5a

9 files changed

Lines changed: 51 additions & 8 deletions

File tree

‎docs/client/transports.md‎

Lines changed: 2 additions & 0 deletions

‎docs_src/identity_assertion/tutorial001.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ async def fetch_id_jag(audience: str, resource: str) -> str:
6262

6363

6464
async def main() -> None:
65-
async with httpx2.AsyncClient(auth=oauth) as http_client:
65+
async with httpx2.AsyncClient(auth=oauth, timeout=httpx2.Timeout(30.0, read=300.0)) as http_client:
6666
transport = streamable_http_client("http://localhost:8001/mcp", http_client=http_client)
6767
async with Client(transport) as client:
6868
result = await client.list_tools()

‎docs_src/oauth_clients/tutorial001.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ async def wait_for_callback() -> AuthorizationCodeResult:
5555

5656

5757
async def main() -> None:
58-
async with httpx2.AsyncClient(auth=oauth) as http_client:
58+
async with httpx2.AsyncClient(auth=oauth, timeout=httpx2.Timeout(30.0, read=300.0)) as http_client:
5959
transport = streamable_http_client("http://localhost:8001/mcp", http_client=http_client)
6060
async with Client(transport) as client:
6161
result = await client.list_tools()

‎docs_src/oauth_clients/tutorial002.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async def set_client_info(self, client_info: OAuthClientInformationFull) -> None
3535

3636

3737
async def main() -> None:
38-
async with httpx2.AsyncClient(auth=oauth) as http_client:
38+
async with httpx2.AsyncClient(auth=oauth, timeout=httpx2.Timeout(30.0, read=300.0)) as http_client:
3939
transport = streamable_http_client("http://localhost:8001/mcp", http_client=http_client)
4040
async with Client(transport) as client:
4141
result = await client.list_tools()

‎examples/clients/simple-auth-client/mcp_simple_auth_client/main.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,9 @@ async def _default_redirect_handler(authorization_url: str) -> None:
233233
await self._run_session(read_stream, write_stream)
234234
else:
235235
print("📡 Opening StreamableHTTP transport connection with auth...")
236-
async with httpx2.AsyncClient(auth=oauth_auth) as custom_client:
236+
async with httpx2.AsyncClient(
237+
auth=oauth_auth, timeout=httpx2.Timeout(30.0, read=300.0)
238+
) as custom_client:
237239
async with streamable_http_client(url=self.server_url, http_client=custom_client) as (
238240
read_stream,
239241
write_stream,

‎examples/snippets/clients/identity_assertion_client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ async def main() -> None:
6666
scope="user",
6767
)
6868

69-
async with httpx2.AsyncClient(auth=oauth_auth) as http_client:
69+
async with httpx2.AsyncClient(auth=oauth_auth, timeout=httpx2.Timeout(30.0, read=300.0)) as http_client:
7070
async with streamable_http_client("http://localhost:8001/mcp", http_client=http_client) as (read, write):
7171
async with ClientSession(read, write) as session:
7272
await session.initialize()

‎examples/snippets/clients/oauth_client.py‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ async def main():
7272
callback_handler=handle_callback,
7373
)
7474

75-
async with httpx2.AsyncClient(auth=oauth_auth) as custom_client:
75+
async with httpx2.AsyncClient(auth=oauth_auth, timeout=httpx2.Timeout(30.0, read=300.0)) as custom_client:
7676
async with streamable_http_client("http://localhost:8001/mcp", http_client=custom_client) as (read, write):
7777
async with ClientSession(read, write) as session:
7878
await session.initialize()

‎examples/stories/_harness.py‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,9 @@ async def _run() -> None:
182182
# server origin and relative paths like "/mcp" resolve.
183183
parts = urlsplit(url)
184184
base = f"{parts.scheme}://{parts.netloc}"
185-
http = await stack.enter_async_context(httpx2.AsyncClient(base_url=base))
185+
http = await stack.enter_async_context(
186+
httpx2.AsyncClient(base_url=base, timeout=httpx2.Timeout(30.0, read=300.0))
187+
)
186188
make = targets
187189
if build_auth is not None:
188190
http.auth = build_auth(http)

‎tests/docs_src/test_client_transports.py‎

Lines changed: 38 additions & 1 deletion

0 commit comments

Comments
 (0)