opengrok-mcp
A read-only MCP server for searching and reading source code indexed by an OpenGrok instance.
opengrok_search— search by full text (wildcards, phrases, AND/OR/NOT, fuzzy, regex), symbol definitions (def), symbol references (symbol), path, or commit messages (hist), optionally filtered by file type; paginated.opengrok_find_file— locate files by name, wildcard, directory, or regex path pattern; returns paths only.opengrok_get_file— read a file's line-numbered contents via its/<project>/...path, with an optional line range (output capped at 30,000 characters).opengrok_list_projects— enumerate project names usable for scoping searches.Scoping — every search accepts
projectsorall_projects; note the schema says the default scope is all projects, while the README describes defaulting to the configured project(s).Safety — all tools are read-only, idempotent, and non-destructive; nothing can be modified.
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@opengrok-mcp find where parseConfig is defined"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
opengrok-mcp
An MCP server that lets an AI agent search and read source code indexed by an OpenGrok instance. Read-only, stdio transport.
Tested against OpenGrok 1.14. It uses the REST search API and the /raw file route, both of which
work anonymously on a default install.
Tools
Tool | Purpose |
| Search by |
| Find files by name or path pattern. |
| Read a file (line-numbered) by the path returned from search, with an optional line range. |
| List the project names on the instance. |
Searches are scoped to the configured default project(s); pass projects to pick others or
all_projects: true to search everything.
Related MCP server: HTTP Client MCP Server
Install
Requires Node.js 20+.
git clone https://github.com/jenkeeri/opengrok-mcp.git
cd opengrok-mcp
npm install && npm run buildConfiguration
All settings are environment variables, normally set in your MCP client's server entry:
Variable | Required | Description |
| yes | Base URL, e.g. |
| no | Comma-separated default project(s). Empty means all projects. |
| no | Free text appended to the server instructions the agent sees. Use it to describe your project layout (what each project is, naming conventions). |
| no | Bearer token, if the instance needs one. |
| no | Basic auth, if the instance needs it. |
| no | Per-request timeout (default |
Example MCP client entry:
{
"mcpServers": {
"opengrok": {
"command": "node",
"args": ["/path/to/opengrok-mcp/dist/index.js"],
"env": {
"OPENGROK_URL": "https://opengrok.example.com",
"OPENGROK_DEFAULT_PROJECT": "myproject",
"OPENGROK_INSTRUCTIONS": "Project 'myproject' is the main branch; 'myproject-1.2' is a release branch."
}
}
}
}Notes
Use the REST parameter names
projects,def,symbolandstart. The web UI names (project,defs,refs) are silently ignored by the API, which makes project filtering appear broken.typetakes an OpenGrok analyzer name (c,cxx,java,python, ...); an unknown name returns zero results.fullwith several bare terms/phrases is OR-ed; useANDexplicitly.path(andfind_file) match per path component, so a regex cannot span/.histresults are de-duplicated; a bare ticket number is exact.Search output is capped at
max_lines_per_file(default 10) lines per file;get_filereports the line range actually returned when it cuts a file at 30000 characters.defandsymbolrely on OpenGrok's language-aware indexing; usefullfor file types it cannot parse.
Development
npm test # unit tests (synthetic fixtures, no network)
npm run typecheck
npm run buildLicense
GPL-3.0, see LICENSE.
Available Tools
4 toolsopengrok_find_fileFind files in OpenGrokARead-onlyIdempotent
Find files by path or file name. Returns file paths only. Examples: "main.cpp" (name), "*.sql" (wildcard), "src/net" (directory), "/.test..py/" (regex). Default scope: none (all projects).
Inputs: path_pattern (required), type, start, projects, +2 more.
opengrok_get_fileRead file from OpenGrokARead-onlyIdempotent
Read a file's content (line-numbered) by the full path returned from search, e.g. "//dir/file.c". Use start_line/end_line for large files; output is cut at 30000 characters.
Inputs: file_path (required), end_line, start_line.
opengrok_list_projectsList OpenGrok projectsARead-onlyIdempotent
List the project names available on the OpenGrok instance (valid values for the projects argument).
Inputs: no named parameters.
opengrok_searchSearch OpenGrokARead-onlyIdempotent
Search source code. Provide at least one of full, def, symbol, path, hist; fields combine with AND.
full: full-text Lucene query. Supports wildcards (foo*), phrases ("a b"), AND/OR/NOT (uppercase), fuzzy (word~), regex (/re/).
def: where a symbol is DEFINED. symbol: where a symbol is referenced or defined. Both need language-aware indexing, so they return nothing for file types OpenGrok cannot parse; fall back to full.
path: restrict by file path (e.g. "src/net", "*.cpp").
hist: search commit messages.
type: OpenGrok analyzer name, e.g. c, cxx, java, python, sh, xml, json, yaml, plain. An unknown name yields zero results. Default scope: none (all projects). Results list files with matching lines (line numbers where available).
Inputs: def, full, hist, path, +6 more.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
Each tool targets a distinct action: search content, read a file, find files by path, list projects. The only overlap is that opengrok_search's 'path' parameter can also filter by path, which could be confused with opengrok_find_file, but the descriptions clarify that search returns matching lines while find_file returns only paths.
All tools use the opengrok_ prefix and snake_case. Three follow verb_noun (get_file, find_file, list_projects), while search is just a verb, a minor deviation from the otherwise consistent pattern.
Four tools is well-scoped for a read-only code search server. Each tool has a clear, non-redundant role: search content, retrieve file contents, find files, and list projects.
The core read-only workflows (search, read, find, list projects) are covered. Minor gaps exist, such as no direct file history/blame tool and no explicit directory listing beyond find_file patterns, but agents can work around these with existing tools.
Maintenance
Related MCP Connectors
Code intelligence for coding agents: semantic, AST, graph, and full-text search. 279+ languages.
Code intelligence for LLMs. Analyze, search, and retrieve code from any public git repository.
GitHub, npm, PyPI, Stack Overflow, arXiv and OpenAlex paper search as agent tools.
Search public open-source code, documentation, metadata, vulnerabilities, changelogs, and examples.
Related MCP Servers
AlicenseNot gradedqualityDmaintenanceProvides AI coding agents with structured access to indexed codebases via semantic search, symbol analysis, and file reading tools.13Server Side Public , v 1- AlicenseNot gradedqualityDmaintenanceEnables AI assistants to explore, search, and read codebase repositories and API specifications efficiently, with support for file searching, content search via ripgrep, and reading API specs.ISC
- AlicenseNot gradedqualityDmaintenanceEnables LLMs to query OpenGrok for source code searches, including definitions, symbols, and project listings, returning clickable URLs.2Apache 2.0
- AlicenseNot gradedqualityBmaintenanceSource-code intelligence for agents, powered by OpenGrok and Go.10Apache 2.0