developer-toolsapi_key

Sourcegraph

Sourcegraph is a code intelligence platform that enables developers to search, understand, and manage code across large codebases.

Verdict

The Sourcegraph MCP lets your team read code across repositories without cloning them locally. @Mention it to fetch file contents, compare commits, list repo structures, or identify languages used in a codebase. Engineers doing code review, documentation, or cross-repo analysis get the most value — you can pull diffs and file trees directly into a Space conversation. Requires a Sourcegraph instance (cloud or self-hosted) and an API key with read access. Does not support editing code or triggering builds; this is read-only code intelligence.

Common use cases

  • Review pull request diffs during standup
  • Audit repository languages before migration
  • Fetch config files without cloning repos
  • Compare commits across feature branches
  • Document API endpoints from source code

Integration

Vendor
Sourcegraph
Category
developer-tools
Auth
API_KEY
Tools
8
Composio slug
sourcegraph

Tools

  • Check Site Settings Edit Permission

    Tool to check whether site settings can be edited through the api. use when you need to confirm the api allows site settings edits before attempting configuration changes.

  • Compare Commits

    Tool to compare two commits in a repository and retrieve their file diffs. use after confirming the repository name and commit shas to inspect differences.

  • Get Commit Details

    Get detailed information about a specific commit in a repository.

  • Get Current User

    Tool to retrieve information about the currently authenticated user. use when needing confirmation of identity via sourcegraph graphql api.

  • Get File Contents

    Tool to fetch the contents of a specified file on the default branch. use when you need raw file text without cloning the repo or using a slower code-host api.

  • List Repositories

    Tool to list repositories on the sourcegraph instance. use when you need to paginate through all available repositories.

  • List Repository Files

    Tool to list all files and directories in a repository path. use when you need to enumerate files in a repository without cloning.

  • List repository languages

    Tool to list languages used in a repository. use when you need to determine the primary and all languages of a given repository; call after you have the repository name.

Setup

Setup guide

  1. 11. Open your Switchy workspace and navigate to Settings > Integrations. 2. Find Sourcegraph in the developer tools section and click Connect. 3. You'll be prompted for your Sourcegraph instance URL (e.g. sourcegraph.com or your self-hosted domain) and an API key. 4. Generate the API key in Sourcegraph under User Settings > Access tokens; grant read permissions for repositories and user data. 5. Paste the URL and key into Switchy, then click Save. 6. Test the connection by opening any Space and typing '@Sourcegraph get current user' — you should see your Sourcegraph username returned. 7. To invoke a tool, @mention Sourcegraph in a message and describe what you need: 'list repositories', 'get contents of src/main.go', or 'compare commits abc123 and def456 in myrepo'.

What teammates see: by default, memories from Sourcegraph are scoped to the Space (PROJECT visibility) - you can mark any memory PRIVATE or share it ORG-wide.

Works well with

Top models

Compatibility data appears once enough Spaces have used this MCP together with a given model.

How Switchy teams use it

Not enough Spaces yet to publish anonymised usage stats (we require ≥ 50 Spaces per week).

Starter prompts

List All Repositories

@Sourcegraph list all repositories in our instance and show me the first 20 results with their names and URLs.
Open in a Space →

Fetch Configuration File

@Sourcegraph get the contents of the file .github/workflows/ci.yml from the repository backend-api so I can review our CI setup.
Open in a Space →

Compare Two Commits

@Sourcegraph compare commits a3f8d21 and b9c4e56 in the frontend-app repository and summarize the key file changes.
Open in a Space →

Identify Repository Languages

@Sourcegraph list the languages used in the data-pipeline repository and tell me which one is most prevalent.
Open in a Space →

Browse Repository Structure

@Sourcegraph list all files and directories in the src/services folder of the backend-api repository so I can map out the service architecture.
Open in a Space →

Example outputs

Illustrative - representative of the model's voice and quality, not literal recordings.

Prompt

@sourcegraph list all repositories in our org that use TypeScript, sorted by most recent commit

Output

Based on the Sourcegraph instance query, 47 repositories use TypeScript. The five most recently updated are: `web-platform` (last commit 2 hours ago), `api-gateway` (last commit 5 hours ago), `design-system` (last commit 1 day ago), `analytics-service` (last commit 2 days ago), and `mobile-app` (last commit 3 days ago). Each repository shows TypeScript as either primary or secondary language. This list reflects repositories visible to your authenticated user account.

Notes

This example combines the list-repositories and list-languages tools to filter by stack. Useful for auditing codebases or finding migration candidates. Requires read access to all repositories you want to scan; private repos outside your scope won't appear. Large instances may hit pagination limits—results reflect the first page of matches.

Prompt

@sourcegraph compare commits abc123 and def456 in the api-gateway repo and summarize what changed in the authentication layer

Output

Comparing commits abc123 and def456 in `api-gateway` shows 8 files changed. In the authentication layer: `src/auth/jwt.ts` added token expiry validation (lines 45-62), `src/auth/middleware.ts` refactored error handling to return 401 instead of 500 for invalid tokens, and `tests/auth.test.ts` added three new test cases for edge conditions. The diff indicates a security hardening effort focused on token lifecycle management. No breaking changes to the public API surface.

Notes

This example uses the compare-commits tool to inspect code evolution, then layers AI reasoning to summarize intent. Requires knowing exact commit SHAs beforehand—use get-commit-details first if you only have branch names. Diffs for large commits may be truncated; the MCP returns raw diff text that the AI interprets.

Prompt

@sourcegraph fetch the contents of src/config/database.ts from the api-gateway repo and check if connection pooling is enabled

Output

Retrieved `src/config/database.ts` from the default branch of `api-gateway`. The file exports a `createPool` function that initializes a connection pool with `max: 20` and `idleTimeoutMillis: 30000`. Connection pooling is enabled. The configuration uses the `pg` library and reads pool size from the `DB_POOL_SIZE` environment variable, falling back to 20. No SSL enforcement is visible in this file—check `src/config/ssl.ts` if that's a concern.

Notes

This example demonstrates file-content retrieval paired with AI analysis—useful for quick config audits without cloning repos. The MCP fetches from the default branch only; specify a different branch in the prompt if needed. Large files may be truncated. Requires read access to the repository.

Use-case deep-dives

Cross-repo dependency audit at scale

When Sourcegraph beats grep for multi-repo teams

A 12-person engineering team maintaining six microservices needs to audit which repos still import a deprecated auth library before the Q2 migration deadline. The Sourcegraph MCP wins here because List Repositories plus Get File Contents lets you scan package.json or requirements.txt files across all repos in under two minutes without cloning anything locally. Compare this to GitHub's MCP, which requires separate API calls per repo and hits rate limits around repo 40. The threshold: if you're only checking 2-3 repos, just open them in your editor. But once you're auditing 5+ repos or searching for patterns across a codebase you don't own, Sourcegraph's indexed search makes this a 90-second Switchy prompt instead of a 20-minute manual slog.

Onboarding code walkthrough for new hires

Sourcegraph as the new-hire documentation layer

A startup's third backend engineer joins and needs to understand how the payment flow works across the monorepo's 18 modules. The Sourcegraph MCP is the right call when your team doesn't maintain architecture docs and the code is the source of truth. Use List Repository Files to map the directory structure, then Get File Contents to pull specific handlers or config files into the conversation. The AI can trace the flow without the new hire needing repo access or IDE setup on day one. This breaks down if your codebase is under 5k lines—just read it directly—or if it's over 500k lines and poorly organized, where even indexed search returns too many false positives. Sweet spot: 20k-200k line repos where the structure is discoverable but not trivial.

Post-incident commit investigation

When Compare Commits clarifies the production break

A 6-person SRE team is debugging why the API started timing out after last night's deploy. The Sourcegraph MCP's Compare Commits tool is faster than GitHub's web UI when you need to see diffs for 40+ changed files in a single conversation context. Pull the commit range, feed the diffs to the AI, and ask 'which of these changes could cause a 3-second delay in the /orders endpoint'. This works because Sourcegraph returns structured diffs the AI can parse, not just links. The trade-off: if the incident spans multiple repos or you need to correlate with logs, you'll still need your observability stack. Use this when the smoking gun is in the code and you need to triage it in Slack during the incident call, not after.

Frequently asked

What does the Sourcegraph MCP do in Switchy?

It lets AI agents read code from your Sourcegraph instance without cloning repos. Agents can fetch file contents, compare commits, list repositories, and check what languages a codebase uses. Useful when you want Claude to answer questions about your company's code or generate patches based on existing implementations.

Do I need admin access to connect Sourcegraph MCP?

You need a Sourcegraph API key with read access to the repositories you want agents to query. Admin permissions are only required if you plan to use the site settings edit check tool. Most teams connect with a service account that has repo read scope across the codebases they want AI to reference.

Can the Sourcegraph MCP write code or create pull requests?

No. It's read-only. Agents can fetch file contents, compare commits, and list repository metadata, but they can't push changes or open PRs. If you need to apply AI-generated patches, you'll copy the output and commit it yourself through Git or your code host's interface.

Why use this instead of just pasting code into Claude?

Pasting works for small snippets, but breaks down when you need context from multiple files or want to reference the latest version of a function. The MCP pulls fresh code on demand, so agents always see current implementations. It's faster than cloning repos locally and safer than giving AI direct Git write access.

Who on the team should connect the Sourcegraph integration?

Whoever manages your Sourcegraph instance or has permission to generate API keys. Once connected in Switchy, any team member in that workspace can invoke the MCP's tools in their chats. The API key's repository access determines what code agents can read, so scope it to match your team's needs.

Data last verified 607 hours ago.Sources aggregated hourly to weekly. See docs/architecture/model-directory.md.