Skip to main content
The Sourcegraph MCP server exposes your Sourcegraph instance’s code search, navigation, and analysis capabilities to AI agents and applications through the Model Context Protocol (MCP). Any MCP-compatible tool can connect to it and use Sourcegraph as a context source.
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:
Both commands prompt you to authenticate through your browser the first time. Replace sourcegraph.example.com with your Sourcegraph instance URL.

Server endpoints

Authentication

Sourcegraph implements Dynamic Client Registration (RFC 7591), so compatible clients register automatically without requiring a pre-configured client ID. DCR-registered applications are granted the mcp 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:
Set the OAuth client’s redirect URI to http://localhost:3334/oauth/callback when using this approach.

Access token

Include a Sourcegraph access token in the Authorization header. You can use the mcp scope to restrict the token to MCP endpoints only:

Client setup

Amp

Claude Code

Cursor

Create or edit ~/.cursor/mcp.json:

VS Code

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 navigation

Version control and history

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).