Kontxt MCP Server

by ReyNeill

10 stars
194 downloads
Not rated
GitHub

About

Indexes local code repositories to provide codebase context to AI clients.

Details

Author
ReyNeill
GitHub stars
10
Downloads
194
Categories
Other, Developer Tools, Knowledge Base

- Connects to a local code repository for analysis.
- Provides the get_codebase_context tool for AI clients.
- Uses Gemini 2.0 Flash (or custom model) with 1M input window.
- Supports SSE (recommended) and stdio transport protocols.
- Tracks token usage and allows configurable token limits (500k, 800k, 1M).
- Accepts user-attached files and additional context from queries.

Setting up with Highlight

This MCP is not yet compatible with Highlight’s one-click setup. However, you can still use it with Highlight by following these steps:

  1. Download and install Highlight from highlightai.com/download
  2. Navigate to the plugins tab and select "Add Custom Plugin"
  3. Configure the plugin with the settings below
    Plugin Name Kontxt MCP Server
    Command (node, npx, python, etc.)

    Please refer to the README for specific instructions on how to obtain API keys or other required environment variables.

  4. Enable "Start Automatically" if you want the plugin to start when Highlight launches

From the repository

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

python kontxt_server.py --repo-path /path/to/your/codebase

PS: you can usepwdto list the project path

The server will start onhttp://127.0.0.1:8080/sseby default.

python kontxt_server.py --repo-path /path/to/your/codebase --host 0.0.0.0 --port 6900

The server can be stopped by pressingCtrl+Cin the terminal where it's running. The server will attempt to close gracefully with a 3-second timeout.

Alternative Running With Stdio Transport

If you prefer to have the client start and manage the server process:

python kontxt_server.py --repo-path /path/to/your/codebase --transport stdio

For this mode, configure your~/.cursor/mcp.jsonfile like this:

{ "mcpServers": { "kontxt-server": { "serverType": "stdio", "command": "python", "args": ["/absolute/path/to/kontxt_server.py", "--repo-path", "/absolute/path/to/your/codebase", "--transport", "stdio"], "env": { "GEMINI_API_KEY": "your-api-key-here" } } } }

- --repo-path PATH:Required. Absolute path to the local code repository to analyze.
- --gemini-api-key KEY: Google Gemini API Key (overrides.envif provided).
- --token-threshold NUM: Target maximum token count for the context. Allowed values are:

- 500000
- 800000 (default)
- 1000000

For security, wildcard CORS is not used. By default, only loopback origins are allowed:

- http://127.0.0.1,http://localhost, and the boundhost:port.

To allow specific web clients during development, pass explicit origins or use an env var:

python kontxt_server.py \ --repo-path /path/to/your/codebase \ --cors-origins http://localhost:3000,http://127.0.0.1:5173 # or via environment variable KONTXT_CORS_ORIGINS="http://localhost:3000,http://127.0.0.1:5173" \ python kontxt_server.py --repo-path /path/to/your/codebase

- Allowed methods:GET,OPTIONS. Headers: all. Credentials: off unless--cors-credentialsis set.

Claude Desktop / Cursor

Paste into your MCP client config file to install this server.

{
    "mcpServers": {
        "kontxt mcp server": {
            "Kontxt": {
                "command": "python",
                "args": [
                    "-m",
                    "venv",
                    "venv"
                ]
            }
        }
    }
}

McpServers

{
    "Kontxt": {
        "command": "python",
        "args": [
            "-m",
            "venv",
            "venv"
        ]
    }
}

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

1. Clone/Download: Get the server code.
2. Create Environment:

    python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate

3. Install Dependencies:
    pip install -r requirements.txt

4. Install tree: Ensure the tree command 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.
5. Configure API Key:
- Copy .env.example to .env.
- Edit .env and add your Google Gemini API Key:
      GEMINI_API_KEY="YOUR_ACTUAL_API_KEY"

- Alternatively, you can provide the key via the --gemini-api-key command-line argument.

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"
    }
  }
}

PS: remember to always refresh the MCP server on Cursor Settings or other client to connect to the MCP via sse

Alternative: Running with stdio Transport

If you prefer to have the client start and manage the server process:

python kontxt_server.py --repo-path /path/to/your/codebase --transport stdio

For this mode, configure your ~/.cursor/mcp.json file like this:

{
  "mcpServers": {
    "kontxt-server": {
      "serverType": "stdio",
      "command": "python",
      "args": ["/absolute/path/to/kontxt_server.py", "--repo-path", "/absolute/path/to/your/codebase", "--transport", "stdio"],
      "env": {
        "GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}

Command Line Arguments

- --repo-path PATH: Required. Absolute path to the local code repository to analyze.
-
--gemini-api-key KEY: Google Gemini API Key (overrides .env if provided).
-
--token-threshold NUM: Target maximum token count for the context. Allowed values are:
- 500000
- 800000 (default)
- 1000000
-
--gemini-model NAME: Specific Gemini model to use (default: models/gemini-2.5-flash-preview-04-17).
-
--tokenizer-model NAME: Hugging Face tokenizer id for token estimation (default: google/gemma-7b; override via KONTXT_TOKENIZER_MODEL).
-
--transport {stdio,sse}: Transport protocol to use (default: sse).
-
--host HOST: Host address for the SSE server (default: 127.0.0.1).
-
--port PORT: Port for the SSE server (default: 8080).
-
--cors-origins ORIGINS: Comma-separated list of allowed CORS origins. If omitted, defaults to loopback only.
-
--cors-credentials: Allow credentials for CORS (disabled by default).

CORS Configuration

For security, wildcard CORS is not used. By default, only loopback origins are allowed:

- http://127.0.0.1, http://localhost, and the bound host:port.

To allow specific web clients during development, pass explicit origins or use an env var:

``bash
python kontxt_server.py \
--repo-path /path/to/your/codebase \
--cors-origins http://localhost:3000,http://127.0.0.1:5173

No reviews yet — be the first

Sign in to leave a review

Use Google, GitHub, or an email account so ratings stay tied to real people.

Email sign in

No reviews posted yet.