MCP-Grep is a server implementation that exposes grep functionality through the Model Context Protocol (MCP). It allows you to perform pattern searches in files using regular expressions through a standardized interface, making it easy to integrate grep capabilities with MCP-compatible clients and Large Language Models (LLMs).
The easiest way to install MCP-Grep for Claude Desktop is via Smithery:
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude
Alternatively, you can install MCP-Grep directly using pip:
pip install mcp-grep
Once installed, you can start the MCP-Grep server using:
# Start the MCP-Grep server
mcp-grep-server
# Or use the MCP Inspector for interactive debugging and testing
mcp-grep-inspector
MCP-Grep provides the following functionality:
You can interact with MCP-Grep programmatically using the MCP Python client:
from mcp.client import MCPClient
# Connect to the MCP-Grep server
client = MCPClient()
# Get information about the grep binary
grep_info = client.get_resource("grep://info")
print(grep_info)
# Search for a pattern in files
result = client.use_tool("grep", {
"pattern": "search_pattern",
"paths": ["file.txt", "directory/"],
"ignore_case": True,
"recursive": True
})
print(result)
One of the powerful features of MCP-Grep is its ability to understand natural language prompts, making it easier to use with LLMs. Here are some examples:
# Basic search
Search for 'error' in log.txt
# Case-insensitive search
Find all instances of 'WARNING' regardless of case in system.log
# With context lines
Search for 'exception' in error.log and show 3 lines before and after each match
# Recursive search
Find all occurrences of 'deprecated' in the src directory and its subdirectories
# Fixed string search (non-regex)
Search for the exact string '.*' in config.js
# Limited results
Show me just the first 5 occurrences of 'TODO' in the project files
# Multiple options
Find 'password' case-insensitively in all .php files, show 2 lines of context, and limit to 10 results
MCP-Grep includes an MCP Inspector integration for interactive debugging and testing:
# Start the MCP Inspector with MCP-Grep
mcp-grep-inspector
This opens a web-based UI where you can:
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.