Skip to main content
Glama

Summarize PDF

summarize
Read-onlyIdempotent

Generate a quick overview of any PDF document, including page count, file size, text presence, image count, and a text preview from the first page. Use it as a first step to decide which detailed tools to apply next.

Instructions

Generate a quick overview report of a PDF document.

Combines metadata, text presence check, image count, and a text preview from the first page into a single summary. Useful as a first step before deciding which detailed tools to use.

Args:

  • file_path (string): Absolute path to a local PDF file

  • response_format ('markdown' | 'json'): Output format (default: 'markdown')

Returns: Summary including: page count, PDF version, file size, tagged/encrypted/signature flags, text presence, image count, and a text preview from page 1.

Examples:

  • Quick overview: { file_path: "/path/to/doc.pdf" }

  • Machine-readable: { file_path: "/path/to/doc.pdf", response_format: "json" }

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_pathYesAbsolute path to a local PDF file (e.g., "/path/to/document.pdf")
response_formatNoOutput format: "markdown" for human-readable, "json" for structured datamarkdown

Implementation Reference

  • Main handler function for the 'summarize' tool. Registers the tool with the MCP server, loads a PDF document, extracts metadata, text preview (first 500 chars), and image count, then returns the result as either markdown or JSON.
    export function registerSummarize(server: McpServer): void {
      server.registerTool(
        'summarize',
        {
          title: 'Summarize PDF',
          description: `Generate a quick overview report of a PDF document.
    
    Combines metadata, text presence check, image count, and a text preview from the first page into a single summary. Useful as a first step before deciding which detailed tools to use.
    
    Args:
      - file_path (string): Absolute path to a local PDF file
      - response_format ('markdown' | 'json'): Output format (default: 'markdown')
    
    Returns:
      Summary including: page count, PDF version, file size, tagged/encrypted/signature flags, text presence, image count, and a text preview from page 1.
    
    Examples:
      - Quick overview: { file_path: "/path/to/doc.pdf" }
      - Machine-readable: { file_path: "/path/to/doc.pdf", response_format: "json" }`,
          inputSchema: SummarizeSchema,
          annotations: {
            readOnlyHint: true,
            destructiveHint: false,
            idempotentHint: true,
            openWorldHint: false,
          },
        },
        async (params: SummarizeInput) => {
          try {
            // Load the PDF document once and reuse for all operations
            const doc = await loadDocument(params.file_path);
    
            try {
              const [metadata, firstPageTexts, imageCount] = await Promise.all([
                getMetadataFromDoc(doc, params.file_path),
                extractTextFromDoc(doc, '1'),
                countImagesFromDoc(doc),
              ]);
    
              const textPreview = firstPageTexts[0]?.text?.slice(0, 500) ?? '';
              const hasText = textPreview.trim().length > 0;
    
              const summary: PdfSummary = {
                filePath: params.file_path,
                metadata,
                textPreview,
                imageCount,
                hasText,
              };
    
              const text =
                params.response_format === ResponseFormat.JSON
                  ? JSON.stringify(summary, null, 2)
                  : formatSummaryMarkdown(summary);
    
              return {
                content: [{ type: 'text' as const, text }],
              };
            } finally {
              await doc.destroy();
            }
          } catch (error) {
            const err = handleStructuredError(error);
            return {
              content: [{ type: 'text' as const, text: JSON.stringify(err, null, 2) }],
              isError: true,
            };
          }
        },
      );
    }
  • Zod schema for the summarize tool input. Defines file_path (string) and response_format ('markdown' | 'json') as required parameters.
    /** summarize */
    export const SummarizeSchema = z
      .object({
        file_path: FilePathSchema,
        response_format: ResponseFormatSchema,
      })
      .strict();
  • Import of registerSummarize in the central tool registration file.
    import { registerSummarize } from './tier1/summarize.js';
  • Call to registerSummarize(server) from the central registerAllTools function.
    registerSummarize(server);
  • Helper function formatSummaryMarkdown that formats the PdfSummary object into a Markdown table with properties like page count, PDF version, file size, tagged/encrypted/signature flags, text presence, image count, and a text preview from the first page.
    export function formatSummaryMarkdown(summary: PdfSummary): string {
      const meta = summary.metadata;
      const lines: string[] = [
        `# PDF Summary`,
        '',
        `| Property | Value |`,
        `|---|---|`,
        `| Pages | ${meta.pageCount} |`,
        `| PDF Version | ${meta.pdfVersion ?? 'Unknown'} |`,
        `| File Size | ${formatFileSize(meta.fileSize)} |`,
        `| Tagged | ${meta.isTagged ? 'Yes' : 'No'} |`,
        `| Encrypted | ${meta.isEncrypted ? 'Yes' : 'No'} |`,
        `| Signatures | ${meta.hasSignatures ? 'Yes' : 'No'} |`,
        `| Has Text | ${summary.hasText ? 'Yes' : 'No'} |`,
        `| Images | ${summary.imageCount} |`,
      ];
    
      if (meta.title) lines.push(`| Title | ${meta.title} |`);
      if (meta.author) lines.push(`| Author | ${meta.author} |`);
    
      if (summary.textPreview) {
        lines.push('', '## Text Preview (first page)', '', summary.textPreview);
      }
    
      return lines.join('\n');
Behavior3/5

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

Annotations already declare readOnlyHint=true, destructiveHint=false, idempotentHint=true. Description adds that it combines several analyses (metadata, text, images) but doesn't contradict annotations or add surprising behaviors. Adequate for a safe read tool.

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?

Structured with summary, details, Args, Returns, Examples. Front-loaded with purpose. Efficient but not overly terse; every section earns its place.

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

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite no output schema, description fully lists return value components. With 100% schema coverage and clear usage guidance, the tool is well-documented for an AI agent.

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?

Input schema has 100% coverage with detailed descriptions for both parameters. Description's Args section echoes schema info with default and enum values, but adds no new meaning beyond what schema provides.

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?

Title and first sentence clearly state the tool generates a quick overview report. Description includes specific elements (metadata, text presence, image count, text preview) and differentiates from siblings by stating it's a first step before using detailed tools.

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?

Explicitly says 'Useful as a first step before deciding which detailed tools to use', which implies context and alternatives. Examples show typical usage. Lacks explicit when-not-to-use but is clear enough.

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/shuji-bonji/pdf-reader-mcp'

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