
    KiV)                        d Z ddlmZ ddlmZmZ ddlmZmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZ erdd	lmZ d
ZdZdZdZdZdZ	 	 	 	 	 	 	 	 d#dedz  dedz  dee   dz  deeeef   z  dz  dee   dz  deegef   dz  deeef   dz  dedz  deedef   gedef   f   fdZddddddddddededz  dedz  dedz  dedz  dee   dz  dedz  deeef   dz  dedz  deedef   gedef   f   fdZ	 	 	 	 	 	 d$dedz  dedz  dedz  dee   dz  deeef   dz  dedz  deedef   gedef   f   fd Z  G d! d"      Z!y)%z_Provides a base mixin class and decorators for easy registration of class methods with FastMCP.    )Callable)TYPE_CHECKINGAny)AnnotationsToolAnnotations)Prompt)Resource)Tool)get_fn_name)FastMCP_mcp_tool_registration_mcp_resource_registration_mcp_prompt_registration_+Nnamedescriptiontagsannotationsexclude_args
serializermetaenabledreturn.c           	      l     dt         dt        f   dt         dt        f   f fd}|S )zADecorator to mark a method as an MCP tool for later registration.func.r   c           	          	xs t        |       
d}|j                         D ci c]  \  }}|	|| }}}t        | t        |       | S c c}}w )N)r   r   r   r   r   r   r   r   )r   itemssetattr_MCP_REGISTRATION_TOOL_ATTR)r   	call_argskvr   r   r   r   r   r   r   r   s       o/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/fastmcp/contrib/mcp_mixin/mcp_mixin.py	decoratorzmcp_tool.<locals>.decorator%   sl    -K-&&($	
	 '0oo&7Ida1=QTI	I19= Js
   
AAr   r   )	r   r   r   r   r   r   r   r   r%   s	   ```````` r$   mcp_toolr'      s5    c* xS/A       )r   titler   	mime_typer   r   r   r   urir)   r*   c          
      p     dt         dt        f   dt         dt        f   f f	d}	|	S )zEDecorator to mark a method as an MCP resource for later registration.r   .r   c           
         	 	xs t        |       
d	}|j                         D ci c]  \  }}|	|| }}}t        | t        |       | S c c}}w )N)	r+   r   r)   r   r*   r   r   r   r   )r   r   r   _MCP_REGISTRATION_RESOURCE_ATTR)r   r!   r"   r#   r   r   r   r   r*   r   r   r)   r+   s       r$   r%   zmcp_resource.<locals>.decoratorE   so    -K-&"&

	 '0oo&7Ida1=QTI	I5yA	 Js
   
AAr&   )
r+   r   r)   r   r*   r   r   r   r   r%   s
   ````````` r$   mcp_resourcer/   7   s6    c* xS/A  $ r(   c                 d     dt         dt        f   dt         dt        f   f fd}|S )zCDecorator to mark a method as an MCP prompt for later registration.r   .r   c                     xs t        |       	d}|j                         D ci c]  \  }}|	|| }}}t        | t        |       | S c c}}w )N)r   r)   r   r   r   r   )r   r   r   _MCP_REGISTRATION_PROMPT_ATTR)
r   r!   r"   r#   r   r   r   r   r   r)   s
       r$   r%   zmcp_prompt.<locals>.decoratord   sf    -K-&
	 '0oo&7Ida1=QTI	I3Y? Js
   
AAr&   )r   r)   r   r   r   r   r%   s   `````` r$   
mcp_promptr3   Z   s5    c* xS/A   r(   c                       e Zd ZdZdefdZdefdddedz  ded	dfd
Zdefdddedz  ded	dfdZ	de
fdddedz  ded	dfdZdeee
fdddedz  dededed	dfdZy)MCPMixina  Base mixin class for objects that can register tools, resources, and prompts
    with a FastMCP server instance using decorators.

    This mixin provides methods like `register_all`, `register_tools`, etc.,
    which iterate over the methods of the inheriting class, find methods
    decorated with `@mcp_tool`, `@mcp_resource`, or `@mcp_prompt`, and
    register them with the provided FastMCP server instance.
    registration_typec           
          t        |       D cg c]]  }t        t        | |            rFt        t        | |      |      r0t        | |      t        t        | |      |      j	                         f_ c}S c c}w )z>Retrieves all methods marked for a specific registration type.)dircallablegetattrhasattrcopy)selfr6   method_names      r$   _get_methods_to_registerz!MCPMixin._get_methods_to_register   sr      #4y

 k23k24EF k*k24EFKKM
 	
 
s   A"A3N
mcp_serverr   prefix	separatorr   c                    | j                  t              D ]  \  }}|r| | |d    |d<   t        j                  ||j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d	      

      }|j                  |        y)a  Registers all methods marked with @mcp_tool with the FastMCP server.

        Args:
            mcp_server: The FastMCP server instance to register tools with.
            prefix: Optional prefix to prepend to tool names. If provided, the
                final name will be f"{prefix}{separator}{original_name}".
            separator: The separator string used between prefix and original name.
                Defaults to '_'.
        r   r   r   r   r   r   output_schemar   r   )
fnr   r   r   r   r   r   rD   r   r   N)r?   r    r
   from_functiongetadd_tool)r=   r@   rA   rB   methodregistration_infotools          r$   register_toolszMCPMixin.register_tools   s     *.)F)F'*
 	&%F% hyk*;F*C)DE "&) %%&**62-11-@&**62-11-@.22>B,00>/33OD&**62)--i8D %+	&r(   c                    | j                  t              D ]  \  }}|r| | |d    |d<   | | |d    |d<   t        j                  ||d   |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d	      

      }|j                  |        y)a  Registers all methods marked with @mcp_resource with the FastMCP server.

        Args:
            mcp_server: The FastMCP server instance to register resources with.
            prefix: Optional prefix to prepend to resource names and URIs. If provided,
                the final name will be f"{prefix}{separator}{original_name}" and the
                final URI will be f"{prefix}{separator}{original_uri}".
            separator: The separator string used between prefix and original name/URI.
                Defaults to '+'.
        r   r+   r)   r   r*   r   r   r   r   )
rE   r+   r   r)   r   r*   r   r   r   r   N)r?   r.   r	   rF   rG   add_resource)r=   r@   rA   rB   rI   rJ   resources          r$   register_resourceszMCPMixin.register_resources   s     *.)F)F+*
 	.%F% hyk*;F*C)DE "&) hyk*;E*B)CD "%(  --%e,&**62'++G4-11-@+//<&**62)--i8-11-@&**62H ##H-1	.r(   c                 l   | j                  t              D ]  \  }}|r| | |d    |d<   t        j                  ||j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d      |j	                  d            }|j                  |        y)	a  Registers all methods marked with @mcp_prompt with the FastMCP server.

        Args:
            mcp_server: The FastMCP server instance to register prompts with.
            prefix: Optional prefix to prepend to prompt names. If provided, the
                final name will be f"{prefix}{separator}{original_name}".
            separator: The separator string used between prefix and original name.
                Defaults to '_'.
        r   r)   r   r   r   r   )rE   r   r)   r   r   r   r   N)r?   r2   r   rF   rG   
add_prompt)r=   r@   rA   rB   rI   rJ   prompts          r$   register_promptszMCPMixin.register_prompts   s     *.)F)F)*
 	*%F% hyk*;F*C)DE "&) ))&**62'++G4-11-@&**62)--i8&**62F !!&)!	*r(   tool_separatorresource_separatorprompt_separatorc                 |    | j                  |||       | j                  |||       | j                  |||       y)a  Registers all marked tools, resources, and prompts with the server.

        This method calls `register_tools`, `register_resources`, and `register_prompts`
        internally, passing the provided prefix and separators.

        Args:
            mcp_server: The FastMCP server instance to register with.
            prefix: Optional prefix applied to all registered items unless overridden
                by a specific separator argument.
            tool_separator: Separator for tool names (defaults to '_').
            resource_separator: Separator for resource names/URIs (defaults to '+').
            prompt_separator: Separator for prompt names (defaults to '_').
        )rA   rB   N)rL   rP   rT   )r=   r@   rA   rU   rV   rW   s         r$   register_allzMCPMixin.register_all   sE    * 	JvP
6EWXjCSTr(   )__name__
__module____qualname____doc__strr?   _DEFAULT_SEPARATOR_TOOLrL   _DEFAULT_SEPARATOR_RESOURCErP   _DEFAULT_SEPARATOR_PROMPTrT   rY    r(   r$   r5   r5   v   s   

# 

 "0	$&$& d
$& 	$&
 
$&R "4	(.(. d
(. 	(.
 
(.Z "2	** d
* 	*
 
*H "5"= 9UU d
U 	U
  U U 
Ur(   r5   )NNNNNNNN)NNNNNN)"r]   collections.abcr   typingr   r   	mcp.typesr   r   fastmcp.prompts.promptr   fastmcp.resources.resourcer	   fastmcp.tools.toolr
   fastmcp.utilities.typesr   fastmcp.serverr   r    r.   r2   r_   r`   ra   r^   setdictlistboolr'   r/   r3   r5   rb   r(   r$   <module>ro      s   e $ % 2 ) / # /&6 ">  :  !   " ;?%).2"&
*t c(T/ !4S>1D8	
 s)d" #$t+ sCx.4
 D[ xS!"HS#X$667B "  &*"& 	  *  :	 
 t  Tz  c(T/  t#  sCx.4
  D[  xS!"HS#X$667 H " "&
*: t c(T/	
 sCx.4
 D[ xS!"HS#X$6678^U ^Ur(   