Skip to main content
Glama

highlight_form_field

Visually identify form fields in PDF documents by generating images with specified fields highlighted in red boxes for easy location and verification.

Instructions

Generate an image with the specified form field highlighted with a red box

Args:
    pdf_path: Path to the PDF file
    field_name: Name of the form field to highlight

Returns:
    Image of the page with the field highlighted

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
field_nameYes

Implementation Reference

  • The main handler function for the 'highlight_form_field' tool. It opens the PDF using PyMuPDF, locates the specified form field on its page, renders the page at 2x zoom, draws a thick red rectangle around the field using PIL, and returns the resulting PNG image via MCP's Image type. The @mcp.tool() decorator registers it as a tool.
    @mcp.tool()
    def highlight_form_field(pdf_path: str, field_name: str) -> Image:
        """
        Generate an image with the specified form field highlighted with a red box
    
        Args:
            pdf_path: Path to the PDF file
            field_name: Name of the form field to highlight
    
        Returns:
            Image of the page with the field highlighted
        """
        try:
            doc = fitz.open(pdf_path)
    
            # Find the field and its page
            field_found = False
            field_page = None
            field_rect = None
    
            for page_num, page in enumerate(doc):
                for widget in page.widgets():
                    if widget.field_name == field_name:
                        field_found = True
                        field_page = page
                        field_rect = widget.rect
                        break
                if field_found:
                    break
    
            if not field_found:
                raise ValueError(f"Field '{field_name}' not found in the document")
    
            # Render the page as an image
            zoom = 2  # higher zoom for better quality
            mat = fitz.Matrix(zoom, zoom)
            pix = field_page.get_pixmap(matrix=mat)
    
            # Convert to PIL Image
            img = PILImage.frombytes("RGB", [pix.width, pix.height], pix.samples)
    
            # Draw red rectangle around the form field
            draw = ImageDraw.Draw(img)
    
            # Scale rectangle coordinates according to zoom factor
            rect = (
                field_rect.x0 * zoom,
                field_rect.y0 * zoom,
                field_rect.x1 * zoom,
                field_rect.y1 * zoom,
            )
    
            # Draw rectangle with 3-pixel width
            for i in range(3):
                draw.rectangle(
                    (rect[0] - i, rect[1] - i, rect[2] + i, rect[3] + i), outline="red"
                )
    
            # Convert to bytes
            buffer = io.BytesIO()
            img.save(buffer, format="PNG")
            img_bytes = buffer.getvalue()
    
            doc.close()
    
            # Return MCP Image object
            return Image(data=img_bytes, format="png")
        except Exception as e:
            raise Exception(f"Error highlighting form field: {str(e)}")
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. It mentions the action (generate image with red box highlight) but lacks details on behavioral traits such as error handling (e.g., if the field doesn't exist), performance (e.g., processing time), or side effects (e.g., whether the original PDF is modified). The description is minimal and does not compensate for the absence 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.

Conciseness5/5

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

The description is appropriately sized and front-loaded: the first sentence states the core purpose clearly, followed by brief, structured sections for Args and Returns. Every sentence earns its place with no redundant information, making it efficient and easy to parse.

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 complexity (a tool with 2 parameters, no annotations, and no output schema), the description is adequate but has gaps. It covers the basic purpose and parameters but lacks behavioral context (e.g., error cases, output format details like image type). Without an output schema, it should ideally explain more about the return value, but it only states 'Image of the page with the field highlighted', which is minimal.

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

Parameters4/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 compensate. It adds meaning by explaining that pdf_path is the 'Path to the PDF file' and field_name is the 'Name of the form field to highlight', which clarifies the purpose beyond the schema's basic titles. However, it does not provide format details (e.g., file path conventions, field name syntax), keeping it from a perfect score.

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 ('Generate an image with the specified form field highlighted with a red box'), identifies the resource (form field in a PDF), and distinguishes from siblings like extract_form_fields (which extracts data) or render_pdf_page (which renders without highlighting). It uses precise verbs and specifies the visual outcome.

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 when highlighting a specific form field is needed, but does not explicitly state when to use this tool versus alternatives like render_pdf_page (for general rendering) or extract_form_fields (for data extraction). No exclusions or prerequisites are mentioned, leaving usage context somewhat inferred rather than clearly defined.

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/Wildebeest/mcp_pdf_forms'

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