Code Search, Read & PR Analysis
Enables LLMs to search and read files in local and GitHub repositories, analyze pull request diffs, and grep code content with built-in security protections.
README
MCP Server: Code Search, Read & PR Analysis
A Python-based Model Context Protocol (MCP) server that enables LLMs to interact with codebases through search, read, and PR analysis capabilities.
Features
Local Operations:
- 🔍 Search: Find files by name (glob) or content (grep) in local repositories
- 📖 Read: Safely read file contents with path traversal protection
GitHub Integration:
- 🔄 PR Analysis: Fetch and analyze GitHub Pull Request diffs
- 🔎 GitHub Search: Search for files by name in any GitHub repository
- 📄 GitHub Read: Read file contents directly from GitHub repositories
- 🔬 Code Grep: Search code content across GitHub repositories
Security & Performance:
- 🔒 Security: Automatic filtering of sensitive files (.env, credentials, keys)
- ⚡ Performance: Uses native tools (ripgrep, git grep) for fast searches
Quick Start
# Install dependencies
uv sync
# Run the server
uv run python -m mcp_server
# Run tests
uv run pytest -v
Installation & Setup
For detailed instructions on running the server and installing it in VS Code, see run.md.
Project Structure
src/mcp_server/
├── server.py # Main MCP server entrypoint (6 tools)
├── tools/
│ ├── search.py # Local file search (glob/grep)
│ ├── read.py # Local safe file reading
│ └── github.py # GitHub integration (PR, search, read, grep)
tests/ # Comprehensive test suite (40 tests)
Available Tools
Local File Operations
1. search_files
Search for files by name pattern or content in local repository.
Parameters:
query(string): Search pattern (file pattern for glob, regex for grep)search_type(string): Either "glob" or "grep"path(string, optional): Root directory to search (defaults to current directory)
2. read_file
Read local file contents with security validation.
Parameters:
file_path(string): Path to the file to read
Security:
- Validates paths to prevent traversal attacks
- Blocks sensitive files (.env, credentials, keys)
GitHub Operations
3. get_pr_diff
Fetch GitHub Pull Request diffs.
Parameters:
repo(string): Repository in format "owner/repo"pr_number(integer): Pull request number
4. search_github_files
Search for files by name in a GitHub repository.
Parameters:
repo(string): Repository in format "owner/repo"query(string): Filename or path pattern to search forpath(string, optional): Path prefix to search within (e.g., "src/")
5. read_github_file
Read file contents directly from a GitHub repository.
Parameters:
repo(string): Repository in format "owner/repo"file_path(string): Path to the file in the repositorybranch(string, optional): Branch name (defaults to "main")
6. grep_github_repo
Search for code content in a GitHub repository (grep-like).
Parameters:
repo(string): Repository in format "owner/repo"query(string): Code content to search forpath(string, optional): Path prefix to search within
Note: GitHub operations require GITHUB_TOKEN environment variable for private repos and to avoid rate limits.
Development
# Install in development mode
uv pip install -e .
# Run tests with coverage
uv run pytest -v
# Lint code
uv run ruff check .
# Format code
uv run ruff format .
Configuration
See run.md for VS Code and Claude Desktop configuration examples.
Security
- All file operations validate paths to prevent directory traversal
- Sensitive files are automatically filtered from search results
- GitHub tokens should be stored securely (use environment variables)
- Server operates in stateless mode
Requirements
- Python 3.12+
- uv package manager
- Optional: ripgrep (for faster grep searches)
- Optional: GitHub token (for GitHub operations)
Documentation
- run.md - Detailed setup and installation guide
- doc.md - Original project specifications
- CLAUDE.md - Claude Code specific guidance
License
See LICENSE file for details.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。