Skip to main content
Glama

exact_word_search

Find exact word matches in files to locate specific terms with precision. Search for complete words only, not partial matches, and get results with line numbers and positions.

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 implementation of the exact_word_search tool, performing file read, regex-based exact word matching with optional case sensitivity, and returning structured results.
    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", }; } }
  • JSON input schema defining parameters for the exact_word_search tool: filePath (required), word (required), caseSensitive (optional boolean).
    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:86-101 (registration)
    Registration and dispatch logic in CallToolRequestSchema handler: checks tool name, parses arguments, calls exactWordSearch, and formats response.
    if (request.params.name === "exact_word_search") { const filePath = String(request.params.arguments?.filePath); const word = String(request.params.arguments?.word); const caseSensitive = Boolean(request.params.arguments?.caseSensitive ?? false); const result = await exactWordSearch(filePath, word, caseSensitive); return { content: [ { type: "text", text: JSON.stringify(result, null, 2), }, ], }; }
  • Utility function to escape special regex characters, used to safely construct word boundary regex patterns.
    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