+
    Q(i'                    :   R t ^ RIHt ^ RIHtHt ^ RIHtHt ^ RI	H
t
Ht ]
'       d   ^ RIHt ]R.]]]]3,          R,          ,          3,          t]R.]]]]3,          R,          ,          3,          t ! R R	4      t ! R
 R]4      t ! R R]4      tR R ltR# )a  Composable lifespans for FastMCP servers.

This module provides a `@lifespan` decorator for creating composable server lifespans
that can be combined using the `|` operator.

Example:
    ```python
    from fastmcp import FastMCP
    from fastmcp.server.lifespan import lifespan

    @lifespan
    async def db_lifespan(server):
        conn = await connect_db()
        yield {"db": conn}
        await conn.close()

    @lifespan
    async def cache_lifespan(server):
        cache = await connect_cache()
        yield {"cache": cache}
        await cache.close()

    mcp = FastMCP("server", lifespan=db_lifespan | cache_lifespan)
    ```

To compose with existing `@asynccontextmanager` lifespans, wrap them explicitly:

    ```python
    from contextlib import asynccontextmanager
    from fastmcp.server.lifespan import lifespan, ContextManagerLifespan

    @asynccontextmanager
    async def legacy_lifespan(server):
        yield {"legacy": True}

    @lifespan
    async def new_lifespan(server):
        yield {"new": True}

    # Wrap the legacy lifespan explicitly
    combined = ContextManagerLifespan(legacy_lifespan) | new_lifespan
    ```
)annotations)AsyncIteratorCallable)AbstractAsyncContextManagerasynccontextmanager)TYPE_CHECKINGAny)FastMCPFastMCP[Any]Nc                  H    ] tR t^=tRtR R lt]R R l4       tR R ltRt	R	# )
LifespanzComposable lifespan wrapper.

Wraps an async generator function and enables composition via the `|` operator.
The wrapped function should yield a dict that becomes part of the lifespan context.
c                    V ^8  d   QhRRRR/# )   fn
LifespanFnreturnNone )formats   "]/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/server/lifespan.py__annotate__Lifespan.__annotate__D   s      : $     c                    Wn         R# )zInitialize a Lifespan wrapper.

Args:
    fn: An async generator function that takes a FastMCP server and yields
        a dict for the lifespan context.
N_fnselfr   s   &&r   __init__Lifespan.__init__D   s	     r   c                    V ^8  d   QhRRRR/# r   serverr
   r   zAsyncIterator[dict[str, Any]]r   )r   s   "r   r   r   N   s     
7 
7\ 
76S 
7r   c                  "   \        V P                  4      ! V4      ;_uu_4       GRj  xL
 pVe   TM/ 5x  RRR4      GRj  xL
  R#  L! L  + GRj  xL 
 '       g   i     R# ; i5izExecute the lifespan as an async context manager.

Args:
    server: The FastMCP server instance.

Yields:
    The lifespan context dict.
N)r   r   r   r"   results   && r   __call__Lifespan.__call__M   sA      'txx0888F".&B6 988888sI   (A-AA-AA-AA-A-A*	A
A*	"A*	$	A-c                    V ^8  d   QhRRRR/# )r   otherr   r   ComposedLifespanr   )r   s   "r   r   r   Z   s     - -H -)9 -r   c                    \        V\        4      '       g#   \        R\        V4      P                   R24      h\        W4      # )zCompose with another lifespan using the | operator.

Args:
    other: Another Lifespan instance.

Returns:
    A ComposedLifespan that runs both lifespans.

Raises:
    TypeError: If other is not a Lifespan instance.
zCannot compose Lifespan with z@. Use @lifespan decorator or wrap with ContextManagerLifespan().)
isinstancer   	TypeErrortype__name__r+   )r   r*   s   &&r   __or__Lifespan.__or__Z   sJ     %**/U0D0D/E FQ R   ,,r   r   N)
r0   
__module____qualname____firstlineno____doc__r   r   r'   r1   __static_attributes__r   r   r   r   r   =   s*     
7 
7- -r   r   c                  H    ] tR t^nt$ RtR]R&   R R lt]R R l4       tRt	R	# )
ContextManagerLifespanzLifespan wrapper for already-wrapped context manager functions.

Use this for functions already decorated with @asynccontextmanager.
LifespanContextManagerFnr   c                    V ^8  d   QhRRRR/# )r   r   r:   r   r   r   )r   s   "r   r   #ContextManagerLifespan.__annotate__v   s      3  r   c                    Wn         R# )z3Initialize with a context manager factory function.Nr   r   s   &&r   r   ContextManagerLifespan.__init__v   s    r   c                    V ^8  d   QhRRRR/# r!   r   )r   s   "r   r   r<   {   s     7 7\ 76S 7r   c                  "   V P                  V4      ;_uu_4       GRj  xL
 pVe   TM/ 5x  RRR4      GRj  xL
  R#  L! L  + GRj  xL 
 '       g   i     R# ; i5ir$   r   r%   s   && r   r'   ContextManagerLifespan.__call__z   s<      88F###v".&B6 $#####sG   A#AA#AA#AA#A#A 	A
A 	A 		A#r   N)
r0   r3   r4   r5   r6   __annotations__r   r   r'   r7   r   r   r   r9   r9   n   s(    
 
"! 7 7r   r9   c                  <    ] tR t^tRtR R lt]R R l4       tRtR# )r+   zTwo lifespans composed together.

Enters the left lifespan first, then the right. Exits in reverse order.
Results are shallow-merged into a single dict.
c               $    V ^8  d   QhRRRRRR/# )r   leftr   rightr   r   r   )r   s   "r   r   ComposedLifespan.__annotate__   s!     	 	X 	h 	4 	r   c                    Wn         W n        R# )zwInitialize a composed lifespan.

Args:
    left: The first lifespan to enter.
    right: The second lifespan to enter.
N_left_right)r   rE   rF   s   &&&r   r   ComposedLifespan.__init__   s     
r   c                    V ^8  d   QhRRRR/# r!   r   )r   s   "r   r   rG      s     2 2\ 26S 2r   c           
    j  "   V P                  V4      ;_uu_4       GRj  xL
 pV P                  V4      ;_uu_4       GRj  xL
 p/ VCVC5x  RRR4      GRj  xL
  RRR4      GRj  xL
  R#  LQ L1 L  + GRj  xL 
 '       g   i     L1; i L(  + GRj  xL 
 '       g   i     R# ; i5i)zExecute both lifespans, merging their results.

Args:
    server: The FastMCP server instance.

Yields:
    The merged lifespan context dict from both lifespans.
NrI   )r   r"   left_resultright_results   &&  r   r'   ComposedLifespan.__call__   sm      JJv+KK<1[1L11    s   B3A2B3BA4B
A8	BA6B B3+B,B34B6B8B>B?
B
BBB3B0	B
B0	(B0	*	B3rI   N)	r0   r3   r4   r5   r6   r   r   r'   r7   r   r   r   r+   r+      s     	 2 2r   r+   c                    V ^8  d   QhRRRR/# )r   r   r   r   r   r   )r   s   "r   r   r      s        r   c                    \        V 4      # )ap  Decorator to create a composable lifespan.

Use this decorator on an async generator function to make it composable
with other lifespans using the `|` operator.

Example:
    ```python
    @lifespan
    async def my_lifespan(server):
        # Setup
        resource = await create_resource()
        yield {"resource": resource}
        # Teardown
        await resource.close()

    mcp = FastMCP("server", lifespan=my_lifespan | other_lifespan)
    ```

Args:
    fn: An async generator function that takes a FastMCP server and yields
        a dict for the lifespan context.

Returns:
    A composable Lifespan wrapper.
)r   )r   s   &r   lifespanrT      s    4 B<r   )r6   
__future__r   collections.abcr   r   
contextlibr   r   typingr   r   fastmcp.server.serverr	   dictstrr   r:   r   r9   r+   rT   r   r   r   <module>r\      s   *X # 3 G %- ~&d38nt6K(LLM
#1$sCx.42GHH 
.- .-b7X 76 2x  2Fr   