Sourcegraph MCP Server
Published
At a glance
- Category
- Code & Git
- Hosted by the vendor
- https://sourcegraph.com/docs/api/mcp
- Watch out for
- The server is supported on Enterprise plans only and runs against a Sourcegraph instance you have access to.
Sourcegraph's MCP server is built into Sourcegraph itself rather than shipped as a separate package. Every Sourcegraph instance on an Enterprise plan exposes it over HTTP under /.api/mcp, and an agent connected to it gets the same code search, navigation and history tools that power the Sourcegraph UI, across every repository the user can already read.
There are three endpoints. /.api/mcp carries the core search, repository, history and Deep Search reading tools. /.api/mcp/all adds the rest, including symbol navigation, revision comparison and starting new Deep Search conversations. /.api/mcp/deepsearch carries only the Deep Search tools. Sourcegraph suggests picking the smallest one that covers what your client needs.
Authentication is OAuth 2.0, either through Dynamic Client Registration (on by default, restricted to the mcp scope) or a pre-registered client, with Sourcegraph access tokens as the fallback for clients that cannot do OAuth. Admins can switch MCP off with mcp.enabled, hide tools with mcp.tools.disabled, and restrict use through the MCP#ACCESS role permission.
How it connects
Your AI app
An assistant or agent that supports MCP
Sourcegraph MCP Server
Runs as
- Remote (HTTP)
Gives the agent
- Code search
- Reading repositories
- Symbol navigation
- History and diffs
- Agentic search
- Scripted aggregation
Sourcegraph
Signs in with
- OAuth / browser sign-in
- Token
What it can do
- Code search
- keyword_search runs exact searches with repo:, file:, rev: and count: filters, and nls_search does looser natural-language matching.
- Reading repositories
- list_repos, list_files, list_refs and read_file let an agent find a repo, browse it, pick a branch or tag and read files by line range.
- Symbol navigation
- go_to_definition and find_references resolve symbols, including across repositories, on the /.api/mcp/all endpoint.
- History and diffs
- commit_search, diff_search, compare_revisions and get_contributor_repos search commit messages, changed code, revision diffs and who worked where.
- Agentic search
- code_finder runs its own search loop and returns file paths and line ranges for a task, while deepsearch and deepsearch_read start and read Deep Search conversations.
- Scripted aggregation
- evaluator runs sandboxed Lua scripts over search results to count, cross-reference or reshape matches.
Setting it up
Replace sourcegraph.example.com with your own instance URL. For Claude Code, run claude mcp add --transport http --scope user sourcegraph https://sourcegraph.example.com/.api/mcp, then claude mcp login sourcegraph (or /mcp inside Claude Code) and finish the browser sign-in. Leaving out --scope user adds it to the current project only. To use an access token instead, export SOURCEGRAPH_ACCESS_TOKEN and add --header "Authorization: token $SOURCEGRAPH_ACCESS_TOKEN", or put an http entry with that header in the project's .mcp.json. In Cursor, add a sourcegraph entry with the url to ~/.cursor/mcp.json, enable it on the Customize page and follow the OAuth prompt. Codex takes a [mcp_servers.sourcegraph] block with the url in ~/.codex/config.toml followed by codex mcp login sourcegraph. Swap the path for /.api/mcp/all if you want navigation tools and new Deep Search conversations.
Where each client keeps its MCP config file, and the JSON it expects (cheat sheet)
Where it helps
- Locate where a feature is implemented in a large monorepo with code_finder before an agent starts editing.
- Trace every caller of a function across services with find_references ahead of a breaking change.
- Work out which release tags contain a fix by combining commit_search with list_refs and its containsCommit filter.
- Review what changed between two releases with compare_revisions and read the relevant files at each revision.
- Count how many repositories still use a deprecated API by running an evaluator script over keyword_search results.
Limitations and things to watch
- The server is supported on Enterprise plans only and runs against a Sourcegraph instance you have access to.
- The default /.api/mcp endpoint cannot start new Deep Search conversations or use navigation tools such as go_to_definition; those need /.api/mcp/all.
- Tools cap their output: read_file returns only the first 200 lines of files over 128KB, and list_files stops at 1000 entries.
- code_finder is metered against the instance's entitlement and returns an error once the quota runs out.
- OAuth clients must request only the mcp scope, otherwise sign-in fails with an invalid_scope error.
Sources
Written from the project's own documentation, checked November 2026.
- sourcegraph.com /docs/api/mcp
- sourcegraph.com /docs/api/mcp/client-integrations
- sourcegraph.com /docs/api/mcp/authentication
How we research: where our facts come from, how often we re-check them, and why no one can pay for a review or a verdict.