Skip to content

Commit 77e7871

Browse files
Kludexfelixweinberger
authored andcommitted
Rename streamablehttp_client to streamable_http_client
1 parent 3e798bf commit 77e7871

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
@@ -1993,12 +1993,12 @@ Run from the repository root:
19931993
import asyncio
19941994

19951995
from mcp import ClientSession
1996-
from mcp.client.streamable_http import streamablehttp_client
1996+
from mcp.client.streamable_http import streamable_http_client
19971997

19981998

19991999
async def main():
20002000
# Connect to a streamable HTTP server
2001-
async with streamablehttp_client("http://localhost:8000/mcp") as (
2001+
async with streamable_http_client("http://localhost:8000/mcp") as (
20022002
read_stream,
20032003
write_stream,
20042004
_,
@@ -2126,7 +2126,7 @@ from pydantic import AnyUrl
21262126

21272127
from mcp import ClientSession
21282128
from mcp.client.auth import OAuthClientProvider, TokenStorage
2129-
from mcp.client.streamable_http import streamablehttp_client
2129+
from mcp.client.streamable_http import streamable_http_client
21302130
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
21312131

21322132

@@ -2180,7 +2180,7 @@ async def main():
21802180
callback_handler=handle_callback,
21812181
)
21822182

2183-
async with streamablehttp_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
2183+
async with streamable_http_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
21842184
async with ClientSession(read, write) as session:
21852185
await session.initialize()
21862186

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
@@ -35,10 +35,7 @@
3535
)
3636
from mcp.client.session import ClientSession
3737
from mcp.client.sse import sse_client
38-
from mcp.client.streamable_http import GetSessionIdCallback, streamablehttp_client
39-
from mcp.shared.context import RequestContext
40-
from mcp.shared.message import SessionMessage
41-
from mcp.shared.session import RequestResponder
38+
from mcp.client.streamable_http import streamable_http_client
4239
from mcp.types import (
4340
ClientResult,
4441
CreateMessageRequestParams,
@@ -190,7 +187,7 @@ def create_client_for_transport(transport: str, server_url: str):
190187
return sse_client(endpoint)
191188
elif transport == "streamable-http":
192189
endpoint = f"{server_url}/mcp"
193-
return streamablehttp_client(endpoint)
190+
return streamable_http_client(endpoint)
194191
else:
195192
raise ValueError(f"Invalid transport: {transport}")
196193

0 commit comments

Comments
 (0)