search_files
Find files containing specific text within the Universal MCP Server to locate relevant documents or code snippets quickly.
Instructions
Search for files containing specific text
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | The text to search for |
Implementation Reference
- src/index.ts:224-247 (handler)Handler case for executing the 'search_files' MCP tool, extracts query from args, logs, calls storage.search, and returns formatted JSON results.case 'search_files': { const { query } = args as { query: string }; logger.info('Tool request received', { operation: 'tool:search', toolName: 'search_files', query, requestId }); const results = await storage.search(query, requestId); return { content: [{ type: 'text', text: JSON.stringify({ success: true, query, resultsCount: results.length, results: results.map(r => ({ key: r.key, preview: r.content.slice(0, 100) + '...' })) }, null, 2) }] }; }
- src/index-multimode.ts:233-256 (handler)Handler case for executing the 'search_files' MCP tool (duplicate in multi-mode server), delegates to storage.search.case 'search_files': { const { query } = args as { query: string }; logger.info('Tool request received', { operation: 'tool:search', toolName: 'search_files', query, requestId }); const results = await storage.search(query, requestId); return { content: [{ type: 'text', text: JSON.stringify({ success: true, query, resultsCount: results.length, results: results.map(r => ({ key: r.key, preview: r.content.slice(0, 100) + '...' })) }, null, 2) }] }; }
- src/index.ts:151-164 (schema)Schema definition for the 'search_files' tool returned in ListTools response, including inputSchema with required 'query' string.{ name: 'search_files', description: 'Search for files containing specific text', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'The text to search for', }, }, required: ['query'], }, },
- src/storage.ts:180-206 (helper)Core implementation of file search in FileStorage class: lists all files, reads contents, checks for query match (case-insensitive), returns matching key-content pairs.async search(query: string, requestId: string): Promise<Array<{ key: string; content: string }>> { try { logger.debug('Searching files', { operation: 'search', query, requestId }); const keys = await this.list(undefined, requestId); const results: Array<{ key: string; content: string }> = []; for (const key of keys) { const content = await this.read(key, requestId); if (content && content.toLowerCase().includes(query.toLowerCase())) { results.push({ key, content }); } } logger.info('Search completed', { operation: 'search', query, resultsCount: results.length, requestId }); return results; } catch (error) { logger.error('Failed to search files', error as Error, { operation: 'search', query, requestId }); throw error; } }