Integrations
Provides enhanced query and search capabilities for code repositories when the 'genius' parameter is enabled, offering improved contextual understanding
Allows accessing and indexing GitHub repositories for code search and querying, supporting both public and private repositories with appropriate authentication
Enables indexing and searching GitLab repositories, providing code search capabilities and repository information retrieval with proper authentication
Greptile MCP Server [COMPLETED]
Quick Run Command Cheatsheet
✅ PROJECT STATUS: ALL TASKS COMPLETED (11/11)
Please see PROJECT_COMPLETION.md for a summary of completed work and USER_GUIDE.md for usage instructions.
Environment | Setup & Install | Run Command |
---|---|---|
Local (Python) | python -m venv .venv && source .venv/bin/activate && pip install -e . | python -m src.main |
Docker | docker build -t greptile-mcp . | docker run --rm --env-file .env -p 8050:8050 greptile-mcp |
Smithery | npm install -g smithery | smithery deploy (see smithery.yaml) |
Fill in
.env
using.env.example
and set yourGREPTILE_API_KEY
andGITHUB_TOKEN
before running.
For full prerequisites, advanced agent usage, integration, and troubleshooting:
See the full documentation in docs/README.md
and agent details in AGENT_USAGE.md.
An MCP (Model Context Protocol) server implementation that integrates with the Greptile API to provide code search and querying capabilities to AI agents.
Features
The server provides four essential Greptile tools that enable AI agents to interact with codebases:
index_repository
: Index a repository for code search and querying.- Process a repository to make it searchable
- Update existing indexes when repositories change
- Configure notification preferences
query_repository
: Query repositories to get answers with code references.- Ask natural language questions about the codebase
- Get detailed answers that reference specific code locations
- Support for conversation history with session IDs
search_repository
: Search repositories for relevant files without generating a full answer.- Find files related to specific concepts or features
- Get contextual matches ranked by relevance
- Faster than full queries when only file locations are needed
get_repository_info
: Get information about an indexed repository.- Check indexing status and progress
- Verify which repositories are available for querying
- Get metadata about indexed repositories
Smithery Deployment
The Greptile MCP server supports deployment via Smithery. A smithery.yaml
configuration file is included in the project root.
Smithery Configuration
The Smithery configuration is defined in smithery.yaml
and supports the following options:
Using with Smithery
To deploy using Smithery:
- Install Smithery:
npm install -g smithery
- Deploy the server:
smithery deploy
- Configure your Smithery client with the required API keys
Additional Documentation
For detailed usage instructions for AI agents, see the Agent Usage Guide.
Prerequisites
- Python 3.12+
- Greptile API Key (from https://app.greptile.com/settings/api)
- GitHub or GitLab Personal Access Token (PAT) with
repo
(or equivalent read) permissions for the repositories you intend to index - Docker (recommended for deployment)
Required Python Packages
fastmcp
- MCP server implementationhttpx
- Async HTTP clientpython-dotenv
- Environment variable managementuvicorn
- ASGI server for SSE transport
Installation
Using pip (for development or local testing)
- Clone this repository:Copy
- Create a virtual environment (recommended):Copy
- Install dependencies:Copy
- Create a
.env
file based on.env.example
:Copy - Configure your environment variables in the
.env
file:Copy
Using Docker (Recommended for deployment)
- Clone the repository:Copy
- Create a
.env
file based on.env.example
and configure your environment variables. - Build the Docker image:Copy
Running the Server
Using pip
SSE Transport (Default)
Ensure TRANSPORT=sse
and PORT=8050
(or your chosen port) are set in your .env
file.
The server will listen on http://<HOST>:<PORT>/sse
.
Stdio Transport
Set TRANSPORT=stdio
in your .env
file. With stdio, the MCP client typically spins up
the MCP server process.
Using Docker
SSE Transport (Default)
The server will listen on http://localhost:8050/sse
(or the host IP if not localhost).
Stdio Transport
Configure your MCP client to run the Docker container with TRANSPORT=stdio
.
Integration with MCP Clients
SSE Configuration Example
Add this to your MCP client's configuration (e.g., mcp_config.json
):
Python with Stdio Configuration Example
Ensure TRANSPORT=stdio
is set in the environment where the command runs:
Docker with Stdio Configuration Example
Detailed Usage Guide
Workflow for Codebase Analysis
- Index repositories you want to analyze using
index_repository
- Verify indexing status with
get_repository_info
to ensure processing is complete - Query the repositories using natural language with
query_repository
- Find specific files related to features or concepts using
search_repository
Session Management for Conversation Context
When interacting with the Greptile MCP server through any client (including Smithery), proper session management is crucial for maintaining conversation context:
- Generate a unique session ID at the beginning of a conversation
- Reuse the same session ID for all related follow-up queries
- Create a new session ID when starting a new conversation
Example session ID management:
Important for Smithery Integration: Agents connecting via Smithery must generate and maintain their own session IDs. The Greptile MCP server does NOT automatically generate session IDs. The session ID should be part of the agent's conversation state.
Best Practices
- Indexing Performance: Smaller repositories index faster. For large monorepos, consider indexing specific branches or tags.
- Query Optimization: Be specific in your queries. Include relevant technical terms for better results.
- Repository Selection: When querying multiple repositories, list them in order of relevance to get the best results.
- Session Management: Use session IDs for follow-up questions to maintain context across queries.
API Reference
1. Index Repository
Indexes a repository to make it searchable in future queries.
Parameters:
remote
(string): The repository host, either "github" or "gitlab"repository
(string): The repository in owner/repo format (e.g., "greptileai/greptile")branch
(string): The branch to index (e.g., "main")reload
(boolean, optional): Whether to force reprocessing of a previously indexed repositorynotify
(boolean, optional): Whether to send an email notification when indexing is complete
Example:
Response:
2. Query Repository
Queries repositories with natural language to get answers with code references.
Parameters:
query
(string): The natural language query about the codebaserepositories
(array): List of repositories to query, each with format:Copysession_id
(string, optional): Session ID for continuing a conversationstream
(boolean, optional): Whether to stream the responsegenius
(boolean, optional): Whether to use enhanced query capabilities
Example:
Response:
3. Search Repository
Searches repositories to find relevant files without generating a full answer.
Parameters:
query
(string): The search query about the codebaserepositories
(array): List of repositories to searchsession_id
(string, optional): Session ID for continuing a conversationgenius
(boolean, optional): Whether to use enhanced search capabilities
Example:
Response:
4. Get Repository Info
Gets information about a specific repository that has been indexed.
Parameters:
remote
(string): The repository host, either "github" or "gitlab"repository
(string): The repository in owner/repo formatbranch
(string): The branch that was indexed
Example:
Response:
Integration Examples
1. Integration with Claude.ai via Anthropic API
2. Integration with an LLM-based Chatbot
3. Command-line Code Querying Tool
Troubleshooting
Common Issues
1. Authentication Failures
Symptom: You receive 401 Unauthorized
or Repository not found with configured credentials
errors.
Solutions:
- Verify your Greptile API key is valid and correctly set in the
.env
file - Check if your GitHub/GitLab token has expired (they typically expire after a set period)
- Ensure your GitHub/GitLab token has the
repo
scope for accessing repositories - Test your GitHub token directly with the GitHub API to verify it's working
Testing GitHub Token:
2. Repository Not Found
Symptom: The API returns a 404 error or "Repository not found" message.
Solutions:
- Verify the repository exists and is accessible with your GitHub/GitLab token
- Double-check the repository format (it should be
owner/repo
) - For private repositories, ensure your token has appropriate access permissions
- Verify the branch name is correct
3. Connection Issues
Symptom: Unable to connect to the MCP server.
Solutions:
- Check if the server is running (
ps aux | grep src.main
) - Verify the port is not being used by another application
- Check network settings and firewall configurations
- Try a different port by changing the
PORT
value in your.env
file
4. Docker Issues
Symptom: Docker container fails to start or operate correctly.
Solutions:
- Check Docker logs:
docker logs <container_id>
- Verify the
.env
file is correctly mounted - Ensure the port mapping is correct in your
docker run
command - Check if the Docker network configuration allows required connections
Logs and Debugging
To enable more verbose logging, set the following environment variables:
For troubleshooting specific MCP interactions, examine the MCP server logs:
Advanced Configuration
Environment Variables
Variable | Description | Default |
---|---|---|
TRANSPORT | Transport method (sse or stdio ) | sse |
HOST | Host to bind to for SSE transport | 0.0.0.0 |
PORT | Port for SSE transport | 8050 |
GREPTILE_API_KEY | Your Greptile API key | (required) |
GITHUB_TOKEN | GitHub/GitLab personal access token | (required) |
GREPTILE_BASE_URL | Greptile API base URL | https://api.greptile.com/v2 |
DEBUG | Enable debug mode | false |
LOG_LEVEL | Logging level | info |
Custom API Endpoints
If you need to use a custom Greptile API endpoint (e.g., for enterprise installations), modify the GREPTILE_BASE_URL
environment variable:
Performance Tuning
For production deployments, consider these performance optimizations:
- Worker Configuration: When using SSE transport with Uvicorn, configure appropriate worker count:Copy
- Timeout Settings: Adjust timeouts for large repositories:Copy
- Memory Optimization: For large deployments, consider container resource limits:Copy
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request
Development Setup
For development, install additional dependencies:
Run tests:
License
This project is licensed under the MIT License - see the LICENSE file for details.
Built by (https://github.com/sosacrazy126)
This server cannot be installed
hybrid server
The server is able to function both locally and remotely, depending on the configuration or use case.
greptile-mcp
Related MCP Servers
- PythonMIT License
- GoMIT License
- TypeScriptApache 2.0
- TypeScriptMIT License