-
Notifications
You must be signed in to change notification settings - Fork 2k
Enhance session start/end hook #1894
Copy link
Copy link
Open
Labels
enhancementImprovement to existing functionality. For issues and smaller PR improvements.Improvement to existing functionality. For issues and smaller PR improvements.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Metadata
Metadata
Assignees
Labels
enhancementImprovement to existing functionality. For issues and smaller PR improvements.Improvement to existing functionality. For issues and smaller PR improvements.serverRelated to FastMCP server implementation or server-side functionality.Related to FastMCP server implementation or server-side functionality.
Enhancement
At the moment the
FastMCPlifespanparameter does not contain any info about the client connection that is beginning/ending (specifically the MCP session ID). This would be useful for remote MCP servers where you want to take some action when a client connects/disconnects. As far as I understand these are the best workarounds right now:access_token()in the lifespan to get the identity of an authenticated user (does not differentiate between sessions)on_message()hook to track the first MCP message sent for a sessionI believe it would be helpful to add access to the MCP session ID in the lifespan handler.