Skip to main content
Glama
xraywu

PDF Extraction MCP Server

by xraywu

extract-pdf-contents

Extract text content from local PDF files with optional page selection, supporting both standard PDF reading and OCR capabilities.

Instructions

Extract contents from a local PDF file, given page numbers separated in comma. Negative page index number supported.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
pagesNo

Implementation Reference

  • Handler logic for 'extract-pdf-contents' tool: validates arguments, instantiates PDFExtractor, calls extract_content, and returns the extracted text as TextContent.
    if name == "extract-pdf-contents":
        if not arguments:
            raise ValueError("Missing arguments")
    
        pdf_path = arguments.get("pdf_path")
        pages = arguments.get("pages")
    
        if not pdf_path:
            raise ValueError("Missing file path")
    
    
        extractor = PDFExtractor()
        extracted_text = extractor.extract_content(pdf_path, pages)
        return [
            types.TextContent(
                type="text",
                text=extracted_text,
            )
        ]
  • Input schema for 'extract-pdf-contents': requires 'pdf_path' string, optional 'pages' string for comma-separated page numbers.
    inputSchema={
        "type": "object",
        "properties": {
            "pdf_path": {"type": "string"},
            "pages": {"type": "string"},
        },
        "required": ["pdf_path"],
    },
  • Registers the 'extract-pdf-contents' tool in the MCP server's list_tools handler, including name, description, and input schema.
    @server.list_tools()
    async def handle_list_tools() -> list[types.Tool]:
        """
        Tools for PDF contents extraction
        """
        return [
            types.Tool(
                name="extract-pdf-contents",
                description="Extract contents from a local PDF file, given page numbers separated in comma. Negative page index number supported.",
                inputSchema={
                    "type": "object",
                    "properties": {
                        "pdf_path": {"type": "string"},
                        "pages": {"type": "string"},
                    },
                    "required": ["pdf_path"],
                },
            )
        ]
  • Core helper method in PDFExtractor class that performs the actual PDF content extraction, supporting both text-based and scanned (OCR) PDFs, with page parsing.
    def extract_content(self, pdf_path: str, pages: Optional[str]) -> List[str]:
        """提取PDF内容的主方法"""
        if not pdf_path:
            raise ValueError("PDF路径不能为空")
    
        try:
            # 检查是否为扫描件
            is_scanned = self.is_scanned_pdf(pdf_path)
            
            # 解析页码
            reader = PdfReader(pdf_path)
            total_pages = len(reader.pages)
            selected_pages = self.parse_pages(pages, total_pages)
            
            # 根据PDF类型选择提取方式
            if is_scanned:
                text = self.extract_text_from_scanned(pdf_path, selected_pages)
            else:
                text = self.extract_text_from_normal(pdf_path, selected_pages)
                
            return text
        except Exception as e:
            raise ValueError(f"提取PDF内容失败: {str(e)}")
Behavior2/5

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

No annotations are provided, so the description carries the full burden. It states the tool extracts contents but doesn't disclose behavioral traits such as what format the extracted contents are in (e.g., text, images), error handling, permissions needed for local file access, or performance considerations. The mention of negative page indices adds some context but is insufficient for a mutation-like operation.

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 brief and to the point with two sentences, front-loading the main action. It avoids unnecessary words, though it could be slightly more structured (e.g., separating parameter explanations).

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

Completeness2/5

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

Given no annotations, 0% schema coverage, and no output schema, the description is incomplete. It lacks details on return values, error cases, file format support, and operational constraints, making it inadequate for a tool that interacts with local files and performs extraction.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, so the description must compensate. It explains that 'pages' accepts 'page numbers separated in comma' and supports 'negative page index number', which adds meaning for one parameter. However, it doesn't clarify 'pdf_path' (e.g., file path format, supported locations) or other details, leaving gaps for the 2 parameters overall.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the verb 'extract' and the resource 'contents from a local PDF file', making the purpose understandable. It specifies the scope of extraction (by page numbers) but doesn't distinguish from siblings since none exist, so it cannot achieve a perfect score of 5.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or exclusions. It mentions 'negative page index number supported' which hints at a feature but doesn't clarify usage context or limitations.

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/xraywu/mcp-pdf-extraction-server'

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