Skip to main content

Git repository documentation indexer with MCP server, CLI, and library interfaces

Project description

repo-ctx User Guide

A multi-provider repository documentation indexer and code analyzer supporting GitLab, GitHub, and local Git repositories.


MCP Tools (10 tools)

Repository Management

Tool Description
repo-ctx-search Search indexed repositories by exact name
repo-ctx-fuzzy-search Fuzzy/typo-tolerant search
repo-ctx-index Index a single repository
repo-ctx-index-group Index all repos in a group/org
repo-ctx-list List all indexed repositories
repo-ctx-docs Retrieve documentation content
// Index a repository
await mcp.call("repo-ctx-index", { repository: "owner/repo" });

// Fuzzy search
await mcp.call("repo-ctx-fuzzy-search", { query: "fastapi", limit: 5 });

// Get documentation
await mcp.call("repo-ctx-docs", { libraryId: "/owner/repo", maxTokens: 8000 });

Code Analysis

Tool Description
repo-ctx-analyze Extract symbols from code
repo-ctx-search-symbol Search symbols by name pattern
repo-ctx-get-symbol-detail Get detailed symbol info
repo-ctx-get-file-symbols List all symbols in a file

Supported languages: Python, JavaScript, TypeScript, Java, Kotlin

// Analyze code (JSON output)
await mcp.call("repo-ctx-analyze", {
  path: "./src",
  language: "python",
  outputFormat: "json"
});

// Search for symbols
await mcp.call("repo-ctx-search-symbol", {
  path: "./src",
  query: "User",
  symbolType: "class"
});

// Get symbol details
await mcp.call("repo-ctx-get-symbol-detail", {
  path: "./src",
  symbolName: "UserService",
  outputFormat: "json"
});

// List file symbols
await mcp.call("repo-ctx-get-file-symbols", {
  filePath: "./src/service.py",
  groupByType: true,
  outputFormat: "json"
});

CLI Commands

Repository Management

# Index repositories
repo-ctx --index owner/repo
repo-ctx --index /path/to/local/repo
repo-ctx --index group/project --provider gitlab

# Search repositories
repo-ctx search fastapi
repo-ctx list
repo-ctx list --provider github

# Get documentation
repo-ctx docs /owner/repo
repo-ctx docs /owner/repo --topic api --max-tokens 8000

Code Analysis

# Analyze code structure
repo-ctx analyze ./src
repo-ctx analyze ./src --output json
repo-ctx analyze ./src --language python --filter-type class
repo-ctx analyze ./src --show-dependencies
repo-ctx analyze ./src --show-callgraph

# Search for symbols
repo-ctx search-symbol ./src User
repo-ctx search-symbol ./src Service --filter-type class --output json

# Get symbol details
repo-ctx symbol-detail ./src UserService
repo-ctx symbol-detail ./src UserService --output json

# List file symbols
repo-ctx file-symbols ./src/service.py
repo-ctx file-symbols ./src/service.py --output json

Output Formats

All analysis commands support --output text|json|yaml:

repo-ctx analyze ./src --output json
repo-ctx search-symbol ./src User --output yaml
repo-ctx symbol-detail ./src MyClass --output json
repo-ctx file-symbols ./src/app.py --output json

Library API

Installation

from repo_ctx import (
    CodeAnalyzer,
    Symbol,
    SymbolType,
    Config,
    Storage,
    GitLabContext,
)

Code Analysis

from repo_ctx import CodeAnalyzer, SymbolType

analyzer = CodeAnalyzer()

# Analyze a single file
code = open("service.py").read()
symbols = analyzer.analyze_file(code, "service.py")

# Analyze multiple files
files = {
    "service.py": open("service.py").read(),
    "models.py": open("models.py").read(),
}
results = analyzer.analyze_files(files)
all_symbols = analyzer.aggregate_symbols(results)

# Filter symbols
classes = analyzer.filter_symbols_by_type(all_symbols, SymbolType.CLASS)
public = analyzer.filter_symbols_by_visibility(all_symbols, "public")

# Search symbols
found = analyzer.find_symbol(all_symbols, "UserService")
matches = analyzer.find_symbols(all_symbols, "user")  # pattern match

# Get statistics
stats = analyzer.get_statistics(all_symbols)
# {'total_symbols': 15, 'by_type': {'class': 3, 'method': 12}, ...}

# Extract dependencies
deps = analyzer.extract_dependencies(code, "service.py")
# [{'type': 'import', 'source': 'service.py', 'target': 'os', ...}]

# Supported languages
languages = analyzer.get_supported_languages()
# ['python', 'javascript', 'typescript', 'java', 'kotlin']

Symbol Properties

symbol = symbols[0]

symbol.name           # "UserService"
symbol.symbol_type    # SymbolType.CLASS
symbol.file_path      # "service.py"
symbol.line_start     # 10
symbol.line_end       # 50
symbol.signature      # "class UserService"
symbol.visibility     # "public" | "private" | "protected"
symbol.language       # "python"
symbol.qualified_name # "UserService"
symbol.documentation  # "Service for managing users."
symbol.is_exported    # True
symbol.metadata       # {"bases": ["BaseService"]}

Repository Indexing

import asyncio
from repo_ctx import Config, GitLabContext

async def main():
    config = Config.load()
    context = GitLabContext(config)
    await context.init()

    # Index repository
    await context.index_repository("owner", "repo")

    # Search
    results = await context.search_libraries("fastapi")
    fuzzy = await context.fuzzy_search_libraries("fasapi", limit=5)

    # Get documentation
    docs = await context.get_documentation("/owner/repo", max_tokens=8000)

asyncio.run(main())

Configuration

Environment Variables

# GitHub (optional for public repos)
export GITHUB_TOKEN=ghp_xxx

# GitLab (required)
export GITLAB_URL=https://gitlab.company.com
export GITLAB_TOKEN=glpat-xxx

MCP Server Config

{
  "mcpServers": {
    "repo-ctx": {
      "command": "uvx",
      "args": ["repo-ctx"],
      "env": {
        "GITHUB_TOKEN": "${GITHUB_TOKEN}",
        "GITLAB_URL": "${GITLAB_URL}",
        "GITLAB_TOKEN": "${GITLAB_TOKEN}"
      }
    }
  }
}

Quick Reference

Interface Analyze Search Detail File Symbols
MCP repo-ctx-analyze repo-ctx-search-symbol repo-ctx-get-symbol-detail repo-ctx-get-file-symbols
CLI analyze search-symbol symbol-detail file-symbols
Library analyze_file() find_symbols() find_symbol() analyze_file()

Output formats: text (default), json, yaml

Languages: Python, JavaScript, TypeScript, Java, Kotlin

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

repo_ctx-0.3.1.tar.gz (330.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

repo_ctx-0.3.1-py3-none-any.whl (76.5 kB view details)

Uploaded Python 3

File details

Details for the file repo_ctx-0.3.1.tar.gz.

File metadata

  • Download URL: repo_ctx-0.3.1.tar.gz
  • Upload date:
  • Size: 330.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for repo_ctx-0.3.1.tar.gz
Algorithm Hash digest
SHA256 152e6eedf7c1434ca8356e1efe9cd7248c34fd324edde76c9fcbee91f3f98a1d
MD5 70b4d042cd35aa82ccc802683b3f0232
BLAKE2b-256 1db772dee06638ca3a9b0fc2da25f5be314110be5d265a78b50ad464a366286c

See more details on using hashes here.

File details

Details for the file repo_ctx-0.3.1-py3-none-any.whl.

File metadata

  • Download URL: repo_ctx-0.3.1-py3-none-any.whl
  • Upload date:
  • Size: 76.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.10.12

File hashes

Hashes for repo_ctx-0.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 443eccd9315e8b4faeebf3485f962af7324b637e235c1d4ac1065437e5360a33
MD5 4ea6fbdec6c07a1d6ea15765e0a1299b
BLAKE2b-256 e3b30ec4a2344b75d39a8173723a1ecf48e067579c8b82eff491d2ef2a208346

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page