MCP server for self-hosted Sourcegraph instances (v5.x+) that don't expose the native /.api/mcp endpoint.
Translates Model Context Protocol tool calls into Sourcegraph GraphQL API requests, giving AI agents (Claude Code, Cursor, etc.) full access to code search and navigation.
| Tool | Description |
|---|---|
keyword_search |
Code search with filters (repo:, file:, lang:, type:) |
nls_search |
Natural language search (keyword fallback on v5.0.x) |
find_references |
Find all usages of a symbol via regex |
go_to_definition |
Jump to symbol definition |
read_file |
Read file contents from a repository |
list_files |
List files/directories in a repository path |
list_repos |
List indexed repositories |
commit_search |
Search commits by message, author, date |
diff_search |
Search code changes (diffs) over time |
compare_revisions |
Compare two revisions showing file diffs |
deepsearch |
Comprehensive codebase investigation |
deepsearch_read |
Extract insights from search results |
get_contributor_repos |
Find repositories a user contributed to |
- Docker
- Sourcegraph access token (Settings > Access tokens)
git clone https://github.com/codeproger/sourcegraph-mcp.git
cd sourcegraph-mcp
docker build -t sourcegraph-mcp .Add to ~/.mcp.json:
{
"mcpServers": {
"sourcegraph": {
"command": "docker",
"args": [
"run", "--rm", "-i",
"-e", "SOURCEGRAPH_URL=https://sourcegraph.example.com",
"-e", "SOURCEGRAPH_TOKEN=sgp_YOUR_TOKEN",
"sourcegraph-mcp"
]
}
}
}go build -o sourcegraph-mcp ./cmd/sourcegraph-mcp
SOURCEGRAPH_URL=https://sourcegraph.example.com SOURCEGRAPH_TOKEN=sgp_... ./sourcegraph-mcp| Variable | Required | Description |
|---|---|---|
SOURCEGRAPH_URL |
Yes | Sourcegraph instance URL |
SOURCEGRAPH_TOKEN |
Yes | Access token |
nls_searchanddeepsearchfall back to keyword search on Sourcegraph v5.0.x (no Cody/semantic search)find_referencesandgo_to_definitionuse regex patterns, not SCIP precise code intelligence
MIT