
    "<i                      d Z ddlmZ ddlZddlZddlZddlZddlZddlZddl	m
Z
mZmZmZmZmZ ddlmZmZmZmZ ddlmZ ddlmZ ddlmZ dd	lmZmZmZmZm Z m!Z! ddl"Z"ddl#Z#ddl$Z%ddl&Z&dd
l'm(Z(m)Z) ddl*m+Z+ ddl,m-Z-m.Z. ddl/m0Z0 ddl1m2Z2 ddl$m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z: ddl$m;Z< ddl$m=Z> ddl$m?Z@ ddl$mAZB ddlCmDZD ddlEmFZG ddlHmIZI ddlJmKZK ddlLmMZMmNZN ddlOZOddlPZOddlQmRZRmSZS ddlTmUZU ddlVm;Z; ddlWmXZX ddlYmZZZ ddl[m\Z\m=Z= ddl]m^Z^ ddl_m`Z`m?Z? dd lambZb dd!lcmdZd dd"lemfZfmgZgmhZh dd#limjZj dd$lkmFZFmlZl dd%lmmnZn dd&lompZp dd'lqmrZrmsZsmtZt dd(lumvZv dd)lwmxZxmAZAmyZy dd*lzm{Z{ dd+l|m}Z} dd,l~mZ dd-lmZ dd.lmZmZ dd/lmZmZ er:dd0lmZ dd1lmZ dd2lmZmZ dd3lmZ dd4lmZmZ dd5lmZ dd6lmZ dd7lmZ dd8lwmZ  ee          ZdSd>Zed?         Zed@         Z ej        dA          ZedBgee-         f         ZedTdE            ZdUdHZ G dI dJee-                   Ze G dK dL                      ZdVdOZdVdPZdWdRZdS )Xz5FastMCP - A more ergonomic interface for MCP servers.    )annotationsN)AsyncIterator	AwaitableCallable
CollectionMappingSequence)AbstractAsyncContextManagerAsyncExitStackasynccontextmanagersuppress)	dataclass)partial)Path)TYPE_CHECKINGAnyGenericLiteralcastoverload)DocketWorker)ReadResourceContents)LifespanResultTNotificationOptions)stdio_server)McpError)METHOD_NOT_FOUNDAnnotationsAnyFunctionCallToolRequestParamsContentBlock	ErrorDataGetPromptResultToolAnnotations)Prompt)Resource)ResourceTemplate)Tool)AnyUrl)
Middleware)Request)Response)	BaseRouteRoute)DisabledErrorNotFoundError)	MCPConfig)FunctionPrompt)PromptManager)FunctionResourcer'   )ResourceManager)FunctionResourceTemplater(   )AuthProvider)
EventStore)StarletteWithLifespancreate_sse_appcreate_streamable_http_app)LowLevelServer)r+   MiddlewareContext)get_task_capabilities)
TaskConfig)handle_prompt_as_taskhandle_resource_as_taskhandle_tool_as_task)Settings)FunctionToolr)   
ToolResult)ToolManager)ToolTransformConfig)log_server_banner)FastMCPComponent)
get_loggertemporary_log_level)NotSetNotSetTClient)FastMCP1Server)ClientTransportClientTransportT)ComponentFn)FastMCPOpenAPIRouteMap)
RouteMapFnFastMCPProxy)ServerSamplingHandler)ToolResultSerializerTypefnCallable[..., Any]namestrreturnc                `     ddl }|                               d fd            }||_        |S )	a#  Create a wrapper function with a custom __name__ for Docket registration.

    Docket uses fn.__name__ as the key for function registration and lookup.
    When mounting servers, we need unique names to avoid collisions between
    mounted servers that have identically-named functions.
    r   Nargsr   kwargsr`   c                 $   K    | i | d {V S N )rb   rc   r\   s     /Users/kimhansen/Desktop/03 Workspace/ceo-agents/chl-effectiveness/mcp-servers/whoop/.venv/lib/python3.11/site-packages/fastmcp/server/server.pywrapperz)_create_named_fn_wrapper.<locals>.wrapperu   s.      R((((((((((    )rb   r   rc   r   r`   r   )	functoolswraps__name__)r\   r^   rj   rh   s   `   rg   _create_named_fn_wrapperrm   l   sU     __R) ) ) ) ) ) GNri   )warnerrorreplaceignore)stdiohttpssestreamable-httpz^([^:]+://)(.*?)$FastMCP[LifespanResultT]serverAsyncIterator[Any]c                  K   i W V  dS )zDefault lifespan context manager that does nothing.

    Args:
        server: The server instance this lifespan is managing

    Returns:
        An empty dictionary as the lifespan result.
    Nrf   )rw   s    rg   default_lifespanrz      s       HHHHHHri   fastmcp_serverYCallable[[LowLevelServer[LifespanResultT]], AbstractAsyncContextManager[LifespanResultT]]c                .     t           d fd            }|S )Nlow_level_serverLowLevelServer[LifespanResultT]r`   AsyncIterator[LifespanResultT]c               v   K   j         t          u ri W V  d S j        st          d          j        W V  d S )Na  FastMCP server has a lifespan defined but no lifespan result is set, which means the server's context manager was not entered.  Are you running the server in a way that supports lifespans? If so, please file an issue at https://github.com/jlowin/fastmcp/issues.)	_lifespanrz   _lifespan_result_setRuntimeError_lifespan_result)r~   r{   s    rg   wrapz_lifespan_proxy.<locals>.wrap   se       #'777HHHHF2 	[  
 -------ri   )r~   r   r`   r   )r   )r{   r   s   ` rg   _lifespan_proxyr      s5    
 . . . . . . Kri   c                     e Zd Z	 	 ddddedddddddddddddddddddddddddddd0Zdd3Zdd5Zedd7            Zedd8            Z	edd9            Z
e
j        dd;            Z
edd<            Zedd=            Zedd?            Zed	dA            Zed
dC            ZddHZed
dI            Z	 	 dddQZ	 	 dddRZddSZddTZddUZddVZdd[Zdd]Zdd_ZddbZdddZddgZddiZ ddkZ!ddmZ"ddoZ#ddqZ$ddsZ%	 	 dddyZ&dd{Z'dd}Z(ddZ)ddZ*d dZ+d!dZ,d"dZ-d#dZ.d$dZ/d%dZ0d&dZ1d'dZ2d(dZ3d)dZ4d*dZ5d+dZ6d,dZ7d,dZ8d-dZ9	 d.d/dZ:	 d.d/dZ;d0dZ<d1dZ=d2dZ>d3dZ?d4dZ@eAdddddeddddddd5d            ZBeA	 d.dddddeddddddd6dÄ            ZB	 d.dddddeddddddd7dƄZBd8dȄZCd9dʄZDddddddddddd˜
d:dτZEd;dфZFeAdddddddddҜd<dԄ            ZGeA	 d.dddddddddҜd=dք            ZG	 d.dddddddddҜd>d؄ZG	 d?d@dلZH	 	 	 	 	 	 	 	 	 	 dAdBdބZI	 	 	 	 	 	 	 dCdDdZJ	 	 ddEdZK	 d.dFdZLeM	 	 	 	 	 dGdHd            ZNeM	 	 	 	 	 	 	 dIdJd            ZOeMdKd            ZPdLdZQeMd.dMd             ZRdS (N  FastMCPN)versionwebsite_urliconsauth
middlewarelifespanmask_error_detailstoolstool_transformationstool_serializerinclude_tagsexclude_tagsinclude_fastmcp_metaon_duplicate_toolson_duplicate_resourceson_duplicate_promptsstrict_input_validationtasks	log_leveldebughostportsse_pathmessage_pathstreamable_http_pathjson_responsestateless_httpsampling_handlersampling_handler_behaviorr^   
str | Noneinstructionsr   r   r   list[mcp.types.Icon] | Noner   AuthProvider | NotSetT | Noner   Sequence[Middleware] | Noner   LifespanCallable | Noner   bool | Noner   *Sequence[Tool | Callable[..., Any]] | Noner   (Mapping[str, ToolTransformConfig] | Noner   ToolResultSerializerType | Noner   Collection[str] | Noner   r   r   DuplicateBehavior | Noner   r   r   r   r   r   r   r   
int | Noner   r   r   r   r   r   -ServerSamplingHandler[LifespanResultT] | Noner   $Literal['always', 'fallback'] | Nonec                  ||nd| _         d | _        g | _        g | _        d| _        t          ||	|          | _        t          ||	          | _        t          ||	          | _
        || _        |pt          | _        d | _        d| _        t!          j                    | _        t'          t(                   | |p|                                 |pt,          j        |||t1          |                     | _        |t4          u r2t,          j        j        t,          j                                        }nd }t=          t>          d z  |          | _         |
rJ|
D ]G} tC          | tD                    stE          j#        | | j                  } | $                    |            H|tK          |          nd | _&        |tK          |          nd | _'        ||nt,          j        j(        | _(        tS          |pg           | _*        | +                                 || _,        |pd| _-        ||nt,          j        j.        | _.        | /                    |||||||||	  	         d S )	NF)duplicate_behaviorr   transformations)r   r   )r{   )fastmcpr^   r   r   r   r   r   )
serializerfallback)	r   r   r   r   r   r   r   r   r   )0_support_tasks_by_default_docket_additional_http_routes_mounted_servers_is_mountedrG   _tool_managerr6   _resource_managerr4   _prompt_manager_tool_serializerrz   r   r   r   asyncioEvent_startedr=   r   generate_namer   __version__r   _mcp_serverrM   settingsserver_authserver_auth_classr   r8   r   
isinstancer)   from_functionadd_toolsetr   r   r   listr   _setup_handlersr   r   r   _handle_deprecated_settings)!selfr^   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   tools!                                    rg   __init__zFastMCP.__init__   s   R 9>8Iuuu& 8:$57 	 +6110+
 +
 +

 3B513
 3
 3
 /<31/
 /
 /
 >M<D<XHX8<*/!'.} BPB
 -++--2w2%#$D999
B
 
B
 
B
 6>>+7'99;;)-lT.A4)H)H	 	$ $ $!$-- V-dt?TUUUDd#### ".!9Ct 	 ".!9Ct 	 '2 $#!9 	$ -11Ar,B,B 	  	 &3 	& $/ ! !6 	! 	((%!5') 	) 
	
 
	
 
	
 
	
 
	
ri   r`   r_   c                @    t          |           j         d| j        dS )N())typerl   r^   r   s    rg   __repr__zFastMCP.__repr__<  s$    t**%66	6666ri   Nonec
           
     $   i }
d|fd|fd|fd|fd|fd|fd|fd|fd	|	ff	D ]=\  }}|6t           j        j        r t          j        d| dt
          d           ||
|<   >t           j                                        |
z  }t          di || _        d
S )z0Handle deprecated settings. Deprecated in 2.8.0.r   r   r   r   r   r   r   r   r   NzProviding `ze` when creating a server is deprecated. Provide it when calling `run` or as a global setting instead.   
stacklevelrf   )	r   r   deprecation_warningswarningsrn   DeprecationWarning
model_dumprD   _deprecated_settings)r   r   r   r   r   r   r   r   r   r   deprecated_settingsr^   argcombined_settingss                 rg   r   z#FastMCP._handle_deprecated_settings?  s     /1 )$eTNTN"\*#%9:m,~.

 	0 	0ID# #8 M Rd  R  R  R*#$   
 -0#D)#,7799<OO$,$A$A/@$A$A!!!ri   rD   c                j    t           j        j        rt          j        dt
          d           | j        S )NzeAccessing `.settings` on a FastMCP instance is deprecated. Use the global `fastmcp.settings` instead.r   r   )r   r   r   r   rn   r   r   r   s    rg   r   zFastMCP.settingsf  s?     0 	Mw"   
 ((ri   c                    | j         j        S re   )r   r^   r   s    rg   r^   zFastMCP.nameq  s    $$ri   c                    | j         j        S re   r   r   r   s    rg   r   zFastMCP.instructionsu  s    ,,ri   valuec                    || j         _        d S re   r   )r   r   s     rg   r   zFastMCP.instructionsy  s    (-%%%ri   c                    | j         j        S re   )r   r   r   s    rg   r   zFastMCP.version}  s    ''ri   c                    | j         j        S re   )r   r   r   s    rg   r   zFastMCP.website_url  s    ++ri   list[mcp.types.Icon]c                P    | j         j        g S t          | j         j                  S re   )r   r   r   r   s    rg   r   zFastMCP.icons  s'    !)I(.///ri   Docket | Nonec                    | j         S )zGet the Docket instance if Docket support is enabled.

        Returns None if Docket is not enabled or server hasn't been started yet.
        )r   r   s    rg   docketzFastMCP.docket  s     |ri   AsyncIterator[None]c           
    	  K   ddl m} ddlm}m}m} |                    t          j        |                     }	 | j	        rdW V  	 |
                    |           dS t          |j        j        |j        j                  4 d{V 	 }|| _        | j        j                                        D ]A}t'          |t(                    r*|j        j        dk    r|                    |j                   B| j        j                                        D ]l}t'          |t6                    rU|j        j        dk    rE|                    t9          t:          dt<          t>                   f         |j                             m| j         j!                                        D ]A}	t'          |	tD                    r*|	j        j        dk    r|                    |	j                   B| j         j#                                        D ]A}
t'          |
tH                    r*|
j        j        dk    r|                    |
j                   B| j%        D ])}| &                    |j'        ||j(                   d{V  *|                    |          }	 |j        j)        |j        j*        |j        j+        d}|j        j,        r|j        j,        |d	<   t[          |fi |4 d{V }|                    |          }	 t]          j/        |0                                          }	 dW V  |1                                 te          t\          j3        t\          j4                  5  t]          j5        |d
           d{V  ddd           n# 1 swxY w Y   nq# |1                                 te          t\          j3        t\          j4                  5  t]          j5        |d
           d{V  ddd           w # 1 swxY w Y   w xY w|
                    |           n# |
                    |           w xY w	 ddd          d{V  n# 1 d{V swxY w Y   |
                    |           d| _        n!# |
                    |           d| _        w xY w	 ddd          d{V  n# 1 d{V swxY w Y   |
                    |           dS # |
                    |           w xY w)z@Manage Docket instance and Worker for background task execution.r   )r   )_current_docket_current_server_current_workerN)r^   url	forbidden.)concurrencyredelivery_timeoutreconnection_delayr^   g       @)timeout)6r   r   fastmcp.server.dependenciesr   r   r   r   weakrefrefr   resetr   r   r^   r   r   r   _toolsvaluesr   rE   task_configmoderegisterr\   r   _promptsr3   r   r   r   r   r   
_resourcesr5   
_templatesr7   r   "_register_mounted_server_functionsrw   prefixr   r   r  worker_namer   r   create_taskrun_forevercancelr   CancelledErrorTimeoutErrorwait_for)r   r   r   r   r   server_tokenr   r   promptresourcetemplatemounteddocket_tokenworker_kwargsworkerworker_tokenworker_tasks                    rg   _docket_lifespanzFastMCP._docket_lifespan  s^      	%$$$$$	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 '**7;t+<+<==[	0  j !!,/////e _)O'   O( O( O( O( O( O( O( O( %
 !.5<<>> 1 1D"4661 ,1[@@000"2;BBDD X XF"6>::X".3{BB Xc9S>6I-JFI(V(VWWW $ 6 A H H J J 5 5H"8-=>>5$05DD444 $ 6 A H H J J 5 5H"8-EFF5$05DD444  $4  GAA         
  /226::( (0'B.6o.P.6o.P5 5M
  2 L080Kf-  &f>>>> @ @ @ @ @ @ @&'6':':6'B'B@*1*=f>P>P>R>R*S*SKU % !, 2 2 4 4 4%-$+$:G<P&" &" !U !U +2*:;PS*T*T*T$T$T$T$T$T$T$T!U !U !U !U !U !U !U !U !U !U !U !U !U !U !U !, 2 2 4 4 4%-$+$:G<P&" &" !U !U +2*:;PS*T*T*T$T$T$T$T$T$T$T!U !U !U !U !U !U !U !U !U !U !U !U !U !U !U !U
 ,11,????O11,?????@ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @ @$ $)),777#'DLL $)),777#'DL'''''_O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O( O(d !!,/////O!!,////s   S +S G9RAQ)P;.&PN8PM;/P;M??PM?P9O5 O)O5)O--O50O-1O55P8P;P%%P;)Q);
Q	Q)Q		Q)R)RRS 
R''S *R'+S Srw   r   r   r  c           	       K   |j         j                                        D ]f}t          |t                    rO|j        j        dk    r?|r| d|j         n|j        }t          |j	        |          }|
                    |           g|j        j                                        D ]}t          |t                    rz|j        j        dk    rj|r| d|j         n|j        }t          t          t          dt           t"                   f         |j	                  |          }|
                    |           |j        j                                        D ]f}t          |t(                    rO|j        j        dk    r?|r| d|j         n|j        }t          |j	        |          }|
                    |           g|j        j                                        D ]f}	t          |	t.                    rO|	j        j        dk    r?|r| d|	j         n|	j        }t          |	j	        |          }|
                    |           g|j        D ]B}
|r|
j        r| d|
j         n|p|
j        }|                     |
j        ||           d{V  CdS )a  Register task-enabled functions from a mounted server with Docket.

        This enables background task execution for mounted server components
        through the parent server's Docket context.

        Args:
            server: The mounted server whose functions to register
            docket: The Docket instance to register with
            prefix: The mount prefix to prepend to function names (matches
                    client-facing tool/prompt names)
        r   _.N)r   r  r  r   rE   r	  r
  keyrm   r\   r  r   r  r3   r   r   r   r   r   r  r5   r^   r  r7   r   r  r  rw   )r   rw   r   r  r   fn_namenamed_fnr  r  r  nestednested_prefixs               rg   r  z*FastMCP._register_mounted_server_functions  s      (/6688 	* 	*D$-- *$2B2G;2V2V4:HV00dh0003DGWEE))) ,5<<>> 		* 		*F6>22*&+{::6<LV22fj222&*3#y~"56	BBG  ))) 0;BBDD 	* 	*H8%566*(-<<9?RV55hm555X]3HKII))) 0;BBDD 	* 	*H8%=>>*(-<<9?RV55hm555X]3HKII))) - 	 	F /$m/6++FM+++- 
 99v}         	 	ri   c                 K   | j         rd W V  d S |                     |           4 d {V 	 }|                                 4 d {V  || _        d| _         t	          t
          d z                       4 d {V }| j        D ]5}|                    |j        	                                           d {V  6| j
                                         	 d W V  | j
                                         n# | j
                                         w xY w	 d d d           d {V  n# 1 d {V swxY w Y   d d d           d {V  n# 1 d {V swxY w Y   d d d           d {V  n# 1 d {V swxY w Y   d| _         d | _        d S )NT)cmF)r   r   r"  r   r   boolr   enter_async_contextrw   _lifespan_managerr   r   clear)r   user_lifespan_resultstackrw   s       rg   r.  zFastMCP._lifespan_manager@  sP     $ 	EEEEF NN4  	* 	* 	* 	* 	* 	* 	* 	*$8!!##	* 	* 	* 	* 	* 	* 	* 	* %9D!(,D%%dTk244 
* 
* 
* 
* 
* 
* 
*"3  F33!=::<< 4           !!###*EEEEM''))))DM'')))))
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
* 
*	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	* 	*& %*! $sr   E'1E9AD!C0D!0D	D!E!
D++E.D+/E2E'
E	E'E	E''
E14E1T	transportTransport | Noneshow_bannerr,  transport_kwargsr   c                   K   |d}|dvrt          d|           |dk    r | j        dd|i| d{V  dS |dv r | j        d||d| d{V  dS t          d|           )	zRun the FastMCP server asynchronously.

        Args:
            transport: Transport protocol to use ("stdio", "sse", or "streamable-http")
        Nrr   >   rt   rs   rr   ru   zUnknown transport: r4  >   rt   rs   ru   )r2  r4  rf   )
ValueErrorrun_stdio_asyncrun_http_asyncr   r2  r4  r5  s       rg   	run_asynczFastMCP.run_async\  s      IGGG>9>>???&$&  '"           <<<%$% #'  #           >9>>???ri   c                T    t          j        t          | j        |fd|i|           dS )zRun the FastMCP server. Note this is a synchronous function.

        Args:
            transport: Transport protocol to use ("stdio", "sse", or "streamable-http")
        r4  N)anyiorunr   r;  r:  s       rg   r>  zFastMCP.runz  sP     		  ( #	 	
 	
 	
 	
 	
ri   c                    | j                                         | j                    | j                                         | j                    | j                                         | j                    | j                                         | j                    | j         	                    | j
                  | j                   |                                  |                                  |                                  dS )z"Set up core MCP protocol handlers.)validate_inputN)r   
list_tools_list_tools_mcplist_resources_list_resources_mcplist_resource_templates_list_resource_templates_mcplist_prompts_list_prompts_mcp	call_toolr   _call_tool_mcp_setup_read_resource_handler_setup_get_prompt_handler_setup_task_protocol_handlersr   s    rg   r   zFastMCP._setup_handlers  s    %##%%d&:;;;)''))$*BCCC2002243TUUU'%%''(>???O""$2N"OO	
 	
 	
 	))+++&&(((**,,,,,ri   c                P     d fd}| j         j        t          j        j        <   dS )a  
        Set up custom read_resource handler that supports task-augmented responses.

        The SDK's read_resource decorator doesn't support CreateTaskResult returns,
        so we register a custom handler that checks request_context.experimental.is_task.
        reqmcp.types.ReadResourceRequestr`   mcp.types.ServerResultc           	       K   | j         j        }d }	 j        j        }|j        j        r|j        j        }n# t          t          f$ r Y nw xY wt          j
        j                                      4 d {V                      t          |                     d {V }|r                    |          rt!          |d          r|j        j        }|dk    r)|s't'          t)          t*          d| d                    |rp|dk    rjt-          |t.          t0          z            rM|                    d	          }t5          t          |          ||           d {V cd d d           d {V  S |r-|dk    r't'          t)          t*          d| d
                    	 d d d           d {V  n# 1 d {V swxY w Y                       |           d {V }|r)g }|D ]}	t-          |	j        t                    rB|                    t<          j                             ||	j        |	j!        pd                     ^t-          |	j        tD                    rjdd l#}
|                    t<          j        $                    ||
%                    |	j                  &                                |	j!        pd                     t<          j        '                    t<          j        (                    |dddii                    S t-          |t<          j        j'                  r|S g }|D ]}	t-          |	j        t                    rB|                    t<          j                             ||	j        |	j!        pd                     ^t-          |	j        tD                    rjdd l#}
|                    t<          j        $                    ||
%                    |	j                  &                                |	j!        pd                     t<          j        '                    t<          j        (                    |                    S )Nr   r	  requiredz
Resource '#' requires task-augmented executioncodemessager   Texclude_none+' does not support task-augmented executionz
text/plain)uritextmimeTyper   zapplication/octet-stream)r\  blobr^  modelcontextprotocol.io/taskreturned_immediately)contents_meta)rb  ))paramsr\  r   request_contextexperimentalis_tasktask_metadataAttributeErrorLookupErrorr   rw   contextContext!_get_resource_or_template_or_noner_   _should_enable_componenthasattrr	  r
  r   r#   r   r   r5   r7   r   rB   _read_resource_mcpcontentappendmcptypesTextResourceContents	mime_typebytesbase64BlobResourceContents	b64encodedecodeServerResultReadResourceResult)rO  r\  	task_metactxr  	task_modetask_meta_dictresultmcp_contentsitemrx  r   s              rg   handlerz5FastMCP._setup_read_resource_handler.<locals>.handler  s     *.C I&6#+ ? # 0 >I"K0    ~-55d5CC ' ' ' ' ' ' ' '!%!G!GC!Q!QQQQQQQ$55h??$  -88$
 !) 4 9I !J..y.&%%5(]S(](](]     ! 	Y+%=%=%$,/GG   .7-A-At-A-T-TN)@ $c#hh.* * $ $ $ $ $ $7' ' ' ' ' ' ' ' ' ' ' ' ' 'B ! Y+%=%=&%%5(eS(e(e(e     E' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' ' 'T  22377777777F  !"  D!$,44 $++I::$'%)\)-)G< ;      $DL%88 	%$++I::$'%+%5%5dl%C%C%J%J%L%L)-)U;U ;     y--I00!-: 6= 1  	 	 	 &#)"899 L  dlC00  ''	66 #!%%)^%C| 7       e44 	!MMM ''	66 #!'!1!1$,!?!?!F!F!H!H%)^%Q7Q 7     9))	,,l,CC  s(   $8 AA:C+F:8/F::
GGN)rO  rP  r`   rQ  )r   request_handlersrs  rt  ReadResourceRequestr   r  s   ` rg   rK  z$FastMCP._setup_read_resource_handler  sG    v	 v	 v	 v	 v	 v	p LS)#)*GHHHri   c                P     d fd}| j         j        t          j        j        <   dS )a  
        Set up custom get_prompt handler that supports task-augmented responses.

        The SDK's get_prompt decorator doesn't support CreateTaskResult returns,
        so we register a custom handler that checks request_context.experimental.is_task.
        rO  mcp.types.GetPromptRequestr`   rQ  c           	     (  K   | j         j        }| j         j        }d }	 
j        j        }|j        j        r|j        j        }n# t          t          f$ r Y nw xY wt          j        j                            
          4 d {V  
                                 d {V }|                    |          }|r
                    |          rt#          |d          r|j        r|j        j        }|dk    r)|s't)          t+          t,          d| d                    |re|dk    r_|                    d	          }t1          
|||           d {V }	t2          j                            |	          cd d d           d {V  S |r-|dk    r't)          t+          t,          d| d
                    	 d d d           d {V  n# 1 d {V swxY w Y   
                    ||           d {V }	t2          j                            |	          S )NrS  r	  rT  zPrompt 'rU  rV  r   TrY  r[  )rd  r^   	argumentsr   re  rf  rg  rh  ri  rj  r   rw   rk  rl  get_promptsgetrn  ro  r	  r
  r   r#   r   r   rA   rs  rt  r|  _get_prompt_mcp)rO  r^   r  r~  r  promptsr  r  r  r  r   s             rg   r  z2FastMCP._setup_get_prompt_handler.<locals>.handler)  sM     :?D
,I I&6#+ ? # 0 >I"K0    ~-55d5CC $ $ $ $ $ $ $ $ $ 0 0 2 2222222 T**!55f==!  66! *	! !' 2 7I !J..y.&%%5(\4(\(\(\     ! >Y+%=%=)2)=)=4)=)P)P'< $	>( ( " " " " " "  #y55f==5$ $ $ $ $ $ $ $ $ $ $ $ $ $< ! Y+%=%=&%%5(d4(d(d(d     ?$ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $ $N  //i@@@@@@@@F9))&111s*   $A AAC-G/G
GGN)rO  r  r`   rQ  )r   r  rs  rt  GetPromptRequestr  s   ` rg   rL  z!FastMCP._setup_get_prompt_handler!  sA    6	2 6	2 6	2 6	2 6	2 6	2p IP)#)*DEEEri   c                    	
 ddl m}m}m}m}m	 ddlm
mm	m
 d	 fd}d	 fd
}d	 fd}d	 
fd}| j        j        |<   | j        j        |<   | j        j        |<   | j        j        |<   dS )z2Register SEP-1686 task protocol handlers with SDK.r   )CancelTaskRequestGetTaskPayloadRequestGetTaskRequestListTasksRequestr|  )tasks_cancel_handlertasks_get_handlertasks_list_handlertasks_result_handlerrO  r  r`   r|  c                z   K   | j                             dd          } |           d {V } |          S NT)by_aliasrZ  rd  r   )rO  rd  r  r|  r   r  s      rg   handle_get_taskz>FastMCP._setup_task_protocol_handlers.<locals>.handle_get_taskw  sU      Z**Dt*LLF,,T6::::::::F<'''ri   r  c                z   K   | j                             dd          } |           d {V } |          S r  r  )rO  rd  r  r|  r   r  s      rg   handle_get_task_resultzEFastMCP._setup_task_protocol_handlers.<locals>.handle_get_task_result|  U      Z**Dt*LLF//f========F<'''ri   r  c                   K   | j         r| j                             dd          ni } |           d {V } |          S r  r  )rO  rd  r  r|  r   r  s      rg   handle_list_tasksz@FastMCP._setup_task_protocol_handlers.<locals>.handle_list_tasks  sk       :
%%t$%GGG 
 .-dF;;;;;;;;F<'''ri   r  c                z   K   | j                             dd          } |           d {V } |          S r  r  )rO  rd  r  r|  r   r  s      rg   handle_cancel_taskzAFastMCP._setup_task_protocol_handlers.<locals>.handle_cancel_task  r  ri   N)rO  r  r`   r|  )rO  r  r`   r|  )rO  r  r`   r|  )rO  r  r`   r|  )	mcp.typesr  r  r  r  r|  fastmcp.server.tasks.protocolr  r  r  r  r   r  )r   r  r  r  r  r  r  r  r  r|  r  r  r  r  s   `        @@@@@rg   rM  z%FastMCP._setup_task_protocol_handlersc  s|   	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
	( 	( 	( 	( 	( 	( 	( 	(
	( 	( 	( 	( 	( 	( 	( 	(
	( 	( 	( 	( 	( 	( 	( 	(	( 	( 	( 	( 	( 	( 	( 	( =L).9" 	)*?@ ?P)*:;?Q)*;<<<ri   rk  MiddlewareContext[Any]	call_next2Callable[[MiddlewareContext[Any]], Awaitable[Any]]c                |   K   |}t          | j                  D ]}t          ||          } ||           d{V S )z)Builds and executes the middleware chain.)r  N)reversedr   r   )r   rk  r  chainmws        rg   _apply_middlewarezFastMCP._apply_middleware  sZ       4?++ 	1 	1BB%000EEU7^^#######ri   r+   c                :    | j                             |           d S re   )r   rr  )r   r   s     rg   add_middlewarezFastMCP.add_middleware  s    z*****ri   dict[str, Tool]c                  K   t          | j                                         d{V           }| j        D ]}	 |j                                         d{V }|                                D ]3\  }}|j        r|j         d| n|}|                    |          ||<   4k# t          $ rF}t          
                    d|j        j        d|            t          j        j        r Y d}~d}~ww xY w|S )zFGet all tools (unfiltered), including mounted servers, indexed by key.Nr$  r%  z(Failed to get tools from mounted server : )dictr   	get_toolsr   rw   itemsr  
model_copy	Exceptionloggerwarningr^   r   r   &mounted_components_raise_on_load_error)r   	all_toolsr  child_toolsr%  r   new_keyes           rg   r  zFastMCP.get_tools  sI     t1;;========>>	, 	 	G$+N$<$<$>$>>>>>>>!,!2!2!4!4 F FIC;B>R77#777sG)-W)E)EIg&&F    [w~?R[[XY[[   #J     A'B!!
C1+<C,,C1r%  r)   c                v   K   |                                   d {V }||vrt          d|           ||         S )NUnknown tool: )r  r1   )r   r%  r   s      rg   get_toolzFastMCP.get_tool  sS      nn&&&&&&&&e 6 6 6777Szri   Tool | Nonec                `   K   	 |                      |           d{V S # t          $ r Y dS w xY w)zGet a tool by key, returning None if not found.

        Used for task config checking where we need the actual tool object
        (including from mounted servers and proxies) but don't want to raise.
        N)r  r1   )r   r%  s     rg   _get_tool_with_task_configz"FastMCP._get_tool_with_task_config  sQ      	s+++++++++ 	 	 	44	s    
--r\  "Resource | ResourceTemplate | Nonec                   K   	 |                      |           d{V S # t          $ r Y nw xY w|                                  d{V }|                                D ]}|                    |          r|c S dS )zTGet a resource or template by URI, searching recursively. Returns None if not found.N)get_resourcer1   get_resource_templatesr  matches)r   r\  	templatesr  s       rg   rm  z)FastMCP._get_resource_or_template_or_none  s      	**3///////// 	 	 	D	 5577777777	!((** 	  	 H$$    ts    
,,dict[str, Resource]c                F  K   t          | j                                         d{V           }| j        D ]}	 |j                                         d{V }|                                D ]`\  }}|j        rt          ||j                  n|}|j        r|j        rd|j         d|j         ini }|	                    ||          ||<   a# t          $ rF}t                              d|j        j        d|            t          j        j        r Y d}~d}~ww xY w|S )zJGet all resources (unfiltered), including mounted servers, indexed by key.Nr^   r$  r%  updatez,Failed to get resources from mounted server r  )r  r   get_resourcesr   rw   r  r  add_resource_prefixr^   r  r  r  r  r   r   r  )	r   all_resourcesr  child_resourcesr%  r  r  r  r  s	            rg   r  zFastMCP.get_resources  s     4#9#G#G#I#IIIIIIIJJ, 	 	G(/(D(D(F(F"F"F"F"F"F"F%4%:%:%<%<  MC #>!+C@@@   #> .6m GN!D!DX]!D!DEE 
 .6-@-@#F .A . .M'**    _7>CV__\]__   #J  s   BC
D<DDr'   c                v   K   |                                   d {V }||vrt          d|           ||         S )NUnknown resource: )r  r1   )r   r%  	resourcess      rg   r  zFastMCP.get_resource  sU      ,,........	i :S : :;;;~ri   dict[str, ResourceTemplate]c                R  K   t          | j                                         d{V           }| j        D ]}	 |j                                         d{V }|                                D ]f\  }}|j        rt          ||j                  n|}i }|j        r |j        r|j         d|j         |d<   ||d<   |	                    ||          ||<   g# t          $ rF}t                              d|j        j        d|            t          j        j        r Y d}~d}~ww xY w|S )zSGet all resource templates (unfiltered), including mounted servers, indexed by key.Nr$  r^   uri_templater  z5Failed to get resource templates from mounted server r  )r  r   r  r   rw   r  r  r  r^   r  r  r  r  r   r   r  )	r   all_templatesr  child_templatesr%  r  r  r  r  s	            rg   r  zFastMCP.get_resource_templates  s     4#9#P#P#R#RRRRRRRSS, 	 	G(/(M(M(O(O"O"O"O"O"O"O%4%:%:%<%<  MC #>!+C@@@  
 .0F~ 9#= Q07-P-P-P-PF6N18~.-5-@-@#F .A . .M'**    hGNL_hhefhh   #J  s   BC
D$<DD$r(   c                v   K   |                                   d{V }||vrt          d|           ||         S )z*Get a registered resource template by key.NzUnknown resource template: )r  r1   )r   r%  r  s      rg   get_resource_templatezFastMCP.get_resource_template  sU      5577777777	i Cc C CDDD~ri   dict[str, Prompt]c                  K   t          | j                                         d{V           }| j        D ]}	 |j                                         d{V }|                                D ]3\  }}|j        r|j         d| n|}|                    |          ||<   4k# t          $ rF}t          
                    d|j        j        d|            t          j        j        r Y d}~d}~ww xY w|S )zHGet all prompts (unfiltered), including mounted servers, indexed by key.Nr$  r  z*Failed to get prompts from mounted server r  )r  r   r  r   rw   r  r  r  r  r  r  r^   r   r   r  )r   all_promptsr  child_promptsr%  r  r  r  s           rg   r  zFastMCP.get_prompts&  sL     !5!A!A!C!CCCCCCCDD, 	 	G&-n&@&@&B&B B B B B B B#0#6#6#8#8 J JKC;B>R77#777sG+1+<+<+<+I+IK((J    ]AT]]Z[]]   #J  r  r&   c                v   K   |                                   d {V }||vrt          d|           ||         S )NUnknown prompt: )r  r1   )r   r%  r  s      rg   
get_promptzFastMCP.get_prompt:  sU      ((********g 83 8 8999s|ri   pathmethods	list[str]include_in_schema^Callable[[Callable[[Request], Awaitable[Response]]], Callable[[Request], Awaitable[Response]]]c                $     d fd}|S )a  
        Decorator to register a custom HTTP route on the FastMCP server.

        Allows adding arbitrary HTTP endpoints outside the standard MCP protocol,
        which can be useful for OAuth callbacks, health checks, or admin APIs.
        The handler function must be an async function that accepts a Starlette
        Request and returns a Response.

        Args:
            path: URL path for the route (e.g., "/auth/callback")
            methods: List of HTTP methods to support (e.g., ["GET", "POST"])
            name: Optional name for the route (to reference this route with
                Starlette's reverse URL lookup feature)
            include_in_schema: Whether to include in OpenAPI schema, defaults to True

        Example:
            Register a custom HTTP route for a health check endpoint:
            ```python
            @server.custom_route("/health", methods=["GET"])
            async def health_check(request: Request) -> Response:
                return JSONResponse({"status": "ok"})
            ```
        r\   (Callable[[Request], Awaitable[Response]]r`   c           	     `    j                             t          |                      | S )N)endpointr  r^   r  )r   rr  r/   )r\   r  r  r^   r  r   s    rg   	decoratorz'FastMCP.custom_route.<locals>.decoratorb  sH     (//#&7     Iri   )r\   r  r`   r  rf   )r   r  r  r^   r  r  s   ````` rg   custom_routezFastMCP.custom_route@  sB    D	 	 	 	 	 	 	 	 	 	 ri   list[BaseRoute]c                    t          | j                  }| j        D ]0}|j                                        }|                    |           1|S )zGet all additional HTTP routes including from mounted servers.

        Returns a list of all custom HTTP routes from this server and
        recursively from all mounted servers.

        Returns:
            List of Starlette BaseRoute objects
        )r   r   r   rw   _get_additional_http_routesextend)r   routesmounted_servermounted_routess       rg   r  z#FastMCP._get_additional_http_routesr  sV     d233 #3 	* 	*N+2NNPPNMM.))))ri   list[MCPTool]c                @   K   t                               d j         d           t          j        j                                       4 d{V                                    d{V } fd|D             cddd          d{V  S # 1 d{V swxY w Y   dS )zg
        List all available tools, in the format expected by the low-level MCP
        server.
        [z] Handler called: list_toolsrS  Nc                R    g | ]#}|                     |j        j                   $S )r^   r   )to_mcp_toolr%  r   .0r   r   s     rg   
<listcomp>z+FastMCP._list_tools_mcp.<locals>.<listcomp>  sK       
 	   )-)B !    ri   )r  r   r^   r   rw   rk  rl  _list_tools_middleware)r   r   s   ` rg   rB  zFastMCP._list_tools_mcp  sN     
 	@@@@AAA>)11$1?? 	 	 	 	 	 	 	 	5577777777E   
 "  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   (B
BB
list[Tool]c                j  K   t           j        j                            |           4 d{V }t	          t
          j                            d          ddd|          }t          | 	                    || j
                   d{V           cddd          d{V  S # 1 d{V swxY w Y   dS )	zD
        List all available tools, applying MCP middleware.
        rS  Nz
tools/listmethodclientrequestrX  sourcer   r	  fastmcp_contextrk  r  )r   rw   rk  rl  r>   rs  rt  ListToolsRequestr   r  _list_toolsr   fastmcp_ctx
mw_contexts      rg   r  zFastMCP._list_tools_middleware  sb     
 >)11$1?? 	 	 	 	 	 	 	;*	22,2GG# +  J ,,&$2B -         	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   A!B""
B,/B,-MiddlewareContext[mcp.types.ListToolsRequest]c           	        K    j                                          d{V } fd|                                D             }d |D             } j        D ]}	 |j                                         d{V }|D ]R}                     |          s|j        }|j        r'|j         d|j         }|	                    |          }|||<   Sx# t          $ ri}	t          t          |dd          dt          |                    }
t                              d|
d	|	            t          j        j        r Y d}	~	d}	~	ww xY wt%          |                                          S )
z+
        List all available tools.
        Nc                >    g | ]}                     |          |S rf   rn  r  s     rg   r  z'FastMCP._list_tools.<locals>.<listcomp>  s=     
 
 
T5R5RSW5X5X

 
 
ri   c                    i | ]
}|j         |S rf   r  )r  r   s     rg   
<dictcomp>z'FastMCP._list_tools.<locals>.<dictcomp>  s    %P%P%Pdh%P%P%Pri   r$  r  rw   r^   z)Failed to list tools from mounted server r  )r   r  r  r   rw   r  rn  r%  r  r  r  getattrreprr  r  r   r   r  r   )r   rk  local_toolsfiltered_localr  r  r  r   r%  r  server_names   `          rg   r  zFastMCP._list_tools  s      !.88::::::::
 
 
 
(//11
 
 
 &Q%P%P%P%P	, 	 	G$+N$I$I$K$KKKKKKK' 
* 
*D88>> ! (C~ 8!(<<$(<<#377%)IcNN
*  	 	 	%GXt44fd7mm  TTTQRTT   #J 	 I$$&&'''   A4C
EAD<<Elist[MCPResource]c                @   K   t                               d j         d           t          j        j                                       4 d{V                                    d{V } fd|D             cddd          d{V  S # 1 d{V swxY w Y   dS )zk
        List all available resources, in the format expected by the low-level MCP
        server.
        r  z ] Handler called: list_resourcesrS  Nc                R    g | ]#}|                     |j        j                   $S ))r\  r   )to_mcp_resourcer%  r   r  r  r   s     rg   r  z/FastMCP._list_resources_mcp.<locals>.<listcomp>  sK       
 	 (( )-)B )    ri   )r  r   r^   r   rw   rk  rl  _list_resources_middleware)r   r  s   ` rg   rD  zFastMCP._list_resources_mcp  sN     
 	DDDDEEE>)11$1?? 	 	 	 	 	 	 	 	"==????????I   
 !*  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  list[Resource]c                .  K   t           j        j                            |           4 d{V }t	          i ddd|          }t          |                     || j                   d{V           cddd          d{V  S # 1 d{V swxY w Y   dS )zH
        List all available resources, applying MCP middleware.
        rS  Nr
  r  zresources/listr  r  )r   rw   rk  rl  r>   r   r  _list_resourcesr  s      rg   r'  z"FastMCP._list_resources_middleware  sO     
 >)11$1?? 	 	 	 	 	 	 	;*' +  J ,,&$2F -         	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	   AB
BB!MiddlewareContext[dict[str, Any]]c           	        K    j                                          d{V } fd|                                D             }d |D             } j        D ]	}	 |j                                         d{V }|D ]m}                     |          s|j        }|j        rBt          |j        |j                  }|
                    |d|j         d|j         i          }|||<   n# t          $ rj}	t          t          |dd          dt          |                    }
t                              d|
d	|	            t"          j        j        r Y d}	~	d}	~	ww xY wt)          |                                          S )
z/
        List all available resources.
        Nc                >    g | ]}                     |          |S rf   r  r&  s     rg   r  z+FastMCP._list_resources.<locals>.<listcomp>  =     
 
 
,,X66

 
 
ri   c                    i | ]
}|j         |S rf   r  )r  r  s     rg   r  z+FastMCP._list_resources.<locals>.<dictcomp>  s)     .
 .
 .
'/HL(.
 .
 .
ri   r^   r$  r  rw   zFailed to list resources from r  )r   r  r  r   rw   r'  rn  r%  r  r  r  r^   r  r  r  r  r  r   r   r  r   )r   rk  local_resourcesr  r  r  r  r  r%  r  r   s   `          rg   r*  zFastMCP._list_resources  s      !% 6 D D F FFFFFFF
 
 
 
+2244
 
 
.
 .
3A.
 .
 .
 , 	 	G(/(Q(Q(S(S"S"S"S"S"S"S / 2 2H88BB ! ",C~ 1(,OO#+#6#6 #$*w~,O,O,O,O#P $7 $ $
 *2M#&&2    %GXt44fd7mm  TTTQRTTUUU#J  M((**+++   BC**
E4AEElist[MCPResourceTemplate]c                @   K   t                               d j         d           t          j        j                                       4 d{V                                    d{V } fd|D             cddd          d{V  S # 1 d{V swxY w Y   dS )zt
        List all available resource templates, in the format expected by the low-level MCP
        server.
        r  z)] Handler called: list_resource_templatesrS  Nc                R    g | ]#}|                     |j        j                   $S ))uriTemplater   )to_mcp_templater%  r   r  r  r   s     rg   r  z8FastMCP._list_resource_templates_mcp.<locals>.<listcomp>:  sK       
 	 (( ()-)B )    ri   )r  r   r^   r   rw   rk  rl  #_list_resource_templates_middleware)r   r  s   ` rg   rF  z$FastMCP._list_resource_templates_mcp1  sN     
 	MMMMNNN>)11$1?? 	 	 	 	 	 	 	 	"FFHHHHHHHHI   
 !*  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  list[ResourceTemplate]c                .  K   t           j        j                            |           4 d{V }t	          i ddd|          }t          |                     || j                   d{V           cddd          d{V  S # 1 d{V swxY w Y   dS )zR
        List all available resource templates, applying MCP middleware.

        rS  Nr
  r  zresources/templates/listr  r  )r   rw   rk  rl  r>   r   r  _list_resource_templatesr  s      rg   r9  z+FastMCP._list_resource_templates_middlewareB  sO      >)11$1?? 	 	 	 	 	 	 	;*1 +  J ,,&$2O -         	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r+  c           	        K    j                                          d{V } fd|                                D             }d |D             } j        D ]	}	 |j                                         d{V }|D ]m}                     |          s|j        }|j        rBt          |j        |j                  }|
                    |d|j         d|j         i          }|||<   n# t          $ rj}	t          t          |dd          dt          |                    }
t                              d|
d	|	            t"          j        j        r Y d}	~	d}	~	ww xY wt)          |                                          S )
z8
        List all available resource templates.
        Nc                >    g | ]}                     |          |S rf   r  r8  s     rg   r  z4FastMCP._list_resource_templates.<locals>.<listcomp>b  r/  ri   c                    i | ]
}|j         |S rf   r  )r  r  s     rg   r  z4FastMCP._list_resource_templates.<locals>.<dictcomp>k  s)     6
 6
 6
'/HL(6
 6
 6
ri   r^   r$  r  rw   z'Failed to list resource templates from r  )r   r  r  r   rw   r9  rn  r%  r  r  r  r^   r  r  r  r  r  r   r   r  r   )r   rk  local_templatesr  r  r  r  r  r%  r  r   s   `          rg   r<  z FastMCP._list_resource_templatesY  s	      !% 6 M M O OOOOOOO
 
 
 
+2244
 
 
6
 6
3A6
 6
 6
 , 	 	G!.LLNNNNNNNN   !0 2 2H88BB ! ",C~ 1(,OO#+#6#6 #$*w~,O,O,O,O#P $7 $ $
 *2M#&&2  	 	 	%GXt44fd7mm  RkRRqRR   #J 	 M((**+++r2  list[MCPPrompt]c                @   K   t                               d j         d           t          j        j                                       4 d{V                                    d{V } fd|D             cddd          d{V  S # 1 d{V swxY w Y   dS )zi
        List all available prompts, in the format expected by the low-level MCP
        server.
        r  z] Handler called: list_promptsrS  Nc                R    g | ]#}|                     |j        j                   $S r  )to_mcp_promptr%  r   r  r  r   s     rg   r  z-FastMCP._list_prompts_mcp.<locals>.<listcomp>  sK       
 	 $$)-)B %    ri   )r  r   r^   r   rw   rk  rl  _list_prompts_middleware)r   r  s   ` rg   rH  zFastMCP._list_prompts_mcp  sN     
 	BBBBCCC>)11$1?? 	 	 	 	 	 	 	 	 99;;;;;;;;G   
 &  	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  list[Prompt]c                j  K   t           j        j                            |           4 d{V }t	          t
          j                            d          ddd|          }t          | 	                    || j
                   d{V           cddd          d{V  S # 1 d{V swxY w Y   dS )	zG
        List all available prompts, applying MCP middleware.

        rS  Nzprompts/listr  r
  r  r  r  )r   rw   rk  rl  r>   rs  rt  ListPromptsRequestr   r  _list_promptsr  s      rg   rF  z FastMCP._list_prompts_middleware  sb      >)11$1?? 	 	 	 	 	 	 	;*	44N4KK% +  J ,,&$2D -         	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	r  /MiddlewareContext[mcp.types.ListPromptsRequest]c           	        K    j                                          d{V } fd|                                D             }d |D             } j        D ]}	 |j                                         d{V }|D ]R}                     |          s|j        }|j        r'|j         d|j         }|	                    |          }|||<   Sx# t          $ ri}	t          t          |dd          dt          |                    }
t                              d|
d	|	            t          j        j        r Y d}	~	d}	~	ww xY wt%          |                                          S )
z-
        List all available prompts.
        Nc                >    g | ]}                     |          |S rf   r  rE  s     rg   r  z)FastMCP._list_prompts.<locals>.<listcomp>  s=     
 
 
,,V44

 
 
ri   c                    i | ]
}|j         |S rf   r  )r  r  s     rg   r  z)FastMCP._list_prompts.<locals>.<dictcomp>  s)     *
 *
 *
#)FJ*
 *
 *
ri   r$  r  rw   r^   z+Failed to list prompts from mounted server r  )r   r  r  r   rw   rF  rn  r%  r  r  r  r  r  r  r  r   r   r  r   )r   rk  local_promptsr  r  r  r  r  r%  r  r   s   `          rg   rJ  zFastMCP._list_prompts  s      #2>>@@@@@@@@
 
 
 
'..00
 
 
*
 *
-;*
 *
 *
 , 	 	G&-n&M&M&O&O O O O O O O+ 
. 
.F88@@ !  *C~ <!(>>&*>>!'!2!2s!2!;!;'-K$$
.  	 	 	%GXt44fd7mm  V+VVSTVV   #J 	 K&&(()))r!  r  dict[str, Any]Ylist[ContentBlock] | tuple[list[ContentBlock], dict[str, Any]] | mcp.types.CallToolResultc           	       K   t                               d| j         d||           t          j        j                            |           4 d{V  	 d}	 | j        j        }|j	        j
        r|j	        j        }n# t          t          f$ r Y nw xY w|                     |           d{V }|r#|                     |          rt!          |d          r|j        j        }|dk    r)|s't'          t)          t*          d| d	                    |r\|d
k    rVt-          |t.                    rA|                    d          }t3          | |||           d{V 	 cddd          d{V  S |rb|d
k    r\t4          j                            t4          j                            dd| d          gddddii          cddd          d{V  S |                     ||           d{V }|                                cddd          d{V  S # t@          $ r}	tC          d|           |	d}	~	wtB          $ r}	tC          d|           |	d}	~	ww xY w# 1 d{V swxY w Y   dS )aR  
        Handle MCP 'callTool' requests.

        Detects SEP-1686 task metadata and routes to background execution if supported.

        Args:
            key: The name of the tool to call
            arguments: Arguments to pass to the tool

        Returns:
            List of MCP Content objects containing the tool results
        r  z&] Handler called: call_tool %s with %srS  Nr	  rT  zTool 'rU  rV  r   TrY  r]  r[  )r   r]  r`  ra  )rq  isErrorrc  r  )"r  r   r^   r   rw   rk  rl  r   re  rf  rg  rh  ri  rj  r  rn  ro  r	  r
  r   r#   r   r   rE   r   rC   rs  rt  CallToolResultTextContent_call_tool_middlewareto_mcp_resultr0   r1   )
r   r%  r  r~  r  r   r  r  r  r  s
             rg   rJ  zFastMCP._call_tool_mcp  s     & 	A	AAA3		
 	
 	
 >)11$1?? B	C B	C B	C B	C B	C B	C B	C B	CAC 	*:C'/ C$'$4$B	&4   D
 "<<SAAAAAAAA+55d;;+  m44+
 !% 0 5I !J..y.&%%5(Y(Y(Y(Y     ! Y+%=%=%dL99 -6-A-At-A-T-TN)< $c9n* * $ $ $ $ $ $ IB	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	CX ! Y+%=%="y77 #	 5 5)/)b#)b)b)b !6 !" !"% %) >$:DA"#  8    [B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	Cz  $99#yIIIIIIII++--}B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C~ ! C C C#$:S$:$:;;B  C C C#$:S$:$:;;BCCB	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	C B	Csn   IH$A=<H=BHBCH1AH/H
I!H44IIII
I&)I&rF   c                  K   t          t                   t          j                            ||          dddt          j        j                                                  }|                     || j	                   d{V S )b
        Applies this server's middleware and delegates the filtered call to the manager.
        r^   r  r
  r  z
tools/callr  r  N)
r>   r!   rs  rt  r   rw   dependenciesget_contextr  
_call_tool)r   r%  r  r  s       rg   rV  zFastMCP._call_tool_middlewareC  s       ''<=I33	3RR#N7CCEE
 
 

 ++$/ , 
 
 
 
 
 
 
 
 	
ri   2MiddlewareContext[mcp.types.CallToolRequestParams]c                  K   |j         j        }t          | j                  D ]}|}|j        r=|                    |j         d          s)|t          |j                  dz   d         }	 |j                            |           d{V }| 	                    |          s|j        
                    ||j         j        pi            d{V c S # t          $ r Y w xY w	 | j                            |           d{V }| 	                    |          r.| j                            ||j         j        pi            d{V S n# t          $ r Y nw xY wt          d|          )z
        Call a tool
        r$     N)r%  r  r  )rX  r^   r  r   r  
startswithlenrw   r  rn  rV  r  r1   r   rI  )r   rk  	tool_namer  try_namer   s         rg   r]  zFastMCP._call_toolW  s      O(	   566 	 	G H~ @ ++w~,@,@,@AA $S%8%81%<%>%>? %^44X>>>>>>>>44T:: $^AAgo7=2           !   	+44Y????????D,,T22 !/99!W_-F-L" :           	 	 	D	 :Y::;;;s+   ,5C",C
CC"A"E 
EEAnyUrl | strlist[ReadResourceContents]c                  K   t                               d| j         d|           t          j        j                            |           4 d{V  	 t          t                   | 	                    |           d{V           cddd          d{V  S # t          $ r%}t          dt          |                    |d}~wt          $ r%}t          dt          |                    |d}~ww xY w# 1 d{V swxY w Y   dS )z
        Handle MCP 'readResource' requests.

        Delegates to _read_resource, which should be overridden by FastMCP subclasses.
        r  z"] Handler called: read_resource %srS  Nr  )r  r   r^   r   rw   rk  rl  r   r   _read_resource_middlewarer0   r1   r_   )r   r\  r  s      rg   rp  zFastMCP._read_resource_mcp  s      	FFFFLLL>)11$1?? 	N 	N 	N 	N 	N 	N 	N 	N
N0188======== 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N ! N N N#$ES$E$EFFAM  N N N#$ES$E$EFFAMN	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	N 	Ns<   C82B
C5# CC5 C00C55C88
DDc                V  K   t          |t                    rt          |          n|}t          t          j                            |          dddt          j        j	        
                                          }t          |                     || j                   d{V           S )rY  )r\  r
  r  zresources/readr  r  N)r   r_   r*   r>   rs  rt  ReadResourceRequestParamsr   rw   r[  r\  r   r  _read_resource)r   r\  	uri_paramr  s       rg   rh  z!FastMCP._read_resource_middleware  s       $.c3#7#7@F3KKKS	&I77I7FF##N7CCEE
 
 

 (("d.A )        
 
 	
ri   6MiddlewareContext[mcp.types.ReadResourceRequestParams]c                  K   t          |j        j                  }t          | j                  D ]}|}|j        r+t          ||j                  s!t          ||j                  }|j        	                    |           d{V }|Y| 
                    |          so	 t          |j                            |           d{V           }|c S # t          $ r Y w xY w	 | j                            |           d{V }| 
                    |          r7| j                            |           d{V }t#          ||j                  gS n# t          $ r Y nw xY wt          d|          )z!
        Read a resource
        N)rq  rv  r  )r_   rX  r\  r  r   r  has_resource_prefixremove_resource_prefixrw   rm  rn  r   rh  r1   r   r  read_resourcer   rv  )r   rk  uri_strr  r%  r  r  rq  s           rg   rk  zFastMCP._read_resource  s      go)**   566 	 	GC~ B*3?? ,S'.AA
 %^MMcRRRRRRRRH00:: GN$L$LS$Q$QQQQQQQRR    	!3@@IIIIIIIIH,,X66  $ 6 D DW M MMMMMMM( '"*"4     	 	 	D	 <<<===s%    .C
CC"A+E 
EEdict[str, Any] | Noner$   c                  K   ddl }t                              d| j         d||           |j        j                            |           4 d{V  	 |                     ||           d{V 	 cddd          d{V  S # t          $ r}t          d|           |d}~wt          $ r}t          d|           |d}~ww xY w# 1 d{V swxY w Y   dS )z
        Handle MCP 'getPrompt' requests.

        Delegates to _get_prompt, which should be overridden by FastMCP subclasses.
        r   Nr  z'] Handler called: get_prompt %s with %srS  r  )
fastmcp.server.contextr  r   r^   rw   rk  rl  _get_prompt_middlewarer0   r1   )r   r^   r  r   r  s        rg   r  zFastMCP._get_prompt_mcp  s      	&%%%B	BBBD)	
 	
 	
 >)11$1?? 		F 		F 		F 		F 		F 		F 		F 		FF!88yIIIIIIIII		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F ! F F F#$=t$=$=>>AE  F F F#$=t$=$=>>AEF		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		F 		Fs<   CB
CB  C-C  CC
CCc                   K   t          t          j                            ||          dddt          j        j                                                  }|                     || j	                   d{V S )rY  rZ  r
  r  zprompts/getr  r  N)
r>   rs  rt  GetPromptRequestParamsr   rw   r[  r\  r  _get_prompt)r   r^   r  r  s       rg   rv  zFastMCP._get_prompt_middleware  s       'I44$)4TT #N7CCEE
 
 

 ++$*: , 
 
 
 
 
 
 
 
 	
ri   3MiddlewareContext[mcp.types.GetPromptRequestParams]c                  K   |j         j        }t          | j                  D ]}|}|j        r=|                    |j         d          s)|t          |j                  dz   d          }	 |j                            |           d {V }| 	                    |          s|j        
                    ||j         j                   d {V c S # t          $ r Y w xY w	 | j                            |           d {V }| 	                    |          r,| j                            ||j         j                   d {V S n# t          $ r Y nw xY wt          d|          )Nr$  r`  rZ  r  )rX  r^   r  r   r  ra  rb  rw   r  rn  rv  r  r1   r   render_prompt)r   rk  r^   r  rd  r  s         rg   ry  zFastMCP._get_prompt  s      #   566 	 	GH~ ;'.';';';<< GN 3 3a 7 9 9:  '~88BBBBBBBB44V<< $^BBgo7           !   	/::4@@@@@@@@F,,V44 !1??)B @           	 	 	D	 7t77888s+   ,5C"*C
CC A E 
EEr   c                    | j                             |           	 ddlm}  |            }|                                 n# t
          $ r Y nw xY w|S )aX  Add a tool to the server.

        The tool function can optionally request a Context object by adding a parameter
        with the Context type annotation. See the @tool decorator for examples.

        Args:
            tool: The Tool instance to register

        Returns:
            The tool instance that was added to the server.
        r   r\  )r   r   r  r\  _queue_tool_list_changedr   )r   r   r\  rk  s       rg   r   zFastMCP.add_tool3  sy     	##D)))	??????!kmmG,,.... 	 	 	D	    $A 
AAc                    | j                             |           	 ddlm}  |            }|                                 dS # t
          $ r Y dS w xY w)zRemove a tool from the server.

        Args:
            name: The name of the tool to remove

        Raises:
            NotFoundError: If the tool is not found
        r   r~  N)r   remove_toolr  r\  r  r   )r   r^   r\  rk  s       rg   r  zFastMCP.remove_toolL  sw     	&&t,,,	??????!kmmG,,..... 	 	 	DD	s   $A 
AArc  transformationrH   c                <    | j                             ||           dS )zAdd a tool transformation.N)r   add_tool_transformation)r   rc  r  s      rg   r  zFastMCP.add_tool_transformation`  s#     	229nMMMMMri   c                :    | j                             |           dS )zRemove a tool transformation.N)r   remove_tool_transformation)r   rc  s     rg   r  z"FastMCP.remove_tool_transformationf  s    55i@@@@@ri   r^   titledescriptionr   tagsoutput_schemar   exclude_argsmetaenabledtask
name_or_fnr    r  r  r  set[str] | Noner  dict[str, Any] | NotSetT | Noner   'ToolAnnotations | dict[str, Any] | Noner  list[str] | Noner  r  r  bool | TaskConfig | NonerE   c                   d S re   rf   r   r  r^   r  r  r   r  r  r   r  r  r  r  s                rg   r   zFastMCP.toolj  s	      sri   %Callable[[AnyFunction], FunctionTool]c                   d S re   rf   r  s                rg   r   zFastMCP.tool|  s	      14ri   str | AnyFunction | None4Callable[[AnyFunction], FunctionTool] | FunctionToolc               X   t          |t                    rt          d	i |}t          |t                    r!t	          t          j        d                    t          j        |          rL|}|}||n| j        }t          j
        |||||||||	|
| j        ||          }|                     |           |S t          |t                    r|t          d| d| d          |}n$||}nt          dt          |                     t!          | j        ||||||||	|
||          S )
am  Decorator to register a tool.

        Tools can optionally request a Context object by adding a parameter with the
        Context type annotation. The context provides access to MCP capabilities like
        logging, progress reporting, and resource access.

        This decorator supports multiple calling patterns:
        - @server.tool (without parentheses)
        - @server.tool (with empty parentheses)
        - @server.tool("custom_name") (with name as first argument)
        - @server.tool(name="custom_name") (with name as keyword argument)
        - server.tool(function, name="custom_name") (direct function call)

        Args:
            name_or_fn: Either a function (when used as @tool), a string name, or None
            name: Optional name for the tool (keyword-only, alternative to name_or_fn)
            description: Optional description of what the tool does
            tags: Optional set of tags for categorizing the tool
            output_schema: Optional JSON schema for the tool's output
            annotations: Optional annotations about the tool's behavior
            exclude_args: Optional list of argument names to exclude from the tool schema.
                Note: `exclude_args` will be deprecated in FastMCP 2.14 in favor of dependency
                injection with `Depends()` for better lifecycle management.
            meta: Optional meta information about the tool
            enabled: Optional boolean to enable or disable the tool

        Examples:
            Register a tool with a custom name:
            ```python
            @server.tool
            def my_tool(x: int) -> str:
                return str(x)

            # Register a tool with a custom name
            @server.tool
            def my_tool(x: int) -> str:
                return str(x)

            @server.tool("custom_name")
            def my_tool(x: int) -> str:
                return str(x)

            @server.tool(name="custom_name")
            def my_tool(x: int) -> str:
                return str(x)

            # Direct function call
            server.tool(my_function, name="custom_name")
            ```
        aA  
                    To decorate a classmethod, first define the method and then call
                    tool() directly on the method instead of using it as a
                    decorator. See https://gofastmcp.com/patterns/decorating-methods
                    for examples and more information.
                    N)r^   r  r  r   r  r  r   r  r  r   r  r  zXCannot specify both a name as first argument and as keyword argument. Use either @tool('z') or @tool(name=''), not both.zAFirst argument to @tool must be a function, string, or None, got r  rf   )r   r  r%   classmethodr7  inspectcleandoc	isroutiner   r)   r   r   r   r_   	TypeErrorr   r   r   )r   r  r^   r  r  r   r  r  r   r  r  r  r  r\   rc  supports_taskr   s                    rg   r   zFastMCP.tool  s   D k4(( 	9)88K88Kj+.. 
	  	 	 	 Z(( -	 BI (d.L  %'+')0"  D MM$K
C(( 	[)3[ [GK[ [ [   #IIIIfTXYcTdTdff  
 I#'#%
 
 
 	
ri   r  c                    | j                             |           	 ddlm}  |            }|                                 n# t
          $ r Y nw xY w|S )zAdd a resource to the server.

        Args:
            resource: A Resource instance to add

        Returns:
            The resource instance that was added to the server.
        r   r~  )r   add_resourcer  r\  _queue_resource_list_changedr   )r   r  r\  rk  s       rg   r  zFastMCP.add_resource  y     	++H555	??????!kmmG002222 	 	 	D	 r  r  c                    | j                             |           	 ddlm}  |            }|                                 n# t
          $ r Y nw xY w|S )zAdd a resource template to the server.

        Args:
            template: A ResourceTemplate instance to add

        Returns:
            The template instance that was added to the server.
        r   r~  )r   add_templater  r\  r  r   )r   r  r\  rk  s       rg   r  zFastMCP.add_template5  r  r  )
r^   r  r  r   rv  r  r  r   r  r  rv  #Annotations | dict[str, Any] | None4Callable[[AnyFunction], Resource | ResourceTemplate]c       
            	
 t          	t                    rt          di 		t          j                  rt          d          d	
 fd}|S )	a  Decorator to register a function as a resource.

        The function will be called when the resource is read to generate its content.
        The function can return:
        - str for text content
        - bytes for binary content
        - other types will be converted to JSON

        Resources can optionally request a Context object by adding a parameter with the
        Context type annotation. The context provides access to MCP capabilities like
        logging, progress reporting, and session information.

        If the URI contains parameters (e.g. "resource://{param}") or the function
        has parameters, it will be registered as a template resource.

        Args:
            uri: URI for the resource (e.g. "resource://my-resource" or "resource://{param}")
            name: Optional name for the resource
            description: Optional description of the resource
            mime_type: Optional MIME type for the resource
            tags: Optional set of tags for categorizing the resource
            enabled: Optional boolean to enable or disable the resource
            annotations: Optional annotations about the resource's behavior
            meta: Optional meta information about the resource

        Examples:
            Register a resource with a custom name:
            ```python
            @server.resource("resource://my-resource")
            def get_data() -> str:
                return "Hello, world!"

            @server.resource("resource://my-resource")
            async get_data() -> str:
                data = await fetch_data()
                return f"Hello, world! {data}"

            @server.resource("resource://{city}/weather")
            def get_weather(city: str) -> str:
                return f"Weather for {city}"

            @server.resource("resource://{city}/weather")
            async def get_weather_with_context(city: str, ctx: Context) -> str:
                await ctx.info(f"Fetching weather for {city}")
                return f"Weather for {city}"

            @server.resource("resource://{city}/weather")
            async def get_weather(city: str) -> str:
                data = await fetch_weather(city)
                return f"Weather for {city}: {data}"
            ```
        zrThe @resource decorator was used incorrectly. Did you forget to call it? Use @resource('uri') instead of @resourcer\   r    r`   Resource | ResourceTemplatec                   t          | t                    r!t          t          j        d                    nj        }dv odv }ddlm}  ||           }t          t          j	        |          j
                  }|s|r7t          j        | 	
|          }                    |           |S |s9|s7t          j        | 	
|          }                    |           |S t          d          )	NaY  
                        To decorate a classmethod, first define the method and then call
                        resource() directly on the method instead of using it as a
                        decorator. See https://gofastmcp.com/patterns/decorating-methods
                        for examples and more information.
                        {}r   )without_injected_parameters)r\   r  r^   r  r  r   rv  r  r  r   r  r  )r\   r\  r^   r  r  r   rv  r  r  r   r  r  ziInvalid resource or template definition due to a mismatch between URI parameters and function parameters.)r   r  r7  r  r  r   r  r  r,  	signature
parametersr(   r   r  r'   r  )r\   r  has_uri_paramsr  
wrapper_fnhas_func_paramsr  r  r   r  r  r   r  rv  r^   r   r  r  r  r\  s           rg   r  z#FastMCP.resource.<locals>.decorator  s   "k** 
 $ 	 	 	 (d.L 
 !CZ6C3JNOOOOOO44R88J"7#4Z#@#@#KLLO & &+9!$ +'# +&   !!(+++# O #1 +'# +&   !!(+++ O  ri   rf   )r\   r    r`   r  )r   r  r   r  r  r  )r   r\  r^   r  r  r   rv  r  r  r   r  r  r  s   ```````````` rg   r  zFastMCP.resourceK  s    F k4(( 	5%4444K S!! 	W  
@	 @	 @	 @	 @	 @	 @	 @	 @	 @	 @	 @	 @	 @	 @	 @	 @	D ri   r  c                    | j                             |           	 ddlm}  |            }|                                 n# t
          $ r Y nw xY w|S )zAdd a prompt to the server.

        Args:
            prompt: A Prompt instance to add

        Returns:
            The prompt instance that was added to the server.
        r   r~  )r   
add_promptr  r\  _queue_prompt_list_changedr   )r   r  r\  rk  s       rg   r  zFastMCP.add_prompt  sy     	''///	??????!kmmG..0000 	 	 	D	 r  r^   r  r  r   r  r  r  r  r3   c                   d S re   rf   
r   r  r^   r  r  r   r  r  r  r  s
             rg   r  zFastMCP.prompt  s	     ri   'Callable[[AnyFunction], FunctionPrompt]c                   d S re   rf   r  s
             rg   r  zFastMCP.prompt	  s	     36#ri   8Callable[[AnyFunction], FunctionPrompt] | FunctionPromptc                  t          |t                    r!t          t          j        d                    t          j        |          rC|}
|}|	|	n| j        }t          j        |
||||||||	  	        }| 	                    |           |S t          |t                    r|t          d| d| d          |}n$||}nt          dt          |                     t          | j        ||||||||		  	        S )	a
  Decorator to register a prompt.

        Prompts can optionally request a Context object by adding a parameter with the
        Context type annotation. The context provides access to MCP capabilities like
        logging, progress reporting, and session information.

        This decorator supports multiple calling patterns:
        - @server.prompt (without parentheses)
        - @server.prompt() (with empty parentheses)
        - @server.prompt("custom_name") (with name as first argument)
        - @server.prompt(name="custom_name") (with name as keyword argument)
        - server.prompt(function, name="custom_name") (direct function call)

        Args:
            name_or_fn: Either a function (when used as @prompt), a string name, or None
            name: Optional name for the prompt (keyword-only, alternative to name_or_fn)
            description: Optional description of what the prompt does
            tags: Optional set of tags for categorizing the prompt
            enabled: Optional boolean to enable or disable the prompt
            meta: Optional meta information about the prompt

        Examples:

            ```python
            @server.prompt
            def analyze_table(table_name: str) -> list[Message]:
                schema = read_table_schema(table_name)
                return [
                    {
                        "role": "user",
                        "content": f"Analyze this schema:
{schema}"
                    }
                ]

            @server.prompt()
            async def analyze_with_context(table_name: str, ctx: Context) -> list[Message]:
                await ctx.info(f"Analyzing table {table_name}")
                schema = read_table_schema(table_name)
                return [
                    {
                        "role": "user",
                        "content": f"Analyze this schema:
{schema}"
                    }
                ]

            @server.prompt("custom_name")
            async def analyze_file(path: str) -> list[Message]:
                content = await read_file(path)
                return [
                    {
                        "role": "user",
                        "content": {
                            "type": "resource",
                            "resource": {
                                "uri": f"file://{path}",
                                "text": content
                            }
                        }
                    }
                ]

            @server.prompt(name="custom_name")
            def another_prompt(data: str) -> list[Message]:
                return [{"role": "user", "content": data}]

            # Direct function call
            server.prompt(my_function, name="custom_name")
            ```
        aC  
                    To decorate a classmethod, first define the method and then call
                    prompt() directly on the method instead of using it as a
                    decorator. See https://gofastmcp.com/patterns/decorating-methods
                    for examples and more information.
                    N)	r\   r^   r  r  r   r  r  r  r  zZCannot specify both a name as first argument and as keyword argument. Use either @prompt('z') or @prompt(name='r  zCFirst argument to @prompt must be a function, string, or None, got r  )r   r  r7  r  r  r  r   r&   r   r  r_   r  r   r   r  )r   r  r^   r  r  r   r  r  r  r  r\   prompt_namer  r  s                 rg   r  zFastMCP.prompt	  s   f j+.. 
	  	 	 	 Z(( )	 BK (d.L 
 ) '"
 
 
F OOF###M
C(( 	_+5_ _KO_ _ _   %KKKKhVZ[eVfVfhh  
 K#

 

 

 
	
ri   c                h  K   |rt          | d           t          |          5  |                                 4 d{V  t                      4 d{V \  }}t                              d| j        d           t                      }| j        	                    ||| j        
                    t          d          |                     d{V  ddd          d{V  n# 1 d{V swxY w Y   ddd          d{V  n# 1 d{V swxY w Y   ddd           dS # 1 swxY w Y   dS )	zRun the server using stdio transport.

        Args:
            show_banner: Whether to display the server banner
            log_level: Log level for the server
        rr   )rw   r2  NStarting MCP server z with transport 'stdio'T)tools_changed)notification_optionsexperimental_capabilities)rI   rL   r.  r   r  infor^   r?   r   r>  create_initialization_optionsr   )r   r4  r   read_streamwrite_streamr  s         rg   r8  zFastMCP.run_stdio_async	  s       	!   
 !++ 	 	--//        '>>       -Hk<KKStySSS  
 1F0G0G-*..#$(FF1D.22 2 2 7P	 G  	 	 	 	 	 	 	 	 	                                                    	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	sZ   D' D	A?C&D	&
C00D	3C04D	7D'	
D	D'D	D''D+.D+rs   )Literal['http', 'streamable-http', 'sse']uvicorn_configlist[ASGIMiddleware] | Nonec                  K   |p| j         j        }|p| j         j        }|p| j         j                                        }|                     ||||	|
          }t          |d          r4t          |j        d          r|j        j        	                    d          n|pd}|rt          | ||||           |pi }ddd	d
}|                    |           d|vr	d|vr||d<   t          |          5  |                                 4 d{V  t          j        |f||d|}t          j        |          }|j        j        	                    d          }t"                              d| j        d|d| d| d| 
           |                                 d{V  ddd          d{V  n# 1 d{V swxY w Y   ddd           dS # 1 swxY w Y   dS )a*  Run the server using HTTP transport.

        Args:
            transport: Transport protocol to use - either "streamable-http" (default) or "sse"
            host: Host address to bind to (defaults to settings.host)
            port: Port to bind to (defaults to settings.port)
            log_level: Log level for the server (defaults to settings.log_level)
            path: Path for the endpoint (defaults to settings.streamable_http_path or settings.sse_path)
            uvicorn_config: Additional configuration for the Uvicorn server
            middleware: A list of middleware to apply to the app
            json_response: Whether to use JSON response format (defaults to settings.json_response)
            stateless_http: Whether to use stateless HTTP (defaults to settings.stateless_http)
        )r  r2  r   r   r   stater  / )rw   r2  r   r   r  r   onzwebsockets-sansio)timeout_graceful_shutdownr   ws
log_configr   N)r   r   r  z with transport z on http://:)r   r   r   r   lowerhttp_appro  r  r  lstriprI   r  rL   r.  uvicornConfigServerr  r  r^   serve)r   r4  r2  r   r   r   r  r  r   r   r   default_log_level_to_useappserver_pathuvicorn_config_from_userconfig_kwargsconfigrw   s                     rg   r9  zFastMCP.run_http_async	  s!     4 5t055t05<2<
%'' 	! mm!')  
 
 sG$$)0F)C)CCIN!!#&&& 	  	#     $2#7R  *+%)
 )

 	5666},,M1Q1Q)AM+& ++ 		% 		%--// % % % % % % % % S$TSS]SS //y~,,S11t49tt	tt`dttgkttnrtt   llnn$$$$$$$% % % % % % % % % % % % % % % % % % % % % % % % % % %		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		% 		%s7   2GBF0G0
F:	:G=F:	>GGGevent_storeEventStore | Noneretry_intervalr:   c                ,   |dv rOt          | |p| j        j        ||| j        ||n| j        j        ||n| j        j        | j        j        |	  	        S |dk    r:t          | | j        j        |p| j        j	        | j        | j        j        |          S dS )a2  Create a Starlette app using the specified HTTP transport.

        Args:
            path: The path for the HTTP endpoint
            middleware: A list of middleware to apply to the app
            json_response: Whether to use JSON response format
            stateless_http: Whether to use stateless mode (new transport per request)
            transport: Transport protocol to use - "http", "streamable-http", or "sse"
            event_store: Optional event store for SSE polling/resumability. When set,
                enables clients to reconnect and resume receiving events after
                server-initiated disconnections. Only used with streamable-http transport.
            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. Only used with
                streamable-http transport.

        Returns:
            A Starlette application configured with the specified transport
        )ru   rs   N)	rw   r   r  r  r   r   r   r   r   rt   )rw   r   r   r   r   r   )
r<   r   r   r   r   r   r   r;   r   r   )r   r  r   r   r   r2  r  r  s           rg   r  zFastMCP.http_app
  s    < 333-%) &B,A'-Y %0 "M2@ &1 #N2A/5%%   ( %!!6CC!:!CY/5%     ri   rv   as_proxyc                    ddl m} ||j        t          k    }|r*t	          ||          st
                              |          }d|_        t          ||          }| j	        
                    |           dS )a
  Mount another FastMCP server on this server with an optional prefix.

        Unlike importing (with import_server), mounting establishes a dynamic connection
        between servers. When a client interacts with a mounted server's objects through
        the parent server, requests are forwarded to the mounted server in real-time.
        This means changes to the mounted server are immediately reflected when accessed
        through the parent.

        When a server is mounted with a prefix:
        - Tools from the mounted server are accessible with prefixed names.
          Example: If server has a tool named "get_weather", it will be available as "prefix_get_weather".
        - Resources are accessible with prefixed URIs.
          Example: If server has a resource with URI "weather://forecast", it will be available as
          "weather://prefix/forecast".
        - Templates are accessible with prefixed URI templates.
          Example: If server has a template with URI "weather://location/{id}", it will be available
          as "weather://prefix/location/{id}".
        - Prompts are accessible with prefixed names.
          Example: If server has a prompt named "weather_prompt", it will be available as
          "prefix_weather_prompt".

        When a server is mounted without a prefix (prefix=None), its tools, resources, templates,
        and prompts are accessible with their original names. Multiple servers can be mounted
        without prefixes, and they will be tried in order until a match is found.

        There are two modes for mounting servers:
        1. Direct mounting (default when server has no custom lifespan): The parent server
           directly accesses the mounted server's objects in-memory for better performance.
           In this mode, no client lifecycle events occur on the mounted server, including
           lifespan execution.

        2. Proxy mounting (default when server has a custom lifespan): The parent server
           treats the mounted server as a separate entity and communicates with it via a
           Client transport. This preserves all client-facing behaviors, including lifespan
           execution, but with slightly higher overhead.

        Args:
            server: The FastMCP server to mount.
            prefix: Optional prefix to use for the mounted server's objects. If None,
                the server's objects are accessible with their original names.
            as_proxy: Whether to treat the mounted server as a proxy. If None (default),
                automatically determined based on whether the server has a custom lifespan
                (True if it has a custom lifespan, False otherwise).
        r   rX   NT)r  rw   )fastmcp.server.proxyrY   r   rz   r   r   r  r   MountedServerr   rr  )r   rw   r  r  rY   r  s         rg   mountzFastMCP.mountY
  s    d 	655555 '+;;H 	.Jv|<< 	.%%f--F
 " '
 
 
 	$$^44444ri   c           	       K   |                                  d{V                                 D ]<\  }}|r|                    | d|           }| j                            |           =|                                 d{V                                 D ]T\  }}|r3t          ||          }|                    d| d|j         i|          }| j        	                    |           U|
                                 d{V                                 D ]T\  }}|r3t          ||          }|                    d| d|j         i|          }| j                            |           U|                                 d{V                                 D ]<\  }}	|r|	                    | d|           }	| j                            |	           =|j        t           k    rddlm}
  |
dt&          d	
           |r0t(                              d| j         d|j         d| d           dS t(                              d| j         d|j                    dS )ay  
        Import the MCP objects from another FastMCP server into this one,
        optionally with a given prefix.

        Note that when a server is *imported*, its objects are immediately
        registered to the importing server. This is a one-time operation and
        future changes to the imported server will not be reflected in the
        importing server. Server-level configurations and lifespans are not imported.

        When a server is imported with a prefix:
        - The tools are imported with prefixed names
          Example: If server has a tool named "get_weather", it will be
          available as "prefix_get_weather"
        - The resources are imported with prefixed URIs using the new format
          Example: If server has a resource with URI "weather://forecast", it will
          be available as "weather://prefix/forecast"
        - The templates are imported with prefixed URI templates using the new format
          Example: If server has a template with URI "weather://location/{id}", it will
          be available as "weather://prefix/location/{id}"
        - The prompts are imported with prefixed names
          Example: If server has a prompt named "weather_prompt", it will be available as
          "prefix_weather_prompt"

        When a server is imported without a prefix (prefix=None), its tools, resources,
        templates, and prompts are imported with their original names.

        Args:
            server: The FastMCP server to import
            prefix: Optional prefix to use for the imported server's objects. If None,
                objects are imported with their original names.
        Nr$  r  r^   )r  r%  r   )rn   zeWhen importing from a server with a lifespan, the lifespan from the imported server will not be used.r   )rX  categoryr   r  z] Imported server z with prefix '')r  r  r  r   r   r  r  r^   r   r  r  r  r  r   r  r   rz   r   rn   RuntimeWarningr  r   )r   rw   r  r%  r   r  resource_keyr  template_keyr  rn   s              rg   import_serverzFastMCP.import_server
  s     J !' 0 0 2 222222299;; 	. 	.IC >f+<+<s+<+<==''---- %+$8$8$:$:::::::AACC 	: 	:MC 23??#.."v$?$?$?$?@l /   "//9999$*$A$A$C$CCCCCCCJJLL 	: 	:MC 23??#.."v$?$?$?$?@l /   "//9999 #)"4"4"6"6666666==?? 	4 	4KC B**&/@/@3/@/@*AA ++F3333///%%%%%%D'     	ILLUDIUUUUFUUU     LLGTYGG&+GGHHHHHri   openapi_specr
  httpx.AsyncClient
route_mapslist[RouteMap] | Noneroute_map_fnOpenAPIRouteMapFn | Nonemcp_component_fnOpenAPIComponentFn | None	mcp_namesdict[str, str] | Noner   rU   c                .    ddl m}	  |	d|||||||d|S )zH
        Create a FastMCP server from an OpenAPI specification.
        r`  rU   )r  r
  r  r  r  r  r  rf   )openapirU   )
clsr  r
  r  r  r  r  r  r   rU   s
             rg   from_openapizFastMCP.from_openapi
  sS     	,+++++~ 	
%!%-	
 	
 	
 	
 		
ri   r  httpx_client_kwargsc	                    ddl m}
 |i }|                    dd           t          j        d	dt          j        |          i|}|p|j        } |
d	|                                 |||||||d|	S )
zE
        Create a FastMCP server from a FastAPI application.
        r`  r   Nbase_urlzhttp://fastapir2  )r  )r  r
  r^   r  r  r  r  r  rf   )r  rU   
setdefaulthttpxAsyncClientASGITransportr  )r  r  r^   r  r  r  r  r  r  r   rU   r
  s               rg   from_fastapizFastMCP.from_fastapi  s      	,+++++&"$&&z3CDDD" 
 
)c222
!
 

  sy~ 

!%-

 

 

 

 
	
ri   backend}Client[ClientTransportT] | ClientTransport | FastMCP[Any] | FastMCP1Server | AnyUrl | Path | MCPConfig | dict[str, Any] | strrY   c                   ddl m} ddlm}m} t          ||          rO|                                r1t          t                    }|	                    d           fd}|}nfd}	|	}n ||          fd}
|
} |d	d|i|S )
aG  Create a FastMCP proxy server for the given backend.

        The `backend` argument can be either an existing `fastmcp.client.Client`
        instance or any value accepted as the `transport` argument of
        `fastmcp.client.Client`. This mirrors the convenience of the
        `fastmcp.client.Client` constructor.
        r   rO   )rY   ProxyClientzProxy detected connected client - reusing existing session for all requests. This may cause context mixing in concurrent scenarios.c                      S re   rf   r
  s   rg   reuse_client_factoryz.FastMCP.as_proxy.<locals>.reuse_client_factory^  s    !Mri   c                 ,                                      S re   newr  s   rg   fresh_client_factoryz.FastMCP.as_proxy.<locals>.fresh_client_factoryd  s    !::<<'ri   c                 ,                                      S re   r  )base_clients   rg   proxy_client_factoryz.FastMCP.as_proxy.<locals>.proxy_client_factoryl  s    "(((ri   client_factoryrf   )
fastmcp.client.clientrP   r  rY   r  r   is_connectedrK   rl   r  )r  r  r   rP   rY   r  proxy_loggerr  r  r  r  r  r
  s              @@rg   r  zFastMCP.as_proxy7  s   . 	100000BBBBBBBBgv&& 	2F ""$$ 6)(33!!M  " " " " " "6( ( ( ( ( "6%+g..K) ) ) ) ) 2N|FF>FXFFFri   	componentrJ   c                    j         sdS | j        	| j        dS | j        "t          fd| j        D                       rdS | j        -t	          t          fd| j        D                                 S dS )a  
        Given a component, determine if it should be enabled. Returns True if it should be enabled; False if it should not.

        Rules:
            - If the component's enabled property is False, always return False.
            - If both include_tags and exclude_tags are None, return True.
            - If exclude_tags is provided, check each exclude tag:
                - If the exclude tag is a string, it must be present in the input tags to exclude.
            - If include_tags is provided, check each include tag:
                - If the include tag is a string, it must be present in the input tags to include.
            - If include_tags is provided and none of the include tags match, return False.
            - If include_tags is not provided, return True.
        FNTc              3  *   K   | ]}|j         v V  d S re   r  )r  etagr  s     rg   	<genexpr>z3FastMCP._should_enable_component.<locals>.<genexpr>  s*      HHd49>)HHHHHHri   c              3  *   K   | ]}|j         v V  d S re   r!  )r  itagr  s     rg   r#  z3FastMCP._should_enable_component.<locals>.<genexpr>  s*      QQtDIN2QQQQQQri   )r  r   r   anyr,  )r   r  s    `rg   rn  z FastMCP._should_enable_components  s    "   	5$):)B4(HHHHd6GHHHHH u(QQQQt?PQQQQQRRRtri   c                ~    | j         }|| dt          j        d           S | d| dt          j        d           S )N-r   )rl   secrets	token_hex)r  r^   
class_names      rg   r   zFastMCP.generate_name  sT    \
< 997#4Q#7#7999 @@4@@'*;A*>*>@@@ri   )NN)>r^   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )r`   r_   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r`   r   )r`   rD   )r`   r   )r   r   r`   r   )r`   r   )r`   r   )r`   r   )rw   r   r   r   r  r   r`   r   )NT)r2  r3  r4  r,  r5  r   r`   r   )r`   r   )rk  r  r  r  r`   r   )r   r+   r`   r   )r`   r  )r%  r_   r`   r)   )r%  r_   r`   r  )r\  r_   r`   r  )r`   r  )r%  r_   r`   r'   )r`   r  )r%  r_   r`   r(   )r`   r  )r%  r_   r`   r&   )
r  r_   r  r  r^   r   r  r,  r`   r  )r`   r  )r`   r  )r`   r  )rk  r  r`   r  )r`   r"  )r`   r(  )rk  r,  r`   r(  )r`   r3  )r`   r:  )rk  r,  r`   r:  )r`   rA  )r`   rG  )rk  rK  r`   rG  )r%  r_   r  rP  r`   rQ  )r%  r_   r  rP  r`   rF   )rk  r^  r`   rF   )r\  re  r`   rf  )rk  rm  r`   rf  re   )r^   r_   r  rs  r`   r$   )rk  rz  r`   r$   )r   r)   r`   r)   )r^   r_   r`   r   )rc  r_   r  rH   r`   r   )rc  r_   r`   r   )r  r    r^   r   r  r   r  r   r   r   r  r  r  r  r   r  r  r  r  rs  r  r   r  r  r`   rE   )r  r   r^   r   r  r   r  r   r   r   r  r  r  r  r   r  r  r  r  rs  r  r   r  r  r`   r  )r  r  r^   r   r  r   r  r   r   r   r  r  r  r  r   r  r  r  r  rs  r  r   r  r  r`   r  )r  r'   r`   r'   )r  r(   r`   r(   )r\  r_   r^   r   r  r   r  r   r   r   rv  r   r  r  r  r   r   r  r  rs  r  r  r`   r  )r  r&   r`   r&   )r  r    r^   r   r  r   r  r   r   r   r  r  r  r   r  rs  r  r  r`   r3   )r  r   r^   r   r  r   r  r   r   r   r  r  r  r   r  rs  r  r  r`   r  )r  r  r^   r   r  r   r  r   r   r   r  r  r  r   r  rs  r  r  r`   r  )TN)r4  r,  r   r   r`   r   )
Trs   NNNNNNNN)r4  r,  r2  r  r   r   r   r   r   r   r  r   r  rs  r   r  r   r   r   r   r`   r   )NNNNrs   NN)r  r   r   r  r   r   r   r   r2  r  r  r  r  r   r`   r:   )rw   rv   r  r   r  r   r`   r   )rw   rv   r  r   r`   r   )NNNNN)r  rP  r
  r  r  r  r  r  r  r  r  r  r  r  r   r   r`   rU   )NNNNNNN)r  r   r^   r   r  r  r  r  r  r  r  r  r  rs  r  r  r   r   r`   rU   )r  r  r   r   r`   rY   )r  rJ   r`   r,  )r^   r   r`   r_   )Srl   
__module____qualname__rM   r   r   r   propertyr   r^   r   setterr   r   r   r   r   r"  r  r.  r;  r>  r   rK  rL  rM  r  r  r  r  r  rm  r  r  r  r  r  r  r  r  rB  r  r  rD  r'  r*  rF  r9  r<  rH  rF  rJ  rJ  rV  r]  rp  rh  rk  r  rv  ry  r   r  r  r  r   r   r  r  r  r  r  r8  r9  r  r  r  r  r  r  r  rn  r   rf   ri   rg   r   r      s?
         #'L

 #"&-1.426,0*.<@IM;?/3/3,07;;?9=/3! !%!##'+/%)&*JNJNML
 L
 L
 L
 L
 L
\7 7 7 7%B %B %B %BN ) ) ) X) % % % X% - - - X- . . . . ( ( ( X( , , , X, 0 0 0 X0    X h0 h0 h0 h0T? ? ? ?B % % % %: '+ @ @ @ @ @@ '+ 
 
 
 
 
*- - - - @S @S @S @SD@P @P @P @PD2R 2R 2R 2Rh	$ 	$ 	$ 	$+ + + +   (   	 	 	 	       >      @      (     "&0 0 0 0 0d   $   "   ,+( +( +( +(Z   "   ,0, 0, 0, 0,d   "   .4, 4, 4, 4,l   "   ./* /* /* /*bYC YC YC YCv
 
 
 
(*< *< *< *<XN N N N*
 
 
 
0.> .> .> .>b =AF F F F F4 =A
 
 
 
 
$&9 &9 &9 &9P   2   (N N N NA A A A 
   "&-1 $9??C)-&*#)-     X"  "&4   "&-1 $9??C)-&*#)-4 4 4 4 4 X4& 04O
   "&-1 $9??C)-&*#)-O
 O
 O
 O
 O
 O
b   ,   4   "&-1 $ $#;?&*)-O O O O O Ob   , 
   "&-1 $#&*)-     X  "&6   "&-1 $#&*)-6 6 6 6 6 X6  04V
   "&-1 $#&*)-V
 V
 V
 V
 V
 V
r AE# # # # #N !?E $0426%)&*M% M% M% M% M%b  26%)&*?E)-%); ; ; ; ;@ " $	F5 F5 F5 F5 F5V "OI OI OI OI OIb 
 -1156:+/ $
 
 
 
 [
6   ,0156:+/59 $&
 &
 &
 &
 [&
P 9G 9G 9G [9Gv   @ A A A A [A A Ari   r   c                  $    e Zd ZU ded<   ded<   dS )r  r   r  zFastMCP[Any]rw   N)rl   r,  r-  __annotations__rf   ri   rg   r  r    s*         ri   r  r\  r  c                    |s| S t                               |           }|st          d|  d          |                                \  }}| | d| S )a  Add a prefix to a resource URI using path formatting (resource://prefix/path).

    Args:
        uri: The original resource URI
        prefix: The prefix to add

    Returns:
        The resource URI with the prefix added

    Examples:
        ```python
        add_resource_prefix("resource://path/to/resource", "prefix")
        "resource://prefix/path/to/resource"
        ```
        With absolute path:
        ```python
        add_resource_prefix("resource:///absolute/path", "prefix")
        "resource://prefix//absolute/path"
        ```

    Raises:
        ValueError: If the URI doesn't match the expected protocol://path format
    Invalid URI format: ". Expected protocol://path format.r  )URI_PATTERNmatchr7  groups)r\  r  r6  protocolr  s        rg   r  r    su    0  
 c""E YWWWWXXX\\^^NHd ''''''ri   c                *   |s| S t                               |           }|st          d|  d          |                                \  }}dt	          j        |           d}t	          j        ||          }|s| S | |                    d           S )ao  Remove a prefix from a resource URI.

    Args:
        uri: The resource URI with a prefix
        prefix: The prefix to remove

    Returns:
        The resource URI with the prefix removed

    Examples:
        ```python
        remove_resource_prefix("resource://prefix/path/to/resource", "prefix")
        "resource://path/to/resource"
        ```
        With absolute path:
        ```python
        remove_resource_prefix("resource://prefix//absolute/path", "prefix")
        "resource:///absolute/path"
        ```

    Raises:
        ValueError: If the URI doesn't match the expected protocol://path format
    r3  r4  ^z/(.*?)$r`  )r5  r6  r7  r7  reescapegroup)r\  r  r6  r8  r  prefix_pattern
path_matchs          rg   rp  rp    s    0  
 c""E YWWWWXXX\\^^NHd 46**333N.$//J 
 -
((++---ri   r,  c                
   |sdS t                               |           }|st          d|  d          |                                \  }}dt	          j        |           d}t          t	          j        ||                    S )aP  Check if a resource URI has a specific prefix.

    Args:
        uri: The resource URI to check
        prefix: The prefix to look for

    Returns:
        True if the URI has the specified prefix, False otherwise

    Examples:
        ```python
        has_resource_prefix("resource://prefix/path/to/resource", "prefix")
        True
        ```
        With other path:
        ```python
        has_resource_prefix("resource://other/path/to/resource", "prefix")
        False
        ```

    Raises:
        ValueError: If the URI doesn't match the expected protocol://path format
    Fr3  r4  r:  r  )r5  r6  r7  r7  r;  r<  r,  )r\  r  r6  r$  r  r>  s         rg   ro  ro    s    0  u c""E YWWWWXXXllnnGAt .6**---N..///ri   )r\   r]   r^   r_   r`   r]   )rw   rv   r`   rx   )r{   rv   r`   r|   )r\  r_   r  r_   r`   r_   )r\  r_   r  r_   r`   r,  )__doc__
__future__r   r   r  r;  r)  r   r  collections.abcr   r   r   r   r   r	   
contextlibr
   r   r   r   dataclassesr   rj   r   pathlibr   typingr   r   r   r   r   r   r=  r  r  rs  r  r   r   r    mcp.server.lowlevel.helper_typesr   mcp.server.lowlevel.serverr   r   mcp.server.stdior   mcp.shared.exceptionsr   r   r   r    r!   r"   r#   r$   r%   r&   	MCPPromptr'   MCPResourcer(   MCPResourceTemplater)   MCPToolpydanticr*   starlette.middlewarer+   ASGIMiddlewarestarlette.requestsr,   starlette.responsesr-   starlette.routingr.   r/   r   fastmcp.serverfastmcp.exceptionsr0   r1   fastmcp.mcp_configr2   fastmcp.promptsfastmcp.prompts.promptr3   fastmcp.prompts.prompt_managerr4   fastmcp.resources.resourcer5   "fastmcp.resources.resource_managerr6   fastmcp.resources.templater7   fastmcp.server.authr8   fastmcp.server.event_storer9   fastmcp.server.httpr:   r;   r<   fastmcp.server.low_levelr=   fastmcp.server.middlewarer>   !fastmcp.server.tasks.capabilitiesr?   fastmcp.server.tasks.configr@   fastmcp.server.tasks.handlersrA   rB   rC   fastmcp.settingsrD   fastmcp.tools.toolrE   rF   fastmcp.tools.tool_managerrG   fastmcp.tools.tool_transformrH   fastmcp.utilities.clirI   fastmcp.utilities.componentsrJ   fastmcp.utilities.loggingrK   rL   fastmcp.utilities.typesrM   rN   fastmcp.clientrP   r  rQ   fastmcp.client.transportsrR   rS   fastmcp.server.openapirT   OpenAPIComponentFnrU   rV   rW   OpenAPIRouteMapFnr  rY   fastmcp.server.sampling.handlerrZ   r[   rl   r  rm   DuplicateBehavior	Transportcompiler5  LifespanCallablerz   r   r   r  r  rp  ro  rf   ri   rg   <module>ry     s/   ; ; " " " " " "   				                              " ! ! ! ! !             G G G G G G G G G G G G G G G G        ! ! ! ! ! ! ! ! A A A A A A K K K K K K K K ) ) ) ) ) ) * * * * * *	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 * ) ) ) ) ) - - - - - - = = = = = = % % % % % %       = = = = = = & & & & & & ( ( ( ( ( ( . . . . . . . .      ; ; ; ; ; ; ; ; ( ( ( ( ( ( " " " " " " 1 1 1 1 1 1 8 8 8 8 8 8 A A A A A A A A > > > > > > Q Q Q Q Q Q Q Q , , , , , , 1 1 1 1 1 1         
 4 3 3 3 3 3 C C C C C C C C C C C C C C 2 2 2 2 2 2         
 & % % % % % = = = = = = = = = = 2 2 2 2 2 2 < < < < < < 3 3 3 3 3 3 9 9 9 9 9 9 E E E E E E E E 3 3 3 3 3 3 3 3 	<%%%%%%444444KKKKKKKKHHHHHH????????FFFFFF111111EEEEEE;;;;;;	H		   " @A =>	 bj-.. "=o"NN 
 	 	 	 	   0m+A m+A m+A m+A m+Ago& m+A m+A m+A`W        
#( #( #( #(L). ). ). ).X$0 $0 $0 $0 $0 $0ri   