Skip to main content
Glama

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
NameRequiredDescriptionDefault
queryYesThe text to search for

Implementation Reference

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

Other 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/Amana03/universal-mcp-server'

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