+
    Q(i4                      a  0 t $ ^ RIHt ^ RIHtHtHt ^ RIHtH	t	 ^ RI
Ht ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI H!t!H"t"H#t# ^ RI$H%t%H&t&H't'H(t( ^ RI)H*t* ^ RI+H,t, ^ RI-H.t. ]'       d   ^ RI/H0t0 ].! ]14      t2 ! R R4      t3]! RRR7      t4R]5R&    ! R R]4      t6]	R R l4       t7 ! R  R!4      t8R(R" R# llt9R)R$ R% llt:R*R& R' llt;R# )+    )annotations)AsyncGeneratorCallable	Generator)asynccontextmanagercontextmanager)
ContextVar)TYPE_CHECKING)build_resource_metadata_url)LifespanResultT)SseServerTransport)
EventStore)StreamableHTTPSessionManager)	Starlette)
Middleware)Request)Response)	BaseRouteMountRoute)LifespanReceiveScopeSend)AuthProvider)RequireAuthMiddleware)
get_logger)FastMCPc                  ,    ] tR t^ tRtR tR R ltRtR# )StreamableHTTPASGIAppz>ASGI application wrapper for Streamable HTTP server transport.c                	    Wn         R # Nsession_manager)selfr$   s   &&Y/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/server/http.py__init__StreamableHTTPASGIApp.__init__#   s    .    c               (    V ^8  d   QhRRRRRRRR/# )	   scoper   receiver   sendr   returnNone )formats   "r&   __annotate__"StreamableHTTPASGIApp.__annotate__&   s(      E G 4 D r)   c                	   "    V P                   P                  WV4      G R j  xL
  R #  L  \         dD   p\        T4      R8X  d.   \        P                  RT 2RR7       Rp\        T RT 24      Thh R p?ii ; i5i)Nz6Task group is not initialized. Make sure to use run().z(Original RuntimeError from mcp library: T)exc_infoa  FastMCP's StreamableHTTPSessionManager task group was not initialized. This commonly occurs when the FastMCP application's lifespan is not passed to the parent ASGI application (e.g., FastAPI or Starlette). Please ensure you are setting `lifespan=mcp_app.lifespan` in your parent app's constructor, where `mcp_app` is the application instance returned by `fastmcp_instance.http_app()`. \nFor more details, see the FastMCP ASGI integration documentation: https://gofastmcp.com/deployment/asgiz\nOriginal error: )r$   handle_requestRuntimeErrorstrloggererror)r%   r,   r-   r.   enew_error_messages   &&&&  r&   __call__StreamableHTTPASGIApp.__call__&   s     	&&55edKKK 	1vQQ>qcBT  < " #&7%88KA3#OPVWW )	s0   A=, *, A=, A:>A55A::A=r#   N__name__
__module____qualname____firstlineno____doc__r'   r>   __static_attributes__r1   r)   r&   r    r        s    H/ r)   r    http_requestN)defaultzContextVar[Request | None]_current_http_requestc                  ,    ] tR t^Ft]R R l4       tRtR# )StarletteWithLifespanc                   V ^8  d   QhRR/# )r+   r/   zLifespan[Starlette]r1   )r2   s   "r&   r3   "StarletteWithLifespan.__annotate__H   s     , ,- ,r)   c                	.    V P                   P                  # r"   )routerlifespan_context)r%   s   &r&   lifespanStarletteWithLifespan.lifespanG   s    {{+++r)   r1   N)rA   rB   rC   rD   propertyrQ   rF   r1   r)   r&   rK   rK   F   s    , ,r)   rK   c                    V ^8  d   QhRRRR/# )r+   requestr   r/   zGenerator[Request, None, None]r1   )r2   s   "r&   r3   r3   M   s     + +g +*H +r)   c              #     "   \         P                  V 4      p V x  \         P                  V4       R #   \         P                  T4       i ; i5ir"   )rI   setreset)rU   tokens   & r&   set_http_requestrZ   L   s<     !%%g.E+##E*##E*s   A4 AAAc                  &    ] tR t^UtRtR tR tRtR# )RequestContextMiddlewarezN
Middleware that stores each request in a ContextVar and sets transport type.
c                	    Wn         R # r"   app)r%   r_   s   &&r&   r'   !RequestContextMiddleware.__init__Z   s    r)   c                	  "   VR ,          R8X  d   ^ RI HpHp \        VR,          P                  RR4      pV'       d	   V! V4      MRp \        \        V4      4      ;_uu_ 4        V P                  WV4      G Rj  xL
  RRR4       Ve   V! V4       R# R# V P                  WV4      G Rj  xL
  R#  L8  + '       g   i     L>; i  Te
   T! T4       i i ; i L-5i)typehttp)reset_transportset_transportr_   transport_typeN)fastmcp.server.contextrd   re   getattrstaterZ   r   r_   )r%   r,   r-   r.   rd   re   rf   transport_tokens   &&&&    r&   r>   !RequestContextMiddleware.__call__]   s     =F"M %U5\%7%79I4PN?MmN;SWO5%gen55((54888 6 #.#O4 / ((54000 9 65 #.#O4 / 1sT   AC
C
 &B7<B5=B7C
 	%C.C/C5B77C	C
 
CCr^   Nr@   r1   r)   r&   r\   r\   U   s    1r)   r\   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r+   routeszlist[BaseRoute]
middlewarezlist[Middleware]debugboolrQ   zCallable | Noner/   rK   r1   )r2   s   "r&   r3   r3   n   s:         	
 r)   c                ^    VP                  ^ \        \        4      4       \        V VVVR7      # )a2  Create a base Starlette app with common middleware and routes.

Args:
    routes: List of routes to include in the app
    middleware: List of middleware to include in the app
    debug: Whether to enable debug mode
    lifespan: Optional lifespan manager for the app

Returns:
    A Starlette application
rm   rn   ro   rQ   )insertr   r\   rK   rr   s   &&&&r&   create_base_apprt   n   s3    & a$<=> 	 r)   c               8    V ^8  d   QhRRRRRRRRRR	R
RRRRR/# )r+   serverFastMCP[LifespanResultT]message_pathr9   sse_pathauthAuthProvider | Nonero   rp   rm   list[BaseRoute] | Nonern   list[Middleware] | Noner/   rK   r1   )r2   s   "r&   r3   r3      sb     | |$|| | 	|
 | #| (| |r)   c           
       a aa . p. p\        V4      oR V V3R lloV'       d   VP                  4       p	VP                  VR7      p
VP                  V
4       VP                  V	4       VP	                  V4      pV'       d   \        V4      MRpVP                  \        V\        SVP                  V4      R.R7      4       VP                  \        V\        SP                  VP                  V4      R7      4       MMR V3R	 llpVP                  \        VVR.R7      4       VP                  \        VSP                  R7      4       V'       d   VP                  V4       VP                  S P                  4       4       V'       d   VP                  V4       \        R
 V 3R ll4       p\        VVVVR7      pS VP                  n        W/P                  n        RVP                  n        V# )a  Return an instance of the SSE server app.

Args:
    server: The FastMCP server instance
    message_path: Path for SSE messages
    sse_path: Path for SSE connections
    auth: Optional authentication provider (AuthProvider)
    debug: Whether to enable debug mode
    routes: Optional list of custom routes
    middleware: Optional list of middleware
Returns:
    A Starlette application with RequestContextMiddleware
c               (    V ^8  d   QhRRRRRRRR/# )	r+   r,   r   r-   r   r.   r   r/   r   r1   )r2   s   "r&   r3   $create_sse_app.<locals>.__annotate__   s(        t  r)   c                r  <"   SP                  WV4      ;_uu_4       GR j  xL
 pSP                  P                  V^ ,          V^,          SP                  P                  4       4      G R j  xL
  R R R 4      GR j  xL
  \	        4       #  Li L  L  + GR j  xL 
 '       g   i     \	        4       # ; i5ir"   )connect_sse_mcp_serverruncreate_initialization_optionsr   )r,   r-   r.   streamsrv   sses   &&& r&   
handle_sse"create_sse_app.<locals>.handle_sse   s     ??54888G$$((

""@@B   98 z 9 9888 zs]   B7BB7AB-B.B2B7=B>B7BB7B4	B
B4	$B4	&B7mcp_pathNGETendpointmethodsr^   c                    V ^8  d   QhRRRR/# )r+   rU   r   r/   r   r1   )r2   s   "r&   r3   r      s     	S 	S 	SH 	Sr)   c                p   <"   S! V P                   V P                  V P                  4      G R j  xL
 #  L5ir"   )r,   r-   _send)rU   r   s   &r&   sse_endpoint$create_sse_app.<locals>.sse_endpoint   s'     #GMM7??GMMRRRRs   ,646c                    V ^8  d   QhRRRR/# r+   r_   r   r/   zAsyncGenerator[None, None]r1   )r2   s   "r&   r3   r            I *D r)   c                  <"   SP                  4       ;_uu_4       GR j  xL
  R 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"   )_lifespan_manager)r_   rv   s   &r&   rQ    create_sse_app.<locals>.lifespan   s/     ++--- .-----sD   A<AA A>AA A	A	
A	A		Arr   r   )r   get_middleware
get_routesextend_get_resource_urlr   appendr   r   required_scopesr   handle_post_message_get_additional_http_routesr   rt   ri   fastmcp_serverpathrf   )rv   rx   ry   rz   ro   rm   rn   server_routesserver_middlewareauth_middlewareauth_routesresource_urlresource_metadata_urlr   rQ   r_   r   r   s   f&&&&&&         @@r&   create_sse_appr      s   . &(M*, \
*C  --/ ooxo8[)  1 --h79E'54 	
 	.(()
 
	
 	)++(()		
	S 	S 	%	
 	++	
 V$;;=>   , 
 $	C  &CIIIIN$CIIJr)   c               D    V ^8  d   QhRRRRRRRRR	R
RRRRRRRRRRRR/# )r+   rv   rw   streamable_http_pathr9   event_storezEventStore | Noneretry_intervalz
int | Nonerz   r{   json_responserp   stateless_httpro   rm   r|   rn   r}   r/   rK   r1   )r2   s   "r&   r3   r3   
  s     u u$uu #u 	u
 u u u u #u (u ur)   c
           
     h  a a . p
. p\        S P                  VVVVR7      o\        S4      pV'       d   VP                  4       pVP	                  VR7      pV
P                  V4       VP                  V4       VP                  V4      pV'       d   \        V4      MRpV'       d   RR.M. ROpV
P                  \        V\        VVP                  V4      VR7      4       M+V'       d   RR.MRpV
P                  \        VVVR7      4       V'       d   V
P                  V4       V
P                  S P                  4       4       V	'       d   VP                  V	4       \        R V V3R ll4       p\        V
VVVR	7      pS VP                  n        VVP                  n        R
VP                  n        V# )aP  Return an instance of the StreamableHTTP server app.

Args:
    server: The FastMCP server instance
    streamable_http_path: Path for StreamableHTTP connections
    event_store: Optional event store for SSE polling/resumability
    retry_interval: Optional retry interval in milliseconds for SSE polling.
        Controls how quickly clients should reconnect after server-initiated
        disconnections. Requires event_store to be set. Defaults to SDK default.
    auth: Optional authentication provider (AuthProvider)
    json_response: Whether to use JSON response format
    stateless_http: Whether to use stateless mode (new transport per request)
    debug: Whether to enable debug mode
    routes: Optional list of custom routes
    middleware: Optional list of middleware

Returns:
    A Starlette application with StreamableHTTP support
)r_   r   r   r   	statelessr   NPOSTDELETEr   c                    V ^8  d   QhRRRR/# r   r1   )r2   s   "r&   r3   0create_streamable_http_app.<locals>.__annotate__o  r   r)   c           
    `  <"   SP                  4       ;_uu_4       GR j  xL
  SP                  4       ;_uu_4       GR j  xL
  R 5x  R R R 4      GR j  xL
  R R R 4      GR j  xL
  R #  LL L- L  + GR j  xL 
 '       g   i     L1; i L(  + GR j  xL 
 '       g   i     R # ; i5ir"   )r   r   )r_   rv   r$   s   &r&   rQ   ,create_streamable_http_app.<locals>.lifespann  sW     ++---/B/B/D/D/D 0E/D---/D/D/D/D----s   B.A-B.BA/BA3	BA1BB.&B'B./B1B3B9A<:
BBBB.B+	B
B+	#B+	%	B.rr   zstreamable-http)r   r   r   )r   r   r    r   r   r   r   r   r   r   r   r   r   r   rt   ri   r   r   rf   )rv   r   r   r   rz   r   r   ro   rm   rn   r   r   streamable_http_appr   r   r   r   http_methodsrQ   r_   r$   s   f&&&&&&&&&          @r&   create_streamable_http_appr   
  s   > &(M*, 3%# O 0@ --/ oo/CoD[)  1 --.BC9E'54 	 #1VX6O 	 	$.'(()
 %
	
 .<)$,$	
 V$;;=>   ,   
 $	C  &CII)CIIN0CIIJr)   )FN)NFNN)NNNFFFNN)<__conditional_annotations__
__future__r   collections.abcr   r   r   
contextlibr   r   contextvarsr	   typingr
   mcp.server.auth.routesr   mcp.server.lowlevel.serverr   mcp.server.sser   mcp.server.streamable_httpr   "mcp.server.streamable_http_managerr   starlette.applicationsr   starlette.middlewarer   starlette.requestsr   starlette.responsesr   starlette.routingr   r   r   starlette.typesr   r   r   r   fastmcp.server.authr   fastmcp.server.auth.middlewarer   fastmcp.utilities.loggingr   fastmcp.server.serverr   rA   r:   r    rI   __annotations__rK   rZ   r\   rt   r   r   )r   s   @r&   <module>r      s    " " ? ? : "   > 6 - L , + & ( 5 5 : : , @ 0-	H	 @ 5?5 1 ,I , + +1 12:|~u ur)   