Skip to content

Commit 68a3148

Browse files
first pass on docs for mcp server
1 parent b40bcdc commit 68a3148

File tree

4 files changed

+181
-8
lines changed

4 files changed

+181
-8
lines changed

docs/docs.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@
4848
"pages": [
4949
"docs/more/syntax-reference",
5050
"docs/more/multi-branch-indexing",
51-
"docs/more/roles-and-permissions"
51+
"docs/more/roles-and-permissions",
52+
"docs/more/mcp-server",
53+
"docs/more/search-contexts"
5254
]
5355
}
5456
]
@@ -71,8 +73,7 @@
7173
"self-hosting/more/authentication",
7274
"self-hosting/more/tenancy",
7375
"self-hosting/more/transactional-emails",
74-
"self-hosting/more/declarative-config",
75-
"self-hosting/more/search-contexts"
76+
"self-hosting/more/declarative-config"
7677
]
7778
},
7879
{

docs/docs/more/mcp-server.mdx

Lines changed: 172 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,172 @@
1+
---
2+
title: Sourcebot MCP server (@sourcebot/mcp)
3+
sidebarTitle: Sourcebot MCP server
4+
---
5+
6+
<Note>
7+
This feature is only available when [self-hosting](/self-hosting) with [authentication](/self-hosting/more/authentication) disabled.
8+
</Note>
9+
10+
The [Model Context Protocol](https://modelcontextprotocol.io/introduction) (MCP) is a open standard for providing context to LLMs. The [@sourcebot/mcp](https://www.npmjs.com/package/@sourcebot/mcp) package is a MCP server that enables LLMs to interface with your Sourcebot instance, enabling MCP clients like Cursor, Vscode, and others to have context over your entire codebase.
11+
12+
## Getting Started
13+
14+
<Steps>
15+
<Step title="Launch Sourcebot">
16+
Follow the self-hosting [quick start guide](/self-hosting/overview#quick-start-guide) to launch Sourcebot and get your code indexed.
17+
</Step>
18+
19+
<Step title="Install the MCP server">
20+
<Note>
21+
Ensure you have [Node.js](https://nodejs.org/en) >= v18.0.0 installed.
22+
</Note>
23+
Next, we can install the [@sourcebot/mcp](https://www.npmjs.com/package/@sourcebot/mcp) MCP server into any supported MCP client:
24+
25+
<AccordionGroup>
26+
<Accordion title="Cursor">
27+
[Cursor MCP docs](https://docs.cursor.com/context/model-context-protocol)
28+
29+
Go to: `Settings` -> `Cursor Settings` -> `MCP` -> `Add new global MCP server`
30+
31+
Paste the following into your `~/.cursor/mcp.json` file. This will install Sourcebot globally within Cursor:
32+
33+
```json
34+
{
35+
"mcpServers": {
36+
"sourcebot": {
37+
"command": "npx",
38+
"args": ["-y", "@sourcebot/mcp@latest" ],
39+
"env": {
40+
"SOURCEBOT_HOST": "http://localhost:3000"
41+
}
42+
}
43+
}
44+
}
45+
```
46+
47+
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted.
48+
</Accordion>
49+
<Accordion title="Windsurf">
50+
[Windsurf MCP docs](https://docs.windsurf.com/windsurf/mcp)
51+
52+
Go to: `Windsurf Settings` -> `Cascade` -> `Add Server` -> `Add Custom Server`
53+
54+
Paste the following into your `mcp_config.json` file:
55+
56+
```json
57+
{
58+
"mcpServers": {
59+
"sourcebot": {
60+
"command": "npx",
61+
"args": ["-y", "@sourcebot/mcp@latest" ],
62+
"env": {
63+
"SOURCEBOT_HOST": "http://localhost:3000"
64+
}
65+
}
66+
}
67+
}
68+
```
69+
70+
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted.
71+
72+
</Accordion>
73+
<Accordion title="VS Code">
74+
[VS Code MCP docs](https://code.visualstudio.com/docs/copilot/chat/mcp-servers)
75+
76+
Add the following to your [settings.json](https://code.visualstudio.com/docs/copilot/chat/mcp-servers):
77+
78+
```json
79+
{
80+
"mcp": {
81+
"servers": {
82+
"sourcebot": {
83+
"type": "stdio",
84+
"command": "npx",
85+
"args": ["-y", "@sourcebot/mcp@latest"]
86+
}
87+
}
88+
}
89+
}
90+
```
91+
92+
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted.
93+
</Accordion>
94+
<Accordion title="Claude Code">
95+
[Claude Code MCP docs](https://docs.anthropic.com/en/docs/claude-code/tutorials#set-up-model-context-protocol-mcp)
96+
97+
Run the following command:
98+
99+
```sh
100+
claude mcp add sourcebot -e http://localhost:3000 -- npx -y @sourcebot/mcp@latest
101+
```
102+
103+
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted.
104+
</Accordion>
105+
<Accordion title="Claude Desktop">
106+
[Claude Desktop MCP docs](https://modelcontextprotocol.io/quickstart/user)
107+
108+
Add the following to your `claude_desktop_config.json`:
109+
110+
```json
111+
{
112+
"mcpServers": {
113+
"sourcebot": {
114+
"command": "npx",
115+
"args": ["-y", "@sourcebot/mcp@latest"],
116+
"env": {
117+
"SOURCEBOT_HOST": "http://localhost:3000"
118+
}
119+
}
120+
}
121+
}
122+
```
123+
124+
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted.
125+
</Accordion>
126+
</AccordionGroup>
127+
</Step>
128+
129+
</Steps>
130+
131+
132+
## Available Tools
133+
134+
135+
### `search_code`
136+
137+
Fetches code that matches the provided regex pattern in `query`.
138+
139+
Parameters:
140+
| Name | Required | Description |
141+
|:----------------------|:---------|:----------------------------------------------------------------------------------------------------------------------------------|
142+
| `query` | yes | Regex pattern to search for. Escape special characters and spaces with a single backslash (e.g., 'console\.log', 'console\ log'). |
143+
| `filterByRepoIds` | no | Restrict search to specific repository IDs (from 'list_repos'). Leave empty to search all. |
144+
| `filterByLanguages` | no | Restrict search to specific languages (GitHub linguist format, e.g., Python, JavaScript). |
145+
| `caseSensitive` | no | Case sensitive search (default: false). |
146+
| `includeCodeSnippets` | no | Include code snippets in results (default: false). |
147+
| `maxTokens` | no | Max tokens to return (default: env.DEFAULT_MINIMUM_TOKENS). |
148+
149+
150+
### `list_repos`
151+
152+
Lists all repositories indexed by Sourcebot.
153+
154+
### `get_file_source`
155+
156+
Fetches the source code for a given file.
157+
158+
Parameters:
159+
| Name | Required | Description |
160+
|:-------------|:---------|:-----------------------------------------------------------------|
161+
| `fileName` | yes | The file to fetch the source code for. |
162+
| `repoId` | yes | The Sourcebot repository ID. |
163+
164+
165+
## Environment Variables
166+
167+
| Name | Default | Description |
168+
|:-------------------------|:-----------------------|:--------------------------------------------------|
169+
| `SOURCEBOT_HOST` | http://localhost:3000 | URL of your Sourcebot instance. |
170+
| `DEFAULT_MINIMUM_TOKENS` | 10000 | Minimum number of tokens to return in responses. |
171+
| `DEFAULT_MATCHES` | 10000 | Number of code matches to fetch per search. |
172+
| `DEFAULT_CONTEXT_LINES` | 5 | Lines of context to include above/below matches. |

docs/self-hosting/more/search-contexts.mdx renamed to docs/docs/more/search-contexts.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebarTitle: Search contexts (EE)
66
import SearchContextSchema from '/snippets/schemas/v3/searchContext.schema.mdx'
77

88
<Note>
9-
This is only available in the Enterprise Edition. Please add your [license key](/self-hosting/license-key) to activate it.
9+
This feature is only available when [self-hosting](/self-hosting) with an active Enterprise license. Please add your [license key](/self-hosting/license-key) to activate it.
1010
</Note>
1111

1212
A **search context** is a user-defined grouping of repositories that helps focus searches on specific areas of your codebase, like frontend, backend, or infrastructure code. Some example queries using search contexts:

packages/mcp/src/index.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,12 +181,12 @@ server.tool(
181181
"Fetches the source code for a given file.",
182182
{
183183
fileName: z.string().describe("The file to fetch the source code for."),
184-
repository: z.string().describe("The repository to fetch the source code for. This is the Sourcebot compatible repository ID."),
184+
repoId: z.string().describe("The repository to fetch the source code for. This is the Sourcebot compatible repository ID."),
185185
},
186-
async ({ fileName, repository }) => {
186+
async ({ fileName, repoId }) => {
187187
const response = await getFileSource({
188188
fileName,
189-
repository,
189+
repository: repoId,
190190
});
191191

192192
if (isServiceError(response)) {
@@ -200,7 +200,7 @@ server.tool(
200200

201201
const content: TextContent[] = [{
202202
type: "text",
203-
text: `file: ${fileName}\nrepository: ${repository}\nlanguage: ${response.language}\nsource:\n${base64Decode(response.source)}`,
203+
text: `file: ${fileName}\nrepository: ${repoId}\nlanguage: ${response.language}\nsource:\n${base64Decode(response.source)}`,
204204
}]
205205

206206
return {

0 commit comments

Comments
 (0)