From 1fcd5e9ecf530caa33a64526591a7676e00c4d1a Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Date: Tue, 30 Sep 2025 08:32:15 -0700 Subject: [PATCH 1/3] docs: add Amp and Claude Code integration examples for MCP server Amp-Thread-ID: https://ampcode.com/threads/T-87005ebc-368d-4ed3-8684-dbc4f758c3d6 Co-authored-by: Amp --- docs/api/mcp/index.mdx | 82 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 82 insertions(+) diff --git a/docs/api/mcp/index.mdx b/docs/api/mcp/index.mdx index ea6473bb3..f6ccf9c66 100644 --- a/docs/api/mcp/index.mdx +++ b/docs/api/mcp/index.mdx @@ -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 From 695c799f0eec715c04403e3ef687ae0c32146280 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Date: Tue, 30 Sep 2025 11:49:36 -0700 Subject: [PATCH 2/3] docs: add callouts for configuration values and move Client Integration section to top --- docs/api/mcp/index.mdx | 176 ++++++++++++++++++++++------------------- 1 file changed, 94 insertions(+), 82 deletions(-) diff --git a/docs/api/mcp/index.mdx b/docs/api/mcp/index.mdx index f6ccf9c66..0048247f6 100644 --- a/docs/api/mcp/index.mdx +++ b/docs/api/mcp/index.mdx @@ -37,6 +37,100 @@ Include your token in the Authorization header: Authorization: token YOUR_ACCESS_TOKEN ``` +## Client Integration + +The Sourcegraph MCP server can be integrated with various AI tools and IDEs that support the Model Context Protocol. + +### Amp + + + To create an access token, visit [Creating an access token](/cli/how-tos/creating_an_access_token). + + +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. + ## Available Tools The MCP server provides these tools for code exploration and analysis: @@ -228,88 +322,6 @@ 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 From cd987d187aa59c07a206f4c34b64b5100a4bbf38 Mon Sep 17 00:00:00 2001 From: Enrique Gonzalez Date: Tue, 30 Sep 2025 11:53:36 -0700 Subject: [PATCH 3/3] docs: maintain consistency on variable used on client config examples --- docs/api/mcp/index.mdx | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/api/mcp/index.mdx b/docs/api/mcp/index.mdx index 0048247f6..56e9a787d 100644 --- a/docs/api/mcp/index.mdx +++ b/docs/api/mcp/index.mdx @@ -79,11 +79,11 @@ You can add the Sourcegraph MCP server to [Amp](https://ampcode.com) in two ways 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 +amp mcp add sourcegraph --header "Authorization=token YOUR_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. + Replace `sourcegraph.sourcegraph.com` with your Sourcegraph instance URL and set `YOUR_ACCESS_TOKEN` environment variable to your access token. ### Claude Code