Skip to content

Commit c40068e

Browse files
Kludexfelixweinberger
authored andcommitted
Rename streamablehttp_client to streamable_http_client
1 parent 2cd178a commit c40068e

File tree

9 files changed

+69
-53
lines changed

9 files changed

+69
-53
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2207,12 +2207,12 @@ Run from the repository root:
22072207
import asyncio
22082208

22092209
from mcp import ClientSession
2210-
from mcp.client.streamable_http import streamablehttp_client
2210+
from mcp.client.streamable_http import streamable_http_client
22112211

22122212

22132213
async def main():
22142214
# Connect to a streamable HTTP server
2215-
async with streamablehttp_client("http://localhost:8000/mcp") as (
2215+
async with streamable_http_client("http://localhost:8000/mcp") as (
22162216
read_stream,
22172217
write_stream,
22182218
_,
@@ -2340,7 +2340,7 @@ from pydantic import AnyUrl
23402340

23412341
from mcp import ClientSession
23422342
from mcp.client.auth import OAuthClientProvider, TokenStorage
2343-
from mcp.client.streamable_http import streamablehttp_client
2343+
from mcp.client.streamable_http import streamable_http_client
23442344
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
23452345

23462346

@@ -2394,7 +2394,7 @@ async def main():
23942394
callback_handler=handle_callback,
23952395
)
23962396

2397-
async with streamablehttp_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
2397+
async with streamable_http_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
23982398
async with ClientSession(read, write) as session:
23992399
await session.initialize()
24002400

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
from mcp.client.auth import OAuthClientProvider, TokenStorage
2020
from mcp.client.session import ClientSession
2121
from mcp.client.sse import sse_client
22-
from mcp.client.streamable_http import streamablehttp_client
22+
from mcp.client.streamable_http import streamable_http_client
2323
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
2424

2525

@@ -212,7 +212,7 @@ async def _default_redirect_handler(authorization_url: str) -> None:
212212
await self._run_session(read_stream, write_stream, None)
213213
else:
214214
print("📡 Opening StreamableHTTP transport connection with auth...")
215-
async with streamablehttp_client(
215+
async with streamable_http_client(
216216
url=self.server_url,
217217
auth=oauth_auth,
218218
timeout=timedelta(seconds=60),

examples/snippets/clients/oauth_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
from mcp import ClientSession
1616
from mcp.client.auth import OAuthClientProvider, TokenStorage
17-
from mcp.client.streamable_http import streamablehttp_client
17+
from mcp.client.streamable_http import streamable_http_client
1818
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
1919

2020

@@ -68,7 +68,7 @@ async def main():
6868
callback_handler=handle_callback,
6969
)
7070

71-
async with streamablehttp_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
71+
async with streamable_http_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
7272
async with ClientSession(read, write) as session:
7373
await session.initialize()
7474

examples/snippets/clients/streamable_basic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
import asyncio
77

88
from mcp import ClientSession
9-
from mcp.client.streamable_http import streamablehttp_client
9+
from mcp.client.streamable_http import streamable_http_client
1010

1111

1212
async def main():
1313
# Connect to a streamable HTTP server
14-
async with streamablehttp_client("http://localhost:8000/mcp") as (
14+
async with streamable_http_client("http://localhost:8000/mcp") as (
1515
read_stream,
1616
write_stream,
1717
_,

src/mcp/client/session_group.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
from mcp.client.session import ElicitationFnT, ListRootsFnT, LoggingFnT, MessageHandlerFnT, SamplingFnT
2626
from mcp.client.sse import sse_client
2727
from mcp.client.stdio import StdioServerParameters
28-
from mcp.client.streamable_http import streamablehttp_client
28+
from mcp.client.streamable_http import streamable_http_client
2929
from mcp.shared.exceptions import McpError
3030
from mcp.shared.session import ProgressFnT
3131

@@ -47,7 +47,7 @@ class SseServerParameters(BaseModel):
4747

4848

4949
class StreamableHttpParameters(BaseModel):
50-
"""Parameters for intializing a streamablehttp_client."""
50+
"""Parameters for intializing a streamable_http_client."""
5151

5252
# The endpoint URL.
5353
url: str
@@ -309,7 +309,7 @@ async def _establish_session(
309309
)
310310
read, write = await session_stack.enter_async_context(client)
311311
else:
312-
client = streamablehttp_client(
312+
client = streamable_http_client(
313313
url=server_params.url,
314314
headers=server_params.headers,
315315
timeout=server_params.timeout,

src/mcp/client/streamable_http.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
from anyio.abc import TaskGroup
1818
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
1919
from httpx_sse import EventSource, ServerSentEvent, aconnect_sse
20+
from typing_extensions import deprecated
2021

2122
from mcp.shared._httpx_utils import McpHttpClientFactory, create_mcp_http_client
2223
from mcp.shared.message import ClientMessageMetadata, SessionMessage
@@ -447,7 +448,7 @@ def get_session_id(self) -> str | None:
447448

448449

449450
@asynccontextmanager
450-
async def streamablehttp_client(
451+
async def streamable_http_client(
451452
url: str,
452453
headers: dict[str, str] | None = None,
453454
timeout: float | timedelta = 30,
@@ -516,3 +517,23 @@ def start_get_stream() -> None:
516517
finally:
517518
await read_stream_writer.aclose()
518519
await write_stream.aclose()
520+
521+
522+
@deprecated("Use `streamable_http_client` instead.")
523+
@asynccontextmanager
524+
async def streamablehttp_client(
525+
url: str,
526+
headers: dict[str, str] | None = None,
527+
timeout: float | timedelta = 30,
528+
sse_read_timeout: float | timedelta = 60 * 5,
529+
terminate_on_close: bool = True,
530+
) -> AsyncGenerator[
531+
tuple[
532+
MemoryObjectReceiveStream[SessionMessage | Exception],
533+
MemoryObjectSendStream[SessionMessage],
534+
GetSessionIdCallback,
535+
],
536+
None,
537+
]:
538+
async with streamable_http_client(url, headers, timeout, sse_read_timeout, terminate_on_close) as streams:
539+
yield streams

tests/client/test_session_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ async def test_disconnect_non_existent_server(self):
280280
(
281281
StreamableHttpParameters(url="http://test.com/stream", terminate_on_close=False),
282282
"streamablehttp",
283-
"mcp.client.session_group.streamablehttp_client",
283+
"mcp.client.session_group.streamable_http_client",
284284
), # url, headers, timeout, sse_read_timeout, terminate_on_close
285285
],
286286
)
@@ -296,7 +296,7 @@ async def test_establish_session_parameterized(
296296
mock_read_stream = mock.AsyncMock(name=f"{client_type_name}Read")
297297
mock_write_stream = mock.AsyncMock(name=f"{client_type_name}Write")
298298

299-
# streamablehttp_client's __aenter__ returns three values
299+
# streamable_http_client's __aenter__ returns three values
300300
if client_type_name == "streamablehttp":
301301
mock_extra_stream_val = mock.AsyncMock(name="StreamableExtra")
302302
mock_client_cm_instance.__aenter__.return_value = (

tests/server/fastmcp/test_integration.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,7 @@
3434
)
3535
from mcp.client.session import ClientSession
3636
from mcp.client.sse import sse_client
37-
from mcp.client.streamable_http import GetSessionIdCallback, streamablehttp_client
38-
from mcp.shared.context import RequestContext
39-
from mcp.shared.message import SessionMessage
40-
from mcp.shared.session import RequestResponder
37+
from mcp.client.streamable_http import streamable_http_client
4138
from mcp.types import (
4239
ClientResult,
4340
CreateMessageRequestParams,
@@ -179,7 +176,7 @@ def create_client_for_transport(transport: str, server_url: str):
179176
return sse_client(endpoint)
180177
elif transport == "streamable-http":
181178
endpoint = f"{server_url}/mcp"
182-
return streamablehttp_client(endpoint)
179+
return streamable_http_client(endpoint)
183180
else: # pragma: no cover
184181
raise ValueError(f"Invalid transport: {transport}")
185182

0 commit comments

Comments
 (0)