Skip to main content
Glama

Embed files in a PDF

pdf_add_attachment
DestructiveIdempotent

Embed XML, CSV, or other files in a PDF as attachments from local paths, https URLs, or data URIs while preserving existing content and returning the updated PDF.

Instructions

Embed one or more files (for example an XML or CSV data file) in a PDF as attachments. Each entry in files has a source (a local path, an https:// URL or a data: URI with base64) and optional name, mime_type, description (at most 1,000 characters) and relationship (Alternative, Data, Source, Supplement or Unspecified, default Unspecified; the PDF/A-3 AFRelationship value). A local path must end in .xml, .csv, .json, .txt, .md, .html, .xlsx, .pdf, .png, .jpg or .jpeg and lie inside the allowed directories (PDFOPS_ROOT, default the working directory). name is 1-255 characters and at most 255 UTF-8 bytes with no / or backslash or control characters, and defaults to the file name of a path or the last part of an https:// URL path (a data: URI needs a name). mime_type looks like text/xml, with no parameters and no #. At most 10 files and 3 MB in total per call, and at most 200 attachments in the finished PDF. A PDF whose list of embedded files has over 2,000 entries (name_tree_too_large) or an unreadable existing name (attachments_too_complex) is refused. A name already used by an attachment in the PDF (as a key or as an entry's /UF or /F), or twice in the call, is refused. Existing content, including any existing attachments, is kept. Each file keeps its full name; the lookup key for qpdf --show-attachment is plain ASCII and is returned in the result as keys. Unknown keys are rejected. The whole file is saved again, so an existing digital signature on the PDF stops validating. Returns the result written to output_path, or inline as an application/pdf resource when output_path is omitted (results over 7 MB are never returned inline: pass output_path); an existing file at output_path is overwritten. 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>",
      "files": "<files>"
    },
    "name": "pdf_add_attachment"
  }
}

Input Schema

NameRequiredDescriptionDefault
filesYesFiles to embed. Nothing is added unless every entry is valid.
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_pathNoPath of a .pdf file to write the result to, inside the allowed directories (PDFOPS_ROOT, default the working directory); an existing file there is overwritten. Omit when running remotely: the PDF is then returned inline as an application/pdf resource for the client to save.

Output Schema

NameRequiredDescriptionDefault
keysNoOne entry per added file, in order: the ASCII key for qpdf --show-attachment (qpdf --list-attachments shows it)
bytesYesSize of the produced PDF in bytes
output_pathNoAbsolute path written, when output_path was supplied
resource_uriNopdfops:// uri of the inline application/pdf resource, when output_path was omitted

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?

Annotations (destructiveHint=true, idempotentHint=true, openWorldHint=true) set expectations, and the description goes well beyond them: existing content and attachments are kept, an existing digital signature stops validating, output_path is overwritten, the source is never modified, and atomicity is implied via the schema note. It also enumerates refusal conditions (name collisions, name_tree_too_large, attachments_too_complex) and hard limits (10 files, 3 MB, 200 attachments, 7 MB inline cap).

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?

Purpose is front-loaded and no sentence is filler, but the body is one dense block paragraph that intermixes validation rules, limits and return behavior, which makes it harder to scan than a short bulleted structure would be. Slightly overlong for a single field, though the complexity justifies much of it.

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?

Covers everything an agent needs before calling a mutation tool: source forms, validation rules, limits, collision behavior, signature invalidation, output destination and overwrite semantics. An output schema exists, yet the description still clarifies the inline-versus-output_path return tradeoff and the 7 MB threshold, leaving no meaningful gap.

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 schema already carries the baseline; the description nonetheless adds real meaning: the meaning of the relationship enum (PDF/A-3 AFRelationship) and its default, the 255-UTF-8-byte and no-slash/control-character constraints on name, default naming rules for paths, URLs and data URIs, and the mime_type format rule (no parameters, no '#').

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?

Opens with a specific verb and resource: 'Embed one or more files ... in a PDF as attachments.' No sibling tool touches attachments, so the operation is unambiguous, and the parenthetical example (XML/CSV data files) anchors the intent further.

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?

Gives concrete operating guidance: local paths must be under PDFOPS_ROOT and use an allowed extension, and URLs/data URIs are the alternative when the server runs remotely. It also explains when to pass output_path versus omitting it for an inline resource. It stops short of explicitly naming sibling alternatives, but none exist for this capability.

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