Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
162 changes: 88 additions & 74 deletions docs/api/mcp/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,16 @@ Authorization: token YOUR_ACCESS_TOKEN

The Sourcegraph MCP server can be integrated with various AI tools and IDEs that support the Model Context Protocol.

### Supported Clients

- [Amp](#amp)
- [Claude Code](#claude-code)
- [Google Gemini Code Assist](#google-gemini-code-assist)
- [VS Code](#vs-code)
- [Cursor](#cursor)
- [Antigravity](#antigravity)
- [OpenCode](#opencode)

### Amp

<Callout type="info">
Expand Down Expand Up @@ -209,24 +219,25 @@ You can add the Sourcegraph MCP server to Google Gemini Code Assist by configuri
3. Save the configuration file.
4. Restart Gemini Code Assist to apply the new configuration.

### Cursor
### VS Code

You can add the Sourcegraph MCP server to Cursor by configuring it in your MCP settings file:
You can add the Sourcegraph MCP server to VS Code by configuring it in your MCP settings file:

1. Open or create the MCP configuration file at `~/.cursor/mcp.json` (or the equivalent path on your system).
1. Create `.vscode/mcp.json` in your project.
2. Add the following configuration:

```json
{
"mcpServers": {
"servers": {
"sourcegraph": {
"type": "http",
"url": "https://your-sourcegraph-instance.com/.api/mcp/v1",
"type": "http",
"headers": {
"Authorization": "token YOUR_ACCESS_TOKEN"
}
}
}
},
"inputs": []
}
```

Expand All @@ -236,25 +247,24 @@ You can add the Sourcegraph MCP server to Cursor by configuring it in your MCP s
</Callout>

3. Save the configuration file.
4. Restart Cursor to apply the new configuration.
4. Restart VS Code to apply the new configuration.

#### VS Code
#### Cursor

1. Create ⁠`.vscode/mcp.json` in your project.
1. Open or create the MCP configuration file at `~/.cursor/mcp.json` (or the equivalent path on your system).
2. Add the following:

```json
{
"servers": {
"mcpServers": {
"sourcegraph": {
"url": "https://your-sourcegraph-instance.com/.api/mcp/v1",
"type": "http",
"url": "https://your-sourcegraph-instance.com/.api/mcp/v1",
"headers": {
"Authorization": "token YOUR_ACCESS_TOKEN"
}
}
},
"inputs": []
}
}
```

Expand All @@ -263,6 +273,9 @@ You can add the Sourcegraph MCP server to Cursor by configuring it in your MCP s
URL and `YOUR_ACCESS_TOKEN` with your access token.
</Callout>

3. Save the configuration file.
4. Restart Cursor to apply the new configuration.

#### Antigravity

1. Create ⁠`.vscode/mcp.json` (Antigravity uses `.vscode` for configs) in your project.
Expand All @@ -288,27 +301,27 @@ You can add the Sourcegraph MCP server to Cursor by configuring it in your MCP s
URL and `YOUR_ACCESS_TOKEN` with your access token.
</Callout>

#### OpenCode
### OpenCode

You can add the Sourcegraph MCP server to OpenCode by configuring it in your MCP settings file:

1. Open or create the MCP configuration file at `~/.config/opencode/opencode.jsonc` (or the equivalent path on your system).
2. Add the following configuration:

```json
{
"mcp": {
"sourcegraph": {
"type": "remote",
"url": "https://your-sourcegraph-instance.com/.api/mcp/v1",
"oauth": false,
"headers": {
"Authorization": "token {env:YOUR_ACCESS_TOKEN}"
}
}
},
"$schema": "https://opencode.ai/config.json"
}
{
"mcp": {
"sourcegraph": {
"type": "remote",
"url": "https://your-sourcegraph-instance.com/.api/mcp/v1",
"oauth": false,
"headers": {
"Authorization": "token {env:YOUR_ACCESS_TOKEN}"
}
}
},
"$schema": "https://opencode.ai/config.json"
}
```

<Callout type="info">
Expand All @@ -318,6 +331,7 @@ You can add the Sourcegraph MCP server to OpenCode by configuring it in your MCP

3. Save the configuration file.
4. Restart OpenCode to apply the changes.

## Available Tools

<Callout type="info">
Expand All @@ -338,11 +352,11 @@ Read file contents with line numbers and support for specific ranges and revisio

**Parameters:**

- `repo` - Repository name (required)
- `path` - File path within repository (required)
- `startLine` - Starting line number (optional)
- `endLine` - Ending line number (optional)
- `revision` - Branch, tag, or commit hash (optional)
- `repo` - Repository name (required)
- `path` - File path within repository (required)
- `startLine` - Starting line number (optional)
- `endLine` - Ending line number (optional)
- `revision` - Branch, tag, or commit hash (optional)

**Use cases:** Reading specific files, examining code sections, reviewing different versions

Expand All @@ -356,19 +370,19 @@ List files and directories in a repository path.

**Parameters:**

- `repo` - Repository name (required)
- `path` - Directory path (optional, defaults to root)
- `revision` - Branch, tag, or commit hash (optional)
- `repo` - Repository name (required)
- `path` - Directory path (optional, defaults to root)
- `revision` - Branch, tag, or commit hash (optional)

#### `sg_list_repos`

Search and list repositories by name patterns with pagination support.

**Parameters:**

- `query` - Search pattern for repository names (required)
- `limit` - Maximum results per page (optional, default 50)
- `after`/`before` - Pagination cursors (optional)
- `query` - Search pattern for repository names (required)
- `limit` - Maximum results per page (optional, default 50)
- `after`/`before` - Pagination cursors (optional)

### Code Search

Expand All @@ -378,13 +392,13 @@ Perform exact keyword searches with boolean operators and filters.

**Parameters:**

- `query` - Search query with optional filters (required)
- `query` - Search query with optional filters (required)

**Supported filters:**

- `repo:` - limit to specific repositories
- `file:` - search specific file patterns
- `rev:` - search specific revisions
- `repo:` - limit to specific repositories
- `file:` - search specific file patterns
- `rev:` - search specific revisions

**Features:** Boolean AND/OR operators, regex patterns

Expand All @@ -394,13 +408,13 @@ Semantic search with flexible linguistic matching.

**Parameters:**

- `query` - Natural language search query (required)
- `query` - Natural language search query (required)

**Supported filters:**

- `repo:` - limit to specific repositories
- `file:` - search specific file patterns
- `rev:` - search specific revisions
- `repo:` - limit to specific repositories
- `file:` - search specific file patterns
- `rev:` - search specific revisions

**Features:** Flexible linguistic matching, stemming, broader results than keyword search

Expand All @@ -412,10 +426,10 @@ Find the definition of a symbol from a usage location.

**Parameters:**

- `repo` - Repository name (required)
- `path` - File path containing symbol usage (required)
- `symbol` - Symbol name to find definition for (required)
- `revision` - Branch, tag, or commit hash (optional)
- `repo` - Repository name (required)
- `path` - File path containing symbol usage (required)
- `symbol` - Symbol name to find definition for (required)
- `revision` - Branch, tag, or commit hash (optional)

**Features:** Cross-repository support, compiler-level accuracy

Expand All @@ -425,10 +439,10 @@ Find all references to a symbol from its definition location.

**Parameters:**

- `repo` - Repository name (required)
- `path` - File path containing symbol definition (required)
- `symbol` - Symbol name to find references for (required)
- `revision` - Branch, tag, or commit hash (optional)
- `repo` - Repository name (required)
- `path` - File path containing symbol definition (required)
- `symbol` - Symbol name to find references for (required)
- `revision` - Branch, tag, or commit hash (optional)

### Version Control & History

Expand All @@ -438,47 +452,47 @@ Search commits by message, author, content, files, and date ranges.

**Parameters:**

- `repos` - Array of repository names (required)
- `messageTerms` - Terms to search in commit messages (optional)
- `authors` - Filter by commit authors (optional)
- `contentTerms` - Search in actual code changes (optional)
- `files` - Filter by file paths (optional)
- `after`/`before` - Date range filters (optional)
- `repos` - Array of repository names (required)
- `messageTerms` - Terms to search in commit messages (optional)
- `authors` - Filter by commit authors (optional)
- `contentTerms` - Search in actual code changes (optional)
- `files` - Filter by file paths (optional)
- `after`/`before` - Date range filters (optional)

#### `sg_diff_search`

Search actual code changes for specific patterns across repositories.

**Parameters:**

- `pattern` - Search pattern for code changes (required)
- `repos` - Array of repository names (required)
- `added` - Search only added code (optional)
- `removed` - Search only removed code (optional)
- `author` - Filter by author (optional)
- `after`/`before` - Date range filters (optional)
- `pattern` - Search pattern for code changes (required)
- `repos` - Array of repository names (required)
- `added` - Search only added code (optional)
- `removed` - Search only removed code (optional)
- `author` - Filter by author (optional)
- `after`/`before` - Date range filters (optional)

#### `sg_compare_revisions`

Compare changes between two specific revisions.

**Parameters:**

- `repo` - Repository name (required)
- `base` - Base revision (older version) (required)
- `head` - Head revision (newer version) (required)
- `first` - Maximum file diffs to return (optional, default 50)
- `after` - Pagination cursor (optional)
- `repo` - Repository name (required)
- `base` - Base revision (older version) (required)
- `head` - Head revision (newer version) (required)
- `first` - Maximum file diffs to return (optional, default 50)
- `after` - Pagination cursor (optional)

#### `sg_get_contributor_repos`

Find repositories where a contributor has made commits.

**Parameters:**

- `author` - Author name or email (required)
- `limit` - Maximum repositories to return (optional, default 20)
- `minCommits` - Minimum commits required (optional, default 1)
- `author` - Author name or email (required)
- `limit` - Maximum repositories to return (optional, default 20)
- `minCommits` - Minimum commits required (optional, default 1)

## Usage Examples

Expand Down
2 changes: 1 addition & 1 deletion src/middleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -146,5 +146,5 @@ export function middleware(request: NextRequest) {
}

export const config = {
matcher: ['/((?!api|_next/static|_next/image|assets|favicon.ico|sw.js).*)']
matcher: ['/((?!api/md|_next/static|_next/image|assets|favicon.ico|sw.js).*)']
};