Skip to content

Commit 356c488

Browse files
Kludexfelixweinberger
authored andcommitted
Rename streamablehttp_client to streamable_http_client
1 parent 3390e49 commit 356c488

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
@@ -2127,12 +2127,12 @@ Run from the repository root:
21272127
import asyncio
21282128

21292129
from mcp import ClientSession
2130-
from mcp.client.streamable_http import streamablehttp_client
2130+
from mcp.client.streamable_http import streamable_http_client
21312131

21322132

21332133
async 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
_,
@@ -2260,7 +2260,7 @@ from pydantic import AnyUrl
22602260

22612261
from mcp import ClientSession
22622262
from mcp.client.auth import OAuthClientProvider, TokenStorage
2263-
from mcp.client.streamable_http import streamablehttp_client
2263+
from mcp.client.streamable_http import streamable_http_client
22642264
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
22652265

22662266

@@ -2314,7 +2314,7 @@ async def main():
23142314
callback_handler=handle_callback,
23152315
)
23162316

2317-
async with streamablehttp_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
2317+
async with streamable_http_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
23182318
async with ClientSession(read, write) as session:
23192319
await session.initialize()
23202320

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

@@ -205,7 +205,7 @@ async def _default_redirect_handler(authorization_url: str) -> None:
205205
await self._run_session(read_stream, write_stream, None)
206206
else:
207207
print("📡 Opening StreamableHTTP transport connection with auth...")
208-
async with streamablehttp_client(
208+
async with streamable_http_client(
209209
url=self.server_url,
210210
auth=oauth_auth,
211211
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
@@ -23,7 +23,7 @@
2323
from mcp import types
2424
from mcp.client.sse import sse_client
2525
from mcp.client.stdio import StdioServerParameters
26-
from mcp.client.streamable_http import streamablehttp_client
26+
from mcp.client.streamable_http import streamable_http_client
2727
from mcp.shared.exceptions import McpError
2828

2929

@@ -44,7 +44,7 @@ class SseServerParameters(BaseModel):
4444

4545

4646
class StreamableHttpParameters(BaseModel):
47-
"""Parameters for intializing a streamablehttp_client."""
47+
"""Parameters for intializing a streamable_http_client."""
4848

4949
# The endpoint URL.
5050
url: str
@@ -250,7 +250,7 @@ async def _establish_session(
250250
)
251251
read, write = await session_stack.enter_async_context(client)
252252
else:
253-
client = streamablehttp_client(
253+
client = streamable_http_client(
254254
url=server_params.url,
255255
headers=server_params.headers,
256256
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
@@ -442,7 +443,7 @@ def get_session_id(self) -> str | None:
442443

443444

444445
@asynccontextmanager
445-
async def streamablehttp_client(
446+
async def streamable_http_client(
446447
url: str,
447448
headers: dict[str, str] | None = None,
448449
timeout: float | timedelta = 30,
@@ -511,3 +512,23 @@ def start_get_stream() -> None:
511512
finally:
512513
await read_stream_writer.aclose()
513514
await write_stream.aclose()
515+
516+
517+
@deprecated("Use `streamable_http_client` instead.")
518+
@asynccontextmanager
519+
async def streamablehttp_client(
520+
url: str,
521+
headers: dict[str, str] | None = None,
522+
timeout: float | timedelta = 30,
523+
sse_read_timeout: float | timedelta = 60 * 5,
524+
terminate_on_close: bool = True,
525+
) -> AsyncGenerator[
526+
tuple[
527+
MemoryObjectReceiveStream[SessionMessage | Exception],
528+
MemoryObjectSendStream[SessionMessage],
529+
GetSessionIdCallback,
530+
],
531+
None,
532+
]:
533+
async with streamable_http_client(url, headers, timeout, sse_read_timeout, terminate_on_close) as streams:
534+
yield streams

tests/client/test_session_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ async def test_disconnect_non_existent_server(self):
272272
(
273273
StreamableHttpParameters(url="http://test.com/stream", terminate_on_close=False),
274274
"streamablehttp",
275-
"mcp.client.session_group.streamablehttp_client",
275+
"mcp.client.session_group.streamable_http_client",
276276
), # url, headers, timeout, sse_read_timeout, terminate_on_close
277277
],
278278
)
@@ -288,7 +288,7 @@ async def test_establish_session_parameterized(
288288
mock_read_stream = mock.AsyncMock(name=f"{client_type_name}Read")
289289
mock_write_stream = mock.AsyncMock(name=f"{client_type_name}Write")
290290

291-
# streamablehttp_client's __aenter__ returns three values
291+
# streamable_http_client's __aenter__ returns three values
292292
if client_type_name == "streamablehttp":
293293
mock_extra_stream_val = mock.AsyncMock(name="StreamableExtra")
294294
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:
184181
raise ValueError(f"Invalid transport: {transport}")
185182

0 commit comments

Comments
 (0)