Grep MCP Server
Provides powerful text search capabilities using the grep command-line utility, allowing users to search files and directories using both natural language descriptions and regex patterns.
Tools
grep_search_intent
Search for patterns using plain English descriptions (e.g., 'email addresses', 'phone numbers', 'TODO comments')
grep_regex
Search using a direct regex pattern
grep_count
Count the number of matches for a pattern
grep_files_with_matches
List only the names of files that contain the pattern
grep_advanced
Execute grep with custom arguments (advanced usage)
README
MCP Server for Grep
A Model Context Protocol (MCP) server that provides powerful text search capabilities using the grep command-line utility. This server allows you to search for patterns in files and directories using both natural language descriptions and direct regex patterns.
Features
🧠 Natural Language Search
- Describe what you're looking for in plain English
- Automatic conversion to appropriate regex patterns
- Built-in patterns for common searches (emails, URLs, phone numbers, etc.)
🔍 Advanced Search Capabilities
- Direct regex pattern matching
- Recursive directory searching
- File extension filtering
- Case-sensitive/insensitive search
- Whole word matching
- Context line display
- Match counting
- File listing with matches
🛡️ Security First
- Safe command execution using
child_process.spawn - Input validation with Zod schemas
- No shell injection vulnerabilities
- Path validation and sanitization
Installation
Method 1: NPM Installation (Recommended)
# Install globally
npm install -g @247arjun/mcp-grep
# Or install locally in your project
npm install @247arjun/mcp-grep
Method 2: From Source
# Clone the repository
git clone https://github.com/247arjun/mcp-grep.git
cd mcp-grep
# Install dependencies
npm install
# Build the project
npm run build
# Optional: Link globally
npm link
Method 3: Direct from GitHub
# Install directly from GitHub
npm install -g git+https://github.com/247arjun/mcp-grep.git
Configuration
Claude Desktop Setup
Add to your Claude Desktop configuration file:
Location:
- macOS:
~/Library/Application Support/Claude/claude_desktop_config.json - Windows:
%APPDATA%/Claude/claude_desktop_config.json
Configuration:
{
"mcpServers": {
"mcp-grep": {
"command": "mcp-grep",
"args": []
}
}
}
Alternative: Using npx (no global install needed)
{
"mcpServers": {
"mcp-grep": {
"command": "npx",
"args": ["@247arjun/mcp-grep"]
}
}
}
Local Development Setup
{
"mcpServers": {
"mcp-grep": {
"command": "node",
"args": ["/absolute/path/to/mcp-grep/build/index.js"]
}
}
}
After adding the configuration, restart Claude Desktop to load the MCP server.
Verification
Test that the server is working:
# Test the built server
node build/index.js
# Should show: "Grep MCP Server running on stdio"
# Press Ctrl+C to exit
Available Tools
1. grep_search_intent
Search using natural language descriptions.
Parameters:
intent(string): Plain English description (e.g., "email addresses", "TODO comments")target(string): File or directory path to searchcase_sensitive(boolean, optional): Case-sensitive search (default: false)max_results(number, optional): Limit number of resultsshow_context(boolean, optional): Show surrounding lines (default: false)context_lines(number, optional): Number of context lines (default: 2)
Example:
{
"intent": "email addresses",
"target": "./src",
"show_context": true,
"context_lines": 1
}
2. grep_regex
Search using direct regex patterns.
Parameters:
pattern(string): Regular expression patterntarget(string): File or directory path to searchcase_sensitive(boolean, optional): Case-sensitive searchwhole_words(boolean, optional): Match whole words onlyinvert_match(boolean, optional): Show non-matching linesmax_results(number, optional): Limit resultsshow_context(boolean, optional): Show context linescontext_lines(number, optional): Context line countfile_extensions(array, optional): Filter by file extensions
Example:
{
"pattern": "function\\s+\\w+\\s*\\(",
"target": "./src",
"file_extensions": ["js", "ts"],
"show_context": true
}
3. grep_count
Count matches for a pattern.
Parameters:
pattern(string): Pattern to counttarget(string): Search targetcase_sensitive(boolean, optional): Case sensitivitywhole_words(boolean, optional): Whole word matchingby_file(boolean, optional): Show count per filefile_extensions(array, optional): File extension filter
4. grep_files_with_matches
List files containing the pattern.
Parameters:
pattern(string): Search patterntarget(string): Directory to searchcase_sensitive(boolean, optional): Case sensitivitywhole_words(boolean, optional): Whole word matchingfile_extensions(array, optional): File extensions to includeexclude_patterns(array, optional): File patterns to exclude
5. grep_advanced
Execute grep with custom arguments (advanced users).
Parameters:
args(array): Array of grep arguments (excluding 'grep' itself)
Built-in Natural Language Patterns
The server recognizes these natural language intents:
Communication
- "email", "email address", "emails" → Email address pattern
- "url", "urls", "website", "link", "links" → URL pattern
- "phone", "phone number", "phone numbers" → Phone number pattern
Network
- "ip", "ip address", "ip addresses" → IPv4 address pattern
Data Types
- "number", "numbers", "integer", "integers" → Numeric patterns
- "date", "dates" → Date patterns
Code Patterns
- "function", "functions" → Function declarations
- "class", "classes" → Class definitions
- "import", "imports" → Import statements
- "export", "exports" → Export statements
- "comment", "comments" → Comment lines
- "todo", "todos" → TODO/FIXME/HACK comments
Error Patterns
- "error", "errors" → Error messages
- "warning", "warnings" → Warning messages
Usage Examples
Search for email addresses in a project
{
"tool": "grep_search_intent",
"intent": "email addresses",
"target": "./src",
"show_context": true
}
Find all TODO comments
{
"tool": "grep_search_intent",
"intent": "todo comments",
"target": "./",
"file_extensions": ["js", "ts", "py"]
}
Search for function definitions with regex
{
"tool": "grep_regex",
"pattern": "^\\s*function\\s+\\w+",
"target": "./src",
"file_extensions": ["js"]
}
Count occurrences of a word
{
"tool": "grep_count",
"pattern": "async",
"target": "./src",
"by_file": true
}
List files containing import statements
{
"tool": "grep_files_with_matches",
"pattern": "^import",
"target": "./src",
"file_extensions": ["js", "ts"]
}
Development
Build and Run
# Development with auto-rebuild
npm run dev
# Production build
npm run build
# Start the server
npm start
Project Structure
mcp-grep/
├── src/
│ └── index.ts # Main server implementation
├── build/ # Compiled JavaScript output
├── package.json # Project configuration
├── tsconfig.json # TypeScript configuration
└── README.md # This file
Troubleshooting
Common Issues
-
"Command not found" error
- Ensure mcp-grep is installed globally:
npm install -g @247arjun/mcp-grep - Or use npx:
"command": "npx", "args": ["@247arjun/mcp-grep"]
- Ensure mcp-grep is installed globally:
-
"Permission denied" error
- Check file permissions:
chmod +x build/index.js - Rebuild the project:
npm run build
- Check file permissions:
-
MCP server not appearing in Claude
- Verify JSON syntax in configuration file
- Restart Claude Desktop completely
- Check that the command path is correct
-
"grep command not found"
- Install grep on your system (usually pre-installed on macOS/Linux)
- Windows users: Install via WSL or use Git Bash
Debugging
Enable verbose logging by setting environment variable:
# For development
DEBUG=1 node build/index.js
# Test with sample input
echo '{"jsonrpc": "2.0", "method": "initialize", "params": {}}' | node build/index.js
Security Notes
- Uses
spawnwithshell: falseto prevent command injection - Validates all file paths before execution
- Blocks potentially dangerous grep flags in advanced mode
- Input validation with Zod schemas
- No access to system files outside specified targets
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。