Skip to main content
Glama

start_search

Read-only

Initiates progressive file and content searches on your local system, streaming results immediately for large directories with options to filter by filename patterns or text within files.

Instructions

                    Start a streaming search that can return results progressively.
                    
                    SEARCH STRATEGY GUIDE:
                    Choose the right search type based on what the user is looking for:
                    
                    USE searchType="files" WHEN:
                    - User asks for specific files: "find package.json", "locate config files"
                    - Pattern looks like a filename: "*.js", "README.md", "test-*.tsx" 
                    - User wants to find files by name/extension: "all TypeScript files", "Python scripts"
                    - Looking for configuration/setup files: ".env", "dockerfile", "tsconfig.json"
                    
                    USE searchType="content" WHEN:
                    - User asks about code/logic: "authentication logic", "error handling", "API calls"
                    - Looking for functions/variables: "getUserData function", "useState hook"
                    - Searching for text/comments: "TODO items", "FIXME comments", "documentation"
                    - Finding patterns in code: "console.log statements", "import statements"
                    - User describes functionality: "components that handle login", "files with database queries"
                    
                    WHEN UNSURE OR USER REQUEST IS AMBIGUOUS:
                    Run TWO searches in parallel - one for files and one for content:
                    
                    Example approach for ambiguous queries like "find authentication stuff":
                    1. Start file search: searchType="files", pattern="auth"
                    2. Simultaneously start content search: searchType="content", pattern="authentication"  
                    3. Present combined results: "Found 3 auth-related files and 8 files containing authentication code"
                    
                    SEARCH TYPES:
                    - searchType="files": Find files by name (pattern matches file names)
                    - searchType="content": Search inside files for text patterns
                    
                    PATTERN MATCHING MODES:
                    - Default (literalSearch=false): Patterns are treated as regular expressions
                    - Literal (literalSearch=true): Patterns are treated as exact strings
                    
                    WHEN TO USE literalSearch=true:
                    Use literal search when searching for code patterns with special characters:
                    - Function calls with parentheses and quotes
                    - Array access with brackets
                    - Object methods with dots and parentheses
                    - File paths with backslashes
                    - Any pattern containing: . * + ? ^ $ { } [ ] | \ ( )
                    
                    IMPORTANT PARAMETERS:
                    - pattern: What to search for (file names OR content text)
                    - literalSearch: Use exact string matching instead of regex (default: false)
                    - filePattern: Optional filter to limit search to specific file types (e.g., "*.js", "package.json")
                    - ignoreCase: Case-insensitive search (default: true). Works for both file names and content.
                    - earlyTermination: Stop search early when exact filename match is found (optional: defaults to true for file searches, false for content searches)
                    
                    DECISION EXAMPLES:
                    - "find package.json" → searchType="files", pattern="package.json" (specific file)
                    - "find authentication components" → searchType="content", pattern="authentication" (looking for functionality)
                    - "locate all React components" → searchType="files", pattern="*.tsx" or "*.jsx" (file pattern)
                    - "find TODO comments" → searchType="content", pattern="TODO" (text in files)
                    - "show me login files" → AMBIGUOUS → run both: files with "login" AND content with "login"
                    - "find config" → AMBIGUOUS → run both: config files AND files containing config code
                    
                    COMPREHENSIVE SEARCH EXAMPLES:
                    - Find package.json files: searchType="files", pattern="package.json"
                    - Find all JS files: searchType="files", pattern="*.js"
                    - Search for TODO in code: searchType="content", pattern="TODO", filePattern="*.js|*.ts"
                    - Search for exact code: searchType="content", pattern="toast.error('test')", literalSearch=true
                    - Ambiguous request "find auth stuff": Run two searches:
                      1. searchType="files", pattern="auth"
                      2. searchType="content", pattern="authentication"
                    
                    PRO TIP: When user requests are ambiguous about whether they want files or content,
                    run both searches concurrently and combine results for comprehensive coverage.
                    
                    Unlike regular search tools, this starts a background search process and returns
                    immediately with a session ID. Use get_more_search_results to get results as they
                    come in, and stop_search to stop the search early if needed.
                    
                    Perfect for large directories where you want to see results immediately and
                    have the option to cancel if the search takes too long or you find what you need.
                    
                    IMPORTANT: Always use absolute paths for reliability. Paths are automatically normalized regardless of slash direction. Relative paths may fail as they depend on the current working directory. Tilde paths (~/...) might not work in all contexts. Unless the user explicitly asks for relative paths, use absolute paths.
                    This command can be referenced as "DC: ..." or "use Desktop Commander to ..." in your instructions.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
pathYes
patternYes
searchTypeNofiles
filePatternNo
ignoreCaseNo
maxResultsNo
includeHiddenNo
contextLinesNo
timeout_msNo
earlyTerminationNo
literalSearchNo

Implementation Reference

  • The main handler function for the 'start_search' tool. Parses input arguments using the schema, calls searchManager.startSearch to execute the search, formats the initial results and session info for display.
    export async function handleStartSearch(args: unknown): Promise<ServerResult> {
      const parsed = StartSearchArgsSchema.safeParse(args);
      if (!parsed.success) {
        return {
          content: [{ type: "text", text: `Invalid arguments for start_search: ${parsed.error}` }],
          isError: true,
        };
      }
    
      try {
        const result = await searchManager.startSearch({
          rootPath: parsed.data.path,
          pattern: parsed.data.pattern,
          searchType: parsed.data.searchType,
          filePattern: parsed.data.filePattern,
          ignoreCase: parsed.data.ignoreCase,
          maxResults: parsed.data.maxResults,
          includeHidden: parsed.data.includeHidden,
          contextLines: parsed.data.contextLines,
          timeout: parsed.data.timeout_ms,
          earlyTermination: parsed.data.earlyTermination,
          literalSearch: parsed.data.literalSearch,
        });
    
        const searchTypeText = parsed.data.searchType === 'content' ? 'content search' : 'file search';
        
        let output = `Started ${searchTypeText} session: ${result.sessionId}\n`;
        output += `Pattern: "${parsed.data.pattern}"\n`;
        output += `Path: ${parsed.data.path}\n`;
        output += `Status: ${result.isComplete ? 'COMPLETED' : 'RUNNING'}\n`;
        output += `Runtime: ${Math.round(result.runtime)}ms\n`;
        output += `Total results: ${result.totalResults}\n\n`;
    
        if (result.results.length > 0) {
          output += "Initial results:\n";
          
          for (const searchResult of result.results.slice(0, 10)) {
            if (searchResult.type === 'content') {
              output += `📄 ${searchResult.file}:${searchResult.line} - ${searchResult.match?.substring(0, 100)}${searchResult.match && searchResult.match.length > 100 ? '...' : ''}\n`;
            } else {
              output += `📁 ${searchResult.file}\n`;
            }
          }
          
          if (result.results.length > 10) {
            output += `... and ${result.results.length - 10} more results\n`;
          }
        }
    
        if (result.isComplete) {
          output += `\n✅ Search completed.`;
        } else {
          output += `\n🔄 Search in progress. Use get_more_search_results to get more results.`;
        }
    
        return {
          content: [{ type: "text", text: output }],
        };
      } catch (error) {
        const errorMessage = error instanceof Error ? error.message : String(error);
        capture('search_session_start_error', { error: errorMessage });
        
        return {
          content: [{ type: "text", text: `Error starting search session: ${errorMessage}` }],
          isError: true,
        };
      }
    }
  • Zod schema defining the input parameters and validation for the start_search tool.
    export const StartSearchArgsSchema = z.object({
      path: z.string(),
      pattern: z.string(),
      searchType: z.enum(['files', 'content']).default('files'),
      filePattern: z.string().optional(),
      ignoreCase: z.boolean().optional().default(true),
      maxResults: z.number().optional(),
      includeHidden: z.boolean().optional().default(false),
      contextLines: z.number().optional().default(5),
      timeout_ms: z.number().optional(), // Match process naming convention
      earlyTermination: z.boolean().optional(), // Stop search early when exact filename match is found (default: true for files, false for content)
      literalSearch: z.boolean().optional().default(false), // Force literal string matching (-F flag) instead of regex
    });
  • Registration/dispatch in the CallToolRequest handler switch statement that maps the 'start_search' tool name to the handleStartSearch function.
    case "start_search":
        result = await handlers.handleStartSearch(args);
        break;
  • Core search logic in SearchManager.startSearch: spawns ripgrep child process, sets up streaming result collection, handles Excel file search integration, manages session lifecycle.
    async startSearch(options: SearchSessionOptions): Promise<{
      sessionId: string;
      isComplete: boolean;
      isError: boolean;
      results: SearchResult[];
      totalResults: number;
      runtime: number;
    }> {
      const sessionId = `search_${++this.sessionCounter}_${Date.now()}`;
      
      // Validate path first
      const validPath = await validatePath(options.rootPath);
    
      // Build ripgrep arguments
      const args = this.buildRipgrepArgs({ ...options, rootPath: validPath });
      
      // Get ripgrep path with fallback resolution
      let rgPath: string;
      try {
        rgPath = await getRipgrepPath();
      } catch (err) {
        throw new Error(`Failed to locate ripgrep binary: ${err instanceof Error ? err.message : String(err)}`);
      }
      
      // Start ripgrep process
      const rgProcess = spawn(rgPath, args);
      
      if (!rgProcess.pid) {
        throw new Error('Failed to start ripgrep process');
      }
    
      // Create session
      const session: SearchSession = {
        id: sessionId,
        process: rgProcess,
        results: [],
        isComplete: false,
        isError: false,
        startTime: Date.now(),
        lastReadTime: Date.now(),
        options,
        buffer: '',
        totalMatches: 0,
        totalContextLines: 0
      };
    
      this.sessions.set(sessionId, session);
    
      // Set up process event handlers
      this.setupProcessHandlers(session);
    
      // Start cleanup interval now that we have a session
      startCleanupIfNeeded();
    
      // Set up timeout if specified and auto-terminate
      // For exact filename searches, use a shorter default timeout
      const timeoutMs = options.timeout ?? (this.isExactFilename(options.pattern) ? 1500 : undefined);
      
      let killTimer: NodeJS.Timeout | null = null;
      if (timeoutMs) {
        killTimer = setTimeout(() => {
          if (!session.isComplete && !session.process.killed) {
            session.process.kill('SIGTERM');
          }
        }, timeoutMs);
      }
    
      // Clear timer on process completion
      session.process.once('close', () => {
        if (killTimer) {
          clearTimeout(killTimer);
          killTimer = null;
        }
      });
    
      session.process.once('error', () => {
        if (killTimer) {
          clearTimeout(killTimer);
          killTimer = null;
        }
      });
    
      capture('search_session_started', {
        sessionId,
        searchType: options.searchType,
        hasTimeout: !!timeoutMs,
        timeoutMs,
        requestedPath: options.rootPath,
        validatedPath: validPath
      });
    
      // For content searches, only search Excel files when contextually relevant:
      // - filePattern explicitly targets Excel files (*.xlsx, *.xls, etc.)
      // - or rootPath is an Excel file itself
      const shouldSearchExcel = options.searchType === 'content' &&
        this.shouldIncludeExcelSearch(options.filePattern, validPath);
    
      if (shouldSearchExcel) {
        this.searchExcelFiles(
          validPath,
          options.pattern,
          options.ignoreCase !== false,
          options.maxResults,
          options.filePattern  // Pass filePattern to filter Excel files too
        ).then(excelResults => {
          // Add Excel results to session (merged after initial response)
          for (const result of excelResults) {
            session.results.push(result);
            session.totalMatches++;
          }
        }).catch((err) => {
          // Log Excel search errors but don't fail the whole search
          capture('excel_search_error', { error: err instanceof Error ? err.message : String(err) });
        });
      }
    
      // Wait for first chunk of data or early completion instead of fixed delay
      // Excel search runs in background and results are merged via readSearchResults
      const firstChunk = new Promise<void>(resolve => {
        const onData = () => {
          session.process.stdout?.off('data', onData);
          resolve();
        };
        session.process.stdout?.once('data', onData);
        setTimeout(resolve, 40); // cap at 40ms instead of 50-100ms
      });
    
      // Only wait for ripgrep first chunk - Excel results merge asynchronously
      await firstChunk;
    
      return {
        sessionId,
        isComplete: session.isComplete,
        isError: session.isError,
        results: [...session.results],
        totalResults: session.totalMatches,
        runtime: Date.now() - session.startTime
      };
    }
  • src/server.ts:494-579 (registration)
    Tool definition/registration in the ListToolsRequest handler that advertises the 'start_search' tool with its schema and description to MCP clients.
        name: "start_search",
        description: `
                Start a streaming search that can return results progressively.
                
                SEARCH STRATEGY GUIDE:
                Choose the right search type based on what the user is looking for:
                
                USE searchType="files" WHEN:
                - User asks for specific files: "find package.json", "locate config files"
                - Pattern looks like a filename: "*.js", "README.md", "test-*.tsx" 
                - User wants to find files by name/extension: "all TypeScript files", "Python scripts"
                - Looking for configuration/setup files: ".env", "dockerfile", "tsconfig.json"
                
                USE searchType="content" WHEN:
                - User asks about code/logic: "authentication logic", "error handling", "API calls"
                - Looking for functions/variables: "getUserData function", "useState hook"
                - Searching for text/comments: "TODO items", "FIXME comments", "documentation"
                - Finding patterns in code: "console.log statements", "import statements"
                - User describes functionality: "components that handle login", "files with database queries"
                
                WHEN UNSURE OR USER REQUEST IS AMBIGUOUS:
                Run TWO searches in parallel - one for files and one for content:
                
                Example approach for ambiguous queries like "find authentication stuff":
                1. Start file search: searchType="files", pattern="auth"
                2. Simultaneously start content search: searchType="content", pattern="authentication"  
                3. Present combined results: "Found 3 auth-related files and 8 files containing authentication code"
                
                SEARCH TYPES:
                - searchType="files": Find files by name (pattern matches file names)
                - searchType="content": Search inside files for text patterns
                
                PATTERN MATCHING MODES:
                - Default (literalSearch=false): Patterns are treated as regular expressions
                - Literal (literalSearch=true): Patterns are treated as exact strings
                
                WHEN TO USE literalSearch=true:
                Use literal search when searching for code patterns with special characters:
                - Function calls with parentheses and quotes
                - Array access with brackets
                - Object methods with dots and parentheses
                - File paths with backslashes
                - Any pattern containing: . * + ? ^ $ { } [ ] | \\ ( )
                
                IMPORTANT PARAMETERS:
                - pattern: What to search for (file names OR content text)
                - literalSearch: Use exact string matching instead of regex (default: false)
                - filePattern: Optional filter to limit search to specific file types (e.g., "*.js", "package.json")
                - ignoreCase: Case-insensitive search (default: true). Works for both file names and content.
                - earlyTermination: Stop search early when exact filename match is found (optional: defaults to true for file searches, false for content searches)
                
                DECISION EXAMPLES:
                - "find package.json" → searchType="files", pattern="package.json" (specific file)
                - "find authentication components" → searchType="content", pattern="authentication" (looking for functionality)
                - "locate all React components" → searchType="files", pattern="*.tsx" or "*.jsx" (file pattern)
                - "find TODO comments" → searchType="content", pattern="TODO" (text in files)
                - "show me login files" → AMBIGUOUS → run both: files with "login" AND content with "login"
                - "find config" → AMBIGUOUS → run both: config files AND files containing config code
                
                COMPREHENSIVE SEARCH EXAMPLES:
                - Find package.json files: searchType="files", pattern="package.json"
                - Find all JS files: searchType="files", pattern="*.js"
                - Search for TODO in code: searchType="content", pattern="TODO", filePattern="*.js|*.ts"
                - Search for exact code: searchType="content", pattern="toast.error('test')", literalSearch=true
                - Ambiguous request "find auth stuff": Run two searches:
                  1. searchType="files", pattern="auth"
                  2. searchType="content", pattern="authentication"
                
                PRO TIP: When user requests are ambiguous about whether they want files or content,
                run both searches concurrently and combine results for comprehensive coverage.
                
                Unlike regular search tools, this starts a background search process and returns
                immediately with a session ID. Use get_more_search_results to get results as they
                come in, and stop_search to stop the search early if needed.
                
                Perfect for large directories where you want to see results immediately and
                have the option to cancel if the search takes too long or you find what you need.
                
                ${PATH_GUIDANCE}
                ${CMD_PREFIX_DESCRIPTION}`,
        inputSchema: zodToJsonSchema(StartSearchArgsSchema),
        annotations: {
            title: "Start Search",
            readOnlyHint: true,
        },
    },
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

The annotations declare readOnlyHint=true, and the description adds valuable behavioral context beyond this: it explains this is a streaming/background search that returns immediately with a session ID, mentions it's 'perfect for large directories where you want to see results immediately,' and warns about path reliability (absolute vs relative paths). While it doesn't mention rate limits or specific performance characteristics, it adds substantial operational context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness3/5

Is the description appropriately sized, front-loaded, and free of redundancy?

While well-structured with clear sections (SEARCH STRATEGY GUIDE, SEARCH TYPES, etc.), the description is extremely verbose with repetitive examples and could be significantly condensed. The 'PRO TIP' and 'IMPORTANT PARAMETERS' sections contain valuable information but the multiple comprehensive examples and decision examples create redundancy. Every sentence adds value but many could be more concise.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness5/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity of 11 parameters with 0% schema coverage, no output schema, and read-only annotations, the description provides exceptional completeness. It covers search strategies, parameter semantics, behavioral characteristics (streaming, background processing), integration with sibling tools (get_more_search_results, stop_search), path handling guidance, and numerous practical examples. It leaves no significant gaps for agent understanding.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 0% schema description coverage for 11 parameters, the description carries the full burden and excels: it explains searchType options with detailed usage scenarios, clarifies pattern matching modes (regex vs literal), provides guidance on literalSearch usage, documents important parameters like filePattern and earlyTermination, and gives comprehensive examples showing parameter combinations. It adds significant meaning beyond the bare schema.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description explicitly states the tool 'starts a streaming search that can return results progressively' and distinguishes it from regular search tools by explaining it returns immediately with a session ID for background processing. It clearly differentiates from sibling tools like get_more_search_results and stop_search by explaining their complementary roles.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines5/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides extensive guidance on when to use searchType='files' versus 'content', including specific scenarios and examples. It explicitly addresses ambiguous cases with a strategy to run both searches in parallel, and provides clear decision examples. The 'SEARCH STRATEGY GUIDE' section offers comprehensive when/when-not guidance.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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/wonderwhy-er/ClaudeComputerCommander'

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