Skip to main content
Glama

find_by_content

Search for files containing specific text within directories using file patterns and result limits to locate content efficiently.

Instructions

Find files containing specific text

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYesText to search for (literal, not regex)
pathNoDirectory to search
file_patternNoFile pattern (e.g., *.ts)
max_resultsNoMaximum results

Implementation Reference

  • Implementation of the find_by_content logic.
    async function findByContentImpl(input: {
      text: string;
      path?: string;
      file_pattern?: string;
      max_results?: number;
    }): Promise<ToolResult> {
      // Escape special regex characters for literal search
      const escapedText = input.text.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
    
      return await grepSearchImpl({
        pattern: escapedText,
        path: input.path,
        glob: input.file_pattern,
        case_sensitive: true,
        max_results: input.max_results ?? 100,
        context_lines: 0,
      });
    }
  • Registration of the find_by_content MCP tool.
    // find_by_content tool (simpler interface)
    server.tool(
      'find_by_content',
      'Find files containing specific text',
      {
        text: z.string().describe('Text to search for (literal, not regex)'),
        path: z.string().optional().describe('Directory to search'),
        file_pattern: z.string().optional().describe('File pattern (e.g., *.ts)'),
        max_results: z.number().optional().describe('Maximum results'),
      },
      async (args) => {
        return await findByContentImpl(args);
      }
    );

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/mcp-tool-shop-org/mcp-file-forge'

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