Skip to content

MCP Server

Code Search includes a built-in Model Context Protocol (MCP) server that lets AI assistants search your code, browse files, and navigate symbols directly.

The MCP server exposes 8 tools:

search_code

Full-text code search with regex, repo filters, and language filters. Returns matched lines with context.

list_repos

List all indexed repositories with filtering by name and status. Supports pagination.

get_repo_branches

Get branches and tags for a repository by ID.

get_file_tree

Browse directory contents in a repository at a specific path and ref.

get_file_content

Read file contents with automatic binary detection and language identification.

search_symbols

Search for symbol definitions — functions, classes, methods, variables.

go_to_definition

Jump to a symbol’s definition from a specific file location (line + column).

find_references

Find all usages of a symbol across the repository.

Terminal window
make build
# Binary is at bin/mcp-server
Terminal window
# Stdio mode — for Claude Desktop, Cursor, etc.
./bin/mcp-server --api-url http://localhost:8080

Or use the Makefile shortcuts:

Terminal window
make dev-mcp # Stdio mode
make dev-mcp-http # HTTP mode on :9090
FlagDefaultDescription
--api-urlhttp://localhost:8080Code Search API server URL
--auth-tokenAuthentication token for the API (env: CODE_SEARCH_AUTH_TOKEN)
--transportstdioTransport type: stdio or http
--http-addr:9090HTTP listen address (only for http transport)

Environment variables override flags:

VariableOverridesDescription
CODE_SEARCH_API_URL--api-urlAPI server URL
CODE_SEARCH_AUTH_TOKEN--auth-tokenAPI authentication token
CODE_SEARCH_MCP_TRANSPORT--transportTransport type
CODE_SEARCH_MCP_HTTP_ADDR--http-addrHTTP listen address

Enterprise deployments with SSO/OIDC require an API token for MCP server access. Without a token, the API will reject requests with 401 Unauthorized.

Creating an API token:

  1. Log in to the Code Search web UI
  2. Go to your profile or the admin panel
  3. Create a new API token (tokens use the cse_ prefix)
  4. Copy the token — it is only shown once

Passing the token:

Via command-line flag:

Terminal window
./bin/mcp-server --api-url http://localhost:8080 --auth-token cse_your_token_here

Via environment variable:

Terminal window
export CODE_SEARCH_AUTH_TOKEN=cse_your_token_here
./bin/mcp-server --api-url http://localhost:8080

Add to your claude_desktop_config.json:

{
"mcpServers": {
"code-search": {
"command": "/path/to/bin/mcp-server",
"args": ["--api-url", "http://localhost:8080"],
"env": {
"CODE_SEARCH_AUTH_TOKEN": "cse_your_token_here"
}
}
}
}

Add to your .mcp.json or project settings:

{
"mcpServers": {
"code-search": {
"command": "/path/to/bin/mcp-server",
"args": ["--api-url", "http://localhost:8080"],
"env": {
"CODE_SEARCH_AUTH_TOKEN": "cse_your_token_here"
}
}
}
}

Add to Cursor’s MCP settings:

{
"mcpServers": {
"code-search": {
"command": "/path/to/bin/mcp-server",
"args": ["--api-url", "http://localhost:8080"],
"env": {
"CODE_SEARCH_AUTH_TOKEN": "cse_your_token_here"
}
}
}
}

For remote setups where the AI client can’t run local processes:

Terminal window
# Start MCP server in HTTP mode
./bin/mcp-server --transport http --http-addr :9090 \
--api-url http://your-code-search:8080

Then configure your client to connect to http://your-mcp-host:9090.

Search across all indexed repositories.

ParameterRequiredDefaultDescription
queryYesSearch query (Zoekt syntax or regex)
reposNoallComma-separated repo filter
languagesNoallComma-separated language filter
file_patternsNoallFile glob patterns
is_regexNofalseTreat query as regex
case_sensitiveNofalseCase-sensitive matching
context_linesNo2Lines of context around matches
limitNo50Maximum results

List indexed repositories.

ParameterRequiredDefaultDescription
searchNoFilter by name
statusNoFilter by status
limitNo50Maximum results
offsetNo0Pagination offset

Browse directory contents.

ParameterRequiredDefaultDescription
repo_idYesRepository ID
pathNorootDirectory path
refNoHEADBranch, tag, or commit

Read a file.

ParameterRequiredDefaultDescription
repo_idYesRepository ID
pathYesFile path
refNoHEADBranch, tag, or commit

Search for symbol definitions (requires SCIP indexing).

ParameterRequiredDefaultDescription
repo_idYesRepository ID
queryYesSymbol name pattern
limitNo20Maximum results

Jump to a symbol’s definition.

ParameterRequiredDefaultDescription
repo_idYesRepository ID
fileYesFile path
lineYesLine number (1-indexed)
columnYesColumn number (0-indexed)

Find all references to a symbol.

ParameterRequiredDefaultDescription
repo_idYesRepository ID
fileYesFile path
lineYesLine number (1-indexed)
columnYesColumn number (0-indexed)
limitNo50Maximum results
AI Assistant (Claude, Cursor, etc.)
│ MCP Protocol (stdio or HTTP)
MCP Server (bin/mcp-server)
│ REST API (HTTP)
Code Search API Server (:8080)
├── PostgreSQL (metadata)
├── Redis (job queue)
└── Zoekt (search index)

The MCP server is a stateless proxy — it translates MCP tool calls into Code Search API requests. It can run alongside the AI client (stdio) or as a shared service (HTTP).