+
    Q(i,                         R t ^ RIHt ^ RIHt ^ RIHt ^ RIH	t	 ^ RI
Ht ^ RIHtHtHt ^ RIHt ^ RIHt  ! R	 R
]4      tR R ltR R ltR R ltR# )zLMiddleware that dereferences $ref in JSON schemas before sending to clients.)Sequence)AnyN)overrideResourceTemplate)CallNext
MiddlewareMiddlewareContextTool)dereference_refsc                   \   a  ] tR t^t o Rt]V 3R lR l4       t]V 3R lR l4       tRtV t	R# )DereferenceRefsMiddlewarea  Dereferences $ref in component schemas before sending to clients.

Some MCP clients (e.g., VS Code Copilot) don't handle JSON Schema $ref
properly. This middleware inlines all $ref definitions so schemas are
self-contained. Enabled by default via ``FastMCP(dereference_schemas=True)``.
c                   < V ^8  d   QhRS[ S[P                  ,          RS[S[P                  S[S[,          3,          RS[S[,          /#    context	call_nextreturn)r	   mtListToolsRequestr   r   r   )format__classdict__s   "k/Users/agent/.openclaw/workspace/venv/lib/python3.14/site-packages/fastmcp/server/middleware/dereference.py__annotate__&DereferenceRefsMiddleware.__annotate__   sL     ; ;"2#6#67; B//$?@; 
$	;    c                n   "   V! V4      G R j  xL
 pV Uu. uF  p\        V4      NK  	  up#  Lu upi 5iN)_dereference_tool)selfr   r   toolstools   &&&  r   on_list_tools'DereferenceRefsMiddleware.on_list_tools   s7       ((49:ED!$'E:: ):   5.5055c                   < V ^8  d   QhRS[ S[P                  ,          RS[S[P                  S[S[,          3,          RS[S[,          /# r   )r	   r   ListResourceTemplatesRequestr   r   r   )r   r   s   "r   r   r   !   sX     F F"2#B#BCF ++X6F-GG
F 
"	#Fr   c                n   "   V! V4      G R j  xL
 pV Uu. uF  p\        V4      NK  	  up#  Lu upi 5ir   )_dereference_resource_template)r    r   r   	templatests   &&&  r   on_list_resource_templates4DereferenceRefsMiddleware.on_list_resource_templates    s7      $G,,	;DE9a.q19EE -Er%    N)
__name__
__module____qualname____firstlineno____doc__r   r#   r,   __static_attributes____classdictcell__)r   s   @r   r   r      s4      ; ; F Fr   r   c                0    V ^8  d   QhR\         R\         /# )r   r"   r   r
   )r   s   "r   r   r   ,   s      D T r   c                j   / pRV P                   9   g   \        V P                   4      '       d   \        V P                   4      VR&   V P                  eE   RV P                  9   g   \        V P                  4      '       d   \        V P                  4      VR&   V'       d   V P	                  VR7      # V # )z4Return a copy of the tool with dereferenced schemas.$defs
parametersoutput_schemaupdate)r9   _has_refr   r:   
model_copy)r"   updatess   & r   r   r   ,   s    !#G$//!Xdoo%>%> 0 A%4%%%$2D2D)E)E#3D4F4F#G g..Kr   c                0    V ^8  d   QhR\         R\         /# )r   templater   r   )r   s   "r   r   r   :   s      -= BR r   c                    RV P                   9   g   \        V P                   4      '       d(   V P                  R\        V P                   4      /R7      # V # )z8Return a copy of the template with dereferenced schemas.r8   r9   r;   )r9   r=   r>   r   )rA   s   &r   r)   r)   :   sS    (%%%(2E2E)F)F"" "283F3F"GH # 
 	
 Or   c                R    V ^8  d   QhR\         \        \        3,          R\        /# )r   schemar   )dictstrr   bool)r   s   "r   r   r   C   s"      T#s(^  r   c                6   RV 9   d   R# V P                  4        F{  p\        V\        4      '       d   \        V4      '       d    R# \        V\        4      '       g   KE  V F0  p\        V\        4      '       g   K  \        V4      '       g   K.    R# 	  K}  	  R# )z$Check if a schema contains any $ref.z$refTF)values
isinstancerE   r=   list)rD   valueitems   &  r   r=   r=   C   si    eT""xeT""dD))htnn 	 ! r   )r3   collections.abcr   typingr   	mcp.typestypesr   typing_extensionsr   fastmcp.resources.templater   $fastmcp.server.middleware.middlewarer   r   r	   fastmcp.tools.toolr   fastmcp.utilities.json_schemar   r   r   r)   r=   r.   r   r   <module>rW      s@    R $   & 7 X X # :F
 F:r   