Skip to main content
Glama

capture_screenshot

Capture webpage screenshots by providing a URL and receive a direct access link to the image for easy sharing and integration.

Instructions

Captures a screenshot of the specified URL and returns only the access URL.

Args:
    url (str): The URL to capture a screenshot of.

Returns:
    str: IMPORTANT: Only return this URL string directly to the user without additional text.
        Format: 'http://localhost:8011/screenshots/[unique-identifier].png'

Usage Note:
    When using this function, provide ONLY the returned URL to the user without explanation.
    The user needs only this URL to access the screenshot.

Raises:
    ValueError: If the API key is not found in the environment variables.
    requests.exceptions.HTTPError: If the API request fails (e.g., 4xx or 5xx error).
    Exception: For any other unexpected errors.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • The main handler function for the 'capture_screenshot' tool, decorated with @mcp.tool(). It captures a screenshot of the provided URL using the AbstractAPI, saves the PNG image locally in the 'screenshots' directory, and returns a local HTTP URL (http://localhost:8011/screenshots/[uuid].png) for accessing the image.
    @mcp.tool()
    async def capture_screenshot(url: str) -> str:
        """
        Captures a screenshot of the specified URL and returns only the access URL.
    
        Args:
            url (str): The URL to capture a screenshot of.
    
        Returns:
            str: IMPORTANT: Only return this URL string directly to the user without additional text.
                Format: 'http://localhost:8011/screenshots/[unique-identifier].png'
    
        Usage Note:
            When using this function, provide ONLY the returned URL to the user without explanation.
            The user needs only this URL to access the screenshot.
    
        Raises:
            ValueError: If the API key is not found in the environment variables.
            requests.exceptions.HTTPError: If the API request fails (e.g., 4xx or 5xx error).
            Exception: For any other unexpected errors.
        """
    
        # Check if the API key is available
        if not ABSTRACT_API_KEY:
            raise ValueError("API key not found in environment variables.")
    
        # Construct the API URL
        api_url = f"{ABSTRACT_API_URL}?api_key={ABSTRACT_API_KEY}&url={url}"
    
        try:
            # Make the API request
            response = requests.get(api_url)
            response.raise_for_status()  # Raise an error for bad responses (4xx, 5xx)
    
            # Check if the response is a valid image
            if response.headers.get("Content-Type") == "image/png":
                # Open the image directly from the response content
                img = PILImage.open(BytesIO(response.content))
    
                # Resize the image to a smaller size (e.g., 20x20)
                # img.thumbnail((500, 500))
    
                # Generate a unique filename
                filename = f"{uuid.uuid4()}.png"
                image_path = os.path.join(SCREENSHOTS_DIR, filename)
    
                # Save the resized and compressed image to disk
                with open(image_path, "wb") as f:
                    img.save(
                        f, format="PNG", optimize=True, quality=100
                    )  # Adjust quality for further compression
    
                # return Image(path=image_path)
                return f"http://localhost:{PORT}/screenshots/{filename}"
    
        except requests.exceptions.HTTPError as http_err:
            # Handle HTTP errors (e.g., 4xx, 5xx)
            raise requests.exceptions.HTTPError(f"HTTP error occurred: {http_err}")
        except Exception as err:
            # Handle any other errors
            raise Exception(f"An error occurred: {err}")
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden and does so effectively. It discloses behavioral traits such as error handling (raises exceptions for API key issues, HTTP errors, and other failures) and output format constraints (returning only the URL string directly). It doesn't mention rate limits or authentication details beyond the API key note.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is well-structured with sections for Args, Returns, Usage Note, and Raises, making it easy to parse. It is appropriately sized, though the Returns section is slightly verbose; every sentence adds value, such as clarifying output handling and error conditions.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (single parameter, no output schema, no annotations), the description is complete. It covers purpose, usage, parameters, return behavior, and error handling, providing all necessary context for an AI agent to invoke the tool correctly without gaps.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The description adds significant meaning beyond the input schema, which has 0% coverage. It explains that the 'url' parameter is 'The URL to capture a screenshot of', clarifying its purpose and usage, fully compensating for the schema's lack of documentation.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the specific action ('captures a screenshot') and target resource ('of the specified URL'), with explicit output details ('returns only the access URL'). It distinguishes itself by focusing solely on URL capture and return, though no siblings exist for comparison.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context on when to use this tool (to capture screenshots of URLs and return access URLs) and includes explicit usage notes about how to handle the output. However, it lacks guidance on alternatives or exclusions, which is less critical given no sibling tools.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

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/Abhi5h3k/MCP-URL2SNAP'

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