Codebase indexing MCP server
概览
A Model Context Protocol (MCP) server that tries to solve condebase indexing (until agents can). - Connects to a user-specified local code repository. - Provides the (get_codebase_context) tool for AI clients (like Cursor, Claude Desktop). - Uses Gemini 2.0 Flash's 1M input window internally to analyze the codebase and generate context based on the user's client querry. - Flash itself can use internal tools (list_repository_structure, read_files, grep_codebase) to understand the code. - Supports both SSE (recommended) and stdio transport protocols. - Supports user-attached files/docs/context from client's queries for more targeted analysis. - Tracks token usage and provides detailed analysis of API consumption. - User-configurable token limit for context generation (options: 500k, 800k, or 1M tokens; default: 800k). 1. Get the server code. 2. 3. 4. Ensure the tree command is available on your system.
README
以下为原文 README 节选,完整内容请查看原文。
Marketplace badges
Kontxt MCP Server
A Model Context Protocol (MCP) server that tries to solve condebase indexing (until agents can).
Features
- Connects to a user-specified local code repository.
- Provides the (
get_codebase_context) tool for AI clients (like Cursor, Claude Desktop). - Uses Gemini 2.0 Flash’s 1M input window internally to analyze the codebase and generate context based on the user’s client querry.
- Flash itself can use internal tools (
list_repository_structure,read_files,grep_codebase) to understand the code. - Supports both SSE (recommended) and stdio transport protocols.
- Supports user-attached files/docs/context from client’s queries for more targeted analysis.
- Tracks token usage and provides detailed analysis of API consumption.
- User-configurable token limit for context generation (options: 500k, 800k, or 1M tokens; default: 800k).
Setup
- Clone/Download: Get the server code.
- Create Environment:
python -m venv venv source venv/bin/activate # On Windows: venv\Scripts\activate - Install Dependencies:
pip install -r requirements.txt - Install
tree: Ensure thetreecommand is available on your system.- macOS:
brew install tree - Debian/Ubuntu:
sudo apt update && sudo apt install tree - Windows: Requires installing a port or using WSL.
- macOS:
- Configure API Key:
- Copy
.env.exampleto.env. - Edit
.envand add your Google Gemini API Key:GEMINI_API_KEY="YOUR_ACTUAL_API_KEY" - Alternatively, you can provide the key via the
--gemini-api-keycommand-line argument.
- Copy
Running as a Standalone Server (Recommended)
By default, the server runs in SSE mode, which allows you to:
- Start the server independently
- Connect from multiple clients
- Keep it running while restarting clients
Run the server:
python kontxt_server.py --repo-path /path/to/your/codebase
PS: you can use pwd to list the project path
The server will start on http://127.0.0.1:8080/sse by default.
For additional options:
python kontxt_server.py --repo-path /path/to/your/codebase --host 0.0.0.0 --port 6900
Shutting Down the Server
The server can be stopped by pressing Ctrl+C in the terminal where it’s running. The server will attempt to close gracefully with a 3-second timeout.
Connecting to the Server from client (Cursor example)
Once your server is running, you can connect Cursor to it by editing your ~/.cursor/mcp.json file:
{
"mcpServers": {
"kontxt-server": {
"serverType": "sse",
"url": "http://localhost:8080/sse"
}
}
}
安装
This server does not publish a one-line install command.
Open the repository installation guide 新手?先看 mcpskill.org 教程 →配置
{
"mcpServers": {
"kontxt-server": {
"serverType": "sse",
"url": "http://localhost:8080/sse"
}
}
}
