Developer Tools & Devops · Sourcegraph + Claude
Sourcegraph MCP with Claude: Search and Review Code Across Large Repositories
The short answer
Claude works with Sourcegraph through the Model Context Protocol (MCP), an open standard that gives Claude secure, permissioned access to the platform. Once connected, Claude can search code across large repositories, fetch repository data, analyse diffs and help review pull requests, all from natural language requests.
What is Sourcegraph?
Sourcegraph is a code intelligence platform that helps developers search, understand and manage code across very large sets of repositories. Engineering teams use it to find where a function is used, understand unfamiliar parts of a codebase and review changes before they are merged. Development leads and platform teams use it to keep large, multi-team codebases navigable and consistent.
How Claude connects to Sourcegraph through MCP
The Model Context Protocol is an open standard that acts like a universal adapter between Claude and other software. It lets Claude use a tool securely, reading information and taking actions, with permissions the organisation sets. For Sourcegraph, the connection is made using an API key, so access follows the permissions of the account it belongs to.
Once connected, Claude can search code across repositories, fetch repository data, analyse diffs and help review pull requests. A developer might ask Claude to find every place a deprecated function is called, or to summarise what a set of changes does. Claude carries out these requests in plain English, using the tool's own search and data.
Permissions and approvals keep people in charge. Access is limited to the repositories the key is allowed to see, and actions that matter, such as posting review comments, can be set to require a person's approval first. Activity can be logged so the engineering team can see what was accessed and when.
What you can automate
Finding code across many repositories
A platform engineer needs to know which services still call an old internal API before a change. Claude searches across the relevant repositories through Sourcegraph and returns a clear list of matches, grouped by team, so the engineer can plan the migration without manually checking dozens of projects.
Assisting pull request reviews
A senior developer receives a large pull request late in the day. Claude analyses the diff, highlights changed behaviour, flags areas that need closer attention and suggests questions for the author. The reviewer keeps the final decision and can accept or reject each suggestion.
Onboarding new engineers
A new hire joining a large codebase asks how authentication works. Claude uses Sourcegraph to locate the relevant modules, summarise the flow and point to the files that matter most. This shortens the time a team lead spends answering the same orientation questions.
Investigating incidents
During a production issue, an on-call engineer asks which recent changes touched a particular module. Claude reviews recent diffs and repository history in Sourcegraph and gives a short timeline, helping the team narrow down the likely cause faster.
Tracking code quality and standards
An engineering manager wants to know how many repositories still use a retired logging pattern. Claude searches for the pattern across the organisation's code and produces a summary by team, which supports planning and clean-up work.
An end-to-end workflow: Pull request review with ticket context
TriggerA developer opens a pull request linked to a Jira ticket for a payment feature.
Claude reads the pull request diff through the Sourcegraph connection.
Claude searches related repositories to find other code that calls the changed functions.
Claude summarises the change and flags possible impacts on other services.
Claude checks the summary against the acceptance criteria stored in the Jira ticket.
The summary and suggested review comments are posted for a human reviewer to approve or edit.
OutcomeReviewers get a clearer picture of each change and its wider impact in less time, while every comment still passes through a person before it reaches the author. Results vary by team and codebase.
How we set it up
Free automation audit
We review your engineering workflows and identify where code search, review and analysis take the most time, and whether Sourcegraph is the right starting point.
Connection design
We set up the Sourcegraph connection using an API key, scoped to the repositories and permissions your team needs, following least-privilege principles.
Workflow design
We design how Claude fits into your review and search processes, including which actions need human approval and how results are recorded.
Testing with real cases
We test the setup against recent pull requests and past questions from your team, then adjust prompts and permissions based on the results.
Launch, monitoring and training
We launch with activity logging and monitoring in place, then train developers and leads on how to use Claude with Sourcegraph safely and effectively.
Who benefits
- Engineering manager
- Gains visibility into code patterns and review workload across teams without adding manual reporting.
- Senior developer
- Spends less time on routine review and search, and more on design and mentoring.
- New engineer
- Gets faster answers to questions about an unfamiliar codebase.
- Platform or security lead
- Keeps tighter control over which code is accessed, with logs of activity.
Security and control
- Access uses an API key scoped to the repositories and permissions the team has approved.
- Actions with business impact, such as posting review comments, can require a person's approval.
- Activity is logged so the engineering team can audit what Claude accessed and why.
- Claude's suggestions are reviewed by people before they influence production code.
- Sensitive repositories can be excluded from the connection entirely.
For teams in the US, UK, India and the Middle East
Organisations in the United States and the United Kingdom can host Claude in their chosen region to meet their data handling requirements. Companies in India must consider the Digital Personal Data Protection Act, 2023, when code or related personal data is processed. Organisations in the UAE and Saudi Arabia must follow local data protection laws, and we select a hosting region that fits those requirements. Final compliance decisions remain with your legal and security teams.
Learn more about Claude and MCP
Anthropic's AI model and assistant.
Secure links between Claude and business tools.
How engineers build and change software with Claude.
Hosted agents that run multi-step work.
The open standard Claude uses to connect to tools.
Frequently asked questions
What does the Sourcegraph MCP server do?
The Sourcegraph MCP server lets AI tools such as Claude connect to Sourcegraph securely. It allows them to search code, fetch repository data, analyse diffs and help with pull request reviews using natural language. The server acts as a controlled gateway, so the AI only reaches what the connection allows.
Is connecting Claude to Sourcegraph secure?
Security depends on how the connection is set up. We use an API key scoped to approved repositories and permissions, apply least-privilege access, and log activity. Sensitive code can be excluded, and actions with business impact can require human approval before they take effect.
What can Claude do with Sourcegraph once connected?
Typically, Claude can search across repositories, retrieve file and repository information, analyse changes between versions and assist with reviewing pull requests. Users make requests in plain English, and Claude carries them out within the permissions it has been given.
How long does setup take?
Timelines depend on the size of your codebase, the number of repositories in scope and how many workflows you want to automate. A focused first project often moves from audit to launch over several weeks, including testing and team training. We confirm the timeline during the free automation audit.
What permissions or plan do I need?
In general, you need a Sourcegraph account with an API key whose permissions cover the repositories you want Claude to access. The exact access level depends on your organisation's Sourcegraph setup, and we confirm what is required during the audit.