This is an MCP (Model Context Protocol) server implementation for Sourcegraph's code search capabilities. It allows language models to perform code search queries against Sourcegraph instances.
- Search code across any Sourcegraph instance (public or private)
- Support for literal, regexp, and structural search patterns
- Configurable search limits and parameters
- Authentication support for private Sourcegraph instances
# Clone the repository
git clone https://github.com/yourusername/code-search-mcp.git
cd code-search-mcp
# Install dependencies
npm install
# Build the project
npm run build# Start the server
npm startOr directly use the node executable:
node build/index.jsThis MCP server exposes a search_code tool with the following parameters:
query(string, required): The search query to executesourcegraphUrl(string, optional): The Sourcegraph instance URL (defaults tohttps://sourcegraph.com)token(string, optional): Authentication token for private Sourcegraph instanceslimit(number, optional): Max number of results to return (defaults to 10)patternType(string, optional): Search pattern type (literal,regexp, orstructural, defaults toliteral)
In Claude, you can use this MCP server by first adding it to your configuration:
# Add the MCP server (stdio transport)
claude mcp add sourcegraph-search -- path/to/code-search-mcp
# Or if you've installed it globally with npm
claude mcp add sourcegraph-search -- code-search-mcpThen you can use Claude Code as normal and it will have access to the Sourcegraph search functionality:
claude codeThen you can ask Claude to use the code search tool:
Search for "context.WithTimeout" in the Go standard library
# Run the development server (builds and starts)
npm run devISC