| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
A Model Context Protocol (MCP) server that provides AI-enhanced code search and context retrieval capabilities using Sourcegraph or Zoekt search backends.
Code Context Provider provides two specialized MCP servers for code search and AI-enhanced context retrieval:
Both servers support multiple search backends (Sourcegraph and Zoekt) and include comprehensive observability through Langfuse.
The project consists of two main MCP servers:
Important: The Context Server depends on the Search Server. You must:
Supported backends:
# Install dependencies
uv sync
# Run search server (start this first)
uv run src/main.py search
# In another terminal, run context server (on different ports)
# Make sure to set MCP_SERVER_URL to the search server's streamable-http endpoint
export MCP_SERVER_URL=http://localhost:8080/codesearch/mcp/
export MCP_SSE_PORT=8001
export MCP_STREAMABLE_HTTP_PORT=8081
uv run src/main.py context# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install package
pip install -e .
# Run search server (start this first)
python src/main.py search
# In another terminal, run context server
export MCP_SERVER_URL=http://localhost:8080/codesearch/mcp/
export MCP_SSE_PORT=8001
export MCP_STREAMABLE_HTTP_PORT=8081
python src/main.py context# Build the image
docker build -t code-context-provider .To run both servers together, create a docker-compose.yml file:
version: '3'
services:
search:
image: code-context-provider
command: search
ports:
- "8000:8000"
- "8080:8080"
environment:
- SEARCH_BACKEND=sourcegraph
- SRC_ENDPOINT=https://sourcegraph.com
- LANGFUSE_ENABLED=false
context:
image: code-context-provider
command: context
ports:
- "8001:8000"
- "8081:8080"
environment:
- MCP_SERVER_URL=http://search:8080/codesearch/mcp/
- LANGFUSE_ENABLED=false
depends_on:
- searchThen run:
docker-compose upSet SEARCH_BACKEND to choose your search backend:
Langfuse provides comprehensive tracing and monitoring for all AI operations.
To enable Langfuse:
export LANGFUSE_ENABLED=true
export LANGFUSE_PUBLIC_KEY=your-public-key
export LANGFUSE_SECRET_KEY=your-secret-key
export LANGFUSE_HOST=your-langfuse-hostNote: The evaluation framework requires Langfuse to be enabled for tracking LLM calls and performance metrics.
The evaluation framework uses configurable LLM models:
# Configure the code snippet finder model
export CODE_SNIPPET_FINDER_MODEL_NAME=gpt-4o-mini # default
# Configure the LLM judge model
export LLM_JUDGE_V2_MODEL_NAME=gpt-4o-mini # default
# Configure the code parser model
export CODE_AGENT_TYPE_PARSER_MODEL_NAME=gpt-4o-mini # default
# Optional: Use custom LLM endpoints
export LLM_JUDGE_V2_BASE_URL=https://your-llm-endpoint
export LLM_JUDGE_V2_API_KEY=your-api-keyDirect access to search backends with three main tools:
# Start search server
uv run src/main.py searchAvailable at:
AI-enhanced search with query understanding and intelligent extraction:
# Start search server first (in one terminal)
uv run src/main.py search
# Then start context server (in another terminal)
export MCP_SERVER_URL=http://localhost:8080/codesearch/mcp/
export MCP_SSE_PORT=8001
export MCP_STREAMABLE_HTTP_PORT=8081
uv run src/main.py contextNote: The Context Server connects to the Search Server via the MCP_SERVER_URL. Ensure:
Available at (when using different ports):
Add to your .cursor/mcp.json:
{
"mcpServers": {
"codesearch": {
"url": "http://localhost:8080/codesearch/mcp/"
},
"contextprovider": {
"url": "http://localhost:8081/contextprovider/mcp/"
}
}
}Search across codebases using advanced query syntax.
Example queries:
Generate a query guide based on your search objective.
Retrieve file contents or explore directory structures.
AI-powered search that understands natural language queries and returns relevant code snippets with explanations.
Reformulate queries into multiple optimized search patterns for better coverage.
# Check code style
uv run ruff check src/
# Format code
uv run ruff format src/For quick testing and dataset creation:
# First, ensure the search server is running:
uv run src/main.py search
# In another terminal, set the MCP server URL and run the agent:
export MCP_SERVER_URL=http://localhost:8080/codesearch/mcp/
# Run the agent interactively (prompts for question and saves to question.json)
uv run src/main.py agentThis creates a question.json file with the question and AI-generated answer that can be used as evaluation data.
Note: The agent command requires the search server to be running as it uses the Context Server's CodeSnippetFinder which connects to the search server via MCP.
Run comprehensive evaluations against a Langfuse dataset:
# First, ensure the search server is running:
uv run src/main.py search
# In another terminal, configure and run evaluation:
export MCP_SERVER_URL=http://localhost:8080/codesearch/mcp/
export LANGFUSE_DATASET_NAME=your-dataset-name # default: code-search-mcp-agentic-v2
# Run evaluation
uv run src/main.py evaluateNote: The evaluation framework also requires the search server to be running.
The evaluation framework provides comprehensive testing capabilities:
The LLM Judge evaluates search results by comparing actual vs expected answers across multiple dimensions:
Langfuse datasets should contain items with the following structure:
{
"input": {
"question": "How do I implement a Redis cache in Python?"
},
"expected_output": {
"snippet": "import redis\n\nclass RedisCache:\n def __init__(self):\n self.client = redis.Redis(host='localhost', port=6379)",
"language": "python",
"description": "Basic Redis cache implementation in Python"
}
}The evaluation generates:
| Variable | Description | Required | Default |
|---|---|---|---|
| SEARCH_BACKEND | Search backend (sourcegraph/zoekt) | Yes | - |
| SRC_ENDPOINT | Sourcegraph URL | Yes (Sourcegraph) | - |
| SRC_ACCESS_TOKEN | Sourcegraph token | No | - |
| ZOEKT_API_URL | Zoekt server URL | Yes (Zoekt) | - |
| MCP_SERVER_URL | Search server URL | Yes (Context) | - |
| MCP_SSE_PORT | SSE server port | No | 8000 |
| MCP_STREAMABLE_HTTP_PORT | HTTP server port | No | 8080 |
| LANGFUSE_ENABLED | Enable Langfuse | No | false |
| LANGFUSE_PUBLIC_KEY | Langfuse public key | If enabled | - |
| LANGFUSE_SECRET_KEY | Langfuse secret key | If enabled | - |
| LANGFUSE_HOST | Langfuse host URL | If enabled | - |
| LANGFUSE_DATASET_NAME | Dataset name for evaluation | For evaluation | code-search-mcp-agentic-v2 |
| CODE_SNIPPET_FINDER_MODEL_NAME | Model for code snippet extraction | No | gpt-4o-mini |
| LLM_JUDGE_V2_MODEL_NAME | Model for LLM judge | No | gpt-4o-mini |
| CODE_AGENT_TYPE_PARSER_MODEL_NAME | Model for code parsing | No | gpt-4o-mini |
| LLM_JUDGE_V2_BASE_URL | Custom LLM endpoint for judge | No | - |
| LLM_JUDGE_V2_API_KEY | API key for custom LLM judge | No | - |
MIT License - see LICENSE file for details.
| Back | FazBrowse Home | New Git URL |