grep.app Code Search
Search code across millions of public GitHub repositories using the grep.app API.
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 frameworkstarlette- Web framework for SSE transportuvicorn- ASGI serveraiohttp- 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 betweenstdio(default) orsse--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 stringlanguage(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
- Fork the repository
- Create a feature branch:
git checkout -b feature/amazing-feature - Make your changes with tests
- Run the test suite:
uv run pytest - Format code:
uv run black . && uv run isort . - Commit changes:
git commit -m 'Add amazing feature' - Push to branch:
git push origin feature/amazing-feature - Open a Pull Request
๐ License
This project is licensed under the MIT License - see the LICENSE file for details.
๐ Acknowledgments
- grep.app for providing the excellent GitHub search API
- MCP (Model Context Protocol) for the protocol specification
- FastMCP for the server framework
๐ Support
- Issues: GitHub Issues
- Repository: GitHub Repository
Made with โค๏ธ for the AI development community
Related Servers
Perplexity AI
Intelligent search, reasoning, and research capabilities powered by Perplexity's specialized AI models.
EzBiz Government Contracting Intelligence
AI-powered federal contract search, agency spending analysis, competitor win tracking, and set-aside monitoring.
Naver Map Direction MCP
Provides geographical and directional data from the Naver Map API.
bioRxiv
Search and retrieve articles from bioRxiv, the preprint server for biology.
EntRoute MCP
MCP Server for AI agents to discover and call pay-per-request APIs via EntRoute. Give Claude, Cursor, Windsurf, or any MCP-compatible agent access to 350+ verified x402 API endpoints across 110+ capabilities โ DeFi prices, web search, prediction markets, news, and more.
DeepResearch
Lightning-Fast, High-Accuracy Deep Research Agent ๐ 8โ10x faster ๐ Greater depth & accuracy ๐ Unlimited parallel runs
doctree-mcp
BM25 search + tree navigation over markdown docs for AI agents. No embeddings, no LLM calls at index time.
Expert Registry MCP Server
An MCP server for expert discovery, registration, and context injection, utilizing vector and graph databases.
RollingGo-Flight-MCP
RollingGo Flight Search MCP Server. Provides airport search and flight query capabilities for AI Agents and MCP clients via FastMCP.
Web Search
Perform Google searches and view web content with advanced bot detection avoidance.