Skip to main content
Glama
opengrok-mcp
by jenkeeri

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

opengrok_search

Search by full text, def (definitions), symbol, path, hist (commit messages) and type, with paging.

opengrok_find_file

Find files by name or path pattern.

opengrok_get_file

Read a file (line-numbered) by the path returned from search, with an optional line range.

opengrok_list_projects

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 build

Configuration

All settings are environment variables, normally set in your MCP client's server entry:

Variable

Required

Description

OPENGROK_URL

yes

Base URL, e.g. https://opengrok.example.com

OPENGROK_DEFAULT_PROJECT

no

Comma-separated default project(s). Empty means all projects.

OPENGROK_INSTRUCTIONS

no

Free text appended to the server instructions the agent sees. Use it to describe your project layout (what each project is, naming conventions).

OPENGROK_TOKEN

no

Bearer token, if the instance needs one.

OPENGROK_USERNAME / OPENGROK_PASSWORD

no

Basic auth, if the instance needs it.

OPENGROK_TIMEOUT_MS

no

Per-request timeout (default 30000).

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, symbol and start. The web UI names (project, defs, refs) are silently ignored by the API, which makes project filtering appear broken.

  • type takes an OpenGrok analyzer name (c, cxx, java, python, ...); an unknown name returns zero results.

  • full with several bare terms/phrases is OR-ed; use AND explicitly. path (and find_file) match per path component, so a regex cannot span /. hist results are de-duplicated; a bare ticket number is exact.

  • Search output is capped at max_lines_per_file (default 10) lines per file; get_file reports the line range actually returned when it cuts a file at 30000 characters.

  • def and symbol rely on OpenGrok's language-aware indexing; use full for file types it cannot parse.

Development

npm test          # unit tests (synthetic fixtures, no network)
npm run typecheck
npm run build

License

GPL-3.0, see LICENSE.

Available Tools

4 tools
opengrok_find_fileFind files in OpenGrokA
Read-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 OpenGrokA
Read-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 projectsA
Read-onlyIdempotent

List the project names available on the OpenGrok instance (valid values for the projects argument).

Inputs: no named parameters.

Tool Schema Changelog

Recent tool additions, removals, and schema changes observed during successful MCP inspections.

Loading tool schema changelog…

    TDQS

    A4.1/5.0

    Scored across 4 tools

    Disambiguation4/5

    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.

    Naming Consistency4/5

    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.

    Tool Count5/5

    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.

    Completeness4/5

    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

    ActivityMaintained
    ResponsivenessNo recent community issues

    Related MCP Connectors

    Related MCP Servers