Model Context Protocol server for SourceGraph code search
Project description
sourcegraph-mcp
Model Context Protocol server for searching code via SourceGraph's GraphQL API. Works with both local and cloud SourceGraph instances.
Why Use This?
Search your entire codebase instantly without loading files into context:
- Fast: Search 500k+ lines in <1 second
- Cost-effective: ~400 tokens per search vs 50k+ tokens loading files
- Accurate: Find exact symbols, methods, and patterns across all repos
Installation
Quick Start (with pipx)
pipx install sourcegraph-mcp
From Source
git clone https://github.com/dalebrubaker/sourcegraph-mcp
cd sourcegraph-mcp
pip install -e .
Configuration
Option 1: Environment Variables (Recommended)
export SOURCEGRAPH_URL=http://192.168.0.130:7080
export SOURCEGRAPH_TOKEN=sgp_local_your_token_here
Option 2: Config File
Create config.json:
{
"sourcegraph_url": "http://192.168.0.130:7080",
"access_token": "sgp_local_your_token_here",
"timeout": 30
}
Option 3: CLI Arguments
sourcegraph-mcp --url http://192.168.0.130:7080 --token sgp_local_...
Setup with MCP Clients
Claude Desktop
Edit ~/Library/Application Support/Claude/claude_desktop_config.json:
{
"mcpServers": {
"sourcegraph": {
"command": "sourcegraph-mcp",
"env": {
"SOURCEGRAPH_URL": "http://192.168.0.130:7080",
"SOURCEGRAPH_TOKEN": "sgp_local_your_token_here"
}
}
}
}
Claude Code
For user-wide access:
claude mcp add sourcegraph -- sourcegraph-mcp --url http://192.168.0.130:7080 --token sgp_local_...
For project-specific access, create .mcp.json in your project root:
{
"mcpServers": {
"sourcegraph": {
"command": "sourcegraph-mcp",
"env": {
"SOURCEGRAPH_URL": "http://192.168.0.130:7080",
"SOURCEGRAPH_TOKEN": "sgp_local_your_token_here"
}
}
}
}
Usage
Once configured, your AI assistant can search your codebase:
"Find the LowerBound method"
"Search for authentication code"
"Show me all uses of the OrderService class"
The MCP server provides three tools:
search_sourcegraph- Search with standard SourceGraph query syntaxsearch_sourcegraph_regex- Search using regex patternsget_sourcegraph_config- View current configuration
Getting a SourceGraph Token
- Navigate to your SourceGraph instance
- Go to Settings → Access tokens
- Click "Generate new token"
- Copy the token (starts with
sgp_)
Local Development
# Clone and install
git clone https://github.com/dalebrubaker/sourcegraph-mcp
cd sourcegraph-mcp
python3 -m venv .venv
source .venv/bin/activate
pip install -e .
# Run with config file
python server.py
# Run with CLI args
python server.py --url http://localhost:3370 --token sgp_local_...
Troubleshooting
"Could not connect to MCP server"
- Verify SourceGraph is running and accessible
- Check URL format (include http:// or https://)
- Test token:
curl -H "Authorization: token sgp_..." http://your-url/.api/graphql
"spawn python ENOENT"
- Use full path to Python:
/path/to/.venv/bin/pythoninstead of justpython - Or use
python3instead ofpython
License
MIT
Contributing
PRs welcome! Please open an issue first to discuss significant changes.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sourcegraph_mcp-1.0.0.tar.gz.
File metadata
- Download URL: sourcegraph_mcp-1.0.0.tar.gz
- Upload date:
- Size: 7.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e7ae804762b1a0660f97cbca7ba72a37643638de251fca47ad06236b502c5bf0
|
|
| MD5 |
5b4cdcc210b5a4d53e6426b83e5dfbf3
|
|
| BLAKE2b-256 |
3c960022907e325643d0e9652e5b16e61427e7048208a75de3060c262f7b1de3
|
File details
Details for the file sourcegraph_mcp-1.0.0-py3-none-any.whl.
File metadata
- Download URL: sourcegraph_mcp-1.0.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8250ef715ecf80c38a698078ebd5859c5864052fa41ffec367a7e74f8adf4788
|
|
| MD5 |
1957bbe98ef452faa96d2c7eb351abad
|
|
| BLAKE2b-256 |
0e216bd70c15d178ea6fd4bdd6ef354c6b0d79beaaa5aed9d72d8164093f8ea9
|