-
Notifications
You must be signed in to change notification settings - Fork 106
Sourcebot MCP #292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Sourcebot MCP #292
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
67cab14
init
brendan-kellam 2492821
initial wip
brendan-kellam 2393c26
futher wip
brendan-kellam 6a87110
update makefile
brendan-kellam a5f01f3
add schema watch mode
brendan-kellam dc7565d
[test] mcp in web package test
brendan-kellam e4570cf
Revert "[test] mcp in web package test"
brendan-kellam 9bab511
upgrade zod
brendan-kellam 3875f8f
switch over to using stdio
brendan-kellam 5d1eb60
wip
brendan-kellam dac66ec
Move URL resolution code to server
brendan-kellam 267d0b9
wip
brendan-kellam 4cf93d7
wip
brendan-kellam 35626c3
feedback
brendan-kellam 04617bc
Add npm stuff
brendan-kellam 1f2f7d9
more tweaks to make it work as a installable package
brendan-kellam df8fbc9
update lockfile
brendan-kellam 5cc1bc6
first pass on docs for mcp server
brendan-kellam a1fbe3c
super basic readme
brendan-kellam 7a0a658
bump mcp version to 1.0.0
brendan-kellam 45c9967
updated docs
brendan-kellam cc85e82
feedback & changelog
brendan-kellam c56916b
Update mcp release date in changelog
brendan-kellam File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,181 @@ | ||
--- | ||
title: Sourcebot MCP server (@sourcebot/mcp) | ||
sidebarTitle: Sourcebot MCP server | ||
--- | ||
|
||
<Note> | ||
This feature is only available when [self-hosting](/self-hosting) with [authentication](/self-hosting/more/authentication) disabled. | ||
</Note> | ||
|
||
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. | ||
|
||
## Getting Started | ||
|
||
<Steps> | ||
<Step title="Launch Sourcebot"> | ||
Follow the self-hosting [quick start guide](/self-hosting/overview#quick-start-guide) to launch Sourcebot and get your code indexed. The host url of your instance (e.g., `http://localhost:3000`) is passed to the MCP server via the `SOURCEBOT_HOST` url. | ||
|
||
If a host is not provided, then the server will fallback to using the demo instance hosted at https://demo.sourcebot.dev. You can see the list of repositories indexed [here](https://demo.sourcebot.dev/~/repos). Add additional repositories by [opening a PR](https://github.com/sourcebot-dev/sourcebot/blob/main/demo-site-config.json). | ||
</Step> | ||
|
||
<Step title="Install the MCP server"> | ||
<Note> | ||
Ensure you have [Node.js](https://nodejs.org/en) >= v18.0.0 installed. | ||
</Note> | ||
Next, we can install the [@sourcebot/mcp](https://www.npmjs.com/package/@sourcebot/mcp) MCP server into any supported MCP client: | ||
|
||
<AccordionGroup> | ||
<Accordion title="Cursor"> | ||
[Cursor MCP docs](https://docs.cursor.com/context/model-context-protocol) | ||
|
||
Go to: `Settings` -> `Cursor Settings` -> `MCP` -> `Add new global MCP server` | ||
|
||
Paste the following into your `~/.cursor/mcp.json` file. This will install Sourcebot globally within Cursor: | ||
|
||
```json | ||
{ | ||
"mcpServers": { | ||
"sourcebot": { | ||
"command": "npx", | ||
"args": ["-y", "@sourcebot/mcp@latest" ], | ||
"env": { | ||
"SOURCEBOT_HOST": "http://localhost:3000" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted. | ||
</Accordion> | ||
<Accordion title="Windsurf"> | ||
[Windsurf MCP docs](https://docs.windsurf.com/windsurf/mcp) | ||
|
||
Go to: `Windsurf Settings` -> `Cascade` -> `Add Server` -> `Add Custom Server` | ||
|
||
Paste the following into your `mcp_config.json` file: | ||
|
||
```json | ||
{ | ||
"mcpServers": { | ||
"sourcebot": { | ||
"command": "npx", | ||
"args": ["-y", "@sourcebot/mcp@latest" ], | ||
"env": { | ||
"SOURCEBOT_HOST": "http://localhost:3000" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted. | ||
|
||
</Accordion> | ||
<Accordion title="VS Code"> | ||
[VS Code MCP docs](https://code.visualstudio.com/docs/copilot/chat/mcp-servers) | ||
|
||
Add the following to your [settings.json](https://code.visualstudio.com/docs/copilot/chat/mcp-servers): | ||
|
||
```json | ||
{ | ||
"mcp": { | ||
"servers": { | ||
"sourcebot": { | ||
"type": "stdio", | ||
"command": "npx", | ||
"args": ["-y", "@sourcebot/mcp@latest"] | ||
}, | ||
"env": { | ||
"SOURCEBOT_HOST": "http://localhost:3000" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted. | ||
</Accordion> | ||
<Accordion title="Claude Code"> | ||
[Claude Code MCP docs](https://docs.anthropic.com/en/docs/claude-code/tutorials#set-up-model-context-protocol-mcp) | ||
|
||
Run the following command: | ||
|
||
```sh | ||
claude mcp add sourcebot -e SOURCEBOT_HOST=http://localhost:3000 -- npx -y @sourcebot/mcp@latest | ||
``` | ||
|
||
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted. | ||
</Accordion> | ||
<Accordion title="Claude Desktop"> | ||
[Claude Desktop MCP docs](https://modelcontextprotocol.io/quickstart/user) | ||
|
||
Add the following to your `claude_desktop_config.json`: | ||
|
||
```json | ||
{ | ||
"mcpServers": { | ||
"sourcebot": { | ||
"command": "npx", | ||
"args": ["-y", "@sourcebot/mcp@latest"], | ||
"env": { | ||
"SOURCEBOT_HOST": "http://localhost:3000" | ||
} | ||
} | ||
} | ||
} | ||
``` | ||
|
||
Replace `http://localhost:3000` with wherever your Sourcebot instance is hosted. | ||
</Accordion> | ||
</AccordionGroup> | ||
</Step> | ||
|
||
<Step title="Prompt the LLM"> | ||
Tell your LLM to `use sourcebot` when prompting. | ||
</Step> | ||
|
||
</Steps> | ||
|
||
|
||
## Available Tools | ||
|
||
|
||
### `search_code` | ||
|
||
Fetches code that matches the provided regex pattern in `query`. | ||
|
||
Parameters: | ||
| Name | Required | Description | | ||
|:----------------------|:---------|:----------------------------------------------------------------------------------------------------------------------------------| | ||
| `query` | yes | Regex pattern to search for. Escape special characters and spaces with a single backslash (e.g., 'console\.log', 'console\ log'). | | ||
| `filterByRepoIds` | no | Restrict search to specific repository IDs (from 'list_repos'). Leave empty to search all. | | ||
| `filterByLanguages` | no | Restrict search to specific languages (GitHub linguist format, e.g., Python, JavaScript). | | ||
| `caseSensitive` | no | Case sensitive search (default: false). | | ||
| `includeCodeSnippets` | no | Include code snippets in results (default: false). | | ||
| `maxTokens` | no | Max tokens to return (default: env.DEFAULT_MINIMUM_TOKENS). | | ||
|
||
|
||
### `list_repos` | ||
|
||
Lists all repositories indexed by Sourcebot. | ||
|
||
### `get_file_source` | ||
|
||
Fetches the source code for a given file. | ||
|
||
Parameters: | ||
| Name | Required | Description | | ||
|:-------------|:---------|:-----------------------------------------------------------------| | ||
| `fileName` | yes | The file to fetch the source code for. | | ||
| `repoId` | yes | The Sourcebot repository ID. | | ||
|
||
|
||
## Environment Variables | ||
|
||
| Name | Default | Description | | ||
|:-------------------------|:-----------------------|:--------------------------------------------------| | ||
| `SOURCEBOT_HOST` | http://localhost:3000 | URL of your Sourcebot instance. | | ||
| `DEFAULT_MINIMUM_TOKENS` | 10000 | Minimum number of tokens to return in responses. | | ||
| `DEFAULT_MATCHES` | 10000 | Number of code matches to fetch per search. | | ||
| `DEFAULT_CONTEXT_LINES` | 5 | Lines of context to include above/below matches. | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
dist/ | ||
node_modules/ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
**/* | ||
!/dist/** | ||
!README.md | ||
!package.json | ||
!CHANGELOG.md |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Changelog | ||
|
||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
## [Unreleased] | ||
|
||
## [1.0.0] - 2025-05-07 | ||
|
||
### Added | ||
- Initial release |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fix VS Code configuration format - misplaced
env
property.The
env
object should be nested under thesourcebot
object, not alongside it within theservers
object. This matches the format used in other client configurations and follows VS Code's MCP configuration structure.📝 Committable suggestion