Skip to main content
Glama
gscfwid

NCCN Guidelines MCP Server

by gscfwid

extract_content

Extract text from specific pages of PDF files containing NCCN clinical guidelines to access precise content without searching entire documents.

Instructions

Extract content from specific pages of a PDF file.

Args:
    pdf_path: Path to the PDF file (relative to the downloads directory or absolute path)
    pages: Comma-separated page numbers to extract (e.g., "1,3,5-7"). 
           If not specified, extracts all pages. Supports negative indexing (-1 for last page).

Returns:
    Extracted text content from the specified pages

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pdf_pathYes
pagesNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • MCP tool handler for 'extract_content'. This is the main async function registered via @mcp.tool() that handles the tool execution, resolves the PDF path, delegates to PDFReader, and returns the extracted content.
    @mcp.tool()
    async def extract_content(pdf_path: str, pages: Optional[str] = None) -> str:
        """
        Extract content from specific pages of a PDF file.
        
        Args:
            pdf_path: Path to the PDF file (relative to the downloads directory or absolute path)
            pages: Comma-separated page numbers to extract (e.g., "1,3,5-7"). 
                   If not specified, extracts all pages. Supports negative indexing (-1 for last page).
        
        Returns:
            Extracted text content from the specified pages
        """
        try:
            # Resolve PDF path
            if not os.path.isabs(pdf_path):
                # Try relative to downloads directory first
                download_path = current_dir / DOWNLOAD_DIR / pdf_path
                if download_path.exists():
                    pdf_path = str(download_path)
                else:
                    # Try relative to current directory
                    current_path = current_dir / pdf_path
                    if current_path.exists():
                        pdf_path = str(current_path)
                    else:
                        logger.error(f"PDF file not found: {pdf_path}")
                        return f"PDF file not found: {pdf_path}"
            
            # Extract content using PDFReader
            content = pdf_reader.extract_content(pdf_path, pages)
            
            if not content.strip():
                logger.warning(f"No content extracted from {pdf_path} (pages: {pages or 'all'})")
                return f"No content extracted from {pdf_path} (pages: {pages or 'all'})"
            
            logger.info(f"Successfully extracted content from {pdf_path} (pages: {pages or 'all'})")
            return content
        
        except Exception as e:
            logger.error(f"Error extracting content from PDF: {str(e)}")
            return f"Error extracting content from PDF: {str(e)}"
  • Core helper function in PDFReader class that performs the actual PDF parsing, extracts text with layout preservation, internal links, and formats the content from specified pages.
    def extract_content(self, pdf_path: str, pages: Optional[str] = None) -> str:
        """Main method for extracting PDF content with internal links"""
        if not pdf_path:
            raise ValueError("PDF path cannot be empty")
    
        try:
            logger.info(f"Starting PDF content extraction from: {pdf_path}")
            
            # Open PDF with pypdf
            self.reader = PdfReader(pdf_path)
            total_pages = len(self.reader.pages)
            
            # Build xref to page mapping
            self.build_xref_to_page_mapping(self.reader)
            
            # Build named destinations mapping
            self.build_named_destinations_mapping(self.reader)
            
            selected_pages = self.parse_pages(pages, total_pages)
            
            logger.info(f"PDF has {total_pages} pages, extracting pages: {[p+1 for p in selected_pages]}")
            
            extracted_contents = []
            
            for page_num in selected_pages:
                if page_num < len(self.reader.pages):
                    page = self.reader.pages[page_num]
                    content = self.extract_page_content(page, page_num)
                    formatted_content = self.format_page_content(content)
                    extracted_contents.append(formatted_content)
                    logger.debug(f"Extracted content from page {page_num + 1}")
            
            logger.info(f"Successfully extracted content from {len(extracted_contents)} pages")
            return "\n\n".join(extracted_contents)
                
        except Exception as e:
            logger.error(f"Failed to extract PDF content: {str(e)}")
            raise ValueError(f"Failed to extract PDF content: {str(e)}")
  • server.py:59-59 (registration)
    Initialization of the FastMCP server instance where tools are registered via decorators.
    mcp = FastMCP("nccn-guidelines")
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It explains the extraction process and return value ('Extracted text content'), but lacks details on error handling, performance limits, or authentication needs. It does not contradict annotations, but offers only basic operational context.

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 well-structured with a clear purpose statement, parameter explanations, and return value. It is front-loaded and efficient, though the parameter details could be slightly more concise. Every sentence adds value without redundancy.

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?

Given the tool's moderate complexity, no annotations, and an output schema present, the description is fairly complete. It covers purpose, parameters, and returns, but lacks usage guidelines and deeper behavioral context. The output schema reduces the need to explain return values in detail.

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

Parameters5/5

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

The description adds significant meaning beyond the input schema, which has 0% description coverage. It clarifies 'pdf_path' as a path relative to downloads or absolute, and details 'pages' with examples, default behavior, and support for negative indexing. This fully compensates for the schema's lack of descriptions.

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 tool's purpose: 'Extract content from specific pages of a PDF file.' It specifies the verb ('extract') and resource ('content from PDF'), but does not explicitly differentiate from sibling tools like 'download_pdf' or 'get_index', which likely serve different purposes (downloading files and indexing content).

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. It mentions that pages can be specified or all pages extracted, but does not indicate scenarios where this tool is preferred over siblings like 'get_index' or 'download_pdf', nor does it outline prerequisites or exclusions.

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/gscfwid/NCCN_guidelines_MCP'

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