npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@247arjun/mcp-grep

v1.0.0

Published

An MCP server that exposes grep functionality with natural language search capabilities

Readme

MCP Grep Server

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

Quick Start

1. Configure with Claude Desktop

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

2. Restart Claude Desktop

After adding the configuration, restart Claude Desktop to load the MCP server.

3. Start Using

Ask Claude to search your files:

  • "Find all email addresses in my project"
  • "Search for TODO comments in JavaScript files"
  • "Count function definitions in the src directory"

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 search
  • case_sensitive (boolean, optional): Case-sensitive search (default: false)
  • max_results (number, optional): Limit number of results
  • show_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 pattern
  • target (string): File or directory path to search
  • case_sensitive (boolean, optional): Case-sensitive search
  • whole_words (boolean, optional): Match whole words only
  • invert_match (boolean, optional): Show non-matching lines
  • max_results (number, optional): Limit results
  • show_context (boolean, optional): Show context lines
  • context_lines (number, optional): Context line count
  • file_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 count
  • target (string): Search target
  • case_sensitive (boolean, optional): Case sensitivity
  • whole_words (boolean, optional): Whole word matching
  • by_file (boolean, optional): Show count per file
  • file_extensions (array, optional): File extension filter

4. grep_files_with_matches

List files containing the pattern.

Parameters:

  • pattern (string): Search pattern
  • target (string): Directory to search
  • case_sensitive (boolean, optional): Case sensitivity
  • whole_words (boolean, optional): Whole word matching
  • file_extensions (array, optional): File extensions to include
  • exclude_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

MCP Integration

This server implements the Model Context Protocol and can be used with any MCP-compatible client.

Supported MCP Clients

  • Claude Desktop (recommended)
  • Cline VS Code Extension
  • Continue.dev
  • Any other MCP-compatible client

Server Configuration Examples

Claude Desktop

{
  "mcpServers": {
    "mcp-grep": {
      "command": "mcp-grep",
      "args": [],
      "description": "Advanced text search capabilities"
    }
  }
}

Alternative: Using npx (no global install needed)

{
  "mcpServers": {
    "mcp-grep": {
      "command": "npx",
      "args": ["@247arjun/mcp-grep"],
      "description": "Advanced text search capabilities"
    }
  }
}

Local Development Setup

{
  "mcpServers": {
    "mcp-grep": {
      "command": "node",
      "args": ["/absolute/path/to/mcp-grep/build/index.js"],
      "description": "Advanced text search capabilities"
    }
  }
}

Troubleshooting

Common Issues

  1. "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"]
  2. "Permission denied" error

    • Check file permissions: chmod +x build/index.js
    • Rebuild the project: npm run build
  3. MCP server not appearing in Claude

    • Verify JSON syntax in configuration file
    • Restart Claude Desktop completely
    • Check that the command path is correct
  4. "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 spawn with shell: false to 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