Skip to main content
Glama
mcp2everything

MCP2Tavily

get_url_content

Extract content from any URL using the Tavily API to retrieve web page information for analysis or processing.

Instructions

Get the content from a specific URL using Tavily API

Args:
    url (str): The URL to extract content from
    
Returns:
    str: The extracted content from the URL

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • Handler function for the 'get_url_content' tool, registered via @mcp.tool() decorator. It defines the input schema via type hints and docstring, and delegates to the internal _get_url_content implementation.
    @mcp.tool()
    def get_url_content(url: str) -> str:
        """Get the content from a specific URL using Tavily API
        
        Args:
            url (str): The URL to extract content from
            
        Returns:
            str: The extracted content from the URL
        """
        return _get_url_content(url)
  • The main helper function containing the tool logic: uses TavilyClient.extract() to fetch URL content, processes it with UTF-8 handling, adds metadata, and includes error handling.
    def _get_url_content(url: str) -> str:
        """Internal function to get content from a specific URL using Tavily API"""
        try:
            tavily_client = TavilyClient(api_key=API_KEY)
            logger.info(f"Attempting to extract content from URL: {url}")
            
            response = tavily_client.extract(url)
            # logger.info(f"Raw API response: {response}")  # 使用 logger 替代 print
            
            # 处理返回的数据结构
            results = response.get('results', [])
            if not results:
                logger.error(f"No results found in response: {response}")
                return "No content found for this URL. API response contains no results."
                
            # 获取第一个结果的原始内容
            first_result = results[0]
            # logger.info(f"First result structure: {list(first_result.keys())}")  # 只记录键名,避免日志过大
            
            content = first_result.get('raw_content', '')
            if not content:
                logger.error("No raw_content found in first result")
                return "No raw content available in the API response"
            
            # 确保响应文本是UTF-8编码
            content = content.encode('utf-8').decode('utf-8')
            
            # 添加一些元数据到输出中
            metadata = f"URL: {url}\n"
            metadata += f"Content length: {len(content)} characters\n"
            metadata += "---\n\n"
            
            logger.info(f"Successfully extracted content with length: {len(content)}")
            return f"{metadata}{content}"
            
        except Exception as e:
            logger.exception(f"Detailed error while extracting URL content")
            return f"Error getting content from URL: {str(e)}"

Tool Definition Quality

Score is being calculated. Check back soon.

Install Server

Other Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mcp2everything/mcp2tavily'

If you have feedback or need assistance with the MCP directory API, please join our Discord server