Skip to main content
Glama
Code Search, Read & PR Analysis

Code Search, Read & PR Analysis

by tuanpham197

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

Related MCP server: Local Code MCP Server

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 for

  • path (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 repository

  • branch (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 for

  • path (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.

Available Tools

6 tools
get_pr_diffC

Fetch and analyze Pull Request changes from GitHub

Inputs: repo (required), pr_number (required).

grep_github_repoC

Search for code content in a GitHub repository (grep-like search)

Inputs: repo (required), query (required), path.

read_fileA

Read the full contents of a file from the local filesystem

Inputs: file_path (required).

read_github_fileC

Read the contents of a file from a GitHub repository

Inputs: repo (required), file_path (required), branch.

search_filesB

Search for files by name pattern (glob) or content (grep) in local codebase

Inputs: query (required), search_type (required), path.

search_github_filesC

Search for files in a GitHub repository by name or path pattern

Inputs: repo (required), query (required), path.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    B3.4/5.0

    Scored across 6 tools

    Disambiguation4/5

    Most tools have distinct purposes, but there is some overlap between grep_github_repo (search for code content) and search_github_files (search for files by name/path), which could cause confusion about which to use for GitHub content searches. The local vs. GitHub separation is clear, but the search functionality has minor ambiguity.

    Naming Consistency5/5

    All tool names follow a consistent snake_case pattern with clear verb_noun structure (e.g., get_pr_diff, read_file, search_files). The naming is predictable and readable throughout the set, with no deviations in style or convention.

    Tool Count5/5

    With 6 tools, the server is well-scoped for its purpose of code search, reading, and PR analysis. Each tool serves a specific function, and the count is appropriate without being too thin or bloated, fitting typical expectations for this domain.

    Completeness4/5

    The toolset covers core operations for code search and reading across local and GitHub contexts, with PR analysis included. A minor gap is the lack of tools for creating or modifying code (e.g., write operations), but for a read/search-focused server, the surface is largely complete and supports key workflows.

    Maintenance

    ActivityInactive
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers

    • A
      license
      A
      quality
      D
      maintenance
      Provides LLM-optimized filesystem access with intelligent file pagination for large files, lightning-fast ripgrep-powered code search with regex support, and security sandboxing to safely explore and search codebases.
      7
      10 npm
      1
      MIT
    • F
      license
      B
      quality
      D
      maintenance
      Provides LLMs with safe, read-only access to local codebases for searching, reading files, and finding function definitions. All source code remains local, ensuring privacy while enabling AI assistants to explore project structures and functionality.
      4
      -
    • A
      license
      Not graded
      quality
      B
      maintenance
      Enables language models to explore and analyze source code repositories through read-only tools for listing directories, reading files, searching code, finding symbols, and inspecting git history, with strict sandboxing and security controls.
      MIT