Skip to main content
Glama
Vaishnavi-Raykar

Ressl AI MCP Server

search_in_file

Search for keywords within files to find all occurrences including partial matches, returning results with line numbers and column positions.

Instructions

Search for a keyword within a specified file. Finds all occurrences including partial matches.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the file to search in
keywordYesKeyword to search for in the file

Implementation Reference

  • The core handler function that implements the logic for searching a keyword within a file, finding all occurrences with line numbers and positions.
    export async function searchInFile(
      filePath: string,
      keyword: string
    ): Promise<SearchResult> {
      try {
        const absolutePath = path.resolve(filePath);
        const fileContent = await fs.readFile(absolutePath, "utf-8");
        const lines = fileContent.split("\n");
        const matches: Match[] = [];
    
        lines.forEach((line, index) => {
          let columnIndex = line.indexOf(keyword);
          while (columnIndex !== -1) {
            matches.push({
              lineNumber: index + 1,
              lineContent: line.trim(),
              columnPosition: columnIndex + 1,
              matchedText: keyword,
            });
            columnIndex = line.indexOf(keyword, columnIndex + 1);
          }
        });
    
        return {
          success: true,
          filePath: absolutePath,
          keyword,
          matches,
          totalMatches: matches.length,
          searchType: "partial match",
        };
      } catch (error) {
        return {
          success: false,
          filePath,
          keyword,
          matches: [],
          totalMatches: 0,
          searchType: "partial match",
          error: error instanceof Error ? error.message : "Unknown error occurred",
        };
      }
    }
  • TypeScript interfaces defining the structure of the search result and individual matches, serving as output schema.
    interface SearchResult {
      success: boolean;
      filePath: string;
      keyword: string;
      matches: Match[];
      totalMatches: number;
      searchType: string;
      error?: string;
    }
    
    interface Match {
      lineNumber: number;
      lineContent: string;
      columnPosition: number;
      matchedText?: string;
    }
  • src/index.ts:24-41 (registration)
    Registration of the 'search_in_file' tool in the ListTools handler, including name, description, and input schema.
    {
      name: "search_in_file",
      description: "Search for a keyword within a specified file. Finds all occurrences including partial matches.",
      inputSchema: {
        type: "object",
        properties: {
          filePath: {
            type: "string",
            description: "Path to the file to search in",
          },
          keyword: {
            type: "string",
            description: "Keyword to search for in the file",
          },
        },
        required: ["filePath", "keyword"],
      },
    },
  • Server-side handler in CallToolRequestSchema that invokes the searchInFile function and formats the response.
    if (request.params.name === "search_in_file") {
      const filePath = String(request.params.arguments?.filePath);
      const keyword = String(request.params.arguments?.keyword);
    
      const result = await searchInFile(filePath, keyword);
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify(result, null, 2),
          },
        ],
      };
    }
  • src/index.ts:7-7 (registration)
    Import statement that brings the searchInFile handler into the main server file.
    import { searchInFile, exactWordSearch } from "./tools/fileSearch.js";
Behavior3/5

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

No annotations are provided, so the description carries the full burden. It discloses the tool's behavior of finding all occurrences with partial matches, which is useful. However, it lacks details on error handling (e.g., what happens if the file doesn't exist), output format (e.g., line numbers, context), or performance aspects like case sensitivity, which are important for a search operation.

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

Conciseness5/5

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

The description is two sentences with zero waste: the first sentence states the core purpose, and the second adds critical behavioral detail (partial matches). It is front-loaded and appropriately sized, with every sentence earning its place by providing essential information.

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

Completeness3/5

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

Given the tool's moderate complexity (search operation with two parameters), no annotations, and no output schema, the description is minimally complete. It covers the basic purpose and key behavior (partial matches) but lacks details on output format, error handling, or advanced usage, leaving gaps that could hinder an AI agent's effective use.

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

Parameters3/5

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

Schema description coverage is 100%, meaning the input schema already fully documents the parameters 'filePath' and 'keyword'. The description adds no additional semantic details beyond what the schema provides (e.g., no examples, constraints, or usage tips), so it meets the baseline of 3 without compensating further.

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 clearly states the specific action ('Search for a keyword'), target resource ('within a specified file'), and scope ('Finds all occurrences including partial matches'). It distinguishes from the sibling tool 'exact_word_search' by explicitly mentioning partial matches, which implies the sibling likely does exact matches only.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool (searching within files for keywords with partial matching). However, it does not explicitly state when not to use it or name the alternative sibling tool 'exact_word_search' as a direct comparison, though the distinction is implied through the mention of partial matches.

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/Vaishnavi-Raykar/mcp-server'

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