Skip to main content
Glama

Find File

find_file
Read-only

Search for files matching a specific pattern while automatically excluding gitignored files. Use wildcards to locate files in any directory of your project.

Instructions

Finds non-gitignored files matching the given file mask within the given relative path. Returns a JSON object with the list of matching files.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
file_maskYesThe filename or file mask (using the wildcards * or ?) to search for.
relative_pathYesThe relative path to the directory to search in; pass "." to scan the project root.

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • The FindFileTool class provides the core handler logic for the 'find_file' tool, implementing the apply method that searches for files matching a given mask in a directory using fnmatch and scan_directory, returning a JSON list of matches.
    class FindFileTool(Tool):
        """
        Finds files in the given relative paths
        """
    
        def apply(self, file_mask: str, relative_path: str) -> str:
            """
            Finds non-gitignored files matching the given file mask within the given relative path
    
            :param file_mask: the filename or file mask (using the wildcards * or ?) to search for
            :param relative_path: the relative path to the directory to search in; pass "." to scan the project root
            :return: a JSON object with the list of matching files
            """
            self.project.validate_relative_path(relative_path, require_not_ignored=True)
    
            dir_to_scan = os.path.join(self.get_project_root(), relative_path)
    
            # find the files by ignoring everything that doesn't match
            def is_ignored_file(abs_path: str) -> bool:
                if self.project.is_ignored_path(abs_path):
                    return True
                filename = os.path.basename(abs_path)
                return not fnmatch(filename, file_mask)
    
            _dirs, files = scan_directory(
                path=dir_to_scan,
                recursive=True,
                is_ignored_dir=self.project.is_ignored_path,
                is_ignored_file=is_ignored_file,
                relative_to=self.get_project_root(),
            )
    
            result = self._to_json({"files": files})
            return result
  • The get_name_from_cls method in the Tool base class derives the tool name 'find_file' from the class name 'FindFileTool' by removing 'Tool' suffix and converting to snake_case.
    @classmethod
    def get_name_from_cls(cls) -> str:
        name = cls.__name__
        if name.endswith("Tool"):
            name = name[:-4]
        # convert to snake_case
        name = "".join(["_" + c.lower() if c.isupper() else c for c in name]).lstrip("_")
        return name
  • The ToolRegistry scans all subclasses of Tool in the serena.tools package and registers them by their derived name, including FindFileTool as 'find_file'.
    if not any(cls.__module__.startswith(pkg) for pkg in tool_packages):
        continue
    is_optional = issubclass(cls, ToolMarkerOptional)
    name = cls.get_name_from_cls()
    if name in self._tool_dict:
        raise ValueError(f"Duplicate tool name found: {name}. Tool classes must have unique names.")
    self._tool_dict[name] = RegisteredTool(tool_class=cls, is_optional=is_optional, tool_name=name)
  • The __init__.py file imports all tool modules, exposing FindFileTool for use and discovery by the ToolRegistry.
    # ruff: noqa
    from .tools_base import *
    from .file_tools import *
    from .symbol_tools import *
    from .memory_tools import *
    from .cmd_tools import *
    from .config_tools import *
    from .workflow_tools import *
    from .jetbrains_tools import *
Behavior3/5

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

Annotations already declare readOnlyHint=true and destructiveHint=false, indicating a safe read operation. The description adds useful behavioral context by specifying 'non-gitignored files' (exclusion behavior) and the return format ('JSON object with the list of matching files'), but does not mention potential limitations like recursion depth or performance implications.

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 functionality and includes essential details (exclusion of gitignored files, return format) without any wasted words.

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

Completeness5/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, rich annotations (readOnlyHint, destructiveHint), 100% schema coverage, and presence of an output schema, the description is complete enough. It covers purpose, key behavioral trait (non-gitignored), and return format, leaving detailed parameter and output documentation to the structured fields.

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?

Schema description coverage is 100%, with both parameters well-documented in the schema. The description adds minimal value beyond the schema by implying the search scope and exclusion of gitignored files, but does not provide additional syntax or format details for the parameters.

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

Purpose5/5

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

The description clearly states the specific action ('Finds'), resource ('non-gitignored files'), and scope ('matching the given file mask within the given relative path'), distinguishing it from siblings like 'list_dir' (which lists directory contents) and 'search_for_pattern' (which searches file content).

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (searching for files by name/mask, excluding gitignored files), but does not explicitly state when not to use it or name alternatives like 'list_dir' for directory listing or 'search_for_pattern' for content search.

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/oraios/serena'

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