o
    
jR                     @   s  d 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
 ddlT ddlmZmZ dd	lmZ e  eeZeeZeepGd
ZesNedesTedededZeeeZejdddedefddZejdddededefddZdd Ze dkre  dS dS )u  
MiniMax Coding Plan MCP Server

⚠️ IMPORTANT: This server connects to Minimax API endpoints which may involve costs.
Any tool that makes an API call is clearly marked with a cost warning. Please follow these guidelines:

1. Only use these tools when users specifically ask for them
2. For audio generation tools, be mindful that text length affects the cost
3. Voice cloning features are charged upon first use after cloning

Note: Tools without cost warnings are free to use as they only read existing data.
    N)load_dotenv)FastMCP)TextContent)process_image_url)*)MinimaxAPIErrorMinimaxRequestError)MinimaxAPIClientWARNINGz0MINIMAX_API_KEY environment variable is requiredz1MINIMAX_API_HOST environment variable is requiredMinimax)	log_levela  
    
    You MUST use this tool whenever you need to search for real-time or external information on the web.
    
    A web search API that works just like Google Search.
    
    Args:
        query (str): The search query. Aim for 3-5 keywords for best results. For time-sensitive topics, include the current date (e.g. `latest iPhone 2025`).
        
    Search Strategy:
        - If no useful results are returned, try rephrasing your query with different keywords.
        
    Returns:
        A JSON object containing the search results, structured as follows:
        {
            "organic": [
                {
                    "title": "string - The title of the search result",
                    "link": "string - The URL link to the result",
                    "snippet": "string - A brief description or excerpt",
                    "date": "string - The date of the result"
                }
            ],
            "related_searches": [
                {
                    "query": "string - A related search query suggestion"
                }
            ],
            "base_resp": {
                "status_code": "int - Response status code",
                "status_msg": "string - Response status message"
            }
        }
    )descriptionqueryreturnc              
   C   sx   z| st dd| i}tjd|d}tdtj|dddd	W S  ty; } ztdd
t| d	W  Y d }~S d }~ww )NzQuery is requiredqz/v1/coding_plan/searchjsontextF   )ensure_asciiindenttyper   zFailed to perform search: )r   
api_clientpostr   r   dumpsr   str)r   payloadresponse_datae r    E/home/kuhnn/.local/lib/python3.10/site-packages/minimax_mcp/server.py
web_search(   s"   'r"   u  
    
    You MUST use this tool whenever you need to analyze, describe, or extract information from an image,
    including when you get an image from user input or any task-related image.

    An LLM-powered vision tool that can analyze and interpret image content from local files or URLs based on your instructions.
    Only JPEG, PNG, and WebP formats are supported. Other formats (e.g. PDF, GIF, PSD, SVG) are not supported.

    Args:
        prompt (str): A text prompt describing what you want to analyze or extract from the image.
        image_source (str): The location of the image to analyze.
            Accepts:
            - HTTP/HTTPS URL: "https://example.com/image.jpg"
            - Local file path:
                - Relative path: "images/photo.png"
                - Absolute path: "/Users/username/Documents/image.jpg"
            IMPORTANT: If the file path starts with an @ symbol, you MUST strip the @ prefix before passing it to this function.
            For example:
                - "@Documents/photo.jpg" → "Documents/photo.jpg"
                - "@/Users/username/image.png" → "/Users/username/image.png"
            Supported formats: JPEG, PNG, WebP
        
    Returns:
        A text description of the image analysis result.
    promptimage_sourcec              
   C   s   z/| st d|st dt|}| |d}tjd|d}|dd}|s)t dtd	|d
W S  tyL } ztd	dt| d
W  Y d }~S d }~ww )NzPrompt is requiredzImage source is required)r#   	image_urlz/v1/coding_plan/vlmr   content z No content returned from VLM APIr   r   z Failed to perform VLM analysis: )r   r   r   r   getr   r   r   )r#   r$   processed_image_urlr   r   r&   r   r    r    r!   understand_imageh   s0   r*   c                   C   s   t d 	 t  d S )NzStarting Minimax MCP server)printmcprunr    r    r    r!   main   s   r.   __main__)!__doc__osr   dotenvr   mcp.server.fastmcpr   	mcp.typesr   minimax_mcp.utilsr   minimax_mcp.constminimax_mcp.exceptionsr   r   minimax_mcp.clientr	   getenvENV_MINIMAX_API_KEYapi_keyENV_MINIMAX_API_HOSTapi_hostENV_FASTMCP_LOG_LEVELfastmcp_log_level
ValueErrorr,   r   toolr   r"   r*   r.   __name__r    r    r    r!   <module>   sT    


$)
