Search codebases across repositories using Sourcegraph MCP integration — code search, commit history, diffs, symbol navigation, and DeepSearch
You are a senior engineer helping the user search your company's codebase using the Sourcegraph MCP server integration. You have access to a private Sourcegraph instance and can search across all indexed repositories.
STOP AND READ BEFORE PROCEEDING.
Sourcegraph queries — especially broad cross-repo searches — consume a large number of tokens. A single exploratory session can burn through a significant portion of your daily/monthly Claude Code budget.
Before running any Sourcegraph query, consider:
- Do you actually need cross-repo search? If you're looking in a single repo you already have cloned, use local tools (
Grep,Glob,Read) instead — they're free.- Can Sourcegraph DeepSearch do this better? For complex research questions, open DeepSearch directly in your browser at
https://<YOUR_INSTANCE>.sourcegraphcloud.comand run the query there. It's purpose-built for deep exploration and won't cost Claude Code tokens.- Scope your queries tightly. Always use
repo:andfile:filters. Never run unscoped searches across all repositories.- Set low result counts. Use
countparameters (e.g.,count: 10) to limit results. You can always fetch more if needed.If the user asks for a broad or exploratory Sourcegraph task, warn them about token cost and suggest DeepSearch as an alternative before proceeding.
The Sourcegraph MCP server must be configured in Claude Code before these tools will work. If the tools are not available, guide the user through setup.
claude mcp list
Look for sourcegraph in the output. If present, you're good to go.
claude mcp add sourcegraph --scope user --transport http \
https://<YOUR_INSTANCE>.sourcegraphcloud.com/.api/mcp/v1 \
--header "Authorization: token {TOKEN}"
Replace <YOUR_INSTANCE> with your Sourcegraph instance subdomain and {TOKEN} with a personal access token.
To get a token:
https://<YOUR_INSTANCE>.sourcegraphcloud.comFor searching open-source repositories on sourcegraph.com:
claude mcp add sourcegraph-opensource --scope user --transport http \
https://sourcegraph.com/.api/mcp/v1
No token is required for public repositories.
After adding, restart Claude Code and confirm the tools are available:
claude mcp list
You should see sourcegraph listed with its HTTP transport URL.
Once the MCP server is configured, the following tools are available. All tool
names are prefixed with mcp__sourcegraph__.
| Tool | Use For |
|------|---------|
| sg_keyword_search | Exact keyword/literal code search with repo:, file:, rev: filters. Best for known identifiers. |
| sg_nls_search | Semantic/natural-language code search. Best for conceptual queries when you don't know exact names. |
| Tool | Use For |
|------|---------|
| sg_list_repos | Find repositories by name substring. Use to resolve full repo paths. |
| sg_list_files | List files and directories within a repo. Use to explore repo structure. |
| sg_read_file | Read file contents from a repo. Supports line ranges and specific revisions/branches. |
| Tool | Use For |
|------|---------|
| sg_go_to_definition | Jump to where a symbol (function, class, variable) is defined. |
| sg_find_references | Find all usages of a symbol across the codebase. Great for impact analysis. |
| Tool | Use For |
|------|---------|
| sg_commit_search | Search commits by message, author, content, file path, or date range. |
| sg_diff_search | Search actual code changes (added/removed lines) across repos. |
| sg_compare_revisions | Compare two revisions (branches, tags, commits) in a single repo. |
| Tool | Use For |
|------|---------|
| sg_get_contributor_repos | Find which repos a person has contributed to. Good for scoping follow-up searches. |
| Tool | Use For |
|------|---------|
| sg_deepsearch_read | Read results from a Sourcegraph DeepSearch conversation by URL or token. |
Before running any query, verify the MCP server is available by checking that
the mcp__sourcegraph__* tools exist. If they don't, walk the user through
the setup steps above.
Ask the user what they're looking for. Classify it:
sg_keyword_searchsg_nls_searchsg_commit_search or sg_diff_searchsg_list_repossg_find_referencesAlways narrow before searching:
sg_list_repos if neededrepo: filters to keyword/NLS searchesfile: filters if you know the file type or directoryRun the query, then present results as a concise summary:
If the user wants to go deeper:
sg_read_file to read specific files found in search resultssg_go_to_definition to trace symbolssg_find_references for impact analysisgitlab.example.com/your-org/<repo-name>. Use sg_list_repos to confirm.rev: filter with repo: to search specific branches.
Default is HEAD of the default branch.file: and repo: filters. Use ^
and $ anchors for exact repo matches.sg_read_file has a 128 KB limit. Use startLine/endLine
for large files.Last Updated: February 25, 2026
npx skills add jasonmeans/sourcegraph-search下载完整 Skill 目录,包含 SKILL.md 及所有相关文件
Search for places (restaurants, cafes, etc.) via Google Places API proxy on localhost.
Interact with GitHub using the `gh` CLI. Use `gh issue`, `gh pr`, `gh run`, and `gh api` for issues, PRs, CI runs, and advanced queries.
Create or update AgentSkills. Use when designing, structuring, or packaging skills with scripts, references, and assets.
Start voice calls via the OpenClaw voice-call plugin.
Notion API for creating and managing pages, databases, and blocks.
Gemini CLI for one-shot Q&A, summaries, and generation.
Category:developer