-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Open
Labels
clientRelated to the FastMCP client SDK or client-side functionality.Related to the FastMCP client SDK or client-side functionality.enhancementImprovement to existing functionality. For issues and smaller PR improvements.Improvement to existing functionality. For issues and smaller PR improvements.httpRelated to HTTP transport, networking, or web server functionality.Related to HTTP transport, networking, or web server functionality.
Description
Enhancement
Currently, the StreamableHTTPTransport doesn't expose the session id callback from MCP's streamablehttp_client.
async with streamablehttp_client(
self.url,
auth=self.auth,
**client_kwargs,
) as transport:
read_stream, write_stream, _ = transport
async with ClientSession(
read_stream, write_stream, **session_kwargs
) as session:
yield sessionFor users wanting to manage some state on the client side related to sessions, it is more complicated to access mcp-session-id without working with lower level code.
Proposal:
async with streamablehttp_client(
self.url,
auth=self.auth,
**client_kwargs,
) as transport:
# _ is replaced with get_session_id and attached to the transport
read_stream, write_stream, get_session_id = transport
self.get_session_id_cb = get_session_id
async with ClientSession(
read_stream, write_stream, **session_kwargs
) as session:
yield session
def get_session_id(self) -> str | None:
if self.get_session_id_cb:
return self.get_session_id_cb()
return NoneMetadata
Metadata
Assignees
Labels
clientRelated to the FastMCP client SDK or client-side functionality.Related to the FastMCP client SDK or client-side functionality.enhancementImprovement to existing functionality. For issues and smaller PR improvements.Improvement to existing functionality. For issues and smaller PR improvements.httpRelated to HTTP transport, networking, or web server functionality.Related to HTTP transport, networking, or web server functionality.