
    #j                        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Z G d d	e          Z G d
 de          Z G d de          Z G d de          ZddZddZdS )u  MCP Apps support — extension negotiation and typed UI metadata models.

Provides constants and Pydantic models for the MCP Apps extension
(io.modelcontextprotocol/ui), enabling tools and resources to carry
UI metadata for clients that support interactive app rendering.
    )annotations)AnyLiteral)	BaseModelField)UI_MIME_TYPE)resolve_ui_mime_typezio.modelcontextprotocol/uic                      e Zd ZU dZ eddd          Zded<    eddd	          Zded
<    eddd          Zded<    eddd          Z	ded<   dddZ
dS )ResourceCSPa  Content Security Policy for MCP App resources.

    Declares which external origins the app is allowed to connect to or
    load resources from.  Hosts use these declarations to build the
    ``Content-Security-Policy`` header for the sandboxed iframe.
    NconnectDomainsz5Origins allowed for fetch/XHR/WebSocket (connect-src)defaultaliasdescriptionlist[str] | Noneconnect_domainsresourceDomainszDOrigins allowed for scripts, images, styles, fonts (script-src etc.)resource_domainsframeDomainsz.Origins allowed for nested iframes (frame-src)frame_domainsbaseUriDomainsz-Allowed base URIs for the document (base-uri)base_uri_domainsTallowpopulate_by_nameextra)__name__
__module____qualname____doc__r   r   __annotations__r   r   r   model_config     [/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/fastmcp/apps/config.pyr   r      s           ).K) ) )O    
 */Z* * *    
 ',eD' ' 'M    
 */C* * *     )-w??LLLr$   r   c                      e Zd ZU dZ edd          Zded<    edd          Zded<    edd	          Zded
<    eddd          Z	ded<   dddZ
dS )ResourcePermissionsa"  Iframe sandbox permissions for MCP App resources.

    Each field, when set (typically to ``{}``), requests that the host
    grant the corresponding Permission Policy feature to the sandboxed
    iframe.  Hosts MAY honour these; apps should use JS feature detection
    as a fallback.
    NzRequest camera accessr   r   zdict[str, Any] | NonecamerazRequest microphone access
microphonezRequest geolocation accessgeolocationclipboardWritezRequest clipboard-write accessr   clipboard_writeTr   r   )r   r   r   r    r   r)   r!   r*   r+   r-   r"   r#   r$   r%   r'   r'   4   s           %*E"9% % %F     )."=) ) )J     */">* * *K     .3U4. . .O     )-w??LLLr$   r'   c                      e Zd ZU dZ eddd          Zded<    edd	          Zd
ed<    edd	          Zded<    edd	          Z	ded<    edd	          Z
ded<    eddd          Zded<   dddZdS )	AppConfiga  Configuration for MCP App tools and resources.

    Controls how a tool or resource participates in the MCP Apps extension.
    On tools, ``resource_uri`` and ``visibility`` specify which UI resource
    to render and where the tool appears.  On resources, those fields must
    be left unset (the resource itself is the UI).

    All fields use ``exclude_none`` serialization so only explicitly-set
    values appear on the wire.  Aliases match the MCP Apps wire format
    (camelCase).
    NresourceUriz<URI of the UI resource (typically ui:// scheme). Tools only.r   z
str | Noneresource_uriz@Where this tool is visible: 'app', 'model', or both. Tools only.r(   z$list[Literal['app', 'model']] | None
visibilityz*Content Security Policy for the app iframezResourceCSP | NonecspzIframe sandbox permissionszResourcePermissions | NonepermissionszDomain for the iframedomainprefersBorderz'Whether the UI prefers a visible borderzbool | Noneprefers_borderTr   r   )r   r   r   r    r   r1   r!   r2   r3   r4   r5   r7   r"   r#   r$   r%   r/   r/   O   sJ        
 
  %uR     L    
 8=uV8 8 8J     $e"N  C     /4e">/ / /K     t9PQQQFQQQQ"'%=# # #N     )-w??LLLr$   r/   c                      e Zd ZdZddZdS )	PrefabAppConfiga  App configuration for Prefab tools with sensible defaults.

    Like ``app=True`` but customizable. Auto-wires the Prefab renderer
    URI and merges the renderer's CSP with any additional domains you
    specify.  The renderer resource is registered automatically.

    Example::

        @mcp.tool(app=PrefabAppConfig())  # same as app=True

        @mcp.tool(app=PrefabAppConfig(
            csp=ResourceCSP(frame_domains=["https://example.com"]),
        ))
    _PrefabAppConfig__contextr   returnNonec                   | j         d| _         	 ddlm}  |            }n# t          $ r i }Y nw xY w|r| j        pt                      }|                    d          }t          |                    d          |j	                  |d<   t          |                    d          |j
                  |d<   t          di || _        d S d S )	Nzui://prefab/renderer.htmlr   )get_renderer_cspT)exclude_noner   r   r#   )r1   prefab_ui.rendererr>   ImportErrorr3   r   
model_dump_merge_domainsgetr   r   )selfr:   r>   renderer_cspuser_cspmerged_datas         r%   model_post_initzPrefabAppConfig.model_post_init   s   $ ;D	;;;;;;++--LL 	 	 	LLL	  	2x0;==H #--4-@@K-;  !233(. .K)* /=  !344)/ /K*+ #11[11DHHH	2 	2s   ! 00N)r:   r   r;   r<   )r   r   r   r    rI   r#   r$   r%   r9   r9   u   s2         2 2 2 2 2 2r$   r9   baser   r   r;   c                x    | |dS t          | pg           }|pg D ]}||vr|                    |           |pdS )z&Merge two domain lists, deduplicating.N)listappend)rJ   r   combinedds       r%   rC   rC      s]    |tDJBH[b  HOOAtr$   appAppConfig | dict[str, Any]dict[str, Any]c                ^    t          | t                    r|                     dd          S | S )zHConvert an AppConfig or dict to the wire-format dict for ``meta["ui"]``.T)by_aliasr?   )
isinstancer/   rB   )rP   s    r%   app_config_to_meta_dictrV      s0    #y!! @~~t$~???Jr$   N)rJ   r   r   r   r;   r   )rP   rQ   r;   rR   )r    
__future__r   typingr   r   pydanticr   r   fastmcp.utilities.mimer   r	   UI_EXTENSION_IDr   r'   r/   r9   rC   rV   r#   r$   r%   <module>r\      sq    # " " " " "         % % % % % % % % ? ? ? ? ? ? O O O O O O.@ @ @ @ @) @ @ @@@ @ @ @ @) @ @ @6#@ #@ #@ #@ #@	 #@ #@ #@L*2 *2 *2 *2 *2i *2 *2 *2Z        r$   