> Documentation index: https://metorial.com/llms.txt. Every page is available as Markdown by adding .md to its URL.

# Set up Sourcegraph in Metorial for Claude, ChatGPT and Cursor
URL: https://metorial.com/docs/integrations/sourcegraph
Last updated: 2026-11-24

Share Sourcegraph with your team in Claude, ChatGPT and Cursor through Metorial: access token or sudo access token sign-in, 14 tools (9 read-only).

---

To give your team Sourcegraph in Claude, ChatGPT, Cursor and other AI clients, an admin shares the Sourcegraph integration in a Metorial portal, and each person connects with an access token. Agents can search code with native query syntax, read repository files and metadata, and discover the authenticated user. The integration has 14 tools, 9 read-only, 2 write and 3 destructive, plus 2 triggers.

**What you will learn**

- How an admin shares Sourcegraph in a portal and how each person connects
- What Sourcegraph asks for when you connect, and where to find it
- How to keep the 9 read-only tools and reject the other 5

**Before you start**

- A [portal](https://metorial.com/docs/platform/workforce/portals) with at least one access group
- An access token from Sourcegraph for each person, or one for a shared connection
- For the CLI steps: the [Metorial CLI](https://metorial.com/docs/platform/cli), signed in to your portal

## Sign-in methods

| Method | Type | What a person provides |
| --- | --- | --- |
| **Access Token** (default) | API token | `token` |
| **Sudo Access Token** | Custom credentials | `token` and `sudoUsername` |

The portal and `metorial setup` use **Access Token** unless someone picks another method.

### Access Token

To connect, a person enters:

- `token`: Sourcegraph access token. Generate one at https://&lt;your-instance>/user/settings/tokens

### Sudo Access Token

To connect, a person enters these values:

- `token`: Sourcegraph sudo access token with site-admin:sudo scope
- `sudoUsername`: Username to perform actions as

### Setup settings

Whichever method you pick, setup also asks for:

- `instanceUrl`: The URL of your Sourcegraph instance (e.g., https://sourcegraph.example.com). Required for all API calls.

## Admin: share Sourcegraph in a portal

### In the dashboard

1. **Open Shared Resources**

   Open **Workforce**, choose the portal, and select **Shared Resources** under **Access**.

2. **Share a new integration**

   Select **Share a Resource**, then **New Integration**, and choose Sourcegraph. Under **Auth Method**, keep **Access Token** or pick another. For how members connect, choose **Each person connects** so everyone enters their own access token, or **Shared connection** to enter one access token for everyone.

3. **Limit the tools**

   Under **Tool Filters**, set the write and destructive groups to **Reject** if agents should only read from Sourcegraph.

4. **Choose who gets it**

   Add the access groups that should see Sourcegraph. When a person asks for access from the portal, the request appears under **Access Requests**.

### With the CLI

The CLI cannot create the per-user Sourcegraph integration. Once it exists, check which groups have it:

```bash
metorial-admin portals access list <portal-id> --type provider_template --search sourcegraph
```

## Employee: connect Sourcegraph

### In the portal

1. **Open Sourcegraph in the catalog**

   Sign in to your portal and open Sourcegraph. The status reads **Available**.

2. **Authenticate**

   Under **Quick setup**, select **Authenticate**. In the setup window, enter your access token (token).

3. **Confirm**

   The status changes to **Configured**. If it later reads **Needs reconnect**, select **Reconnect** and sign in again.

### With the CLI

```bash
metorial catalog search sourcegraph
metorial setup <catalog-item-id>
```

`catalog search` prints the catalog item ID. `metorial setup` uses **Access Token**. To connect with **Sudo Access Token** instead, find its ID with `metorial catalog get <catalog-item-id>` and add `--auth-method <auth-method-id>`.

### Add it to your AI client

`metorial install` adds your Sourcegraph connection to a local MCP client such as Claude Code, Cursor or Codex. `metorial list` prints the integration ID and `metorial client list` the client identifiers.

```bash
metorial list sourcegraph
metorial client list
metorial install <client-identifier> <integration-id>
```

For a client that takes a server URL, such as ChatGPT, `metorial install custom <integration-id>` creates an installation token and shows the endpoint details.

## Make it read-only

Open the integration's **Tool Filters** and set the write and destructive groups to **Reject**. Agents keep the 9 read-only tools, such as `search_code` and `get_repository`, and lose the 2 write tools, such as `create_code_insight` or `create_code_monitor`, and the 3 destructive tools, such as `close_batch_change` or `delete_code_insight`.

Employees see the result on the integration's page in the portal under **Tool access**. For the full walkthrough, see [Tool permissions](https://metorial.com/docs/platform/guides/tool-permissions).

## Check it worked

```bash
metorial list sourcegraph
metorial tools <integration-id>
metorial call <integration-id> get_current_user -d '{}'
```

`metorial tools` lists the 14 tools, minus any you rejected. `get_current_user` takes no input. It gets information about the currently authenticated user, including username, email, site admin status, and organization memberships.

To see every input a tool takes, run `metorial schema <integration-id> <tool-key>`.

## Tools

### Read-only tools (9)

- `list_batch_changes`: List batch changes on the Sourcegraph instance.
- `list_repositories`: List repositories connected to the Sourcegraph instance.
- `list_code_insights`: List Code Insight views on the Sourcegraph instance.
- `get_repository`: Get detailed information about a specific repository including branches, tags, clone status, and external source metadata. Needs `repositoryName`.
- `get_batch_change`: Get detailed information about a specific batch change including its changesets (pull requests/merge requests). Needs `batchChangeId`.
- `get_file_content`: Read the content of a file or list directory entries from a repository on Sourcegraph. Needs `repositoryName` and `filePath`.
- `search_code`: Search code, paths, commits, diffs and symbols with native Sourcegraph query syntax. Needs `query`.
- `list_code_monitors`: List code monitors for the current user.
- `get_current_user`: Get information about the currently authenticated user, including username, email, site admin status, and organization memberships.

### Write tools (2)

- `create_code_monitor`: Create a new code monitor that watches for code changes matching a search query. Needs `description`, `namespaceUserId` and `query`.
- `create_code_insight`: Create a new line chart search insight that tracks code patterns over time. Needs `title` and `dataSeries`.

### Destructive tools (3)

- `delete_code_insight`: Delete a Code Insight view from the Sourcegraph instance. Needs `insightViewId`.
- `delete_code_monitor`: Delete a code monitor from the Sourcegraph instance. Needs `codeMonitorId`.
- `close_batch_change`: Close a batch change. Needs `batchChangeId`.

## Triggers

Sourcegraph has 2 triggers, which fire on events in Sourcegraph:

- `code_monitor_notification`: Triggered when a code monitor detects matching changes in new commits.
- `batch_change_events`: Triggered when batch changes or their changesets are created, updated, closed, or deleted via Sourcegraph outgoing webhooks.

## Next steps

- [Claude Code](https://metorial.com/docs/platform/clients/claude-code), [Cursor](https://metorial.com/docs/platform/clients/cursor), [Codex](https://metorial.com/docs/platform/clients/codex) and [ChatGPT](https://metorial.com/docs/platform/clients/chatgpt): connect each client to your portal and use Sourcegraph there
- [Tool permissions](https://metorial.com/docs/platform/guides/tool-permissions): tool filters and what employees see
- [Sourcegraph on metorial.com](https://metorial.com/integrations/sourcegraph): the integration overview