
    h78j                        d Z ddlZddlZddlZddlmZ ddlmZ ddlm	Z	 ddl
mZ  ej        e          Z ed          Ze                                	 	 	 	 	 	 d&dededededz  dedededeeeef                  fd            Ze                                	 	 	 	 	 	 	 	 	 	 	 d'dededededz  dededededz  dedz  dedz  dedz  dedz  deeeef                  fd            Ze                                	 	 	 	 	 	 d&dededededz  dedededeeeef                  fd            Ze                                	 	 	 	 	 	 	 	 	 d(dededededz  dededededz  dedz  dedz  deeeef                  fd             Ze                                	 	 	 d)dededededeeeef                  f
d!            Ze                                d*d#ed$edeeeez  f         fd%            ZdS )+zMCP server for DDGS.    N)Any)FastMCP)DDGS)_expand_proxy_tb_aliaszddgs-searchus-enmoderate
      autoqueryregion
safesearch	timelimitmax_resultspagebackendreturnc           	      x    K   t          j         fd           d{V }t          |          S )a  Perform a text search using DDGS.

    Args:
        query: Search query string
        region: Region for search (e.g., us-en, uk-en, ru-ru)
        safesearch: Safe search setting (on, moderate, off)
        timelimit: Time limit (d, w, m, y) or custom date range
        max_results: Maximum number of results to return
        page: Page number of results
        backend: Search backend (auto, or specific engine)

    Returns:
        List of search results with title, href, and body

    c            	          t          t          t          j                            d                                                             S N
DDGS_PROXYproxy)r   r   r   r   r   r   r   )r   r   osenvirongettextr   r   r   r   r   r   r   s   [/home/rurouni/.hermes/hermes-agent/venv/lib/python3.11/site-packages/ddgs/api_server/mcp.py<lambda>zsearch_text.<locals>.<lambda>-   T    1"*..2N2NOOPPPUU!# V 
 
     Nasyncio	to_threadlistr   r   r   r   r   r   r   resultss   ``````` r   search_textr)            2 %	
 	
 	
 	
 	
 	
 	
 	
 	
 	

 
 
 
 
 
 
 
G ==r"   sizecolor
type_imagelayoutlicense_imagec                     	
K   t          j        
 	fd           d{V }t          |          S )a  Perform an image search using DDGS.

    Args:
        query: Image search query string
        region: Region for search (e.g., us-en, uk-en, ru-ru)
        safesearch: Safe search setting (on, moderate, off)
        timelimit: Time limit (d, w, m, y) or custom date range
        max_results: Maximum number of results to return
        page: Page number of results
        backend: Search backend (auto, or specific engine)
        size: Image size (Small, Medium, Large, Wallpaper)
        color: Image color filter
        type_image: Image type (photo, clipart, gif, transparent, line)
        layout: Image layout (Square, Tall, Wide)
        license_image: Image license filter

    Returns:
        List of image search results with title, image URL, and source

    c                      t          t          t          j                            d                                                  
 	          S )Nr   r   )r   r   r   r   r   r   r   r+   r,   r-   r.   r/   )r   r   r   r   r   images)r   r,   r.   r/   r   r   r   r   r   r+   r   r-   s   r   r    zsearch_images.<locals>.<lambda>^   sc    1"*..2N2NOOPPPWW!#!' X 
 
 r"   Nr#   )r   r   r   r   r   r   r   r+   r,   r-   r.   r/   r(   s   ```````````` r   search_imagesr3   :   s      F %	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
       G  ==r"   c           	      x    K   t          j         fd           d{V }t          |          S )a  Perform a news search using DDGS.

    Args:
        query: News search query string
        region: Region for search (e.g., us-en, uk-en, ru-ru)
        safesearch: Safe search setting (on, moderate, off)
        timelimit: Time limit (d, w, m, y) or custom date range
        max_results: Maximum number of results to return
        page: Page number of results
        backend: Search backend (auto, or specific engine)

    Returns:
        List of news results with title, URL, source, and date

    c            	          t          t          t          j                            d                                                             S r   )r   r   r   r   r   newsr   s   r   r    zsearch_news.<locals>.<lambda>   r!   r"   Nr#   r'   s   ``````` r   search_newsr7   p   r*   r"   
resolutiondurationlicense_videosc
                     	K   t          j        	 f
d           d{V }
t          |
          S )a  Perform a video search using DDGS.

    Args:
        query: Video search query string
        region: Region for search (e.g., us-en, uk-en, ru-ru)
        safesearch: Safe search setting (on, moderate, off)
        timelimit: Time limit (d, w, m) or custom date range
        max_results: Maximum number of results to return
        page: Page number of results
        backend: Search backend (auto, or specific engine)
        resolution: Video resolution (high, standard)
        duration: Video duration (short, medium, long)
        license_videos: Video license (creativeCommon, youtube)

    Returns:
        List of video search results with title, URL, and metadata

    c                     
 t          t          t          j                            d                                                  	 
  
        S )Nr   r   )
r   r   r   r   r   r   r   r8   r9   r:   )r   r   r   r   r   videos)
r   r9   r:   r   r   r   r   r8   r   r   s
   r   r    zsearch_videos.<locals>.<lambda>   s]    1"*..2N2NOOPPPWW!#!) X 
 
 r"   Nr#   )r   r   r   r   r   r   r   r8   r9   r:   r(   s   `````````` r   search_videosr>      s      > %	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
 	
       G ==r"   c                 l    K   t          j         fd           d{V }t          |          S )aG  Perform a book search using DDGS.

    Args:
        query: Books search query string
        max_results: Maximum number of results to return
        page: Page number of results
        backend: Search backend (auto, or specific engine)

    Returns:
        List of book search results with title, author, and metadata

    c                      t          t          t          j                            d                                                             S )Nr   r   )r   r   r   r   )r   r   r   r   r   books)r   r   r   r   s   r   r    zsearch_books.<locals>.<lambda>   sK    1"*..2N2NOOPPPVV#	 W 
 
 r"   Nr#   )r   r   r   r   r(   s   ```` r   search_booksrB      sm      & %	
 	
 	
 	
 	
 	
 	
       G ==r"   text_markdownurlfmtc                 F    K   t          j         fd           d{V S )a  Extract content from a URL.

    Args:
        url: The URL to fetch and extract content from.
        fmt: Output format: "text_markdown", "text_plain", "text_rich", "text" (raw HTML), "content" (raw bytes).

    Returns:
        Dictionary with url and content keys.

    c                      t          t          t          j                            d                                                             S )Nr   r   rD   rE   )r   r   r   r   r   extract)rE   rD   s   r   r    z!extract_content.<locals>.<lambda>   sE    1"*..2N2NOOPPPXX Y 
 
 r"   N)r$   r%   rH   s   ``r   extract_contentrJ      sV       "	
 	
 	
 	
 	
        r"   )r   r   Nr	   r
   r   )r   r   Nr	   r
   r   NNNNN)	r   r   Nr	   r
   r   NNN)r	   r
   r   )rC   )__doc__r$   loggingr   typingr   mcp.server.fastmcpr   ddgsr   
ddgs.utilsr   	getLogger__name__loggermcptoolstrintr&   dictr)   r3   r7   r>   rB   bytesrJ    r"   r   <module>r[      sc       				       & & & & & &       - - - - - -		8	$	$ gm    # ### # Tz	#
 # # # 
$sCx.# # # #L    ! $2 222 2 Tz	2
 2 2 2 *2 :2 d
2 $J2 :2 
$sCx.2 2 2 2j    # ### # Tz	#
 # # # 
$sCx.# # # #L    !!%, ,,, , Tz	,
 , , , d
, Dj, $J, 
$sCx., , , ,^  	   	
 
$sCx.   :  s  4SSX[HXCY      r"   