Skip to main content

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

TypeSupportedNotes
API key (token)YesPrimary for gateway. Include your Sourcegraph access token in the header: Authorization: token YOUR_ACCESS_TOKEN.
OAuth 2.0YesSupported 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 searchkeyword_search (exact keywords, boolean, regex) and nls_search (natural language / semantic search) with filters like repo:, file:, rev:.
  • File and repository operationsread_file (with line ranges and revisions), list_files, list_repos (with pagination).
  • Code navigationgo_to_definition, find_references (cross-repo, compiler-accurate).
  • Version control and historycommit_search, diff_search, compare_revisions, get_contributor_repos.
  • Deep Searchdeepsearch_read to 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.com or sourcegraph.company.com for self-hosted
  • Sourcegraph access token — Create one with the scopes your tools need (e.g. Creating an access token). For OAuth, user:all scope 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

  1. Log in to Cequence AI Gateway.
  2. Choose your tenant.
  3. Go to App catalogue.
  4. Filter by Remote MCP server.
  5. Search for Sourcegraph MCP and then select it.
  6. Click Create MCP server.
  7. Enter your Sourcegraph instance when prompted (e.g. sourcegraph.com or your self-hosted hostname). The gateway builds the URL (e.g. https://<instance>/.api/mcp/v1).
  8. 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.
  9. 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/v1 per manifest); Deep Search agent at /.api/mcp/deepsearch.
  • Limits: File size limit for read_file is 128 KB; use line ranges for larger files. Use pagination and filters to keep result sets manageable.
  • Best practices: Use list_repos first to scope searches; start broad with nls_search then narrow; use list_files before read_file to confirm file existence; chain tools (e.g. list_reposcommit_search).
  • Official documentation: Sourcegraph MCP Server, Creating an access token, OAuth apps. Feature is experimental.