MCP Keyword Search Server
An MCP (Model Context Protocol) server that searches for keywords in files and returns matching lines with line numbers and match counts.
Features
search_keyword tool that finds all occurrences of a keyword in a file
Returns line numbers, full line content, and match counts
Supports case-sensitive and case-insensitive search
Counts multiple matches per line
Clear error handling for missing files or invalid inputs
Installation
Quick Start
Option 1: Test with MCP Inspector (Recommended)
This opens a web UI at http://localhost:6277 where you can test the tool interactively.
Option 2: Use with Claude Desktop
Add to your Claude Desktop config file:
macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
Restart Claude Desktop and the tool will be available.
Tool: search_keyword
Parameters:
filePath(string, required): Absolute path to the file to searchkeyword(string, required): The keyword to search forcaseSensitive(boolean, optional): Whether search is case-sensitive (default: false)
Example Input:
Example Output:
Testing
Using MCP Inspector UI
Start the inspector:
npx @modelcontextprotocol/inspector node build/index.jsOpen
http://localhost:6277in your browserNavigate to the "Tools" tab
Select
search_keywordFill in the parameters and click "Run Tool"
Test Case Examples
Test 1: Basic Search (Case-Insensitive)
Input:
Expected Output:
Test 2: Case-Sensitive Search
Input:
Expected: Only finds "KEYWORD" (not "keyword" or "KeYwOrD")
Test 3: No Matches
Input:
Expected Output:
Test 4: Error Handling
Input:
Expected Output:
Test 5: Search in Code Files
Input:
Expected: Finds all const declarations in the TypeScript file
Quick Command Line Test
How It Works
Input: You provide a file path and keyword to search
Processing: The tool reads the file, splits it into lines, and searches each line
Matching: Counts how many times the keyword appears on each line
Output: Returns all matching lines with line numbers and counts
Troubleshooting
Inspector won't start
Port already in use
The inspector uses port 6277 by default. If it's in use, close other apps or the inspector will use a different port automatically.
File not found errors
Always use absolute paths for the filePath parameter. Relative paths may not work correctly.
Changes not reflecting
After modifying the source code, rebuild:
Development
Project Structure
License
MIT
This server cannot be installed
local-only server
The server can only run on the client's local machine because it depends on local resources.
Enables searching for keywords in files with support for case-sensitive/insensitive matching, returning line numbers, full line content, and match counts for all occurrences.