Labsco
lechibang-1512 logo

Pecorino

from lechibang-1512

mcp server for code indexing and code quality metrics

πŸ”₯πŸ”₯πŸ”₯βœ“ VerifiedFreeAdvanced setup

Pecorino MCP Server

A Model Context Protocol (MCP) server for deep Git history statistics, repository health tracking, and Object-Oriented Design (OOD) metrics analysis.

Pecorino allows Large Language Models (LLMs) and dev tools (such as Claude Desktop or Cursor) to inspect codebases, analyze code structures, compute complexity/maintainability indexes, and detect risk hotspots.


✨ Features

  • πŸ”Œ Model Context Protocol (MCP): Exposes 4 unified tools (browse, metrics, report, update_index) to your AI assistant.
  • πŸ“Š Git History Analytics: Commits, LOC growth, author contributions, activity patterns, and team performance tracking.
  • πŸ“ Object-Oriented Design Metrics: Afferent/efferent coupling (Ca/Ce), instability (I), abstractness (A), and Distance-from-Main-Sequence (D) analysis.
  • 🚨 Risk Hotspot Detection: Combines code churn (revision frequency) and complexity to pinpoint high-risk source files.
  • πŸ—„οΈ Fast DuckDB-backed AST Indexing: Leverages tree-sitter to index class definitions, functions, and imports for rapid codebase navigation and search.
  • πŸ’» Flexible CLI & HTTP SSE: Run as a standard CLI tool, start a local stdio MCP server, or deploy as a network-accessible SSE server.

πŸ› οΈ Exposed MCP Tools

Once connected, your AI assistant can use the following tools:

1. /browse

Inspects directories, files, or performs a semantic FTS search on the indexed codebase.

  • Parameters:
    • target (string, required): Absolute path to the file or directory.
    • view (string, optional): "summary" (default), "classes", "functions", "deps" (imports), "tree" (directory tree), or "search" (semantic search).
    • query (string, optional): The search term (required if view is "search").

2. /metrics

Computes design metrics, cyclomatic complexity, Halstead metrics, or risk hotspots.

  • Parameters:
    • target (string, required): Absolute path to the file or folder.
    • what (array of strings, optional): Metrics to run ("oop", "complexity", "hotspots", or "all").

3. /report

Runs a full repository scan and exports a structured JSON report directly to <repo_name>_report/pecorino_metrics.json inside your specified output directory.

  • Parameters:
    • repo_path (string, required): Absolute path to the Git repository.
    • output_path (string, required): Absolute path to the output directory.

4. /update_index

Performs tree-sitter AST analysis and populates the DuckDB codebase index for fast semantic searching.

  • Parameters:
    • target (string, required): Absolute path to the file or folder to index.

πŸ“‚ Repository Layout

  • src/cli/ β€” Command-line interface and entry points.
  • src/core/ β€” Core metrics collector and configuration.
  • src/git/ β€” Git history and commit log parsers.
  • src/mcp_server/ β€” MCP server endpoints and core logic.
    • src/mcp_server/index.py β€” DuckDB Full-Text Search (FTS) codebase index.
    • src/mcp_server/gorgonzola_graph.py β€” Gorgonzola graph database adapter.
  • src/metrics/ β€” Maintainability index and Object-Oriented design metrics analyzers.
  • src/parsers/ β€” AST parsing (using Tree-sitter).
  • src/transports/ β€” MCP Adapters (stdio, fastAPI).
  • src/utils/ β€” Export formats and helper utilities.
  • tests/ β€” Automated test suites.

πŸ–₯️ Command Line Interface (CLI)

You can also run Pecorino directly via the terminal:

Copy & paste β€” that's it
# Start the stdio MCP server manually
pecorino-mcp --transport stdio

# Start the SSE MCP server (requires Starlette & Uvicorn: pip install -e .[sse])
pecorino-mcp --transport sse --host 127.0.0.1 --port 8000

# Run a CLI analysis and save the report inside a directory
python pecorino.py /path/to/repo /path/to/output_dir

For comprehensive CLI flags, transport details, and configuration options, see the Local Server Deployment Guide.


πŸ“„ License & Contributing

This project is licensed under the GNU Affero General Public License v3 (AGPL-3.0) - see the LICENSE file for details. Contributions, bug reports, and improvements are welcome! Open an issue or submit a pull request with small, focused changes.