Skip to main content

mcp_kit.patch_mcp

Utility functions for MCP client connections.

streamablehttp_client

http_streamable_session

async def http_streamable_session(
url: str, headers: dict[str, Any] | None
) -> tuple[ClientSession, AsyncExitStack]

Create an HTTP streamable MCP client session.

Establishes a connection to an MCP server over HTTP and returns both the session and the exit stack for proper cleanup.

Arguments:

  • url: URL of the MCP server
  • headers: Optional HTTP headers to include in requests

Returns:

Tuple of (ClientSession, AsyncExitStack) for the connection