Skip to main content
Glama

Local file finder

find_files

Search for local files by name or glob pattern under the allowed root directory, with optional subdirectory and maximum results.

Instructions

Find local files by name under the allowed root. The default root is ~/Desktop. Set NANOMCP_FILE_ROOT to change it.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesFilename substring or glob pattern, such as *.pdf.
rootNoOptional subdirectory under NANOMCP_FILE_ROOT.
max_resultsNo

Implementation Reference

  • Main handler function for the 'find_files' tool. Takes arguments dict, extracts 'query' (required), 'root' (optional subdirectory), and 'max_results' (default 20, clamped 1-100). Walks the filesystem under the allowed root using os.walk, supports glob patterns if query contains wildcards (*?[]), otherwise does substring matching. Skips .git, __pycache__, node_modules, and dot-directories. Returns formatted file list or stops early when max_results or 20,000 file scan limit is reached.
    def find_files(arguments: dict[str, Any]) -> str:
        query = str(arguments.get("query", "")).strip()
        if not query:
            raise ToolError("query is required")
    
        root = search_root(arguments.get("root"))
        max_results = clamp_int(arguments.get("max_results", 20), 1, 100)
        query_lower = query.lower()
        use_glob = any(char in query for char in "*?[]")
    
        matches: list[str] = []
        visited = 0
        limit = 20_000
    
        for current, dirs, files in os.walk(root):
            dirs[:] = [
                d
                for d in dirs
                if d not in {".git", "__pycache__", "node_modules"}
                and not d.startswith(".")
            ]
            visited += len(files)
    
            for filename in files:
                filename_lower = filename.lower()
                if use_glob:
                    ok = fnmatch.fnmatch(filename_lower, query_lower)
                else:
                    ok = query_lower in filename_lower
                if ok:
                    path = Path(current) / filename
                    matches.append(str(path))
                    if len(matches) >= max_results:
                        return format_file_matches(query, root, matches, truncated=True)
    
            if visited >= limit:
                return format_file_matches(query, root, matches, truncated=True)
    
        return format_file_matches(query, root, matches, truncated=False)
  • Helper function 'allowed_root' that returns the base directory for file searches. Defaults to ~/Desktop, overridable via NANOMCP_FILE_ROOT environment variable.
    def allowed_root() -> Path:
        default_root = Path.home() / "Desktop"
        configured = os.environ.get("NANOMCP_FILE_ROOT", str(default_root))
        return Path(configured).expanduser().resolve()
  • Helper function 'search_root' that resolves and validates the root directory for a search. Ensures the target root is within the allowed root (prevents path traversal). Checks existence and directory status.
    def search_root(root_arg: Any) -> Path:
        base = allowed_root()
        if root_arg is None or str(root_arg).strip() == "":
            root = base
        else:
            candidate = Path(str(root_arg)).expanduser()
            root = candidate if candidate.is_absolute() else base / candidate
            root = root.resolve()
    
        try:
            root.relative_to(base)
        except ValueError as exc:
            raise ToolError(f"root must be inside allowed root: {base}") from exc
    
        if not root.exists():
            raise ToolError(f"root does not exist: {root}")
        if not root.is_dir():
            raise ToolError(f"root is not a directory: {root}")
        return root
  • Helper function 'format_file_matches' that formats the list of matching files into a human-readable string, optionally noting if results were truncated.
    def format_file_matches(
        query: str,
        root: Path,
        matches: list[str],
        truncated: bool,
    ) -> str:
        if not matches:
            return f"No files matching {query!r} under {root}."
    
        lines = [f"Files matching {query!r} under {root}:"]
        lines.extend(f"- {path}" for path in matches)
        if truncated:
            lines.append("- Search stopped after reaching the result or scan limit.")
        return "\n".join(lines)
  • Tool registration entry in the TOOLS list. Defines the 'find_files' tool with name, title, description, and inputSchema (query required string/glob, optional root string, optional max_results integer with min=1 max=100 default=20).
    {
        "name": "find_files",
        "title": "Local file finder",
        "description": (
            "Find local files by name under the allowed root. The default root is "
            "~/Desktop. Set NANOMCP_FILE_ROOT to change it."
        ),
        "inputSchema": {
            "type": "object",
            "properties": {
                "query": {
                    "type": "string",
                    "description": "Filename substring or glob pattern, such as *.pdf.",
                },
                "root": {
                    "type": "string",
                    "description": "Optional subdirectory under NANOMCP_FILE_ROOT.",
                },
                "max_results": {
                    "type": "integer",
                    "minimum": 1,
                    "maximum": 100,
                    "default": 20,
                },
            },
            "required": ["query"],
            "additionalProperties": False,
        },
    },
  • The 'call_tool' function dispatches 'find_files' requests to the find_files handler function and wraps the result via tool_result().
    if name == "find_files":
        return tool_result(find_files(arguments))
Behavior2/5

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

No annotations are provided, so the description carries full burden. It mentions the root directory and default, but it does not disclose important behaviors such as case sensitivity, recursion depth, glob pattern handling, permissions, or the structure of returned results.

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 extremely concise: two sentences. The first sentence states purpose and scope, the second provides configuration info. Every sentence adds value with no redundancy.

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 that there is no output schema, the description should hint at return format or behavior. It does not mention what is returned (file paths, metadata), sorting, recursion, or error handling. The tool is simple but the agent may need more context for correct invocation.

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 input schema already describes two of three parameters (query and root). The description adds context about the root default and environment variable configuration, but does not enhance understanding of max_results or clarify glob pattern syntax beyond what the schema provides.

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 tool's function: 'Find local files by name under the allowed root.' It specifies the scope (local files) and the constraint (under a root). The siblings are unrelated (datetime and weather), so there is no ambiguity.

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 explicit guidance on when to use this tool versus alternatives. It does not mention when not to use it or any prerequisites. Given that siblings are unrelated, implicit guidance is minimal.

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/szfmsmdx/nanomcp'

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