Set up Sourcegraph in Metorial for Claude, ChatGPT and Cursor
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'll 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 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, 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://<your-instance>/user/settings/tokens
Sudo Access Token
To connect, a person enters these values:
token: Sourcegraph sudo access token with site-admin:sudo scopesudoUsername: 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
Open Shared Resources
Open Workforce, choose the portal, and select Shared Resources under Access.
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.
Limit the tools
Under Tool Filters, set the write and destructive groups to Reject if agents should only read from Sourcegraph.
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:
Employee: connect Sourcegraph
In the portal
Open Sourcegraph in the catalog
Sign in to your portal and open Sourcegraph. The status reads Available.
Authenticate
Under Quick setup, select Authenticate. In the setup window, enter your access token (token).
Confirm
The status changes to Configured. If it later reads Needs reconnect, select Reconnect and sign in again.
With the CLI
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.
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.
Check it worked
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. NeedsrepositoryName.get_batch_change: Get detailed information about a specific batch change including its changesets (pull requests/merge requests). NeedsbatchChangeId.get_file_content: Read the content of a file or list directory entries from a repository on Sourcegraph. NeedsrepositoryNameandfilePath.search_code: Search code, paths, commits, diffs and symbols with native Sourcegraph query syntax. Needsquery.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. Needsdescription,namespaceUserIdandquery.create_code_insight: Create a new line chart search insight that tracks code patterns over time. NeedstitleanddataSeries.
Destructive tools (3)
delete_code_insight: Delete a Code Insight view from the Sourcegraph instance. NeedsinsightViewId.delete_code_monitor: Delete a code monitor from the Sourcegraph instance. NeedscodeMonitorId.close_batch_change: Close a batch change. NeedsbatchChangeId.
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, Cursor, Codex and ChatGPT: connect each client to your portal and use Sourcegraph there
- Tool permissions: tool filters and what employees see
- Sourcegraph on metorial.com: the integration overview