Skip to main content
Glama

capture_screenshot

Capture screenshots from 3D Slicer's application window, slice views, or 3D rendering views to provide visual feedback for AI-assisted medical image analysis.

Instructions

Capture a screenshot from 3D Slicer's views.

This tool provides real-time visual feedback of the current state of Slicer, enabling AI to observe the GUI and make informed decisions in a complete REACT loop.

Parameters: view_type (str): Type of screenshot to capture. Options: - "application" (default): Full application window including all panels and views - "slice": A specific slice view (Red/Yellow/Green) - "3d": The 3D rendering view

view_name (str): For slice views, specify which view to capture. Options: "red", "yellow", "green" Only used when view_type="slice"

slice_offset (float): For slice views, offset in mm relative to slice origin. Only used when view_type="slice"

slice_orientation (str): For slice views, specify orientation. Options: "axial", "sagittal", "coronal" Only used when view_type="slice"

camera_axis (str): For 3D views, specify camera view direction. Options: "L" (Left), "R" (Right), "A" (Anterior), "P" (Posterior), "I" (Inferior), "S" (Superior) Only used when view_type="3d"

image_size (int): Pixel size of output image (for slice and 3D views). Only used when view_type="slice" or view_type="3d"

Returns: A list containing text and/or image content. The image is returned in MCP's standard format for proper display in AI clients.

Examples:

  • Capture full application: {"tool": "capture_screenshot", "arguments": {"view_type": "application"}}

  • Capture Red slice view: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red"}}

  • Capture 3D view from anterior: {"tool": "capture_screenshot", "arguments": {"view_type": "3d", "camera_axis": "A"}}

  • Capture axial slice: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red", "slice_orientation": "axial"}}

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
view_typeNoapplication
view_nameNo
slice_offsetNo
slice_orientationNo
camera_axisNo
image_sizeNo

Implementation Reference

  • The primary handler function for the 'capture_screenshot' tool, including the @mcp.tool() decorator for automatic registration in FastMCP. It handles input parameters to construct API requests to the 3D Slicer Web Server for capturing screenshots from application, slice, or 3D views. Processes the image response into base64 MCP ImageContent with accompanying text.
    @mcp.tool()
    def capture_screenshot(
        view_type: str = "application",
        view_name: str = None,
        slice_offset: float = None,
        slice_orientation: str = None,
        camera_axis: str = None,
        image_size: int = None
    ) -> list:
        """
        Capture a screenshot from 3D Slicer's views.
    
        This tool provides real-time visual feedback of the current state of Slicer,
        enabling AI to observe the GUI and make informed decisions in a complete REACT loop.
    
        Parameters:
        view_type (str): Type of screenshot to capture. Options:
            - "application" (default): Full application window including all panels and views
            - "slice": A specific slice view (Red/Yellow/Green)
            - "3d": The 3D rendering view
        
        view_name (str): For slice views, specify which view to capture.
            Options: "red", "yellow", "green"
            Only used when view_type="slice"
        
        slice_offset (float): For slice views, offset in mm relative to slice origin.
            Only used when view_type="slice"
        
        slice_orientation (str): For slice views, specify orientation.
            Options: "axial", "sagittal", "coronal"
            Only used when view_type="slice"
        
        camera_axis (str): For 3D views, specify camera view direction.
            Options: "L" (Left), "R" (Right), "A" (Anterior), "P" (Posterior), 
                     "I" (Inferior), "S" (Superior)
            Only used when view_type="3d"
        
        image_size (int): Pixel size of output image (for slice and 3D views).
            Only used when view_type="slice" or view_type="3d"
    
        Returns:
            A list containing text and/or image content. The image is returned
            in MCP's standard format for proper display in AI clients.
    
        Examples:
        - Capture full application: {"tool": "capture_screenshot", "arguments": {"view_type": "application"}}
        - Capture Red slice view: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red"}}
        - Capture 3D view from anterior: {"tool": "capture_screenshot", "arguments": {"view_type": "3d", "camera_axis": "A"}}
        - Capture axial slice: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red", "slice_orientation": "axial"}}
        """
        try:
            # Determine the API endpoint based on view_type
            if view_type == "application":
                api_url = f"{SLICER_WEB_SERVER_URL}/screenshot"
                params = {}
                description = "full application window"
                
            elif view_type == "slice":
                if not view_name:
                    return [TextContent(type="text", text="Error: view_name is required for slice screenshots (red, yellow, or green)")]
                
                api_url = f"{SLICER_WEB_SERVER_URL}/slice"
                params = {"view": view_name.lower()}
                description = f"{view_name} slice view"
                
                # Add optional parameters
                if slice_offset is not None:
                    params["offset"] = slice_offset
                if slice_orientation:
                    params["orientation"] = slice_orientation.lower()
                    description += f" ({slice_orientation})"
                if image_size:
                    params["size"] = image_size
                    
            elif view_type == "3d":
                api_url = f"{SLICER_WEB_SERVER_URL}/threeD"
                params = {}
                description = "3D view"
                
                # Add optional parameters
                if camera_axis:
                    params["lookFromAxis"] = camera_axis.upper()
                    description += f" from {camera_axis} axis"
                    
            else:
                return [TextContent(type="text", text=f"Error: Invalid view_type '{view_type}'. Must be 'application', 'slice', or '3d'")]
    
            # Make the request to Slicer Web Server
            # Smart proxy handling: disable for localhost, use system default for others
            response = requests.get(api_url, params=params, proxies=get_proxy_config(api_url))
            response.raise_for_status()
            
            # Check if response is an image
            if response.headers.get('Content-Type', '').startswith('image/'):
                # Convert image bytes to base64
                image_base64 = base64.b64encode(response.content).decode('utf-8')
                
                # Return using MCP's content types
                return [
                    TextContent(
                        type="text",
                        text=f"Screenshot of {description} captured successfully"
                    ),
                    ImageContent(
                        type="image",
                        data=image_base64,
                        mimeType="image/png"
                    )
                ]
            else:
                # Unexpected response type
                return [TextContent(type="text", text=f"Error: Unexpected response type: {response.headers.get('Content-Type')}")]
                
        except requests.exceptions.HTTPError as e:
            return [TextContent(type="text", text=f"HTTP Error {e.response.status_code}: {str(e)}")]
        except requests.exceptions.RequestException as e:
            return [TextContent(type="text", text=f"Connection error: {str(e)}. Make sure Slicer Web Server is running.")]
        except Exception as e:
            return [TextContent(type="text", text=f"Error: {str(e)}")]
  • The docstring provides detailed schema information including parameter descriptions, types, options, usage examples, and return format for the capture_screenshot tool.
    Capture a screenshot from 3D Slicer's views.
    
    This tool provides real-time visual feedback of the current state of Slicer,
    enabling AI to observe the GUI and make informed decisions in a complete REACT loop.
    
    Parameters:
    view_type (str): Type of screenshot to capture. Options:
        - "application" (default): Full application window including all panels and views
        - "slice": A specific slice view (Red/Yellow/Green)
        - "3d": The 3D rendering view
    
    view_name (str): For slice views, specify which view to capture.
        Options: "red", "yellow", "green"
        Only used when view_type="slice"
    
    slice_offset (float): For slice views, offset in mm relative to slice origin.
        Only used when view_type="slice"
    
    slice_orientation (str): For slice views, specify orientation.
        Options: "axial", "sagittal", "coronal"
        Only used when view_type="slice"
    
    camera_axis (str): For 3D views, specify camera view direction.
        Options: "L" (Left), "R" (Right), "A" (Anterior), "P" (Posterior), 
                 "I" (Inferior), "S" (Superior)
        Only used when view_type="3d"
    
    image_size (int): Pixel size of output image (for slice and 3D views).
        Only used when view_type="slice" or view_type="3d"
    
    Returns:
        A list containing text and/or image content. The image is returned
        in MCP's standard format for proper display in AI clients.
    
    Examples:
    - Capture full application: {"tool": "capture_screenshot", "arguments": {"view_type": "application"}}
    - Capture Red slice view: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red"}}
    - Capture 3D view from anterior: {"tool": "capture_screenshot", "arguments": {"view_type": "3d", "camera_axis": "A"}}
    - Capture axial slice: {"tool": "capture_screenshot", "arguments": {"view_type": "slice", "view_name": "red", "slice_orientation": "axial"}}
    """
  • The @mcp.tool() decorator registers the capture_screenshot function with the FastMCP server instance 'mcp'.
    @mcp.tool()
Behavior4/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors: it's a read-only operation (capturing screenshots implies no mutation), provides real-time visual feedback, and returns content in MCP's standard format for display. It doesn't mention rate limits, authentication needs, or error conditions, but covers the core functionality well given the lack of annotations.

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 clear sections (purpose, parameters, returns, examples). It's appropriately sized for a tool with 6 parameters, though some sentences like 'enabling AI to observe the GUI...' could be more concise. Overall, it's front-loaded with the core purpose and efficiently documents parameters without unnecessary fluff.

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

Completeness4/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 (6 parameters, no output schema, no annotations), the description is quite complete. It covers purpose, detailed parameter usage, return format, and includes practical examples. The main gap is the lack of output schema, but the description compensates by specifying the return format. It could benefit from more behavioral context like error handling, but it's largely sufficient.

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?

Schema description coverage is 0%, so the description must fully compensate. It does this excellently by providing detailed parameter semantics: it explains each parameter's purpose, lists all valid options with clear enums (e.g., 'application', 'slice', '3d' for view_type), specifies dependencies (e.g., 'Only used when view_type="slice"'), and includes default values. This adds substantial meaning beyond the bare schema.

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

Purpose4/5

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

The description clearly states the tool's purpose: 'Capture a screenshot from 3D Slicer's views.' It specifies the resource (3D Slicer's views) and verb (capture), but doesn't explicitly differentiate from sibling tools like 'execute_python_code' or 'list_nodes', which have completely different functions. The description is clear but lacks explicit sibling differentiation.

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

Usage Guidelines3/5

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

The description implies usage context through the phrase 'enabling AI to observe the GUI and make informed decisions in a complete REACT loop,' suggesting this is for visual feedback during AI interaction. However, it doesn't provide explicit guidance on when to use this tool versus alternatives (none of which are screenshot-related), nor does it mention any prerequisites or exclusions. Usage is implied rather than explicitly stated.

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/zhaoyouj/mcp-slicer'

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