Skip to content

Rename streamablehttp_client to streamable_http_client #1177

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1471,12 +1471,12 @@ Run from the repository root:
import asyncio

from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.streamable_http import streamable_http_client


async def main():
# Connect to a streamable HTTP server
async with streamablehttp_client("http://localhost:8000/mcp") as (
async with streamable_http_client("http://localhost:8000/mcp") as (
read_stream,
write_stream,
_,
Expand Down Expand Up @@ -1604,7 +1604,7 @@ from pydantic import AnyUrl

from mcp import ClientSession
from mcp.client.auth import OAuthClientProvider, TokenStorage
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.streamable_http import streamable_http_client
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken


Expand Down Expand Up @@ -1658,7 +1658,7 @@ async def main():
callback_handler=handle_callback,
)

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
from mcp.client.auth import OAuthClientProvider, TokenStorage
from mcp.client.session import ClientSession
from mcp.client.sse import sse_client
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.streamable_http import streamable_http_client
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken


Expand Down Expand Up @@ -207,7 +207,7 @@ async def _default_redirect_handler(authorization_url: str) -> None:
await self._run_session(read_stream, write_stream, None)
else:
print("📡 Opening StreamableHTTP transport connection with auth...")
async with streamablehttp_client(
async with streamable_http_client(
url=self.server_url,
auth=oauth_auth,
timeout=timedelta(seconds=60),
Expand Down
4 changes: 2 additions & 2 deletions examples/snippets/clients/oauth_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

from mcp import ClientSession
from mcp.client.auth import OAuthClientProvider, TokenStorage
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.streamable_http import streamable_http_client
from mcp.shared.auth import OAuthClientInformationFull, OAuthClientMetadata, OAuthToken


Expand Down Expand Up @@ -68,7 +68,7 @@ async def main():
callback_handler=handle_callback,
)

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

Expand Down
4 changes: 2 additions & 2 deletions examples/snippets/clients/streamable_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@
import asyncio

from mcp import ClientSession
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.streamable_http import streamable_http_client


async def main():
# Connect to a streamable HTTP server
async with streamablehttp_client("http://localhost:8000/mcp") as (
async with streamable_http_client("http://localhost:8000/mcp") as (
read_stream,
write_stream,
_,
Expand Down
6 changes: 3 additions & 3 deletions src/mcp/client/session_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
from mcp import types
from mcp.client.sse import sse_client
from mcp.client.stdio import StdioServerParameters
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.streamable_http import streamable_http_client
from mcp.shared.exceptions import McpError


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


class StreamableHttpParameters(BaseModel):
"""Parameters for intializing a streamablehttp_client."""
"""Parameters for intializing a streamable_http_client."""

# The endpoint URL.
url: str
Expand Down Expand Up @@ -250,7 +250,7 @@ async def _establish_session(
)
read, write = await session_stack.enter_async_context(client)
else:
client = streamablehttp_client(
client = streamable_http_client(
url=server_params.url,
headers=server_params.headers,
timeout=server_params.timeout,
Expand Down
27 changes: 26 additions & 1 deletion src/mcp/client/streamable_http.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from anyio.abc import TaskGroup
from anyio.streams.memory import MemoryObjectReceiveStream, MemoryObjectSendStream
from httpx_sse import EventSource, ServerSentEvent, aconnect_sse
from typing_extensions import deprecated

from mcp.shared._httpx_utils import McpHttpClientFactory, create_mcp_http_client
from mcp.shared.message import ClientMessageMetadata, SessionMessage
Expand Down Expand Up @@ -438,7 +439,7 @@ def get_session_id(self) -> str | None:


@asynccontextmanager
async def streamablehttp_client(
async def streamable_http_client(
url: str,
headers: dict[str, str] | None = None,
timeout: float | timedelta = 30,
Expand Down Expand Up @@ -507,3 +508,27 @@ def start_get_stream() -> None:
finally:
await read_stream_writer.aclose()
await write_stream.aclose()


@deprecated("Use `streamable_http_client` instead.")
@asynccontextmanager
async def streamablehttp_client(
url: str,
headers: dict[str, str] | None = None,
timeout: float | timedelta = 30,
sse_read_timeout: float | timedelta = 60 * 5,
terminate_on_close: bool = True,
httpx_client_factory: McpHttpClientFactory = create_mcp_http_client,
auth: httpx.Auth | None = None,
) -> AsyncGenerator[
tuple[
MemoryObjectReceiveStream[SessionMessage | Exception],
MemoryObjectSendStream[SessionMessage],
GetSessionIdCallback,
],
None,
]:
async with streamable_http_client(
url, headers, timeout, sse_read_timeout, terminate_on_close, httpx_client_factory, auth
) as streams:
yield streams
4 changes: 2 additions & 2 deletions tests/client/test_session_group.py
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ async def test_disconnect_non_existent_server(self):
(
StreamableHttpParameters(url="http://test.com/stream", terminate_on_close=False),
"streamablehttp",
"mcp.client.session_group.streamablehttp_client",
"mcp.client.session_group.streamable_http_client",
), # url, headers, timeout, sse_read_timeout, terminate_on_close
],
)
Expand All @@ -292,7 +292,7 @@ async def test_establish_session_parameterized(
mock_read_stream = mock.AsyncMock(name=f"{client_type_name}Read")
mock_write_stream = mock.AsyncMock(name=f"{client_type_name}Write")

# streamablehttp_client's __aenter__ returns three values
# streamable_http_client's __aenter__ returns three values
if client_type_name == "streamablehttp":
mock_extra_stream_val = mock.AsyncMock(name="StreamableExtra")
mock_client_cm_instance.__aenter__.return_value = (
Expand Down
4 changes: 2 additions & 2 deletions tests/server/fastmcp/test_integration.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
)
from mcp.client.session import ClientSession
from mcp.client.sse import sse_client
from mcp.client.streamable_http import streamablehttp_client
from mcp.client.streamable_http import streamable_http_client
from mcp.types import (
CreateMessageResult,
ElicitResult,
Expand Down Expand Up @@ -172,7 +172,7 @@ def create_client_for_transport(transport: str, server_url: str):
return sse_client(endpoint)
elif transport == "streamable-http":
endpoint = f"{server_url}/mcp"
return streamablehttp_client(endpoint)
return streamable_http_client(endpoint)
else:
raise ValueError(f"Invalid transport: {transport}")

Expand Down
Loading
Loading