Skip to main content
Glama

crop-dicom-image

Crop DICOM medical images by removing specified boundary percentages to focus on relevant anatomical regions within medical imaging workflows.

Instructions

Crop a loaded DICOM image by removing boundary percentage

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
series_uidYesSeries UID of the loaded DICOM image
boundary_percentageNoPercentage of image to crop from each boundary (0.0-0.5)

Implementation Reference

  • MCP tool handler for 'crop-dicom-image'. Retrieves cached DICOM image by series_uid, crops it using crop_image helper with boundary_percentage, caches the result, and returns shape information.
    elif name == "crop-dicom-image":
        series_uid = arguments.get("series_uid")
        boundary_percentage = float(arguments.get("boundary_percentage", 0.2))
        
        if not series_uid or series_uid not in dicom_cache:
            raise ValueError(f"Invalid or not loaded series UID: {series_uid}. Use load-dicom-series first.")
            
        if boundary_percentage <= 0 or boundary_percentage >= 0.5:
            raise ValueError("Boundary percentage must be between 0 and 0.5")
            
        # Get the cached image
        cached_data = dicom_cache[series_uid]
        original_image = cached_data["image"]
        
        # Crop the image
        cropped_image = crop_image(original_image, boundary_percentage)
        
        # Cache the cropped image with a new ID
        cropped_uid = f"{series_uid}_cropped_{int(boundary_percentage*100)}"
        dicom_cache[cropped_uid] = {
            "image": cropped_image,
            "metadata": cached_data["metadata"],
            "original": series_uid,
            "crop_percentage": boundary_percentage
        }
        
        # Return summary information
        original_shape = original_image.shape
        cropped_shape = cropped_image.shape
        
        return [
            types.TextContent(
                type="text",
                text=f"Cropped DICOM image {series_uid} to {cropped_uid}\n" +
                     f"Original shape: {original_shape}\n" +
                     f"Cropped shape: {cropped_shape}\n" +
                     f"Boundary percentage: {boundary_percentage}"
            )
        ]
  • Registration of the 'crop-dicom-image' tool in the MCP server's list_tools handler, including name, description, and input schema.
    types.Tool(
        name="crop-dicom-image",
        description="Crop a loaded DICOM image by removing boundary percentage",
        inputSchema={
            "type": "object",
            "properties": {
                "series_uid": {"type": "string", "description": "Series UID of the loaded DICOM image"},
                "boundary_percentage": {"type": "number", "description": "Percentage of image to crop from each boundary (0.0-0.5)"},
            },
            "required": ["series_uid"],
        },
    )
  • Helper function crop_image that performs the actual image cropping by slicing the numpy array based on boundary percentage.
    def crop_image(image: np.ndarray, boundary_percentage: float = 0.2) -> np.ndarray:
        """Crop an image by removing the specified percentage from each boundary"""
        if boundary_percentage <= 0 or boundary_percentage >= 0.5:
            raise ValueError("Boundary percentage must be between 0 and 0.5")
        
        shape = image.shape
        boundary = [int(s * boundary_percentage) for s in shape]
        
        # Calculate slice indices
        slices = tuple(slice(b, s - b) for b, s in zip(boundary, shape))
        
        # Return cropped image
        return image[slices]
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. While it states the tool performs a crop operation, it fails to describe key behavioral traits: whether this is a destructive modification to the original image or creates a new version, what happens if the boundary percentage is invalid (e.g., out of range), or any performance considerations (e.g., processing time for large images). This leaves significant gaps in understanding the tool's effects.

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

Conciseness5/5

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

The description is a single, efficient sentence that directly states the tool's purpose without unnecessary words. It is front-loaded with the core action ('Crop a loaded DICOM image') and includes essential detail ('by removing boundary percentage') in a compact form. Every part of the sentence contributes meaning, making it highly concise and well-structured.

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

Completeness3/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 (image cropping with two parameters) and the absence of annotations and output schema, the description is partially complete. It clearly defines the action but lacks details on behavioral outcomes, error handling, and output format. While the schema covers parameters well, the description does not compensate for missing annotation and output information, leaving the agent with incomplete context for safe and effective use.

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

Parameters3/5

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

The input schema has 100% description coverage, with clear documentation for both parameters ('series_uid' and 'boundary_percentage'), including the range for the latter. The description adds minimal value beyond the schema by implying the crop applies uniformly to all boundaries, but it does not elaborate on parameter interactions or provide examples. Given the high schema coverage, a baseline score of 3 is appropriate.

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 ('crop') and target resource ('a loaded DICOM image'), with additional detail about the method ('by removing boundary percentage'). It distinguishes itself from sibling tools like 'extract-dicom-metadata' or 'load-dicom-series' by focusing on image manipulation rather than metadata extraction or loading operations.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives. It does not mention prerequisites (e.g., that the DICOM image must already be loaded via another tool), nor does it specify scenarios where cropping is appropriate (e.g., for removing artifacts or focusing on regions of interest). Without such context, the agent lacks direction on optimal usage.

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/shaunporwal/DICOM-MCP'

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