search_package_files
Search for files across all Arch Linux packages in repositories to locate specific files or patterns within installed packages.
Instructions
Search for files across all packages in repositories. Requires package database sync (pacman -Fy). Only works on Arch Linux.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filename_pattern | Yes | File name or pattern to search for (e.g., 'vim' or '*.service') |
Implementation Reference
- src/arch_ops_server/pacman.py:771-862 (handler)The core asynchronous handler function that implements the 'search_package_files' tool. It uses the 'pacman -F' command to search for files matching the given pattern across all packages in the repositories, parses the output, and returns structured results with package and file information.async def search_package_files(filename_pattern: str) -> Dict[str, Any]: """ Search for files across all packages. Args: filename_pattern: Filename pattern to search for Returns: Dict with matching files and packages """ if not IS_ARCH: return create_error_response( "NotSupported", "Package file search is only available on Arch Linux" ) if not check_command_exists("pacman"): return create_error_response( "CommandNotFound", "pacman command not found" ) logger.info(f"Searching for files matching: {filename_pattern}") try: # First check if file database is synced exit_code, stdout, stderr = await run_command( ["pacman", "-F", filename_pattern], timeout=30, check=False ) if exit_code == 1 and "database" in stderr.lower(): return create_error_response( "DatabaseNotSynced", "Package file database not synced. Run 'sudo pacman -Fy' first.", "File database needs to be synchronized before searching" ) if exit_code != 0 and not stdout.strip(): logger.info(f"No files found matching {filename_pattern}") return { "pattern": filename_pattern, "match_count": 0, "matches": [] } # Parse output: "repository/package version\n path/to/file" matches = [] current_package = None for line in stdout.strip().split('\n'): if not line.strip(): continue if line.startswith(' '): # This is a file path if current_package: file_path = line.strip() matches.append({ "package": current_package["package"], "repository": current_package["repository"], "version": current_package["version"], "file": file_path }) else: # This is a package line: "repository/package version" parts = line.split() if len(parts) >= 2: repo_pkg = parts[0].split('/') if len(repo_pkg) == 2: current_package = { "repository": repo_pkg[0], "package": repo_pkg[1], "version": parts[1] } logger.info(f"Found {len(matches)} files matching {filename_pattern}") return { "pattern": filename_pattern, "match_count": len(matches), "matches": matches } except Exception as e: logger.error(f"File search failed: {e}") return create_error_response( "CommandError", f"Failed to search package files: {str(e)}" )
- The input schema definition for the MCP tool 'search_package_files', including the expected 'filename_pattern' parameter as a required string.Tool( name="search_package_files", description="[ORGANIZATION] Search for files across all packages in repositories. Requires package database sync (pacman -Fy). Only works on Arch Linux.", inputSchema={ "type": "object", "properties": { "filename_pattern": { "type": "string", "description": "File name or pattern to search for (e.g., 'vim' or '*.service')" } }, "required": ["filename_pattern"] } ),
- src/arch_ops_server/server.py:1274-1281 (registration)The dispatch logic in the MCP server's call_tool handler that registers and invokes the 'search_package_files' tool by calling the imported handler function with the provided arguments.elif name == "search_package_files": if not IS_ARCH: return [TextContent(type="text", text="Error: search_package_files only available on Arch Linux systems")] filename_pattern = arguments["filename_pattern"] result = await search_package_files(filename_pattern) return [TextContent(type="text", text=json.dumps(result, indent=2))]
- src/arch_ops_server/server.py:26-46 (registration)Import statement in server.py that brings the 'search_package_files' handler into scope for MCP tool registration.from . import ( # Wiki functions search_wiki, get_wiki_page_as_text, # AUR functions search_aur, get_aur_info, get_pkgbuild, analyze_pkgbuild_safety, analyze_package_metadata_risk, install_package_secure, # Pacman functions get_official_package_info, check_updates_dry_run, remove_package, remove_packages_batch, list_orphan_packages, remove_orphans, find_package_owner, list_package_files, search_package_files,
- ToolMetadata entry providing categorization, platform requirements, permissions, workflow, and related tools for 'search_package_files'."search_package_files": ToolMetadata( name="search_package_files", category="organization", platform="arch", permission="read", workflow="search", related_tools=["list_package_files", "find_package_owner"], prerequisite_tools=[]