A minimal and powerful MCP (Model Context Protocol) server that wraps ripgrep for efficient code search. This server allows AI models like Anthropic's Claude to search code repositories quickly and accurately using ripgrep's high-performance search capabilities.
The Ripgrep MCP server provides AI models with a powerful tool to search through code repositories. It supports:
- Fast, efficient code search using ripgrep's optimized algorithms
- Regular expression and literal string search
- Path filtering and type-specific searches
- Clear, consistent JSON output that AI models can easily interpret
- Security features like path traversal prevention
- Both local binary and Docker container deployment options
- Rust 1.86 or later
- ripgrep (
rg) installed and in PATH - Docker (optional, for containerized deployment)
# Clone the repository
git clone https://github.com/randomm/mcp-rg.git
cd mcp-rg
# Build for release
cargo build --release
# The binary will be available at target/release/mcp-rg# Clone the repository
git clone https://github.com/randomm/mcp-rg.git
cd mcp-rg
# Build Docker image
docker build -t ripgrep-mcp .Claude Desktop allows you to use MCP servers through simple configuration. Follow these steps:
- Open Claude menu on your computer and select "Settings…"
- Click on "Developer" in the left-hand bar of the Settings pane
- Click on "Edit Config"
- Add the ripgrep MCP configuration to your
claude_desktop_config.json:
{
"mcpServers": {
"ripgrep": {
"command": "/path/to/mcp-rg/target/release/mcp-rg",
"env": {
"FILES_ROOT": "/path/to/your/code/directory",
"LOG_LEVEL": "error"
}
}
}
}- Replace
/path/to/mcp-rg/target/release/mcp-rgwith the actual absolute path to the compiled binary - Set
FILES_ROOTto the directory you want to search (must be an absolute path) - Restart Claude Desktop
- A hammer icon should appear in your input box - click it to see and use the ripgrep search tool
You can also run the MCP server in a Docker container:
{
"mcpServers": {
"ripgrep-docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/path/to/your/code:/app/files",
"-e",
"FILES_ROOT=/app/files",
"-e",
"LOG_LEVEL=error",
"ripgrep-mcp"
]
}
}
}Important: The -i flag is crucial for STDIO transport to work correctly with Docker.
Claude Code CLI provides a more direct way to add and manage MCP servers:
# Add the ripgrep MCP server to your local environment
claude mcp add ripgrep -e FILES_ROOT=/path/to/your/code/directory -- /path/to/mcp-rg/target/release/mcp-rg
# Or use the add-json command for more configuration options
claude mcp add-json ripgrep '{
"type": "stdio",
"command": "/path/to/mcp-rg/target/release/mcp-rg",
"env": {
"FILES_ROOT": "/path/to/your/code/directory",
"LOG_LEVEL": "error"
}
}'To add it to a project for the entire team, use:
# Add to project scope (creates/updates .mcp.json)
claude mcp add ripgrep -s project -e FILES_ROOT=/path/to/your/code/directory -- /path/to/mcp-rg/target/release/mcp-rgYou can also run the MCP server in a Docker container with Claude Code:
# Add the ripgrep MCP server in a Docker container
claude mcp add ripgrep-docker -- docker run -i --rm -v /path/to/your/code:/app/files -e FILES_ROOT=/app/files ripgrep-mcpTo use the ripgrep MCP server with Cursor editor:
- Navigate to Settings, then Cursor Settings
- Select MCP on the left
- Click "Add new global MCP server" at the top right
- Enter the following configuration:
{
"ripgrep": {
"command": "/path/to/mcp-rg/target/release/mcp-rg",
"env": {
"FILES_ROOT": "/path/to/your/code/directory",
"LOG_LEVEL": "error"
}
}
}- Save the configuration and restart Cursor
You can also run the MCP server in a Docker container:
{
"ripgrep-docker": {
"command": "docker",
"args": [
"run",
"-i",
"--rm",
"-v",
"/path/to/your/code:/app/files",
"-e",
"FILES_ROOT=/app/files",
"ripgrep-mcp"
]
}
}For containerized deployment:
# Build Docker image
docker build -t ripgrep-mcp .
# Run with STDIO transport (for direct model connections)
# The -i flag is crucial for STDIO transport to work
docker run -i --rm -v /path/to/your/code:/app/files -e FILES_ROOT=/app/files ripgrep-mcp
# Using docker-compose
docker-compose upThe server implements the following MCP transport protocols:
- STDIO (Standard Input/Output): The default transport for local integrations. All examples above use this transport method.
- HTTP with SSE: Not currently implemented, but could be added for remote connections in the future.
Docker containers can successfully use STDIO transport for MCP communication. Key requirements:
- The Docker container must be run with the
-iflag orstdin_open: truein docker-compose.yml to keep STDIN open - All logging in the application should be directed to STDERR, not STDOUT, to avoid interfering with the JSON-RPC protocol
- The container should be built for the same architecture as the host system, or using a multi-stage build
- For Claude Desktop or other MCP clients to communicate with the Docker container, they must be configured to launch Docker with the proper arguments
Example docker-compose.yml configuration:
services:
ripgrep-mcp:
build: .
stdin_open: true # Equivalent to -i flag, keeps STDIN open
volumes:
- ./:/app/files
environment:
- FILES_ROOT=/app/filesThe server implements the Model Context Protocol (MCP) and exposes a single tool:
Searches files using ripgrep.
pattern(string, required): Search patternpath(string, optional): Relative path within root directoryfixed_strings(boolean, optional): Use fixed strings instead of regexcase_sensitive(boolean, optional): Case-sensitive searchline_numbers(boolean, optional): Include line numbers in outputcontext_lines(number, optional): Number of context lines to showfile_types(array of strings, optional): File types to include (e.g., "rust", "js")max_depth(number, optional): Maximum depth to search
{
"matches": [
"path/to/file.rs:10: println!(\"Hello, world!\");"
],
"stats": {
"matched_lines": 1,
"elapsed_ms": 5
}
}With an MCP client, you can send requests to the server using the following format:
{
"jsonrpc": "2.0",
"id": 1,
"method": "tools/call",
"params": {
"name": "search",
"arguments": {
"pattern": "fn main",
"path": "src",
"fixed_strings": false,
"line_numbers": true
}
}
}The repository includes test scripts to verify the functionality of the MCP server:
# Make the test script executable
chmod +x tests/test_local_mcp.sh
# Run the test
./tests/test_local_mcp.sh# Make the test script executable
chmod +x tests/test_mcp_docker.sh
# Build the Docker image if you haven't already
docker build -t ripgrep-mcp .
# Run the test
./tests/test_mcp_docker.shIf the tests pass, you'll see a success message confirming that the MCP server is working correctly.
Once the ripgrep MCP server is connected to Claude, you can use it like this:
Query: "Search for 'async fn' in the src directory"
Claude will use the ripgrep search tool to find instances of "async fn" in your source code and display the results.
Query: "Find all function definitions related to configuration in the project"
Claude will search for functions related to configuration using ripgrep and analyze the results.
Query: "Search for error handling patterns in the codebase and exclude test files"
Claude will craft an appropriate ripgrep search query to find error handling patterns while excluding test files.
For direct testing without Claude, you can send JSON-RPC requests to the server:
# For local binary
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | \
FILES_ROOT=/path/to/your/code ./target/release/mcp-rg
# For Docker
echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{}}' | \
docker run -i --rm -v /path/to/your/code:/app/files ripgrep-mcpFILES_ROOT: Root directory to search (default: current directory)LOG_LEVEL: Logging level (trace, debug, info, warn, error) (default: info)
- The server implements path traversal prevention
- All inputs are validated
- The Docker container runs as a non-root user
- Only provide access to code repositories that you want the AI model to search
If you encounter issues:
- Check that ripgrep (
rg) is installed and available in your PATH - Verify that the
FILES_ROOTdirectory exists and is accessible - For permission issues, check that the user running the server has read access to the files
- Set
LOG_LEVEL=debugfor more detailed logs
If you're running the server in Docker:
- Make sure to include the
-iflag when running the container (docker run -i ...) - Ensure the volume is correctly mounted (
-v /host/path:/app/files) - Check that ripgrep is installed in the container (our Dockerfile takes care of this)
- For filesystem permission issues, you may need to adjust the user in the Dockerfile
- Always build the Docker image using the multi-stage build in our Dockerfile rather than using a pre-built binary, as architecture compatibility issues may arise (e.g., ARM64 vs x86_64)
- If you encounter "too many open files" errors when mounting volumes, try restarting the Docker daemon
src/main.rs: Application entry pointsrc/config.rs: Configuration managementsrc/error.rs: Error handlingsrc/ripgrep.rs: Ripgrep wrappersrc/mcp.rs: MCP server implementation
cargo testContributions are welcome! Here are ways you can contribute:
- Bug Fixes: Help fix issues and improve the server's stability
- New Features: Implement new search capabilities or MCP tools
- Documentation: Improve README, code documentation, or examples
- Testing: Add more tests or testing utilities
Please follow these steps to contribute:
- Fork the repository
- Create a feature branch (
git checkout -b feature/awesome-feature) - Make your changes
- Run tests to ensure everything works
- Commit your changes (
git commit -m 'Add awesome feature') - Push to the branch (
git push origin feature/awesome-feature) - Open a Pull Request