Skip to main content
Glama

find

Search for files by pattern within virtual filesystem workspaces, supporting multiple storage providers and scopes.

Instructions

Find files matching a pattern.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
requestYes

Implementation Reference

  • The core handler function that implements the find tool logic, recursively searching directories for files matching the given pattern using fnmatch.
    async def find(self, request: FindRequest) -> FindResponse:
        """
        Find files matching a pattern.
    
        Args:
            request: FindRequest with pattern, path, and max_results
    
        Returns:
            FindResponse with matching paths
        """
        vfs = self.workspace_manager.get_current_vfs()
        resolved_path = self.workspace_manager.resolve_path(request.path)
    
        results: list[str] = []
        truncated = False
    
        async def search(current_path: str) -> None:
            nonlocal truncated
            if len(results) >= request.max_results:
                truncated = True
                return
    
            filenames = await vfs.ls(current_path)
            for name in filenames:
                if len(results) >= request.max_results:
                    truncated = True
                    break
    
                # Construct full path
                if current_path == "/":
                    full_path = f"/{name}"
                else:
                    full_path = f"{current_path}/{name}"
    
                # Check if name matches pattern
                if fnmatch(name, request.pattern):
                    results.append(full_path)
    
                # Recurse into directories
                node_info = await vfs.get_node_info(full_path)
                if node_info and node_info.is_dir:
                    await search(full_path)
    
        await search(resolved_path)
        return FindResponse(
            pattern=request.pattern, matches=results, truncated=truncated
        )
  • Registration of the 'find' tool using the @server.tool decorator, which delegates execution to the VFSTools.find method.
    @server.tool
    async def find(request: FindRequest):
        """Find files matching a pattern."""
        return await vfs_tools.find(request)
  • Pydantic models defining the input schema (FindRequest with pattern, path, max_results) and output schema (FindResponse with matches and truncation status) for the find tool.
    class FindRequest(BaseModel):
        """Request to find files"""
    
        pattern: str
        path: str = "."
        max_results: int = Field(default=100, ge=1, le=1000)
    
    
    class FindResponse(BaseModel):
        """Response from find operation"""
    
        pattern: str
        matches: list[str]
        truncated: bool = False

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/chrishayuk/chuk-mcp-vfs'

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