@@ -2127,12 +2127,12 @@ Run from the repository root:
21272127import asyncio
21282128
21292129from mcp import ClientSession
2130- from mcp.client.streamable_http import streamablehttp_client
2130+ from mcp.client.streamable_http import streamable_http_client
21312131
21322132
21332133async def main ():
21342134 # Connect to a streamable HTTP server
2135- async with streamablehttp_client (" http://localhost:8000/mcp" ) as (
2135+ async with streamable_http_client (" http://localhost:8000/mcp" ) as (
21362136 read_stream,
21372137 write_stream,
21382138 _,
@@ -2256,11 +2256,12 @@ cd to the `examples/snippets` directory and run:
22562256import asyncio
22572257from urllib.parse import parse_qs, urlparse
22582258
2259+ import httpx
22592260from pydantic import AnyUrl
22602261
22612262from mcp import ClientSession
22622263from mcp.client.auth import OAuthClientProvider, TokenStorage
2263- from mcp.client.streamable_http import streamablehttp_client
2264+ from mcp.client.streamable_http import streamable_http_client
22642265from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
22652266
22662267
@@ -2314,15 +2315,16 @@ async def main():
23142315 callback_handler = handle_callback,
23152316 )
23162317
2317- async with streamablehttp_client(" http://localhost:8001/mcp" , auth = oauth_auth) as (read, write, _):
2318- async with ClientSession(read, write) as session:
2319- await session.initialize()
2318+ async with httpx.AsyncClient(auth = oauth_auth, follow_redirects = True ) as custom_client:
2319+ async with streamable_http_client(" http://localhost:8001/mcp" , http_client = custom_client) as (read, write, _):
2320+ async with ClientSession(read, write) as session:
2321+ await session.initialize()
23202322
2321- tools = await session.list_tools()
2322- print (f " Available tools: { [tool.name for tool in tools.tools]} " )
2323+ tools = await session.list_tools()
2324+ print (f " Available tools: { [tool.name for tool in tools.tools]} " )
23232325
2324- resources = await session.list_resources()
2325- print (f " Available resources: { [r.uri for r in resources.resources]} " )
2326+ resources = await session.list_resources()
2327+ print (f " Available resources: { [r.uri for r in resources.resources]} " )
23262328
23272329
23282330def run ():
0 commit comments