o
    iZ                  	   @   s|   d Z ddlmZmZ ddlZg dZdZdZG dd deZ			dd	e	e
e
f dB d
ejdB dejdB dejfddZdS )z@Utilities for creating standardized httpx AsyncClient instances.    )AnyProtocolN)create_mcp_http_clientMCP_DEFAULT_TIMEOUTMCP_DEFAULT_SSE_READ_TIMEOUTg      >@g     r@c                	   @   sH   e Zd Z			ddeeef dB dejdB dejdB dejfddZ	dS )	McpHttpClientFactoryNheaderstimeoutauthreturnc                 C   s   d S )N )selfr   r	   r
   r   r   K/home/ubuntu/.local/lib/python3.10/site-packages/mcp/shared/_httpx_utils.py__call__   s   zMcpHttpClientFactory.__call__NNN)
__name__
__module____qualname__dictstrhttpxTimeoutAuthAsyncClientr   r   r   r   r   r      s    r   r   r	   r
   r   c                 C   s\   ddi}|du rt jttd|d< n||d< | dur| |d< |dur&||d< t jdi |S )	a	  Create a standardized httpx AsyncClient with MCP defaults.

    This function provides common defaults used throughout the MCP codebase:
    - follow_redirects=True (always enabled)
    - Default timeout of 30 seconds if not specified

    Args:
        headers: Optional headers to include with all requests.
        timeout: Request timeout as httpx.Timeout object.
            Defaults to 30 seconds if not specified.
        auth: Optional authentication handler.

    Returns:
        Configured httpx.AsyncClient instance with MCP defaults.

    Note:
        The returned AsyncClient must be used as a context manager to ensure
        proper cleanup of connections.

    Examples:
        # Basic usage with MCP defaults
        async with create_mcp_http_client() as client:
            response = await client.get("https://api.example.com")

        # With custom headers
        headers = {"Authorization": "Bearer token"}
        async with create_mcp_http_client(headers) as client:
            response = await client.get("/endpoint")

        # With both custom headers and timeout
        timeout = httpx.Timeout(60.0, read=300.0)
        async with create_mcp_http_client(headers, timeout) as client:
            response = await client.get("/long-request")

        # With authentication
        from httpx import BasicAuth
        auth = BasicAuth(username="user", password="pass")
        async with create_mcp_http_client(headers, timeout, auth) as client:
            response = await client.get("/protected-endpoint")
    follow_redirectsTN)readr	   r   r
   r   )r   r   r   r   r   )r   r	   r
   kwargsr   r   r   r      s   /r   r   )__doc__typingr   r   r   __all__r   r   r   r   r   r   r   r   r   r   r   r   r   <module>   s&    
