Client Integrations
Set up the Sourcegraph MCP server with your preferred AI coding tool or IDE.
Supported on Enterprise plans.
Supported Clients
Claude Code
Add the Sourcegraph MCP server to Claude Code:
BASHclaude mcp add --transport http sourcegraph https://sourcegraph.example.com/.api/mcp
Then run /mcp in Claude Code and follow the browser authentication flow.
To share an access-token configuration with a project, set SOURCEGRAPH_ACCESS_TOKEN in your environment and add the following to .mcp.json in the project root:
JSON{ "mcpServers": { "sourcegraph": { "type": "http", "url": "https://sourcegraph.example.com/.api/mcp", "headers": { "Authorization": "token ${SOURCEGRAPH_ACCESS_TOKEN}" } } } }
You can also add an access-token configuration for the current project with the CLI:
BASHclaude mcp add --transport http sourcegraph https://sourcegraph.example.com/.api/mcp \ --header "Authorization: token $SOURCEGRAPH_ACCESS_TOKEN"
Locally scoped servers take precedence over project-scoped servers with the same name.
Codex
Add the Sourcegraph MCP server to Codex by adding the following to ~/.codex/config.toml, or to .codex/config.toml for a trusted project:
TOML[mcp_servers.sourcegraph] url = "https://sourcegraph.example.com/.api/mcp" scopes = ["mcp"]
Then authenticate with codex mcp login sourcegraph.
scopes = ["mcp"] is required. Without it, Codex's OAuth login fails with
an invalid_scope error because Sourcegraph's MCP endpoints require the
mcp scope. See Troubleshooting: invalid_scope error during
OAuth for details.
Cursor
Add the following to ~/.cursor/mcp.json, or to .cursor/mcp.json for a project:
JSON{ "mcpServers": { "sourcegraph": { "url": "https://sourcegraph.example.com/.api/mcp" } } }
Enable the server from Cursor Settings > Tools & MCP and follow the OAuth prompt. See Cursor's MCP documentation for more information.
To authenticate with a Sourcegraph access token instead, set SOURCEGRAPH_ACCESS_TOKEN in Cursor's environment and add an authorization header:
JSON{ "mcpServers": { "sourcegraph": { "url": "https://sourcegraph.example.com/.api/mcp", "headers": { "Authorization": "token ${env:SOURCEGRAPH_ACCESS_TOKEN}" } } } }
Copilot
Add the Sourcegraph MCP server to GitHub Copilot CLI:
BASHcopilot mcp add --transport http sourcegraph https://sourcegraph.example.com/.api/mcp
Then run /mcp auth sourcegraph and follow the authentication flow.
OpenCode
Add the following to ~/.config/opencode/opencode.json for a global configuration, or to opencode.json in a project root for a project-specific configuration:
JSON{ "$schema": "https://opencode.ai/config.json", "mcp": { "sourcegraph": { "type": "remote", "url": "https://sourcegraph.example.com/.api/mcp" } } }
Then authenticate with opencode mcp auth sourcegraph. See OpenCode's MCP documentation for more information.
To authenticate with a Sourcegraph access token instead, disable OAuth and add an authorization header:
JSON{ "$schema": "https://opencode.ai/config.json", "mcp": { "sourcegraph": { "type": "remote", "url": "https://sourcegraph.example.com/.api/mcp", "oauth": false, "headers": { "Authorization": "token {env:SOURCEGRAPH_ACCESS_TOKEN}" } } } }
Amp
Add the Sourcegraph MCP server to Amp:
BASHamp mcp add sourcegraph https://sourcegraph.example.com/.api/mcp
Amp starts the OAuth flow in your browser when it connects to the server.
To authenticate with a Sourcegraph access token instead, add an authorization header:
BASHamp mcp add sourcegraph --header "Authorization=token $SOURCEGRAPH_ACCESS_TOKEN" https://sourcegraph.example.com/.api/mcp
You can also configure the access-token connection in VS Code's settings.json:
JSON{ "amp.mcpServers": { "sourcegraph": { "url": "https://sourcegraph.example.com/.api/mcp", "headers": { "Authorization": "token ${SOURCEGRAPH_ACCESS_TOKEN}" } } } }
In all examples, replace sourcegraph.example.com with your Sourcegraph instance URL. For Claude Code, Cursor, OpenCode, and Amp access-token authentication, set SOURCEGRAPH_ACCESS_TOKEN in the client's environment. In other access-token examples, replace YOUR_ACCESS_TOKEN with a Sourcegraph access token.
Google Gemini Code Assist
You can add the Sourcegraph MCP server to Google Gemini Code Assist by configuring the .gemini/settings.json file:
-
Open or create the configuration file at
~/.gemini/settings.json(or the equivalent path on your system). -
Add the following configuration:
JSON{ "mcpServers": { "sourcegraph": { "httpUrl": "https://your-sourcegraph-instance.com/.api/mcp", "headers": { "Authorization": "token YOUR_ACCESS_TOKEN" } } } }Replace
your-sourcegraph-instance.comwith your Sourcegraph instance URL andYOUR_ACCESS_TOKENwith your access token. -
Save the configuration file.
-
Restart Gemini Code Assist to apply the new configuration.
VS Code
You can add the Sourcegraph MCP server to VS Code in one of two ways:
Option 1: code CLI
- Run the following command to add the MCP server to the global configuration
BASHcode --add-mcp "{ \"name\": \"sourcegraph\", \"type\": \"remote\", \"url\": \"https://your-sourcegraph-instance.com/.api/mcp\" }"
- Launch or restart VS Code to apply the new configuration.
Option 2: VSCode mcp.json
-
Create
.vscode/mcp.jsonin your project. -
Add the following configuration:
JSON{ "servers": { "sourcegraph": { "type": "http", "url": "https://your-sourcegraph-instance.com/.api/mcp" } }, "inputs": [] } -
Save the configuration file.
-
Restart VS Code to apply the new configuration.
Antigravity
-
Create
.vscode/mcp.json(Antigravity uses.vscodefor configs) in your project. -
Add the following:
JSON{ "servers": { "sourcegraph": { "url": "https://your-sourcegraph-instance.com/.api/mcp", "type": "http", "headers": { "Authorization": "token YOUR_ACCESS_TOKEN" } } }, "inputs": [] }Replace
your-sourcegraph-instance.comwith your Sourcegraph instance URL andYOUR_ACCESS_TOKENwith your access token.
Windsurf
-
Create
~/.codeium/windsurf/mcp_config.json. -
Add the following:
JSON{ "mcpServers": { "sourcegraph": { "serverUrl": "https://your-sourcegraph-instance.com/.api/mcp", "headers": { "Authorization": "token YOUR_ACCESS_TOKEN", "Content-Type": "application/json" } } } }Replace
your-sourcegraph-instance.comwith your Sourcegraph instance URL andYOUR_ACCESS_TOKENwith your access token. -
Save the configuration file.