Sourcegraph MCP
The Sourcegraph Model Context Protocol (MCP) server gives AI agents and applications programmatic access to your Sourcegraph instance’s code search, navigation, and analysis capabilities. Connect via Cequence AI Gateway to search code, read files, navigate definitions and references, and query version control—all from your AI client. Supported on Sourcegraph Enterprise (version 6.8+); the feature is experimental and may change.
1. Overview
Sourcegraph MCP can be used with Sourcegraph Cloud (sourcegraph.com) or your self-hosted instance. The server URL is built from your instance hostname; when you add it in Cequence AI Gateway, you supply your instance (e.g. sourcegraph for sourcegraph.com, or your self-hosted hostname).
- Server URL (template):
https://{your-sourcegraph-instance}/.api/mcp/v1
Examples:https://sourcegraph.com/.api/mcp/v1(Cloud),https://sourcegraph.company.com/.api/mcp/v1(self-hosted) - Transport: HTTP (Streamable HTTP)
- Hosted by: You (self-hosted) or Sourcegraph (sourcegraph.com)
Alternative endpoint for Deep Search agent: /.api/mcp/deepsearch (same host).
2. Supported authentication types
| Type | Supported | Notes |
|---|---|---|
| API key (token) | Yes | Primary for gateway. Include your Sourcegraph access token in the header: Authorization: token YOUR_ACCESS_TOKEN. |
| OAuth 2.0 | Yes | Supported with Dynamic Client Registration (DCR) when enabled in site config (auth.idpDynamicClientRegistrationEnabled: true). For clients that don’t support DCR, you can create an OAuth app manually and use mcp-remote with static client info. |
When you add Sourcegraph MCP in Cequence AI Gateway, you typically configure an API key (token). For OAuth-only clients, use DCR if available or the manual OAuth setup described in the vendor docs.
3. What can you do with this MCP server
With the Sourcegraph MCP server, you can:
- Code search —
keyword_search(exact keywords, boolean, regex) andnls_search(natural language / semantic search) with filters likerepo:,file:,rev:. - File and repository operations —
read_file(with line ranges and revisions),list_files,list_repos(with pagination). - Code navigation —
go_to_definition,find_references(cross-repo, compiler-accurate). - Version control and history —
commit_search,diff_search,compare_revisions,get_contributor_repos. - Deep Search —
deepsearch_readto read Deep Search conversation results (by URL or read token).
Result limits and pagination (after/before cursors) keep responses efficient and avoid context overflow.
4. Prerequisites
Before adding Sourcegraph MCP in Cequence AI Gateway, ensure you have:
- Access to Cequence AI Gateway (e.g. beta.aigateway.cequence.ai)
- A Sourcegraph instance (Enterprise 6.8+): Sourcegraph Cloud or self-hosted
- Your instance URL or hostname — e.g.
sourcegraph.comorsourcegraph.company.comfor self-hosted - Sourcegraph access token — Create one with the scopes your tools need (e.g. Creating an access token). For OAuth,
user:allscope is required when using a manually created OAuth app. - For OAuth authentication: an auth app with client credentials in your vendor account, unless the server supports DCR. Sourcegraph supports OAuth with DCR when the feature is enabled in site configuration.
5. Example workflows
- “Search my codebase for authentication login logic.”
- “Read src/auth/login.go in github.com/myorg/myrepo (lines 1–50).”
- “Find recent commits with ‘bug fix’ in github.com/myorg/myrepo in the last week.”
- “Where is getUser defined and where is it referenced?”
- “Compare main and feature/x in github.com/myorg/myrepo.”
6. Connecting MCP server from Cequence AI Gateway
- Log in to Cequence AI Gateway.
- Choose your tenant.
- Go to App catalogue.
- Filter by Remote MCP server.
- Search for Sourcegraph MCP and then select it.
- Click Create MCP server.
- Enter your Sourcegraph instance when prompted (e.g.
sourcegraph.comor your self-hosted hostname). The gateway builds the URL (e.g.https://<instance>/.api/mcp/v1). - Configure API key (token) auth: use your Sourcegraph access token in the
Authorization: token <token>header as required by the gateway. If using OAuth, complete the vendor’s OAuth or DCR flow. - Complete the setup as prompted, select tools, and deploy.
Use the generated MCP server URL in your client as described in the Client Configuration docs. For detailed UI steps and screenshots, see Create a third-party MCP Server.
7. Additional information
- Endpoints: Full tool suite at
/.api/mcp(or/.api/mcp/v1per manifest); Deep Search agent at/.api/mcp/deepsearch. - Limits: File size limit for
read_fileis 128 KB; use line ranges for larger files. Use pagination and filters to keep result sets manageable. - Best practices: Use
list_reposfirst to scope searches; start broad withnls_searchthen narrow; uselist_filesbeforeread_fileto confirm file existence; chain tools (e.g.list_repos→commit_search). - Official documentation: Sourcegraph MCP Server, Creating an access token, OAuth apps. Feature is experimental.