You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: packages/web/src/features/mcp/server.ts
+43-24Lines changed: 43 additions & 24 deletions
Original file line number
Diff line number
Diff line change
@@ -30,6 +30,42 @@ const MAX_TREE_DEPTH = 10;
30
30
constDEFAULT_MAX_TREE_ENTRIES=1000;
31
31
constMAX_MAX_TREE_ENTRIES=10000;
32
32
33
+
constTOOL_DESCRIPTIONS={
34
+
search_code: dedent`
35
+
Searches for code that matches the provided search query as a substring by default, or as a regular expression if useRegex is true. Useful for exploring remote repositories by
36
+
searching for exact symbols, functions, variables, or specific code patterns.
37
+
38
+
To determine if a repository is indexed, use the \`list_repos\` tool. By default, searches are global and will search the default branch of all repositories. Searches can be
39
+
scoped to specific repositories, languages, and branches.
40
+
41
+
When referencing code outputted by this tool, always include the file's external URL as a link. This makes it easier for the user to view the file, even if they don't have it locally checked out.
42
+
`,
43
+
list_commits: dedent`Get a list of commits for a given repository.`,
44
+
list_repos: dedent`Lists repositories in the organization with optional filtering and pagination.`,
45
+
read_file: dedent`Reads the source code for a given file.`,
46
+
list_tree: dedent`
47
+
Lists files and directories from a repository path. This can be used as a repo tree tool or directory listing tool.
48
+
Returns a flat list of entries with path metadata and depth relative to the requested path.
49
+
`,
50
+
list_language_models: dedent`Lists the available language models configured on the Sourcebot instance. Use this to discover which models can be specified when calling ask_codebase.`,
51
+
ask_codebase: dedent`
52
+
DO NOT USE THIS TOOL UNLESS EXPLICITLY ASKED TO. THE PROMPT MUST SPECIFICALLY ASK TO USE THE ask_codebase TOOL.
53
+
54
+
Ask a natural language question about the codebase. This tool uses an AI agent to autonomously search code, read files, and find symbol references/definitions to answer your question.
55
+
56
+
This is a blocking operation that may take 60+ seconds to research the codebase, so only invoke it if the user has explicitly asked you to by specifying the ask_codebase tool call in the prompt.
57
+
58
+
The agent will:
59
+
- Analyze your question and determine what context it needs
60
+
- Search the codebase using multiple strategies (code search, symbol lookup, file reading)
61
+
- Synthesize findings into a comprehensive answer with code references
62
+
63
+
Returns a detailed answer in markdown format with code references, plus a link to view the full research session (including all tool calls and reasoning) in the Sourcebot web UI.
64
+
65
+
When using this in shared environments (e.g., Slack), you can set the visibility parameter to 'PUBLIC' to ensure everyone can access the chat link.
66
+
`,
67
+
};
68
+
33
69
exportfunctioncreateMcpServer(): McpServer{
34
70
constserver=newMcpServer({
35
71
name: 'sourcebot-mcp-server',
@@ -39,8 +75,7 @@ export function createMcpServer(): McpServer {
39
75
server.registerTool(
40
76
"search_code",
41
77
{
42
-
description: dedent`
43
-
Searches for code that matches the provided search query as a substring by default, or as a regular expression if useRegex is true. Useful for exploring remote repositories by searching for exact symbols, functions, variables, or specific code patterns. To determine if a repository is indexed, use the \`list_repos\` tool. By default, searches are global and will search the default branch of all repositories. Searches can be scoped to specific repositories, languages, and branches. When referencing code outputted by this tool, always include the file's external URL as a link. This makes it easier for the user to view the file, even if they don't have it locally checked out.`,
78
+
description: TOOL_DESCRIPTIONS.search_code,
44
79
inputSchema: {
45
80
query: z
46
81
.string()
@@ -194,7 +229,7 @@ export function createMcpServer(): McpServer {
194
229
server.registerTool(
195
230
"list_commits",
196
231
{
197
-
description: dedent`Get a list of commits for a given repository.`,
232
+
description: TOOL_DESCRIPTIONS.list_commits,
198
233
inputSchema: z.object({
199
234
repo: z.string().describe("The name of the repository to list commits for."),
200
235
query: z.string().describe("Search query to filter commits by message content (case-insensitive).").optional(),
@@ -232,7 +267,7 @@ export function createMcpServer(): McpServer {
232
267
server.registerTool(
233
268
"list_repos",
234
269
{
235
-
description: dedent`Lists repositories in the organization with optional filtering and pagination.`,
270
+
description: TOOL_DESCRIPTIONS.list_repos,
236
271
inputSchema: z.object({
237
272
query: z.string().describe("Filter repositories by name (case-insensitive)").optional(),
238
273
page: z.number().int().positive().describe("Page number for pagination (min 1). Default: 1").optional().default(1),
@@ -272,7 +307,7 @@ export function createMcpServer(): McpServer {
272
307
server.registerTool(
273
308
"read_file",
274
309
{
275
-
description: dedent`Reads the source code for a given file.`,
path: z.string().describe("The path to the file."),
@@ -305,10 +340,7 @@ export function createMcpServer(): McpServer {
305
340
server.registerTool(
306
341
"list_tree",
307
342
{
308
-
description: dedent`
309
-
Lists files and directories from a repository path. This can be used as a repo tree tool or directory listing tool.
310
-
Returns a flat list of entries with path metadata and depth relative to the requested path.
311
-
`,
343
+
description: TOOL_DESCRIPTIONS.list_tree,
312
344
inputSchema: {
313
345
repo: z.string().describe("The name of the repository to list files from."),
314
346
path: z.string().describe("Directory path (relative to repo root). If omitted, the repo root is used.").optional().default(''),
@@ -447,7 +479,7 @@ export function createMcpServer(): McpServer {
447
479
server.registerTool(
448
480
"list_language_models",
449
481
{
450
-
description: dedent`Lists the available language models configured on the Sourcebot instance. Use this to discover which models can be specified when calling ask_codebase.`,
@@ -458,20 +490,7 @@ export function createMcpServer(): McpServer {
458
490
server.registerTool(
459
491
"ask_codebase",
460
492
{
461
-
description: dedent`
462
-
Ask a natural language question about the codebase. This tool uses an AI agent to autonomously search code, read files, and find symbol references/definitions to answer your question.
463
-
464
-
The agent will:
465
-
- Analyze your question and determine what context it needs
466
-
- Search the codebase using multiple strategies (code search, symbol lookup, file reading)
467
-
- Synthesize findings into a comprehensive answer with code references
468
-
469
-
Returns a detailed answer in markdown format with code references, plus a link to view the full research session (including all tool calls and reasoning) in the Sourcebot web UI.
470
-
471
-
When using this in shared environments (e.g., Slack), you can set the visibility parameter to 'PUBLIC' to ensure everyone can access the chat link.
472
-
473
-
This is a blocking operation that may take 30-60+ seconds for complex questions as the agent researches the codebase.
474
-
`,
493
+
description: TOOL_DESCRIPTIONS.ask_codebase,
475
494
inputSchema: z.object({
476
495
query: z.string().describe("The query to ask about the codebase."),
477
496
repos: z.array(z.string()).optional().describe("The repositories accessible to the agent. If not provided, all repositories are accessible."),
0 commit comments