Skip to main content

Grep MCP Server - non official MCP for grep.app

Project description

Grep MCP Server

A Model Context Protocol (MCP) server that provides GitHub code search capabilities through the grep.app API. This server enables AI assistants to search through millions of GitHub repositories for specific code patterns, functions, and implementations.

🚀 Features

  • 🔍 GitHub Code Search: Search across millions of GitHub repositories using grep.app's powerful search index
  • 🎯 Advanced Filtering: Filter results by programming language, repository, and file path
  • 📊 Smart Formatting: Results include syntax highlighting, repository grouping, and summary statistics
  • ⚡ High Performance: Async implementation with proper error handling and rate limiting
  • 🛠️ Multiple Transport Modes: Supports both stdio and SSE (Server-Sent Events) transport
  • 📝 Rich Results: Returns file paths, line numbers, code snippets, and repository information

📋 Requirements

  • Python: 3.10 or higher
  • Dependencies:
    • mcp - Model Context Protocol framework
    • starlette - Web framework for SSE transport
    • uvicorn - ASGI server
    • aiohttp - Async HTTP client for API requests

🔧 Installation

Using uv (Recommended)

# Install directly from PyPI
uv add grep-mcp

# Or install from source
git clone https://github.com/galperetz/grep-mcp.git
cd grep-mcp
uv sync

Using pip

pip install grep-mcp

🎯 Usage

As MCP Server (Recommended)

Add to your MCP client configuration:

{
  "mcpServers": {
    "grep-mcp": {
      "command": "uvx",
      "args": ["grep-mcp"]
    }
  }
}

Direct Execution

# Run with stdio transport (default)
python -m grep_mcp

# Run with SSE transport
python -m grep_mcp --transport sse --host 0.0.0.0 --port 8080

Command Line Arguments

  • --transport: Choose between stdio (default) or sse
  • --host: Host to bind to for SSE mode (default: 0.0.0.0)
  • --port: Port to listen on for SSE mode (default: 8080)

🔧 Available Tools

grep_query

Search GitHub repositories for specific code patterns.

Parameters:

  • query (required): The search query string
  • language (optional): Programming language filter (e.g., "Python", "JavaScript")
  • repo (optional): Repository filter in format "owner/repo" (e.g., "fastapi/fastapi")
  • path (optional): Path filter for specific directories (e.g., "src/")

Examples:

# Basic search
grep_query("async def main")

# Search Python files only
grep_query("FastAPI", language="Python")

# Search specific repository
grep_query("class Config", repo="fastapi/fastapi")

# Search in specific directory
grep_query("import", path="src/")

# Combined filters
grep_query("async def", language="Python", repo="fastapi/fastapi")

📊 Response Format

The tool returns structured JSON with:

{
  "query": "your search query",
  "summary": {
    "total_results": 12345,
    "results_shown": 10,
    "repositories_found": 4,
    "top_languages": [
      { "language": "Python", "count": 8500 },
      { "language": "JavaScript", "count": 2000 }
    ],
    "top_repositories": [{ "repository": "owner/repo", "count": 150 }]
  },
  "results_by_repository": [
    {
      "repository": "owner/repo",
      "matches_count": 89,
      "files": [
        {
          "file_path": "src/main.py",
          "branch": "main",
          "total_matches": 5,
          "line_numbers": [10, 25, 30],
          "language": "python",
          "code_snippet": "```python\nasync def main():\n    app = FastAPI()\n    return app\n```"
        }
      ]
    }
  ]
}

🏗️ Architecture

  • FastMCP Framework: Built on the FastMCP framework for easy MCP server development
  • Async HTTP Client: Uses aiohttp for non-blocking API requests
  • Response Formatting: Intelligent parsing and formatting of grep.app responses
  • Error Handling: Comprehensive error handling for API failures, timeouts, and rate limits
  • Transport Flexibility: Supports both stdio and web-based SSE transport modes

🛡️ Error Handling

The server handles various error conditions gracefully:

  • Rate Limiting: Automatic detection and user-friendly error messages
  • Network Timeouts: 30-second timeout with proper error reporting
  • API Failures: Graceful handling of grep.app API issues
  • Invalid Parameters: Comprehensive parameter validation with helpful error messages

🧪 Testing

Run the test suite:

# Using uv
uv run pytest

# Using pytest directly
pytest tests/

Test coverage includes:

  • MCP server initialization
  • Tool parameter validation
  • Error handling scenarios
  • Response formatting
  • Platform compatibility

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch: git checkout -b feature/amazing-feature
  3. Make your changes with tests
  4. Run the test suite: uv run pytest
  5. Format code: uv run black . && uv run isort .
  6. Commit changes: git commit -m 'Add amazing feature'
  7. Push to branch: git push origin feature/amazing-feature
  8. Open a Pull Request

📝 License

This project is licensed under the MIT License - see the LICENSE file for details.

🙏 Acknowledgments

📞 Support


Made with ❤️ for the AI development community

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

iflow_mcp_galprz_grep_mcp-1.0.3.tar.gz (12.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

iflow_mcp_galprz_grep_mcp-1.0.3-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file iflow_mcp_galprz_grep_mcp-1.0.3.tar.gz.

File metadata

  • Download URL: iflow_mcp_galprz_grep_mcp-1.0.3.tar.gz
  • Upload date:
  • Size: 12.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_galprz_grep_mcp-1.0.3.tar.gz
Algorithm Hash digest
SHA256 2df1672582e56511e099fc4bf776657f41aa7eb9c84ec089402469c14416ff9c
MD5 769de87ded76ca5520c78b1a802725bb
BLAKE2b-256 27b55461f205f1b93df824c373b2382525e7b295d194da41080eaa7070fe80c1

See more details on using hashes here.

File details

Details for the file iflow_mcp_galprz_grep_mcp-1.0.3-py3-none-any.whl.

File metadata

  • Download URL: iflow_mcp_galprz_grep_mcp-1.0.3-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.0 {"installer":{"name":"uv","version":"0.10.0","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Debian GNU/Linux","version":"13","id":"trixie","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for iflow_mcp_galprz_grep_mcp-1.0.3-py3-none-any.whl
Algorithm Hash digest
SHA256 e2633090311125efd993ce902d1b60457f0264a6b096b367756779c58450f877
MD5 601ab4826668780893cb4450a2f21043
BLAKE2b-256 529155183f354819e3a3a288f59046a010b55a5d593db05aa4ebf2cb9db5d8fa

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page