-
Notifications
You must be signed in to change notification settings - Fork 2k
Make the starlet lifespan state publically accessible #3180
Copy link
Copy link
Open
Labels
duplicateDuplicates an existing open issue. Reference the original issue when applying.Duplicates an existing open issue. Reference the original issue when applying.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
duplicateDuplicates an existing open issue. Reference the original issue when applying.Duplicates an existing open issue. Reference the original issue when applying.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
Starlet has a concept of lifespan state where we can provide context values for the whole lifespan of a server, like singleton instances (e.g. a s3 client we don't want to create for each request)
https://starlette.dev/lifespan/#lifespan-state
Right now they are processed by the FastMCP server. However, they are only accessible via the
_lifespanattribute.If would be nice to have a public api in the fastmcp instance or in the context itself.
Would be even better if the lifespan access could somehow be typed, but afaik this is something the starlet devs also struggle with due to lacking support in the asynccontextmanager.
Example: