search-files
Search for files in a specified directory by matching path fragments, returning metadata such as name, path, size, and creation date.
Instructions
Поиск файлов по фрагменту пути
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| directory | No | Каталог для поиска | / |
| query | Yes | Фрагмент пути для поиска |
Implementation Reference
- src/file_finder_mcp/server.py:33-57 (handler)The handle_call_tool function is the MCP handler that processes calls to the 'search-files' tool, validates arguments, invokes the search_files helper, and formats the response.@server.call_tool() async def handle_call_tool( name: str, arguments: dict | None ) -> list[types.TextContent]: """ Обрабатывает выполнение инструментов. """ if name != "search-files": raise ValueError(f"Неизвестный инструмент: {name}") if not arguments or "query" not in arguments: raise ValueError("Отсутствует обязательный параметр 'query'") query = arguments["query"] directory = arguments.get("directory", "/") result = search_files(query, directory) return [ types.TextContent( type="text", text=result, ) ]
- src/file_finder_mcp/server.py:22-29 (schema)The inputSchema defines the parameters for the 'search-files' tool: required 'query' string and optional 'directory' string.inputSchema={ "type": "object", "properties": { "query": {"type": "string", "description": "Фрагмент пути для поиска"}, "directory": {"type": "string", "description": "Каталог для поиска", "default": "/"}, }, "required": ["query"], },
- src/file_finder_mcp/server.py:13-32 (registration)The handle_list_tools function registers the 'search-files' tool by returning a list containing its Tool object with name, description, and schema.@server.list_tools() async def handle_list_tools() -> list[types.Tool]: """ Описывает доступные инструменты. """ return [ types.Tool( name="search-files", description="Поиск файлов по фрагменту пути", inputSchema={ "type": "object", "properties": { "query": {"type": "string", "description": "Фрагмент пути для поиска"}, "directory": {"type": "string", "description": "Каталог для поиска", "default": "/"}, }, "required": ["query"], }, ) ]
- src/file_finder_mcp/server.py:58-81 (helper)The search_files helper function implements the file searching logic using os.walk, collects file stats, and returns JSON-formatted results.def search_files(query: str, directory: str) -> str: """ Выполняет поиск файлов в заданном каталоге. Возвращает результат в формате JSON. """ matches = [] for root, _, files in os.walk(directory): for file in files: if query in file: file_path = os.path.join(root, file) try: stats = os.stat(file_path) matches.append({ "name": file, "path": file_path, "size": stats.st_size, "created": datetime.fromtimestamp(stats.st_ctime).isoformat(), }) except Exception: continue return json.dumps({"files": matches}, indent=2)