o
    ip6                     @  s.  d dl mZ d dlZd dlZd dlZd dlmZ d dlm	Z	m
Z
mZmZ d dlmZ d dlmZmZmZ d dlmZ d dlmZmZmZmZ d d	lmZ d d
lmZ eeZe ddZ!ed Z"ed Z#dZ$e	rnd dl%m&Z& G dd deZ'G dd deddZ(G dd deZ)G dd deZ*dddZ+dS )     )annotationsN)Path)TYPE_CHECKING	AnnotatedAnyLiteral)user_data_dir)FieldImportStringfield_validator)	FieldInfo)BaseSettingsEnvSettingsSourcePydanticBaseSettingsSourceSettingsConfigDict)Self)
get_loggerFASTMCP_ENV_FILEz.env)DEBUGINFOWARNINGERRORCRITICAL)warnerrorreplaceignorei   )AuthProviderc                      s"   e Zd ZdZd
 fdd	Z  ZS )ExtendedEnvSettingsSourcez
    A special EnvSettingsSource that allows for multiple env var prefixes to be used.

    Raises a deprecation warning if the old `FASTMCP_SERVER_` prefix is used.
    fieldr   
field_namestrreturntuple[Any, str, bool]c                   sj   | j d }r.|D ]#}|| _t ||\}}}|d ur-|dkr&td |||f  S q
t ||S )Nenv_prefixesFASTMCP_SERVER_zTUsing `FASTMCP_SERVER_` environment variables is deprecated. Use `FASTMCP_` instead.)configget
env_prefixsuperget_field_valueloggerwarning)selfr   r    prefixesprefixenv_val	field_keyvalue_is_complex	__class__ V/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/fastmcp/settings.pyr*   +   s   
z)ExtendedEnvSettingsSource.get_field_value)r   r   r    r!   r"   r#   )__name__
__module____qualname____doc__r*   __classcell__r5   r5   r3   r6   r   $   s    r   c                   @  s   e Zd ZU ded< dS )ExtendedSettingsConfigDictzlist[str] | Noner$   N)r7   r8   r9   __annotations__r5   r5   r5   r6   r<   ?   s   
 r<   F)totalc                   @  s&   e Zd ZU edddZdZded< dS )ExperimentalSettingsFASTMCP_EXPERIMENTAL_r   )r(   extraFzAnnotated[bool, Field(description=inspect.cleandoc('\n                Whether to use the new OpenAPI parser. This parser was introduced\n                for testing in 2.11 and will become the default soon.\n                '))]enable_new_openapi_parserN)r7   r8   r9   r   model_configrB   r=   r5   r5   r5   r6   r?   C   s   
 r?   c                   @  s  e Zd ZU dZeddgedddddZdaddZdbddZe	dcddZ
eddddZeedd d!Zd"ed#< d Zd$ed%< dZd$ed&< d'Zd(ed)< ed)d*d+e	d,d- Ze Zd.ed/< dZd0ed1< dZd2ed3< dZd4ed5< d6Zd7ed8< d9Zd:ed;< d<Zd	ed=< d>Zd?ed@< dAZd	edB< dCZ d	edD< dEZ!d	edF< d Z"d$edG< d Z#dHedI< d Z$dJedK< e%e&dLdMZ'dNedO< d Z(d$edP< d Z)d$edQ< d9Z*dRedS< d9Z+dTedU< d9Z,dVedW< dZ-dXedY< d Z.dZed[< dZ/d\ed]< eded_d`Z0d9S )fSettingszFastMCP settings.FASTMCP_r%   r   __T)r$   env_filerA   env_nested_delimiter#nested_model_default_partial_updatevalidate_assignmentattrr!   r"   r   c                 C  sR   | }d|v r$| dd\}}t||std| dt||}d|v st||S )zz
        Get a setting. If the setting contains one or more `__`, it will be
        treated as a nested setting.
        rF      Setting  does not exist.)splithasattrAttributeErrorgetattr)r-   rK   settingsparent_attrr5   r5   r6   get_settingb   s   


zSettings.get_settingvalueNonec                 C  sX   | }d|v r$| dd\}}t||std| dt||}d|v st||| dS )zz
        Set a setting. If the setting contains one or more `__`, it will be
        treated as a nested setting.
        rF   rL   rM   rN   N)rO   rP   rQ   rR   setattr)r-   rK   rV   rS   rT   r5   r5   r6   set_settingo   s   

zSettings.set_settingsettings_clstype[BaseSettings]init_settingsr   env_settingsdotenv_settingsfile_secret_settings&tuple[PydanticBaseSettingsSource, ...]c                 C  s   |t |||fS N)r   )clsrZ   r\   r]   r^   r_   r5   r5   r6   settings_customise_sources|   s
   z#Settings.settings_customise_sourcesr   c                 C  s   t d | S )z
        This property is for backwards compatibility with FastMCP < 2.8.0,
        which accessed fastmcp.settings.settings
        zLUsing fastmcp.settings.settings is deprecated. Use fastmcp.settings instead.)r+   r,   )r-   r5   r5   r6   rS      s   zSettings.settingsfastmcpF)	appauthorr   homebool	test_modelog_enabledr   	LOG_LEVEL	log_levelbefore)modec                 C  s   t |tr	| S |S ra   )
isinstancer!   upper)rb   vr5   r5   r6   normalize_log_level   s   
zSettings.normalize_log_levelr?   experimentalzAnnotated[bool, Field(description=inspect.cleandoc('\n                If True, will use rich tracebacks for logging.\n                '))]enable_rich_tracebacksa_  Annotated[bool, Field(description=inspect.cleandoc("\n                Whether to show deprecation warnings. You can completely reset\n                Python's warning behavior by running `warnings.resetwarnings()`.\n                Note this will NOT apply to deprecation warnings from the\n                settings class itself.\n                "))]deprecation_warningsa  Annotated[bool, Field(description=inspect.cleandoc('\n                Many MCP components operate in anyio taskgroups, and raise\n                ExceptionGroups instead of exceptions. If this setting is True, FastMCP Clients\n                will `raise` the first error in any ExceptionGroup instead of raising\n                the ExceptionGroup as a whole. This is useful for debugging, but may\n                mask other errors.\n                '))]'client_raise_first_exceptiongroup_errorpathar  Annotated[Literal['protocol', 'path'], Field(description=inspect.cleandoc('\n                When perfixing a resource URI, either use path formatting (resource://prefix/path)\n                or protocol formatting (prefix+resource://path). Protocol formatting was the default in FastMCP < 2.4;\n                path formatting is current default.\n                '))]resource_prefix_formatNzAnnotated[float | None, Field(description="The timeout for the client's initialization handshake, in seconds. Set to None or 0 to disable.")]client_init_timeoutz	127.0.0.1hosti@  intportz/ssesse_pathz
/messages/message_pathz/mcpstreamable_http_pathdebuga  Annotated[bool, Field(description=inspect.cleandoc('\n                If True, error details from user-supplied functions (tool, resource, prompt)\n                will be masked before being sent to clients. Only error messages from explicitly\n                raised ToolError, ResourceError, or PromptError will be included in responses.\n                If False (default), all error details will be included in responses, but prefixed\n                with appropriate context.\n                '))]mask_error_detailsa  Annotated[bool, Field(description=inspect.cleandoc('\n                If True, tool inputs are strictly validated against the input\n                JSON schema. For example, providing the string "10" to an\n                integer field will raise an error. If False, compatible inputs\n                will be coerced to match the schema, which can increase\n                compatibility. For example, providing the string "10" to an\n                integer field will be coerced to 10. Defaults to False.\n                '))]strict_input_validationz9List of dependencies to install in the server environment)default_factorydescriptionz	list[str]server_dependenciesjson_responsestateless_httpaU  Annotated[str | None, Field(description=inspect.cleandoc("\n                Configure the authentication provider for the server by specifying\n                the full module path to an AuthProvider class (e.g., \n                'fastmcp.server.auth.providers.google.GoogleProvider').\n\n                The specified class will be imported and instantiated automatically\n                during FastMCP server creation. Any class that inherits from AuthProvider\n                can be used, including custom implementations.\n\n                If None, no automatic configuration will take place.\n\n                This setting is *always* overridden by any auth provider passed to the\n                FastMCP constructor.\n\n                Note that most auth providers require additional configuration\n                that must be provided via env vars.\n\n                Examples:\n                  - fastmcp.server.auth.providers.google.GoogleProvider\n                  - fastmcp.server.auth.providers.jwt.JWTVerifier\n                  - mycompany.auth.CustomAuthProvider\n                "))]server_autha/  Annotated[set[str] | None, Field(description=inspect.cleandoc('\n                If provided, only components that match these tags will be\n                exposed to clients. A component is considered to match if ANY of\n                its tags match ANY of the tags in the set.\n                '))]include_tagsa0  Annotated[set[str] | None, Field(description=inspect.cleandoc('\n                If provided, components that match these tags will be excluded\n                from the server. A component is considered to match if ANY of\n                its tags match ANY of the tags in the set.\n                '))]exclude_tagsaz  Annotated[bool, Field(description=inspect.cleandoc("\n                Whether to include FastMCP meta in the server's MCP responses.\n                If True, a `_fastmcp` key will be added to the `meta` field of\n                all MCP component responses. This key will contain a dict of\n                various FastMCP-specific metadata, such as tags.\n                "))]include_fastmcp_metaaE  Annotated[bool, Field(description=inspect.cleandoc('\n                If True, errors encountered when loading mounted components (tools, resources, prompts)\n                will be raised instead of logged as warnings. This is useful for debugging\n                but will interrupt normal operation.\n                '))]&mounted_components_raise_on_load_erroraN  Annotated[bool, Field(description=inspect.cleandoc('\n                If True, the server banner will be displayed when running the server via CLI.\n                This setting can be overridden by the --no-banner CLI flag.\n                Set to False via FASTMCP_SHOW_CLI_BANNER=false to suppress the banner.\n                '))]show_cli_bannerAuthProvider | Nonec                 C  s.   ddl m} | jsd S |t}|| j}|S )Nr   )get_cached_typeadapter)fastmcp.utilities.typesr   r   r
   validate_python)r-   r   type_adapter
auth_classr5   r5   r6   server_auth_classy  s   zSettings.server_auth_class)rK   r!   r"   r   )rK   r!   rV   r   r"   rW   )rZ   r[   r\   r   r]   r   r^   r   r_   r   r"   r`   )r"   r   )r"   r   )1r7   r8   r9   r:   r<   ENV_FILErC   rU   rY   classmethodrc   propertyrS   r   r   rf   r=   rh   ri   rk   r   rq   r?   rr   rs   rt   ru   rw   rx   ry   r{   r|   r}   r~   r   r   r   r	   listr   r   r   r   r   r   r   r   r   r   r5   r5   r5   r6   rD   V   s   
 
	









!
)




rD   namer!   c                 C  sF   | dkrddl }|j}|jrtjdtdd |S tdt d|  d	)
zo
    Used to deprecate the module-level Image class; can be removed once it is no longer imported to root.
    rS   r   NzV`from fastmcp.settings import settings` is deprecated. use `fastmcp.settings` instead.   )
stacklevelzmodule 'z' has no attribute '')rd   rS   rt   warningsr   DeprecationWarningrQ   r7   )r   rd   rS   r5   r5   r6   __getattr__  s   r   )r   r!   ),
__future__r   _annotationsinspectosr   pathlibr   typingr   r   r   r   platformdirsr   pydanticr	   r
   r   pydantic.fieldsr   pydantic_settingsr   r   r   r   typing_extensionsr   fastmcp.utilities.loggingr   r7   r+   getenvr   rj   DuplicateBehaviorTEN_MB_IN_BYTESfastmcp.server.auth.authr   r   r<   r?   rD   r   r5   r5   r5   r6   <module>   s4      9