Skip to main content

fastmcp.client.transports.base

Classes

SessionKwargs

Keyword arguments for the MCP ClientSession constructor.

ClientTransport

Abstract base class for different MCP client transport mechanisms. A Transport is responsible for establishing and managing connections to an MCP server, and providing a ClientSession within an async context. Methods:

connect_session

connect_session(self, **session_kwargs: Unpack[SessionKwargs]) -> AsyncIterator[ClientSession]
Establishes a connection and yields an active ClientSession. The ClientSession is not expected to be initialized in this context manager. The session is guaranteed to be valid only within the scope of the async context manager. Connection setup and teardown are handled within this context. Args:
  • **session_kwargs: Keyword arguments to pass to the ClientSession constructor (e.g., callbacks, timeouts).

close

close(self)
Close the transport.

get_session_id

get_session_id(self) -> str | None
Get the session ID for this transport, if available.