Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions docs/api/mcp/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,88 @@ Find repositories where a contributor has made commits.
}
```

## Client Integration

The Sourcegraph MCP server can be integrated with various AI tools and IDEs that support the Model Context Protocol.

### Amp

You can add the Sourcegraph MCP server to [Amp](https://ampcode.com) in two ways:

#### Option 1: VSCode settings.json

1. Open VSCode's `settings.json` file.
2. Add the following configuration:

```json
{
"amp.mcpServers": {
"sourcegraph": {
"url": "https://your-sourcegraph-instance.com/.api/mcp/v1",
"headers": {
"Authorization": "token YOUR_ACCESS_TOKEN"
}
}
}
}
```

Replace `your-sourcegraph-instance.com` with your Sourcegraph instance URL and `YOUR_ACCESS_TOKEN` with your access token.

3. Save the configuration file.
4. Restart VS Code to apply the new configuration.

#### Option 2: Amp CLI

Run the following command in your terminal:

```bash
amp mcp add sourcegraph --header "Authorization=token $SRC_ACCESS_TOKEN" https://sourcegraph.sourcegraph.com/.api/mcp/v1
```

Replace `sourcegraph.sourcegraph.com` with your Sourcegraph instance URL and set `$SRC_ACCESS_TOKEN` environment variable to your access token.

### Claude Code

You can add the Sourcegraph MCP server to [Claude Code](https://claude.ai/code) in two ways:

#### Option 1: Project-scoped server (via .mcp.json file)

1. Create a `.mcp.json` file in your project root if it doesn't exist.
2. Add the following configuration:

```json
{
"mcpServers": {
"sourcegraph": {
"url": "https://your-sourcegraph-instance.com/.api/mcp/v1",
"headers": {
"Authorization": "token YOUR_ACCESS_TOKEN"
}
}
}
}
```

Replace `your-sourcegraph-instance.com` with your Sourcegraph instance URL and `YOUR_ACCESS_TOKEN` with your access token.

3. Save the configuration file.
4. Restart Claude Code to apply the new configuration.

#### Option 2: Locally-scoped server (via CLI command)

You can also add the Sourcegraph MCP server as a locally-scoped server, which is only available to you in the current project:

1. Run the following command in your terminal:

```bash
claude mcp add sourcegraph -s local --url https://your-sourcegraph-instance.com/.api/mcp/v1 --header "Authorization: token YOUR_ACCESS_TOKEN"
```

Replace `your-sourcegraph-instance.com` with your Sourcegraph instance URL and `YOUR_ACCESS_TOKEN` with your access token.

Locally-scoped servers take precedence over project-scoped servers with the same name and are stored in your project-specific user settings.

## Best Practices

1. **Repository Scoping:** Use `sg_list_repos` first to find relevant repositories for better performance
Expand Down