
# OpenGrok MCP Server
**Code intelligence for any OpenGrok-indexed codebase — search, read, blame, symbol navigation, diffs, commit history, call graphs, dependency maps, and guided investigation. Optimized for token efficiency through Code Mode and AST-aware code reads.**
[](https://www.npmjs.com/package/opengrok-mcp-server) [](https://registry.modelcontextprotocol.io) [](https://github.com/IcyHot09/opengrok-mcp-server/actions/workflows/ci.yml) [](https://github.com/IcyHot09/opengrok-mcp-server/releases)
---
## Quick Start
**Option 1 — VS Code Extension**
Install **OpenGrok MCP** from the VS Code Marketplace, or search "OpenGrok" in the Extensions panel. The configuration panel opens on first launch — enter your OpenGrok endpoint, username, and password, then click **Save Settings** and reload when prompted.
The extension provides a visual configuration UI and manages the MCP server process automatically. No Python, external Node.js install, or manual environment setup required.
**Option 2 — npm / npx CLI**
```bash
npm install -g opengrok-mcp-server
opengrok-mcp setup # interactive wizard: URL, credentials, MCP client registration
```
Or run without installing:
```bash
npx opengrok-mcp-server setup
```
Other CLI commands:
```bash
opengrok-mcp status # health check: validates connectivity and detects installed MCP clients
opengrok-mcp setup --test # test the stored connection without the wizard
opengrok-mcp setup --set contextBudget=generous # update one stored setting non-interactively
opengrok-mcp export-audit --format json --output audit.jsonl # export the audit log
opengrok-mcp version # print version and exit
opengrok-mcp help # show all commands
```
Works with any MCP-compatible client (CLI or IDE). See [MCP_CLIENTS.md](MCP_CLIENTS.md) for config format and troubleshooting.
Credentials are stored in the OS keychain (macOS Keychain, Windows Credential Manager, Linux libsecret) with an AES-256-GCM encrypted file fallback for headless environments.
---
> [!TIP]
> **Automatic Updates** — The extension checks GitHub for new releases once per 24 hours and notifies you when one is available. Use **OpenGrok: Check for Updates** to check on demand.
---
## The Problem
Engineers working in large codebases face a specific gap when using AI coding assistants. The model's context window contains the file currently open, the conversation, and whatever has been manually shared — but a production codebase has structure, history, and cross-module relationships that exist entirely outside that window.
A symbol defined in one module and called from seventy others. A function whose behavior only becomes clear from the three commits that shaped it. An include chain stretching across a dozen directories. A call graph showing which components depend on a service before it gets refactored.
Without access to the code index, the model fills these gaps by guessing: it fabricates file paths, invents function signatures, misattributes changes to authors. The model is not wrong because it is unintelligent — it is wrong because it is isolated.
OpenGrok already solves this for human engineers. It indexes source in dozens of programming languages, maintains a full-text index across committed history, and exposes definition lookups, reference graphs, blame, directory traversal, and file history through a REST API. The problem was that AI tools had no way to reach it.
---
## How It Works
```text
┌──────────────────────────────────────────────────────┐
│ AI Client (Claude, Copilot, Cursor, Codex …) │
└─────────────────────┬────────────────────────────────┘
│ MCP (stdio or HTTP)
┌─────────────────────▼────────────────────────────────┐
│ OpenGrok MCP Server (Node.js) │
│ opengrok_api ──── full API spec, once per session │
│ opengrok_execute ─ run JavaScript in sandbox │
│ │
│ OpenGrok client ── search · symbols · blame · diffs │
└─────────────────────┬────────────────────────────────┘
│ HTTP (REST + web fallback)
┌─────────────────────▼────────────────────────────────┐
│ OpenGrok │
│ search · symbols · call graphs · index health │
└──────────────────────────────────────────────────────┘
```
The server exposes two primary tools. `opengrok_api` delivers the full API specification at session start. Every subsequent operation goes through `opengrok_execute`: the AI writes a JavaScript program using the `env.opengrok.*` object — `search`, `getFileContent`, `getFileAnnotate`, `getFileHistory`, `browseDir`, `getFileSymbols` — and submits it as a single execution.
Intermediate results stay inside the sandbox; only the final `return` value crosses back to the context window. A complete investigation — find the symbol, read the definition, check who changed it, trace the callers — is one script, not a sequence of round-trips with results flowing through the context between each. Token savings of 80–95% are typical for complex investigations.
All `env.opengrok.*` calls appear **synchronous** inside sandbox code — the QuickJS WASM VM bridges async HTTP calls transparently over a SharedArrayBuffer + Atomics channel (8 MB data region, 62 s per-call timeout, 62 s hard execution cap), while keeping the Node.js event loop free.
**Memory bank** — two files persist across turns and session restarts: `active-task.md` (4 KB) for current investigation state and `investigation-log.md` (32 KB) for append-only findings. Inside the sandbox: `env.opengrok.readMemory()` / `env.opengrok.writeMemory()`. See the [Memory Bank](#memory-bank) reference below.
---
## Reference