Skip to main content
Glama

search-pdfs

Search for PDF files in directories using pattern matching to locate specific documents quickly.

Instructions

Search for PDF files in a directory with optional pattern matching

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
base_pathYesBase directory to search in
patternNoPattern to match against filenames (e.g., 'report*.pdf')
recursiveNoWhether to search in subdirectories

Implementation Reference

  • Handler implementation for the 'search-pdfs' tool. Searches for PDF files in the specified base directory (recursively by default) matching the given filename pattern using substring matching (case-insensitive). Returns list of matching full paths.
    elif name == "search-pdfs":
        base_path = arguments.get("base_path")
        pattern = arguments.get("pattern", "*.pdf")
        recursive = arguments.get("recursive", True)
        
        if not base_path:
            raise ValueError("Missing base_path argument")
    
        # Normalize the base path to handle Windows paths
        base_path = os.path.normpath(base_path)
        found_files = []
        
        try:
            if recursive:
                for root, _, files in os.walk(base_path):
                    for filename in files:
                        # Convert both pattern and filename to lowercase for case-insensitive matching
                        if filename.lower().endswith('.pdf'):
                            # Remove the .pdf from pattern if it exists for more flexible matching
                            search_pattern = pattern.lower().replace('.pdf', '')
                            if search_pattern in filename.lower():
                                full_path = os.path.join(root, filename)
                                found_files.append(full_path)
            else:
                for file in os.listdir(base_path):
                    if file.lower().endswith('.pdf'):
                        search_pattern = pattern.lower().replace('.pdf', '')
                        if search_pattern in file.lower():
                            full_path = os.path.join(base_path, file)
                            found_files.append(full_path)
    
            return [types.TextContent(
                type="text",
                text=f"Found {len(found_files)} PDF files:\n" + 
                    "\n".join(f"- {f}" for f in found_files)
            )]
            
        except Exception as e:
            return [types.TextContent(
                type="text",
                text=f"Error searching for PDFs: {str(e)}\nBase path: {base_path}"
            )]
  • Registration of the 'search-pdfs' tool in the @server.list_tools() handler, including name, description, and input schema definition.
    types.Tool(
        name="search-pdfs",
        description="Search for PDF files in a directory with optional pattern matching",
        inputSchema={
            "type": "object",
            "properties": {
                "base_path": {
                    "type": "string",
                    "description": "Base directory to search in"
                },
                "pattern": {
                    "type": "string",
                    "description": "Pattern to match against filenames (e.g., 'report*.pdf')"
                },
                "recursive": {
                    "type": "boolean",
                    "description": "Whether to search in subdirectories",
                    "default": True
                }
            },
            "required": ["base_path"]
        }
    ),
  • Input schema for the 'search-pdfs' tool defining the parameters: base_path (required), pattern (optional, defaults to '*.pdf'), recursive (optional boolean, defaults to true).
    inputSchema={
        "type": "object",
        "properties": {
            "base_path": {
                "type": "string",
                "description": "Base directory to search in"
            },
            "pattern": {
                "type": "string",
                "description": "Pattern to match against filenames (e.g., 'report*.pdf')"
            },
            "recursive": {
                "type": "boolean",
                "description": "Whether to search in subdirectories",
                "default": True
            }
        },
        "required": ["base_path"]
    }
Behavior2/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 states the search action but lacks critical details such as permission requirements, error handling (e.g., invalid paths), performance implications (e.g., large directories), or output format (e.g., list of file paths). This is a significant gap for a tool with potential side effects like file system access.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Search for PDF files in a directory') and adds a concise modifier ('with optional pattern matching'). There is no wasted text, making it easy for an agent to parse quickly.

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 the lack of annotations and output schema, the description is incomplete. It doesn't explain what the tool returns (e.g., a list of file paths, metadata), error conditions, or behavioral nuances like recursion depth limits. For a search tool with file system interaction, this leaves the agent under-informed about critical operational aspects.

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?

The schema description coverage is 100%, so the input schema fully documents all three parameters (base_path, pattern, recursive). The description adds no additional semantic context beyond implying pattern matching, which is already covered in the schema. This meets the baseline for high schema coverage.

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 with a specific verb ('Search') and resource ('PDF files in a directory'), and includes the optional capability ('pattern matching'). It doesn't explicitly distinguish from sibling tools like 'find-related-pdfs', but the focus on file search is clear and non-tautological.

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 like 'find-related-pdfs' or other siblings. It mentions optional pattern matching but doesn't specify scenarios or exclusions, leaving the agent to infer usage from the tool name alone.

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/hanweg/mcp-pdf-tools'

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