This project provides a self-contained Docker API server that clones a Git repository, indexes it using embedding models, and exposes an endpoint to retrieve relevant code and documentation snippets for natural language questions.
It's the "Retrieval" piece for a RAG (Retrieval-Augmented Generation) system, designed to feed an external AI agent (like an n8n workflow) with the necessary context to answer questions about a codebase.
Free Mode (Default - Local Embeddings):
docker run -p 8000:8000 \
-e REPO_URL="https://github.com/n8n-io/n8n.git" \
-e REPO_BRANCH="master" \
-v ./mcp_data/chroma_db:/app/chroma_db \
--name mcp-server \
flaviomagacho/mcp-git-server:latest
OpenAI Mode (Paid - High Quality):
docker run -p 8000:8000 \
-e REPO_URL="https://github.com/n8n-io/n8n.git" \
-e REPO_BRANCH="master" \
-e EMBEDDING_PROVIDER="openai" \
-e OPENAI_API_KEY="YOUR_SECURE_API_KEY" \
-v ./mcp_data/chroma_db:/app/chroma_db \
--name mcp-server \
flaviomagacho/mcp-git-server:latest
π Private GitHub Repository:
docker run -p 8000:8000 \
-e REPO_URL="https://github.com/your-username/private-repo.git" \
-e REPO_BRANCH="main" \
-e GITHUB_TOKEN="ghp_your_personal_token_here" \
-v ./mcp_data/chroma_db:/app/chroma_db \
--name mcp-server \
flaviomagacho/mcp-git-server:latest
π Private Bitbucket Repository:
docker run -p 8000:8000 \
-e REPO_URL="https://bitbucket.org/workspace/private-repo.git" \
-e REPO_BRANCH="main" \
-e BITBUCKET_USERNAME="your_username" \
-e BITBUCKET_APP_PASSWORD="your_app_password" \
-v ./mcp_data/chroma_db:/app/chroma_db \
--name mcp-server \
flaviomagacho/mcp-git-server:latest
π Documentation:
- GitHub: PRIVATE_REPOS.mdβ
- Bitbucket: BITBUCKET.mdβ
# Clone the repository
git clone https://github.com/magacho/mcp-git-server.git
cd mcp-git-server
# Build the image
docker build -t mcp-git-server .
# Run locally
docker run -p 8000:8000 \
-e REPO_URL="https://github.com/n8n-io/n8n.git" \
-e REPO_BRANCH="master" \
-v ./chroma_db:/app/chroma_db \
mcp-git-server
GET /health
Returns server status:
{
"status": "ready"
}
POST /retrieve
Content-Type: application/json
{
"query": "How does authentication work in the application?",
"top_k": 5
}
Returns relevant code snippets:
{
"results": [
{
"content": "Code snippet content...",
"metadata": {
"source": "path/to/file.py"
},
"relevance_score": 0.95
}
],
"total_results": 5
}
GET /embedding-info
Returns information about the current embedding provider:
{
"provider": "sentence-transformers",
"available_providers": {
"sentence-transformers": {
"available": true,
"cost": "Free",
"quality": "Good"
},
"openai": {
"available": true,
"cost": "$0.0001 per 1K tokens",
"quality": "Excellent"
}
}
}
| Variable | Description | Default | Required |
|---|---|---|---|
REPO_URL | Git repository URL (HTTPS or SSH) | - | β Yes |
REPO_BRANCH | Branch to clone | main | No |
GITHUB_TOKEN | GitHub PAT for private repos | - | No |
EMBEDDING_PROVIDER | Embedding provider (sentence-transformers, openai, huggingface, auto) | sentence-transformers | No |
OPENAI_API_KEY | OpenAI API key (required if provider is openai) | - | Conditional |
TOKEN_COUNT_METHOD | Token counting method (local, tiktoken, auto) | auto | No |
Supports two authentication methods:
GitHub Personal Access Token (PAT) - HTTPS
export GITHUB_TOKEN=ghp_your_token
export REPO_URL=https://github.com/user/private-repo.git
SSH Keys
export [email protected]:user/private-repo.git
docker run -v ~/.ssh:/root/.ssh:ro ...
See PRIVATE_REPOS.mdβ for complete documentation.
| Provider | Cost | Quality | Speed | Use Case |
|---|---|---|---|---|
sentence-transformers | Free | Good | Fast | Development, testing, personal projects |
openai | $0.0001/1K tokens | Excellent | Medium | Production, high quality requirements |
huggingface | Free | Variable | Medium | Experimentation, custom models |
βββββββββββββββ ββββββββββββββββ βββββββββββββββ
β Client ββββββΆβ FastAPI ββββββΆβ Vector β
β (n8n, etc) β β Server β β Database β
βββββββββββββββ ββββββββββββββββ β (Chroma) β
β βββββββββββββββ
β
βΌ
ββββββββββββββββ
β Embeddings β
β (Local/API) β
ββββββββββββββββ
β
βΌ
ββββββββββββββββ
β Git Repo β
β (Cloned) β
ββββββββββββββββ
.py, .js, .ts, .jsx, .tsx, .java, .cpp, .c, .h, .cs, .php, .rb, .swift, .go, .rs.html, .css, .vue, .svelte.json, .yml, .yaml, .xml, .env.sh, .bash, .sql.tf, .tfvars, .hcl (Terraform/HCL).md, .txt, .pdfREADME, LICENSE, DOCKERFILE, MAKEFILE, etc.AI-Powered Code Assistance
Knowledge Base
CI/CD Integration
Private Projects
# Install development dependencies
pip install -r requirements-dev.txt
# Run tests
pytest
# Run with coverage
pytest --cov=. --cov-report=html
# Run specific test file
pytest tests/unit/test_models.py -v
# Clone repository
git clone https://github.com/magacho/mcp-git-server.git
cd mcp-git-server
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install dependencies
pip install -r requirements.txt
pip install -r requirements-dev.txt
# Run locally
export REPO_URL=https://github.com/example/repo.git
python main.py
# Access API
curl http://localhost:8000/health
Problem: Server is slow to start
Problem: Out of memory errors
Problem: Authentication failed for private repo
repo scope) and is not expired.Problem: Embedding errors
MIT License - See LICENSEβ for details.
Contributions are welcome! Please:
See GIT_COMMIT_GUIDE.mdβ for commit conventions.
If this project helped you, please consider giving it a β on GitHub!
Made with β€οΈ for the developer community
Content type
Image
Digest
sha256:cd1cb278aβ¦
Size
618.1 MB
Last updated
11 months ago
docker pull flaviomagacho/mcp-git-server