Skip to main content
Glama

exact_word_search

Find exact word matches in files to locate specific terms without partial matches, using case sensitivity options for precise text searches.

Instructions

Search for an exact word match within a specified file. Only matches complete words, not partial matches.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
filePathYesPath to the file to search in
wordYesExact word to search for in the file
caseSensitiveNoWhether the search should be case sensitive

Implementation Reference

  • Core handler function executing the exact word search using regex for word boundaries, supporting case-sensitive option, reading file, finding matches, and returning SearchResult.
    export async function exactWordSearch( filePath: string, word: string, caseSensitive: boolean = false ): Promise<SearchResult> { try { const absolutePath = path.resolve(filePath); const fileContent = await fs.readFile(absolutePath, "utf-8"); const lines = fileContent.split("\n"); const matches: Match[] = []; const wordBoundaryPattern = caseSensitive ? new RegExp(`\\b${escapeRegex(word)}\\b`, "g") : new RegExp(`\\b${escapeRegex(word)}\\b`, "gi"); lines.forEach((line, index) => { let match; const regex = new RegExp(wordBoundaryPattern); while ((match = regex.exec(line)) !== null) { matches.push({ lineNumber: index + 1, lineContent: line.trim(), columnPosition: match.index + 1, matchedText: match[0], }); } }); return { success: true, filePath: absolutePath, keyword: word, matches, totalMatches: matches.length, searchType: caseSensitive ? "exact word (case sensitive)" : "exact word (case insensitive)", }; } catch (error) { return { success: false, filePath, keyword: word, matches: [], totalMatches: 0, searchType: "exact word", error: error instanceof Error ? error.message : "Unknown error occurred", }; } }
  • Input schema defining parameters for the exact_word_search tool: filePath (string, required), word (string, required), caseSensitive (boolean, optional, default false).
    inputSchema: { type: "object", properties: { filePath: { type: "string", description: "Path to the file to search in", }, word: { type: "string", description: "Exact word to search for in the file", }, caseSensitive: { type: "boolean", description: "Whether the search should be case sensitive", default: false, }, }, required: ["filePath", "word"], },
  • src/index.ts:42-64 (registration)
    Registration of the exact_word_search tool in the ListTools response, including name, description, and input schema.
    { name: "exact_word_search", description: "Search for an exact word match within a specified file. Only matches complete words, not partial matches.", inputSchema: { type: "object", properties: { filePath: { type: "string", description: "Path to the file to search in", }, word: { type: "string", description: "Exact word to search for in the file", }, caseSensitive: { type: "boolean", description: "Whether the search should be case sensitive", default: false, }, }, required: ["filePath", "word"], }, },
  • Type definitions for SearchResult (output) and Match interfaces used by the handler.
    interface SearchResult { success: boolean; filePath: string; keyword: string; matches: Match[]; totalMatches: number; searchType: string; error?: string; }
  • Utility function to escape special regex characters in the search word.
    function escapeRegex(text: string): string { return text.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); }

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