Skip to main content
Glama
StepanCooleague

file-finder-mcp

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
NameRequiredDescriptionDefault
directoryNoКаталог для поиска/
queryYesФрагмент пути для поиска

Implementation Reference

  • 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, ) ]
  • 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"], },
  • 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"], }, ) ]
  • 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)

Other Tools

Related 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/StepanCooleague/file-finder-mcp'

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