Skip to main content
Glama

Extract text and tables from a PDF

pdf_extract_text
DestructiveIdempotent

Extract page-by-page text and tables from born-digital PDFs in reading order, with optional line positions; scanned PDFs without a text layer are listed but not OCR'd.

Instructions

Read the text of a born-digital PDF (one made by software: invoices, statements, reports, contracts, forms), page by page, in reading order, plus any tables found from the text layout as rows of cells. Scanned PDFs (images of pages) have no text layer and come back listed in pages_without_text: OCR is not supported. Set include_lines to also get each line with its position in PDF points from the bottom-left of the page as the viewer sees it, the same frame pdf_edit uses, so you can stamp text next to something you found. Up to 200 pages per call; pass pages to read a large document in parts. To search for specific text instead, use pdf_find_text. With tables_format xlsx the tables come back as one Excel workbook instead (one sheet per table, all cells text): written to output_path (a .xlsx file) when given, otherwise returned inline as an application/vnd.openxmlformats-officedocument.spreadsheetml.sheet resource (a workbook over 7 MB is never returned inline: pass output_path). The source PDF is never modified; output_path is only written with tables_format xlsx.

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>"
    },
    "name": "pdf_extract_text"
  }
}

Input Schema

NameRequiredDescriptionDefault
pagesNoPages to read, 1-based: "1-3,5,8-". Default: all pages.
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.
output_pathNoOnly with tables_format xlsx: path of a .xlsx file to write the workbook to, inside the allowed directories (PDFOPS_ROOT, default the working directory); an existing file there is overwritten. Omit when running remotely: the workbook is then returned inline as a resource for the client to save.
include_linesNoAlso return every line of text with x, y, width and font size in points. Default false (smaller output).
tables_formatNocsv adds a csv string (RFC 4180, CRLF line ends) to each table next to rows. xlsx instead returns one Excel workbook, one sheet per table ("Page 3 Table 1"), with a short summary (no text, lines or rows); every cell is a text string, never a formula, and numbers are not converted. xlsx fails with no_tables when the pages read have no table (if the read stopped early the error says so and names the pages value to continue with). Default json. In csv cell values are returned verbatim: a cell starting with = + - or @ can run as a formula if the CSV is opened in a spreadsheet, so sanitise before opening.

Output Schema

NameRequiredDescriptionDefault
bytesNoOnly with tables_format=xlsx: size of the workbook
pagesNo
truncatedNo
page_countNoPages in the document
output_pathNoOnly with tables_format=xlsx: absolute path written, when output_path was supplied
resource_uriNoOnly with tables_format=xlsx: where the workbook resource is attached, when output_path was omitted
truncated_byNoOnly with tables_format=xlsx and truncated: which cap stopped the read or cut the workbook
cells_truncatedNoOnly with tables_format=xlsx: a cell over 32,767 characters was cut
pages_without_textNo

Schema Changelog

Changes observed during successful MCP inspections.

  1. Addedv0.5.0

TDQS

A4.8/5.0
Behavior5/5

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

Goes well past the annotations: it discloses the 200-page limit, the 7 MB inline-resource cap, that the source PDF is never modified, and that output_path is the only write target and only under tables_format xlsx — which reconciles the destructiveHint=true. It also warns that CSV output is subject to formula injection, a behavior an agent could not infer from structured fields.

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?

Front-loads purpose before the xlsx conditional and ends on the safety-relevant note about the source file, so the ordering is sensible. It is, however, one dense paragraph with stacked parentheticals that could be split into three shorter sentences for easier scanning; almost no wording is pure waste.

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?

For a six-parameter tool with an output schema, the description covers the gaps the schema cannot: what counts as a supported input, pagination strategy, the inline-vs-file fork, and the no_tables error. Nothing an agent needs in order to call it correctly is missing.

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 100%, so the baseline is 3, and the description genuinely adds meaning on top: include_lines is explained as positions in PDF points from the bottom-left frame shared with pdf_edit, with the concrete use case of stamping text next to a found element. The xlsx branch explains where the workbook lands and when it comes back as a resource instead, though the pages/password parameters get no additional prose.

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?

States a specific verb and resource (extract text + tables from a PDF), scopes it to born-digital PDFs with examples of document types, and explicitly differentiates from the sibling search tool pdf_find_text. The scanned-PDF exclusion is stated in the same breath, so an agent can immediately tell whether this tool applies.

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

Usage Guidelines5/5

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

Gives explicit routing: use pdf_find_text when searching for specific text, pass pages to chunk a large document, omit output_path when running remotely. It also names the failure condition (xlsx with no tables raises no_tables) and the size ceiling (200 pages), which tells the agent when to change approach rather than guess.

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