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
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
Code search
Code navigation
Version control and history
Deep Search
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
1
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.2
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.3
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.4
Chain tools together
Combine tools for richer analysis:
list_repos → keyword_search → go_to_definition → find_references.5
Paginate large result sets
Use
after/before cursors for tools that support pagination (list_repos, compare_revisions, get_contributor_repos).