Skip to main content
Glama

search-pdfs

Locate PDF files in a directory using pattern matching for filenames. Supports recursive searches through subdirectories for efficient file discovery.

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

  • The execution handler for the 'search-pdfs' tool. It searches for PDF files in the specified base_path (recursively by default) matching the given pattern (default '*.pdf'), using substring matching on filenames.
    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 within the @server.list_tools() response, 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 definition for the 'search-pdfs' tool, specifying parameters: base_path (required), pattern, recursive.
    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"] }

Other Tools

Related 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