The Sourcegraph MCP server is available on Enterprise plans.
Quick start
MCP clients that support OAuth can connect with a single command — no manual token setup required:- Amp
- Claude Code
sourcegraph.example.com with your Sourcegraph instance URL.
Server endpoints
| Endpoint | Description |
|---|---|
/.api/mcp | Full suite of Sourcegraph tools |
/.api/mcp/deepsearch | Deep Search agent endpoint |
Authentication
OAuth 2.0 (recommended)
Sourcegraph implements Dynamic Client Registration (RFC 7591), so compatible clients register automatically without requiring a pre-configured client ID. DCR-registered applications are granted themcp scope, which restricts access to MCP endpoints only.
If your client doesn’t support Dynamic Client Registration, you can manually create an OAuth application in your Sourcegraph instance and use mcp-remote as a bridge:
http://localhost:3334/oauth/callback when using this approach.
Access token
Include a Sourcegraph access token in theAuthorization header. You can use the mcp scope to restrict the token to MCP endpoints only:
Client setup
Amp
- CLI
- VS Code settings.json
Claude Code
- CLI
- .mcp.json
Cursor
Create or edit~/.cursor/mcp.json:
VS Code
- CLI
- .vscode/mcp.json
Windsurf
Create~/.codeium/windsurf/mcp_config.json:
OpenCode
Edit~/.config/opencode/opencode.jsonc:
Google Gemini Code Assist
Edit~/.gemini/settings.json:
Available tools
All tools implement result limits to prevent context window overflow. For large result sets, use pagination cursors (after/before) or narrow your search with more specific filters.
File and repository operations
| Tool | Description |
|---|---|
read_file | Read file contents with line numbers. Supports line ranges and specific revisions. Max file size: 128 KB. |
list_files | List files and directories in a repository path. |
list_repos | Search and list repositories by name pattern with pagination. |
Code search
| Tool | Description |
|---|---|
keyword_search | Exact keyword search with boolean operators (AND/OR), regex, and filters (repo:, file:, rev:). |
nls_search | Semantic search with natural language matching, stemming, and broader results than keyword search. |
Code navigation
| Tool | Description |
|---|---|
go_to_definition | Find a symbol’s definition from a usage location. Cross-repository, compiler-accurate. |
find_references | Find all references to a symbol from its definition location. |
Version control and history
| Tool | Description |
|---|---|
commit_search | Search commits by message, author, content, file paths, and date range. |
diff_search | Search actual code changes (diffs) for specific patterns. Filter by added/removed lines, author, and date. |
compare_revisions | Show the diff between two revisions of a repository. |
get_contributor_repos | Find repositories a contributor has committed to. |
Deep Search
| Tool | Description |
|---|---|
deepsearch | Ask a detailed question about your codebase. Deep Search performs multi-step research and returns a comprehensive answer with evidence. |
deepsearch_read | Read a previous Deep Search conversation by URL or read token. |
Admins can disable the
deepsearch tool on the default MCP endpoint by contacting your account team or adjusting site configuration. This does not affect the dedicated /.api/mcp/deepsearch endpoint.Best practices
Start with repository discovery
Use
list_repos first to identify the repositories relevant to your task. Scoping subsequent searches to specific repositories improves performance and result quality.Search broadly, then narrow
Start with
nls_search for natural language queries, then use keyword_search with specific filters once you know what you’re looking for.Verify before reading
Use
list_files to confirm a file exists before calling read_file. For large files, use startLine/endLine parameters to read only the relevant section.Chain tools together
Combine tools for richer analysis:
list_repos → keyword_search → go_to_definition → find_references.