Codebase Intelligence MCP Server

Codebase Intelligence MCP Server

A production-grade MCP server for local git repositories that provides tools for code search, git history analysis, complexity metrics, test discovery, and dependency management.

Category
访问服务器

README

Codebase Intelligence MCP Server

CI Python 3.11+ License: MIT

A production-grade Model Context Protocol (MCP) server that exposes powerful code analysis and repository intelligence tools. Designed for local git repositories, this server provides tools for code search, git history analysis, complexity metrics, test discovery, and dependency management.

Perfect for integrating with Claude, Cursor, or other LLM-based development tools via MCP clients.

Quick Start (< 2 minutes)

# 1. Install
git clone https://github.com/atishay2411/langgraph-mcp-server
cd langgraph-mcp-server
pip install -e .

# 2. Set repository path
export CODEBASE_INTEL_REPO_ROOT=/path/to/your/git/repo

# 3. Run server (stdio mode - zero config)
python -m codebase_intel.server

# ✓ Ready for MCP clients!

Architecture

LLM Client (Claude/Cursor)
          │
          ├─ LangGraph Agent (custom StateGraph)
          │
          └─ MCP Client (MultiServerMCPClient)
                    │
          ┌─────────▼─────────┐
          │   MCP Transport   │
          │ (stdio or HTTP)   │
          └─────────┬─────────┘
                    │
       ┌────────────▼────────────┐
       │   FastMCP Server        │
       │ (codebase_intel)        │
       └────┬──────────┬─────────┘
            │          │
      ┌─────▼──┐    ┌──▼────────┐
      │9 Tools │    │4 Resources│
      │2 Prompts    │2 Prompts  │
      └─────┬──┘    └───────────┘
            │
    Repository (read-only)

Tools (9 available)

Tool Params Description Security
read_file() path, start_line, end_line Read files with line-range support ✓ Traversal guard
list_directory() path, max_depth Recursive directory tree (auto-exclude .git, node_modules) ✓ Dir exclusion
search_code() pattern, glob, regex Code search (literal + regex, glob patterns) ✓ Binary skip
git_log() path, max_count, since Repository history with filtering ✓ Subprocess allowlist
git_blame() path, start_line, end_line Per-line git attribution ✓ Arg list only
git_show() ref, path Show commit/tree/blob ✓ Ref validation
analyze_complexity() path, min_rank Cyclomatic complexity (Python, radon) ✓ Dir exclusion
list_dependencies() (none) Parse pyproject.toml/requirements.txt/package.json ✓ Error handling
discover_tests() path AST-based test discovery (no execution) ✓ No code exec

Resources (ambient context):

  • repo://structure — Dir tree (3 levels)
  • repo://readme — README content
  • repo://dependencies — All deps
  • repo://git-log — Last 20 commits

Prompts (templates with embedded data):

  • code_review_prompt(path, focus) — Customizable code review
  • summarize_recent_changes_prompt(max_commits) — Git history summary

Modes

Stdio Transport (local, zero-auth)

export CODEBASE_INTEL_REPO_ROOT=/path/to/repo
python -m codebase_intel.server
# Clients connect via stdin/stdout

HTTP Transport (remote, bearer-token auth)

export CODEBASE_INTEL_REPO_ROOT=/path/to/repo
export CODEBASE_INTEL_TRANSPORT=streamable-http
export CODEBASE_INTEL_AUTH_TOKEN=$(openssl rand -hex 32)
python -m codebase_intel.server
# Server at http://localhost:8000/mcp (requires Bearer token)

Docker

export TARGET_REPO_PATH=/path/to/repo
export CODEBASE_INTEL_AUTH_TOKEN=$(openssl rand -hex 32)
docker-compose up
# Server at http://localhost:8000/mcp

LangGraph Client Example

export GROQ_API_KEY=your_key
export CODEBASE_INTEL_REPO_ROOT=/path/to/repo
python -m codebase_intel_client "What's the most complex function?"

The client uses a custom StateGraph (explicit agent & tools nodes, not prebuilt one-liner) demonstrating production-grade LangGraph patterns.

Configuration

# Required
CODEBASE_INTEL_REPO_ROOT=/path/to/repo

# Optional (env vars, see .env.example)
CODEBASE_INTEL_LOG_LEVEL=INFO
CODEBASE_INTEL_TRANSPORT=stdio  # or streamable-http
CODEBASE_INTEL_AUTH_TOKEN=...   # required for HTTP

See .env.example for full options.

Security

Path Traversal Preventionresolve_within_repo() + normalization
Safe Git Execution — Argument lists, no shell, allowlisted subcommands
Directory Exclusions.git, node_modules, venv, etc. auto-skipped
Bearer Token Auth — Constant-time comparison, no side-channels
No Code Execution — AST-based parsing, no imports/subprocess for untrusted code
Read-Only Design — No write capabilities anywhere

Testing

pytest tests/ -v                              # All tests
pytest tests/ --cov=src/ --cov-report=html   # With coverage
pytest tests/test_tool_files.py -v           # Specific file

111+ tests passing (93% pass rate) covering security, tools, auth, dependencies, git operations, test discovery.

CI/CD

✅ Lint (ruff)
✅ Type-check (mypy)
✅ Tests (pytest + coverage)
✅ Docker build validation

See .github/workflows/ci.yml.

Project Layout

src/codebase_intel/              # MCP Server (9 tools, 4 resources, 2 prompts)
  ├── server.py                   # FastMCP assembly
  ├── config.py, logging_conf.py
  ├── security/                   # Path guard, git subprocess wrapper
  ├── tools/                       # 9 MCP tools
  ├── resources/, prompts/         # Resources & prompts
  └── auth/                        # Bearer token middleware

src/codebase_intel_client/       # LangGraph Client
  ├── graph.py                    # Custom StateGraph
  ├── nodes.py                    # Agent nodes
  ├── config.py, state.py
  └── run.py                      # CLI entrypoint

tests/                            # 111+ tests
.github/workflows/ci.yml          # GitHub Actions
Dockerfile, docker-compose.yml    # Containerization

Example Queries

# Find complex functions
"What functions in src/ have high cyclomatic complexity?"

# Analyze dependencies
"List all Python dependencies and their versions."

# Search patterns
"Find all async functions in the codebase."

# Test coverage
"Which test files exist and how many tests do we have?"

# Git insights
"What changed in the last 5 commits?"

Limitations (v1)

  • Python complexity analysis only (JS/TS coming)
  • Single repository (no monorepo support)
  • Read-only (by design)
  • Requires .git directory

Contributing

  1. Fork & branch
  2. pytest tests/ && ruff check .
  3. Submit PR

License

MIT — See LICENSE

Built With


Questions? Open an issue.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选