This feature is only available when self-hosting with authentication disabled.

The Model Context Protocol (MCP) is a open standard for providing context to LLMs. The @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

1

Launch Sourcebot

Follow the self-hosting 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. Add additional repositories by opening a PR.

2

Install the MCP server

Ensure you have Node.js >= v18.0.0 installed.

Next, we can install the @sourcebot/mcp MCP server into any supported MCP client:

3

Prompt the LLM

Tell your LLM to use sourcebot when prompting.

Available Tools

search_code

Fetches code that matches the provided regex pattern in query.

Parameters:

NameRequiredDescription
queryyesRegex pattern to search for. Escape special characters and spaces with a single backslash (e.g., ‘console.log’, ‘console\ log’).
filterByRepoIdsnoRestrict search to specific repository IDs (from ‘list_repos’). Leave empty to search all.
filterByLanguagesnoRestrict search to specific languages (GitHub linguist format, e.g., Python, JavaScript).
caseSensitivenoCase sensitive search (default: false).
includeCodeSnippetsnoInclude code snippets in results (default: false).
maxTokensnoMax 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:

NameRequiredDescription
fileNameyesThe file to fetch the source code for.
repoIdyesThe Sourcebot repository ID.

Environment Variables

NameDefaultDescription
SOURCEBOT_HOSThttp://localhost:3000URL of your Sourcebot instance.
DEFAULT_MINIMUM_TOKENS10000Minimum number of tokens to return in responses.
DEFAULT_MATCHES10000Number of code matches to fetch per search.
DEFAULT_CONTEXT_LINES5Lines of context to include above/below matches.