by erniebrodeur
mcp-grep is a Python-based MCP server that brings grep functionality to LLMs, allowing natural language pattern searching and file analysis.
mcp-grep is a Python-based server that exposes the functionality of the grep
command-line utility through the Model Context Protocol (MCP). This allows Large Language Models (LLMs) and other MCP-compatible clients to interact with grep
for pattern searching and file analysis using natural language prompts.
Installation:
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude
pip install mcp-grep
Running the Server:
mcp-grep-server
mcp-grep-inspector
API Usage (Python Client):
from mcp.client import MCPClient
client = MCPClient()
grep_info = client.get_resource("grep://info")
print(grep_info)
result = client.use_tool("grep", {
"pattern": "search_pattern",
"paths": ["file.txt", "directory/"],
"ignore_case": True,
"recursive": True
})
print(result)
Natural Language Prompts: mcp-grep understands natural language queries, making it easy to integrate with LLMs. Examples include:
grep
binary information (path, version, supported features).grep
options: case-insensitive matching, context lines, max match count, fixed string matching, recursive directory searching.grep
queries.Q: What is MCP? A: MCP stands for Model Context Protocol, which is a protocol designed to allow language models to interact with external tools and resources.
Q: Can I use mcp-grep with other LLMs besides Claude? A: Yes, mcp-grep is designed to be compatible with any MCP-compatible client, not just Claude Desktop.
Q: Does mcp-grep support all grep
functionalities?
A: mcp-grep supports common and frequently used grep
features, as listed in the "Key Features" section. For a comprehensive list, refer to the project's documentation or the grep
man page.
Q: How can I contribute to mcp-grep?
A: You can contribute by cloning the repository, installing in development mode (pip install -e ".[dev]"
), and running tests (pytest
). Refer to the "Development" section in the README for more details.
A grep server implementation that exposes grep functionality through the Model Context Protocol (MCP).
To install Grep Server for Claude Desktop automatically via Smithery:
npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude
pip install mcp-grep
MCP-Grep runs as a server that can be used by MCP-compatible clients:
# Start the MCP-Grep server
mcp-grep-server
# Or use the MCP Inspector for interactive debugging and testing
mcp-grep-inspector
The server exposes the following MCP functionality:
grep://info
- Returns information about the system grep binarygrep
- Searches for patterns in files using the system grep binaryUsing 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)
MCP-Grep understands natural language prompts, making it easier to use with LLMs. 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:
# Clone the repository
git clone https://github.com/erniebrodeur/mcp-grep.git
cd mcp-grep
# Install in development mode
pip install -e ".[dev]"
# Run tests
pytest
MIT
Please log in to share your review and rating for this MCP.