Grep MCP server

Exposes the system grep binary's functionality for searching files with regular expressions, supporting common options like case-insensitive matching, context lines, and recursive directory searching.
Back to servers
Provider
Ernie Brodeur
Release date
Mar 21, 2025
Language
Python
Package
Stats
1.4K downloads
2 stars

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).

Installation Options

Installing via Smithery

The easiest way to install MCP-Grep for Claude Desktop is via Smithery:

npx -y @smithery/cli install @erniebrodeur/mcp-grep --client claude

Manual Installation

Alternatively, you can install MCP-Grep directly using pip:

pip install mcp-grep

Running the Server

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

Available Features

MCP-Grep provides the following functionality:

  • Information about your system's grep binary (path, version, supported features)
  • Pattern searching in files using regular expressions
  • Support for common grep options, including:
    • Case-insensitive matching
    • Context lines (before and after matches)
    • Maximum match count
    • Fixed string matching (non-regex)
    • Recursive directory searching
  • Natural language prompt understanding for easier use with LLMs

API Usage

Using the MCP Python Client

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)

Using Natural Language Prompts

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 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

Using the MCP Inspector

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:

  • Explore available resources and tools
  • Test grep operations with different parameters
  • View formatted results
  • Debug issues with your grep queries

How to add this MCP server to Cursor

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.

Adding an MCP server to Cursor globally

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"
            ]
        }
    }
}

Adding an MCP server to a project

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.

How to use the MCP server

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.

Want to 10x your AI skills?

Get a free account and learn to code + market your apps using AI (with or without vibes!).

Nah, maybe later