Skip to content

Commit aaf0b1e

Browse files
authored
fix(mcp): modify ask_codebase prompt to require explicit call out (#995)
* modify ask_codebase prompt to require explicit call out * changelog
1 parent f0cef5e commit aaf0b1e

File tree

2 files changed

+44
-24
lines changed

2 files changed

+44
-24
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
## [Unreleased]
99

1010
### Changed
11+
- Require explicit invokation of ask_codebase tool in MCP [#995](https://github.com/sourcebot-dev/sourcebot/pull/995)
1112
- Gate MCP API behind authentication when Ask GitHub is enabled. [#994](https://github.com/sourcebot-dev/sourcebot/pull/994)
1213

1314
## [4.15.4] - 2026-03-11

packages/web/src/features/mcp/server.ts

Lines changed: 43 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,42 @@ const MAX_TREE_DEPTH = 10;
3030
const DEFAULT_MAX_TREE_ENTRIES = 1000;
3131
const MAX_MAX_TREE_ENTRIES = 10000;
3232

33+
const TOOL_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+
3369
export function createMcpServer(): McpServer {
3470
const server = new McpServer({
3571
name: 'sourcebot-mcp-server',
@@ -39,8 +75,7 @@ export function createMcpServer(): McpServer {
3975
server.registerTool(
4076
"search_code",
4177
{
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,
4479
inputSchema: {
4580
query: z
4681
.string()
@@ -194,7 +229,7 @@ export function createMcpServer(): McpServer {
194229
server.registerTool(
195230
"list_commits",
196231
{
197-
description: dedent`Get a list of commits for a given repository.`,
232+
description: TOOL_DESCRIPTIONS.list_commits,
198233
inputSchema: z.object({
199234
repo: z.string().describe("The name of the repository to list commits for."),
200235
query: z.string().describe("Search query to filter commits by message content (case-insensitive).").optional(),
@@ -232,7 +267,7 @@ export function createMcpServer(): McpServer {
232267
server.registerTool(
233268
"list_repos",
234269
{
235-
description: dedent`Lists repositories in the organization with optional filtering and pagination.`,
270+
description: TOOL_DESCRIPTIONS.list_repos,
236271
inputSchema: z.object({
237272
query: z.string().describe("Filter repositories by name (case-insensitive)").optional(),
238273
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 {
272307
server.registerTool(
273308
"read_file",
274309
{
275-
description: dedent`Reads the source code for a given file.`,
310+
description: TOOL_DESCRIPTIONS.read_file,
276311
inputSchema: {
277312
repo: z.string().describe("The repository name."),
278313
path: z.string().describe("The path to the file."),
@@ -305,10 +340,7 @@ export function createMcpServer(): McpServer {
305340
server.registerTool(
306341
"list_tree",
307342
{
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,
312344
inputSchema: {
313345
repo: z.string().describe("The name of the repository to list files from."),
314346
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 {
447479
server.registerTool(
448480
"list_language_models",
449481
{
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.`,
482+
description: TOOL_DESCRIPTIONS.list_language_models,
451483
},
452484
async () => {
453485
const models = await getConfiguredLanguageModelsInfo();
@@ -458,20 +490,7 @@ export function createMcpServer(): McpServer {
458490
server.registerTool(
459491
"ask_codebase",
460492
{
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,
475494
inputSchema: z.object({
476495
query: z.string().describe("The query to ask about the codebase."),
477496
repos: z.array(z.string()).optional().describe("The repositories accessible to the agent. If not provided, all repositories are accessible."),

0 commit comments

Comments
 (0)