Sourcegraph MCP Server
Official Sourcegraph MCP server. Code search (keyword, semantic, commit, diff), code navigation, repo browsing, and Deep Search agent across your codebases.
The Sourcegraph MCP server is the official Model Context Protocol implementation hosted on your Sourcegraph instance. It gives AI agents and IDE assistants like Claude Code, Cursor, Amp, and Codex programmatic access to Sourcegraph's code search, navigation, and analysis capabilities through a standardized HTTP interface. It launched with Sourcegraph v6.8 in September 2025 and is currently marked experimental.
The server exposes tools for file and repository exploration (read_file, list_files, list_repos), code search (keyword_search with boolean operators and regex, nls_search for semantic/natural language matching), code navigation (go_to_definition, find_references with cross-repository accuracy), and version control history (commit_search, diff_search, compare_revisions, get_contributor_repos). A separate Deep Search endpoint runs multi-step agentic research over your code via the deepsearch and deepsearch_read tools, and an evaluator tool runs sandboxed Lua scripts for aggregation over search results.
The MCP server is available only on Sourcegraph Enterprise plans (Cloud or self-hosted) running v6.8 or later. Authentication uses either OAuth 2.0 with Dynamic Client Registration (RFC 7591, scoped to mcp) or a personal access token in the Authorization header. Access is gated by the MCP#ACCESS RBAC permission, separate from repository permissions.
Tools
| Tool | Description |
|---|---|
read_file |
Read file contents with line numbers. Supports line ranges and specific revisions. Max file size 128 KB. |
list_files |
Browse directory structures within a repository. |
list_repos |
Search and list repositories by name pattern with pagination. |
keyword_search |
Exact keyword search with boolean operators (AND/OR), regex, and filters. |
nls_search |
Semantic/natural language search with stemming and flexible linguistic matching. |
evaluator |
Run sandboxed Lua scripts for aggregation and computation over search results. |
go_to_definition |
Locate a symbol's definition from a usage location. Cross-repository and compiler-accurate. |
find_references |
Identify all references to a symbol across repositories. |
commit_search |
Query commits by message, author, content, or files touched. |
diff_search |
Search diffs/code changes across repositories and history. |
compare_revisions |
Compare two specific revisions of a repository. |
get_contributor_repos |
Find repositories that a given author has contributed to. |
deepsearch |
Create a new Deep Search conversation that performs multi-step research to answer complex questions about the codebase. |
deepsearch_read |
Read the results of an existing Deep Search conversation. |
Prerequisites
- Sourcegraph Enterprise plan (Cloud or self-hosted) running v6.8 or later
- Site setting
mcp.enabledset totrue - A user account with the
MCP#ACCESSRBAC permission - A Sourcegraph access token, or an OAuth-capable MCP client
Server endpoints
Replace sourcegraph.example.com with your own instance hostname.
https://sourcegraph.example.com/.api/mcp— core search toolshttps://sourcegraph.example.com/.api/mcp/all— full tool suitehttps://sourcegraph.example.com/.api/mcp/deepsearch— Deep Search agent only
Claude Code
claude mcp add --transport http sg https://sourcegraph.example.com/.api/mcp
Or add to .mcp.json:
{
"mcpServers": {
"sourcegraph": {
"type": "http",
"url": "https://sourcegraph.example.com/.api/mcp",
"headers": {
"Authorization": "token YOUR_ACCESS_TOKEN"
}
}
}
}
Cursor (~/.cursor/mcp.json)
{
"mcpServers": {
"sourcegraph": {
"type": "http",
"url": "https://sourcegraph.example.com/.api/mcp",
"headers": {
"Authorization": "token YOUR_ACCESS_TOKEN"
}
}
}
}
VS Code (.vscode/mcp.json)
{
"servers": {
"sourcegraph": {
"type": "http",
"url": "https://sourcegraph.example.com/.api/mcp"
}
},
"inputs": []
}
Amp
amp mcp add sg https://sourcegraph.example.com/.api/mcp
Authentication
Two options are supported:
- OAuth 2.0 with Dynamic Client Registration (RFC 7591): preferred for interactive clients. Enable with
auth.idpDynamicClientRegistrationEnabled: trueat the site level. Registered clients are scoped tomcp. - Access token: create a token in your Sourcegraph user settings and pass it as
Authorization: token YOUR_ACCESS_TOKEN.
- Let Claude Code or Cursor search across all your private repositories with
keyword_searchandnls_searchbefore generating code, so suggestions match real internal patterns - Use
go_to_definitionandfind_referencesto ask an agent to trace how a function or symbol is used across services without cloning every repo locally - Investigate regressions by combining
commit_searchanddiff_searchto find when a specific line or behavior changed and who authored it - Run
deepsearchto get multi-step research answers like "how do we handle auth across all backend services" without manually wiring up multiple queries - Aggregate codebase metrics (file counts, language breakdowns, API usage) by running Lua scripts through the
evaluatortool over search results
- "Use Sourcegraph to find every call site of
chargeCustomeracross our repos and summarize the call patterns." - "Search our codebase semantically for places that implement rate limiting and list the strategies used."
- "Run a Deep Search to explain how authentication flows from the gateway through our microservices."
- "Find the commit that introduced the
LegacyBillingclass and show me its diff." - "Compare revisions
v6.7.0andv6.8.0of thefrontendrepo and summarize the breaking changes."
- Official, first-party server hosted directly by your Sourcegraph instance, no extra infrastructure to run
- Broad tool coverage: search, semantic search, navigation, history, diffs, and a Deep Search agent
- OAuth 2.0 with Dynamic Client Registration plus token auth, gated by RBAC permissions
- Cross-repository, compiler-accurate code navigation that local IDEs cannot match at scale
- Restricted to Sourcegraph Enterprise plans on v6.8 or later, not available on free or Cloud personal tiers
- Marked experimental: tools and endpoints may change or be removed in future releases
- No write operations: read-only access to code, no batch changes or code modification via MCP
- GitHub MCP server for searching code, issues, and PRs hosted on GitHub
- GitLab MCP server for GitLab-hosted repositories
- Community Sourcegraph MCP implementations (for example
najva-ai/sourcegraph-mcpand0xb8001/mcp-sourcegraph) that wrap the public GraphQL API for non-Enterprise users