Skip to main content
Glama

Find text in a PDF

pdf_find_text
Read-onlyIdempotent

Search born-digital PDFs for words, phrases, or regex patterns and return each match's page and bounding box in PDF points, so agents can locate text for stamping.

Instructions

Search a born-digital PDF (one made by software: invoices, statements, reports, contracts, forms) for a word, phrase or pattern and get each hit with its page and box in PDF points from the bottom-left of the page as the viewer sees it, y on the text baseline: the same frame pdf_edit uses, so a hit's x, y, width and height tell you where to stamp. Case-insensitive unless case_sensitive is true. Set regex to treat query as a regular expression from a safe subset (literals, classes, dot, anchors, word boundaries, groups, alternation, quantifiers including lazy ones); backreferences, lookahead, lookbehind, named groups, property escapes and inline flags are rejected. A match never spans lines. Scanned PDFs have no text layer: their pages are listed in pages_without_text (no OCR). While next_page is not null, call again with pages set to next_page followed by a dash (for example 4-) to continue with no gaps or repeated hits. If truncated is true but next_page is null, hits on a page listed in pages_skipped beyond max_hits cannot be retrieved: raise max_hits or narrow the query. Read-only: the source is never modified.

Tool call template

Replace each placeholder with a value matching the input schema. Only required parameters are included; add optional parameters as needed.

{
  "id": 1,
  "jsonrpc": "2.0",
  "method": "tools/call",
  "params": {
    "arguments": {
      "pdf_path": "<pdf_path>",
      "query": "<query>"
    },
    "name": "pdf_find_text"
  }
}

Input Schema

NameRequiredDescriptionDefault
pagesNoPages to search, 1-based: "1-3,5,8-". Default: all pages. At most 200 pages per call.
queryYesText to find, or a pattern when regex is true. At most 200 characters.
regexNoTreat query as a regular expression (the supported subset). Default false.
max_hitsNoStop once more hits than this exist. Default 100.
passwordNoPassword to open the input, only needed for a user-password PDF (owner-locked files with an empty user password open without it).
pdf_pathYesPDF source: a path to a .pdf file inside the allowed directories (PDFOPS_ROOT, default the working directory), an https:// URL, or a data:application/pdf;base64,… URI. Use a URL or data URI when this server runs remotely (Smithery, hosted gateways) where local paths do not exist.
whole_wordNoOnly report matches with no letter, digit, underscore or combining mark directly before or after. Default false.
case_sensitiveNoDefault false: matching ignores case.

Output Schema

NameRequiredDescriptionDefault
hitsYes
countYesHits returned
next_pageYesFirst page not fully searched, or null when finished
truncatedYesThe scan stopped before every selected page was searched; continue from next_page while it is not null; null with truncated means hits beyond max_hits on a page in pages_skipped were dropped
lines_skippedNo
pages_scannedYes
pages_skippedNo
pages_without_textYes

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.5.0

TDQS

A4.6/5.0
Behavior5/5

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

Beyond the read-only, idempotent annotations, the description discloses that the source is never modified, that scanned PDFs lack a text layer, that matches never span lines, and that regex support is limited to a safe subset with specific exclusions. It also explains pagination behavior and truncation failure modes in useful detail.

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 dense but well front-loaded: purpose first, then coordinate frame, matching semantics, regex rules, scanned-PDF limits, and pagination recovery. A few details repeat the schema, such as the case-sensitive default and the '4-' continuation syntax, but the structure remains efficient for a complex search tool.

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?

Although an output schema exists, the description still explains the useful shape of a hit: page, box, and viewer-relative coordinates. It covers the tool's meaningful complexities, including scanned-PDF limits, regex restrictions, and pagination edge cases, leaving no important invocation behavior unstated.

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 coverage is already 100%, so the schema carries most parameter documentation. The description still adds substantive meaning by enumerating the supported regex subset beyond the schema's vague 'supported subset' and by explaining how max_hits interacts with truncation and pages_skipped.

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 states a specific verb and resource: search a born-digital PDF for a word, phrase, or pattern and return each hit with page and bounding box. It distinguishes itself from extraction-style siblings by emphasizing hit locations and explicitly connects its coordinate frame to pdf_edit.

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?

It gives clear when-to-use guidance for born-digital PDFs and an explicit when-not for scanned PDFs, whose pages are listed in pages_without_text with no OCR. It also explains continuation and truncation recovery, though it does not name an alternative sibling tool for plain text extraction.

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