
    i                        d Z ddlmZ ddlmZmZ ddlmZmZ dZ	dZ
 G d de      Z G d	 d
e      Z G d de      ZddZddZy)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Fieldzio.modelcontextprotocol/uiztext/html;profile=mcp-appc                      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
y)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descriptionz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     c/Users/bowang/.openclaw/workspace/ChatDev/.venv/lib/python3.12/site-packages/fastmcp/server/apps.pyr	   r	      s     ).K)O% 
 */Z*& 
 ',D'M# 
 */C*&  )-w?Lr!   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
y)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$   2   s~     %*"9%F!  )."=)J%  */">*K&  .34.O*  )-w?Lr!   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y)	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   
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   r/   r   r0   r1   r2   r3   r5   r   r    r!   r"   r,   r,   M   s    
  %R L* 
 8=V8J4  $"NC	  /4">/K+  t9PQFJQ"'=#NK  )-w?Lr!   r,   c                L    t        | t              r| j                  dd      S | S )zHConvert an AppConfig or dict to the wire-format dict for ``meta["ui"]``.T)by_aliasexclude_none)
isinstancer,   
model_dump)apps    r"   app_config_to_meta_dictr<   s   s$    #y!~~t$~??Jr!   c                V    ||S | j                         j                  d      rt        S y)a'  Return the appropriate MIME type for a resource URI.

    For ``ui://`` scheme resources, defaults to ``UI_MIME_TYPE`` when no
    explicit MIME type is provided. This ensures UI resources are correctly
    identified regardless of how they're registered (via FastMCP.resource,
    the standalone @resource decorator, or resource templates).

    Args:
        uri: The resource URI string
        explicit_mime_type: The MIME type explicitly provided by the user

    Returns:
        The resolved MIME type (explicit value, UI default, or None)
    Nzui://)lower
startswithUI_MIME_TYPE)uriexplicit_mime_types     r"   resolve_ui_mime_typerC   z   s-     %!!
yy{g&r!   N)r;   zAppConfig | dict[str, Any]returnzdict[str, Any])rA   strrB   r.   rD   r.   )r   
__future__r   typingr   r   pydanticr   r   UI_EXTENSION_IDr@   r	   r$   r,   r<   rC   r    r!   r"   <module>rJ      sU    #  %.*@) @@@) @6#@	 #@Lr!   