4 min read

Amazon S3 interactive PDF extraction with MCP server

Run a local MCP server to extract text from text-based PDFs in Amazon S3 on demand; Amazon Textract is still recommended for OCR and.

The Brieftide

TL;DR

  • 01Run a local MCP server to extract text from text-based PDFs in Amazon S3 on demand; Amazon Textract is still recommended for OCR and.
  • 02An MCP-based server called s3-pdf-extractor lets you pull text from text-based PDFs stored in Amazon S3 in real time, without batch pipelines.
  • 03The solution connects a command-line client, the Model Context Protocol (MCP), a Python MCP server and Amazon S3 (with IAM), returning extracted text to the client on demand.

An MCP-based server called s3-pdf-extractor lets you pull text from text-based PDFs stored in Amazon S3 in real time, without batch pipelines. The solution connects a command-line client, the Model Context Protocol (MCP), a Python MCP server and Amazon S3 (with IAM), returning extracted text to the client on demand.

How does the solution work?

The system uses four components: a CLI user interface, the MCP layer for communication, a custom MCP server that fetches and parses PDFs, and Amazon S3 for storage protected by AWS IAM. The MCP server downloads the specified S3 object to a temporary file, extracts text with PyPDF2, returns a TextContent response and then removes the temp file.

Under the hood the code example registers a tool named extract_s3_pdf_text and implements a call_tool handler that uses boto3 to download the PDF, PyPDF2.PdfReader to extract page text, and mcp.types.TextContent to return the extracted content. The repository name used in the example is s3-pdf-extractor and the server is started with python s3_pdf_extractor.py.

How does this compare with Amazon Textract?

For text-based PDFs in development or proof of concept work the MCP server approach is far cheaper and simpler; for scanned documents, OCR, forms, tables or production SLAs use Amazon Textract. The post gives an indicative cost example for approximately 10,000 text-based PDF pages per month: Textract-related costs are listed as approximately $15 for Textract processing, $2 for Amazon S3 storage, $1 for AWS Lambda compute, and $5 to $10 for LLM token processing, totaling approximately $23 to $28 per month.

By contrast the MCP server example lists an indicative monthly cost of Amazon S3 storage $2 and data transfer $0.50, for a total of approximately $2.50. The post emphasizes these figures are illustrative and not a strict head-to-head comparison; Textract covers OCR, advanced form and table extraction and enterprise SLAs, while the MCP option handles direct text extraction where the PDF already encodes text.

What do you need to run it?

You need an AWS account with S3 read permissions, Python 3.10 or later, AWS CLI configured credentials, and the Kiro CLI installed and logged in. The example commands include creating a virtual environment, then pip install mcp boto3 PyPDF2, creating s3_pdf_extractor.py with the provided MCP server code, and adding a Kiro CLI MCP configuration entry pointing to the server command.

The implementation example shows how the MCP server lists the extract_s3_pdf_text tool (with a JSON input schema requiring bucket and key), downloads the file with boto3.client('s3').download_file, extracts text by iterating reader.pages and calling page.extract_text(), and returns the text as TextContent. The server logs successes and errors and ensures temporary files are cleaned up.

Why it matters

Interactive, on-demand access to document text removes the latency of batch pipelines for time-sensitive tasks such as audits, legal lookups or meeting queries. The MCP server pattern gives an AI assistant direct programmatic access to S3-hosted, text-encoded PDFs with minimal infrastructure and clear IAM-based permissioning, making small-scale interactive workflows much faster and cheaper than routing everything through a managed document-processing service.

What to watch

Check whether your PDFs are text-encoded or scanned: if PDFs require OCR, the guidance is explicit to use Amazon Textract. Also watch for any production needs for SLAs or advanced extraction (forms, tables, handwriting); those are listed as Textract use cases in the post. A concrete next milestone is validating the pattern on your dataset at the sample scale used in the example: roughly 10,000 pages per month to compare costs and capabilities.

MCP-based PDF extraction architecture
Command-line client (Kiro CLI)MCP layerMCP server (s3-pdf-extractor)PDF parsing component (PyPDF2)Amazon S3 (bucket/object)AWS IAM (permissions)
Advertisement

Written by The Brieftide · Source: AWS Machine Learning

The Brieftide Daily · 06:00

Briefs like this one, in your inbox every morning.

 

FreeOne email a dayEvery claim sourcedUnsubscribe in one click
Advertisement