Skip to content

Commit 5f69406

Browse files
committed
Rename streamablehttp_client to streamable_http_client
1 parent 0b1b52b commit 5f69406

File tree

9 files changed

+71
-54
lines changed

9 files changed

+71
-54
lines changed

README.md

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

14731473
from mcp import ClientSession
1474-
from mcp.client.streamable_http import streamablehttp_client
1474+
from mcp.client.streamable_http import streamable_http_client
14751475

14761476

14771477
async def main():
14781478
# Connect to a streamable HTTP server
1479-
async with streamablehttp_client("http://localhost:8000/mcp") as (
1479+
async with streamable_http_client("http://localhost:8000/mcp") as (
14801480
read_stream,
14811481
write_stream,
14821482
_,
@@ -1604,7 +1604,7 @@ from pydantic import AnyUrl
16041604

16051605
from mcp import ClientSession
16061606
from mcp.client.auth import OAuthClientProvider, TokenStorage
1607-
from mcp.client.streamable_http import streamablehttp_client
1607+
from mcp.client.streamable_http import streamable_http_client
16081608
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken
16091609

16101610

@@ -1658,7 +1658,7 @@ async def main():
16581658
callback_handler=handle_callback,
16591659
)
16601660

1661-
async with streamablehttp_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
1661+
async with streamable_http_client("http://localhost:8001/mcp", auth=oauth_auth) as (read, write, _):
16621662
async with ClientSession(read, write) as session:
16631663
await session.initialize()
16641664

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

Lines changed: 4 additions & 8 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

@@ -188,9 +188,7 @@ async def _default_redirect_handler(authorization_url: str) -> None:
188188
# Create OAuth authentication handler using the new interface
189189
oauth_auth = OAuthClientProvider(
190190
server_url=self.server_url.replace("/mcp", ""),
191-
client_metadata=OAuthClientMetadata.model_validate(
192-
client_metadata_dict
193-
),
191+
client_metadata=OAuthClientMetadata.model_validate(client_metadata_dict),
194192
storage=InMemoryTokenStorage(),
195193
redirect_handler=_default_redirect_handler,
196194
callback_handler=callback_handler,
@@ -207,7 +205,7 @@ async def _default_redirect_handler(authorization_url: str) -> None:
207205
await self._run_session(read_stream, write_stream, None)
208206
else:
209207
print("📡 Opening StreamableHTTP transport connection with auth...")
210-
async with streamablehttp_client(
208+
async with streamable_http_client(
211209
url=self.server_url,
212210
auth=oauth_auth,
213211
timeout=timedelta(seconds=60),
@@ -322,9 +320,7 @@ async def interactive_loop(self):
322320
await self.call_tool(tool_name, arguments)
323321

324322
else:
325-
print(
326-
"❌ Unknown command. Try 'list', 'call <tool_name>', or 'quit'"
327-
)
323+
print("❌ Unknown command. Try 'list', 'call <tool_name>', or 'quit'")
328324

329325
except KeyboardInterrupt:
330326
print("\n\n👋 Goodbye!")

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
@@ -438,7 +439,7 @@ def get_session_id(self) -> str | None:
438439

439440

440441
@asynccontextmanager
441-
async def streamablehttp_client(
442+
async def streamable_http_client(
442443
url: str,
443444
headers: dict[str, str] | None = None,
444445
timeout: float | timedelta = 30,
@@ -507,3 +508,23 @@ def start_get_stream() -> None:
507508
finally:
508509
await read_stream_writer.aclose()
509510
await write_stream.aclose()
511+
512+
513+
@deprecated("Use `streamable_http_client` instead.")
514+
@asynccontextmanager
515+
async def streamablehttp_client(
516+
url: str,
517+
headers: dict[str, str] | None = None,
518+
timeout: float | timedelta = 30,
519+
sse_read_timeout: float | timedelta = 60 * 5,
520+
terminate_on_close: bool = True,
521+
) -> AsyncGenerator[
522+
tuple[
523+
MemoryObjectReceiveStream[SessionMessage | Exception],
524+
MemoryObjectSendStream[SessionMessage],
525+
GetSessionIdCallback,
526+
],
527+
None,
528+
]:
529+
async with streamable_http_client(url, headers, timeout, sse_read_timeout, terminate_on_close) as streams:
530+
yield streams

tests/client/test_session_group.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ async def test_disconnect_non_existent_server(self):
276276
(
277277
StreamableHttpParameters(url="http://test.com/stream", terminate_on_close=False),
278278
"streamablehttp",
279-
"mcp.client.session_group.streamablehttp_client",
279+
"mcp.client.session_group.streamable_http_client",
280280
), # url, headers, timeout, sse_read_timeout, terminate_on_close
281281
],
282282
)
@@ -292,7 +292,7 @@ async def test_establish_session_parameterized(
292292
mock_read_stream = mock.AsyncMock(name=f"{client_type_name}Read")
293293
mock_write_stream = mock.AsyncMock(name=f"{client_type_name}Write")
294294

295-
# streamablehttp_client's __aenter__ returns three values
295+
# streamable_http_client's __aenter__ returns three values
296296
if client_type_name == "streamablehttp":
297297
mock_extra_stream_val = mock.AsyncMock(name="StreamableExtra")
298298
mock_client_cm_instance.__aenter__.return_value = (

tests/server/fastmcp/test_integration.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
)
3030
from mcp.client.session import ClientSession
3131
from mcp.client.sse import sse_client
32-
from mcp.client.streamable_http import streamablehttp_client
32+
from mcp.client.streamable_http import streamable_http_client
3333
from mcp.types import (
3434
CreateMessageResult,
3535
ElicitResult,
@@ -172,7 +172,7 @@ def create_client_for_transport(transport: str, server_url: str):
172172
return sse_client(endpoint)
173173
elif transport == "streamable-http":
174174
endpoint = f"{server_url}/mcp"
175-
return streamablehttp_client(endpoint)
175+
return streamable_http_client(endpoint)
176176
else:
177177
raise ValueError(f"Invalid transport: {transport}")
178178

0 commit comments

Comments
 (0)