search
Search for files on your system using advanced options like regex, case sensitivity, and sorting to quickly locate documents, applications, and media.
Instructions
Search for files using Everything Search
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Search query | |
| scope | No | Search scope (default: C:) | |
| caseSensitive | No | Match case | |
| wholeWord | No | Match whole words only | |
| regex | No | Use regular expressions | |
| path | No | Search in paths | |
| maxResults | No | Maximum number of results (1-1000, default: 100) | |
| sortBy | No | Sort results by | |
| ascending | No | Sort in ascending order |
Implementation Reference
- src/server.js:7-18 (schema)Zod schema defining input parameters for the 'search' tool, including query, scope, search options, sorting, and pagination.const SearchSchema = z.object({ query: z.string().describe("Search query"), scope: z.string().default("C:").describe("Search scope (default: C:)"), caseSensitive: z.boolean().default(false).describe("Match case"), wholeWord: z.boolean().default(false).describe("Match whole words only"), regex: z.boolean().default(false).describe("Use regular expressions"), path: z.boolean().default(false).describe("Search in paths"), maxResults: z.number().min(1).max(1000).default(32).describe("Maximum number of results (1-1000, default: 32 for HTML, 4294967295 for JSON)"), sortBy: z.enum(['name', 'path', 'size', 'date_modified']).default('name').describe("Sort results by"), ascending: z.boolean().default(true).describe("Sort in ascending order"), offset: z.number().min(0).default(0).describe("Display results from the nth result") });
- src/server.js:65-132 (handler)Core handler function 'searchFiles' that executes the file search by querying the Everything Search HTTP API (localhost:8011), handles parameters, rate limiting, error handling, and returns raw results.const searchFiles = async (params) => { try { // Add rate limiting await new Promise(resolve => setTimeout(resolve, 100)); // Properly handle scope concatenation const searchQuery = params.scope ? params.scope.endsWith('\\') ? `${params.scope}${params.query}` : `${params.scope}\\${params.query}` : params.query; const response = await axios.get("http://localhost:8011/", { params: { search: searchQuery, json: 1, path_column: 1, size_column: 1, date_modified_column: 1, case: params.caseSensitive ? 1 : 0, wholeword: params.wholeWord ? 1 : 0, regex: params.regex ? 1 : 0, path: params.path ? 1 : 0, count: params.maxResults, offset: params.offset, sort: params.sortBy, ascending: params.ascending ? 1 : 0 }, timeout: 10000 // 10 second timeout }); // Validate response structure if (!response.data || typeof response.data.totalResults === 'undefined') { throw new Error('Invalid response from Everything Search API'); } // Handle empty results according to API documentation if (!response.data.results) { response.data.results = []; response.data.totalResults = 0; } return response.data; } catch (error) { if (axios.isAxiosError(error)) { console.error('Axios error details:', { code: error.code, message: error.message, response: error.response?.data, config: { url: error.config?.url, params: error.config?.params } }); if (error.code === 'ECONNREFUSED') { throw new Error( "Could not connect to Everything Search. Make sure the HTTP server is enabled in Everything's settings (Tools > Options > HTTP Server)." ); } if (error.code === 'ETIMEDOUT') { throw new Error("Everything Search API request timed out. The server might be busy or unresponsive."); } throw new Error(`Everything Search API error: ${error.message}`); } console.error('Non-Axios error:', error); throw error; } };
- src/server.js:21-37 (helper)Helper function to format file sizes from bytes to human-readable units (KB, MB, etc.).const formatFileSize = (size) => { if (!size) return "N/A"; const bytes = parseInt(size); if (isNaN(bytes)) return "N/A"; const units = ['bytes', 'KB', 'MB', 'GB', 'TB']; let value = bytes; let unitIndex = 0; while (value >= 1024 && unitIndex < units.length - 1) { value /= 1024; unitIndex++; } return `${value.toFixed(2)} ${units[unitIndex]}`; };
- src/server.js:40-63 (helper)Helper function to convert Windows FILETIME to readable date string, handling invalid dates.const formatFileTime = (fileTime) => { if (!fileTime || fileTime === "" || fileTime === "0") return "No date"; try { const bigIntTime = BigInt(fileTime); if (bigIntTime === 0n) return "No date"; const windowsMs = bigIntTime / 10000n; const epochDiffMs = 11644473600000n; const unixMs = Number(windowsMs - epochDiffMs); const dateObj = new Date(unixMs); // Check if date is valid (not 1980-02-01 which indicates invalid/placeholder date) if (dateObj.getFullYear() === 1980 && dateObj.getMonth() === 1 && dateObj.getDate() === 1) { return "No date"; } return dateObj.toLocaleString(); } catch (error) { console.error('Date conversion error:', error); console.error('Value:', fileTime); return "Invalid date"; } };
- src/server.js:143-146 (registration)Registration of the 'search' tool in server capabilities, providing description and input schema.search: { description: "Search for files using Everything Search", inputSchema: zodToJsonSchema(SearchSchema) }
- src/server.js:152-158 (registration)Handler for 'listTools' request that registers and describes the 'search' tool.server.setRequestHandler("listTools", async () => ({ tools: [{ name: "search", description: "Search for files using Everything Search", inputSchema: zodToJsonSchema(SearchSchema) }] }));
- src/server.js:163-183 (handler)Tool execution handler in 'callTool' request: validates args, calls searchFiles, formats results with helpers, returns MCP response.if (name === "search") { const validatedArgs = SearchSchema.parse(args); const results = await searchFiles(validatedArgs); const formattedResults = results.results.length > 0 ? results.results.map((result) => { const size = result.type === "folder" ? "(folder)" : formatFileSize(result.size); const date = formatFileTime(result.date_modified); return `Name: ${result.name}\nPath: ${result.path}\nSize: ${size}\nModified: ${date}\n`; }).join("\n") : "No results found"; const summary = `Found ${results.totalResults} results:\n\n`; return { content: [{ type: "text", text: summary + formattedResults }] }; }